This document describes the network protocol used by the Pyile application over TCP/IP on port 4702. The protocol is used for communication and authentication between peers.
The Pyile protocol is used for peer-to-peer communication and authentication. This protocol allows for a single central authenticator that establishes the network and is the source of all authentication within the given network. With this in mind, the authenticating peer has a unique role. It is still considered a peer which means that they still have full communication functionalities. The Pyile protocol supports another type of peer which is a non-authenticating peer or just peer. This type of peer only can be authenticated and send messages.
- Port 4702: Used as the main connection between peer and authenticating peer.
- Distribution Socket: This randomly generated socket is responsible for the sets that the authenticating peer sends when a peer has joined or left.
- Peer Port: Randomly generated port that is within the private use range. Used for communication between all peers.
- Temporary Port: Used to send messages and broadcast but is then closed immediately after.
- Authenticating peer is established listening on port 4702 for potential peers
- Authenticating peer, then generates a random port and begins to listen to already established peers. (Should only be themselves)
- A Joining peer then requests to be authenticated by the initial peer.
- The initial peer then checks if the peer is already banned and then checks the password.
- If the password is correct, then the peer is added and then given the list of peers that can be communicated with.
- A heartbeat is then established between both peers.
- The joining peer can now communicate in the network through broadcasting or individual messaging.
- When a peer is authenticated, A heartbeat is established between the authenticating peer and peer.
- The peer is in a constant state of listening, waiting to send a response to the authenticating peer.
- If a timeout is reached on either sides, the peer will be removed from the list of established peers and must reauthenticate.
- Any time an exit is called by a peer, the instance variable disconnected will be set to True. All sockets will be closed and any loose threads will be joined.
- When the authenticating peer has changes made to the list of peers, it will then redistribute the list to all the peers in the network. This flow acts as a central authority of who is an actual peer of the network.
- Banned status - First message sent to peer from authenticating peer. if banned, connection with joining peer is dropped
- Authenticated - Second message sent from authenticating peer. If authenticated, a heartbeat is established
- Heartbeat - Sent throughout the life of the connection that ensures both peers are still alive.
- Set Distributions - When the Authenticating peer has made changes to the peer list, it redistributes to all the peers in the network.
- Communication - Simple messaging between peers
The messenger within Pyile acts as an interface that allows for other programs to robustly use the protocol. Therefore, there can be multiple frontend implementations. This messenger contains error handling along with all of the messages sent to and from the peer.
The protocol implements an authentication process equipped with a password check and banned status. At this time, there is no encryption.
pip install pyile_protocol
import threading
from pyile_protocol.lib.peers.AuthPeer import AuthPeer
auth_peer = AuthPeer(address=("192.168.1.66", 4702), password_attempts=1, password="password")
auth_thread = threading.Thread(target=auth_peer.authenticate_peers)
peer_thread = threading.Thread(target=auth_peer.connect)
auth_thread.start()
peer_thread.start()
while not auth_peer.disconnected:
data = input("~: ")
if data == "exit":
auth_peer.leave()
elif data == "peers":
print(auth_peer.peers)
else:
auth_peer.broadcast(data)import threading
from pyile_protocol.lib.peers.JoinPeer import JoinPeer
peer = JoinPeer(address=("192.168.1.65", 4702))
peer.get_authenticated(("192.168.1.66", 4702), "password")
connect_thread = threading.Thread(target=peer.connect)
connect_thread.start()
while not peer.disconnected:
data = input("~: ")
if data == "exit":
peer.leave()
elif data == "peers":
print(peer.peers)
else:
peer.broadcast(data)