Package: pyile-protocol
Pyile Protocol Documentation:Introduction: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.Protocol OverviewThe Pyile protocol is used for peer-to-peer communication and authentication. This protocol allows for a single central 
authenticator that established 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 anon-authenticatingpeer or justpeer.
This type of peer only can be authenticated and send messages.Sockets:Port 4702: Used as the main connection between peer and authenticating peer.Dynamic and private port: Randomly generated port that is within the private use range. Used for communication between
    all peers.Temporary Socket: Used to send messages and broadcast but is then closed immediately after.Protocol FlowAuthenticating peer is established listening on port 4702 for potential peersAuthenticating 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.Special FlowsHeartbeatWhen 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.ExitAny time an exit is called by a peer, the instance variabledisconnectedwill be set to True. All sockets will be closed and any loose threads will be joined.Figure 1Message TypesBanned status - First message sent to peer from authenticating peer. if banned, connection with joining peer is droppedAuthenticated - Second message sent from authenticating peer. If authenticated, a heartbeat is establishedHeartbeat - 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 peersError HandlingThe protocol has custom exceptions to further the detail of errors:AuthenticationExceptionStatusExceptionSendExceptionRecvExceptionSecurityThe protocol implements an authentication process equipped with a password check and banned status. At this time, there is no encryption.Code ExampleInstallpip install pyile_protocolAuthenticating Peerimportthreadingfrompyile_protocol.lib.peers.AuthPeerimportAuthPeerauth_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()whilenotauth_peer.disconnected:data=input("~: ")ifdata=="exit":auth_peer.leave()elifdata=="peers":print(auth_peer.peers)else:auth_peer.broadcast(data)Peerimportthreadingfrompyile_protocol.lib.peers.JoinPeerimportJoinPeerpeer=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()whilenotpeer.disconnected:data=input("~: ")ifdata=="exit":peer.leave()elifdata=="peers":print(peer.peers)else:peer.broadcast(data)