- Subject - Computer Networks
- Semester - Spring 2024
-
Config file:
IPandPortof seed nodes are hard-coded
-
Seed:
- Initializes functions to create and bind sockets
create_bind(), write logswrite(), and handle incoming connections from peersbegin(). - Implements a thread function
peer_conn()to handle peer connections, processing various types of messages received. - Upon receiving a connection request from a peer, it responds by sending its peer list.
- Monitors for "dead" messages from peers and removes them from the peer list accordingly.
- Listens for incoming connections from peers and spawns separate threads to handle each connection.
- Provides functionality to listen for and accept incoming connections
begin(), manage peer listspeer_conn(), and handle dead peerspeer_conn(). - Utilizes threading
threading.Threadto handle multiple peer connections concurrently. - Reads the port number for the seed node from user input and initializes necessary variables
PORT.
- Initializes functions to create and bind sockets
-
Reporting the node as Dead:
- When 3 consecutive liveness requests do not receive a reply, the peer sends a message of the following format to all the seeds it is connected to:
Dead Node:DeadNode.IP:self.timestamp:self.IP
- When 3 consecutive liveness requests do not receive a reply, the peer sends a message of the following format to all the seeds it is connected to:
-
Peer:
- MessagesLst (ML) being printed in peerlog.
- Connects to
least_integer(n/2)+1seed nodes. - Initializes a Peer class
Peerto manage peer addresses. - Defines functions to create and bind sockets
create_bind(), write logswrite(), and handle incoming connectionsbegin(). - Initiates a listening loop
begin()to accept incoming connections from peers. - Implements a handler
handlePeer()for each peer connection, processing various types of messages received. - Provides functionality to connect to other peers
peerConnect(), manage peer lists, and handle dead peerspeerDead(). - Implements gossiping among peers
handleGossip()by exchanging messages and ensuring message uniqueness. - Manages liveness testing
work()to monitor peer availability and take action upon failures. - Utilizes a worker function
work()to manage different tasks such as socket creation, liveness checking, and gossiping concurrently. - Utilizes threading
threading.Threadand a queueQueueto manage concurrent execution of tasks. - Reads seed addresses from a configuration file and connects to a subset of them
seedConnect().
-
Gossip message:
- Peer generates msg of the format:
self.timestamp:self.IP:self.Msg#
- Peer generates msg of the format:
-
Liveliness message:
- If 3 consecutive liveness messages are not replied to, the node will notify the seed nodes that it is connected to, that this particular IP Address is not responding
-
Request Message Format:
Liveness Request:self.timestamp:self.IP
-
Reply Message Format:
Liveness Reply:sender.timestamp:sender.IP:self.IP
-
Log file:
- SeedLog file store the connection requests from new peers as well as the output from dead node.
- Each peer has its own log file where it writes the list of peers it got from seed nodes. Gossip messages are also logged with timestamp.
- Clone this repository
- Edit config.txt to add localhost IP address and any port number. Sample has been provided
- Run
python seed.pyand enter the port number used in config file. Repeat the same for all ports - Run
python peer.pyand enter any port number. - If another instance of peer is started, gossips would start.
- All of this is logged in the output file.