Skip to main content

Protocol library for p2p messaging and authentication.

Project description

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 Overview

The 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 a non-authenticating peer or just peer. 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 Flow

  • 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.

Special Flows

Heartbeat

  • 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.

Exit

  • 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.
Figure 1

Message Types

  • 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

Error Handling

The protocol has custom exceptions to further the detail of errors:

  • AuthenticationException
  • StatusException
  • SendException
  • RecvException

Security

The protocol implements an authentication process equipped with a password check and banned status. At this time, there is no encryption.

Code Example

Install

pip install pyile_protocol

Authenticating Peer

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)

Peer

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyile_protocol-0.1.1.tar.gz (22.5 kB view details)

Uploaded Source

File details

Details for the file pyile_protocol-0.1.1.tar.gz.

File metadata

  • Download URL: pyile_protocol-0.1.1.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pyile_protocol-0.1.1.tar.gz
Algorithm Hash digest
SHA256 514f13d86c7a95758f8d6666cade87ad6e7827535cee6b2231c4d4c2c457f0ed
MD5 5e74ec33d3f357066737ce82dfabafa5
BLAKE2b-256 f12a565c04166e107653617f3af9e8f89a410e4e57220cb5dd56b2a03be566cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page