A simple peer-to-peer (P2P) file sharing system for distributed P2P communication, inspired by Gnutella. Whenever a node wants to download a file, it broadcasts its request across the network. Other nodes that have the requested file (or a similar one) respond with their offers. Finally, the user selects one of these offers, and the file transfer takes place.
- Decentralized peer-to-peer file sharing
- Configurable network topology via a .conf file
- Message types for:
- Discovery – find files across the network
- Offer – return matching files from peers
- Ack – confirm file selection
- Metadata – provide file details before transfer
- Data – transfer raw file chunks
- Supports intermediate routing between peers (not just direct connections)
- Resilient against flooding with sequence numbers and aging mechanism
- CLI interface for easy interaction
A peer broadcasts a query (file name) to its neighbors. Duplicate queries are avoided using (sequence_number, host_id) tuples.
Peers respond with a list of matching files if they have them.
The requester selects one of the offers and sends an acknowledgment.
Metadata of the file (e.g., file size) is sent first.
Finally, the raw file chunks are transferred peer-to-peer. Intermediate peers forward packets if needed.
Make sure all your nodes are connected to each other in a single network.
Edit topology.conf to define your peer and its neighbors:
[Self]
HOST_ID = 1
[Neighbours]
HOST_IPS = 192.168.1.197, 192.168.1.156, 192.168.1.155
Each peer needs a unique HOST_ID and a list of neighbor IPs.
Inside the project’s root directory, the repository/ folder must contain:
tx/→ files you want to sharerx/→ files you will receive
Start a peer with:
python3 peer.py
- The peer will load the network configuration.
- You can issue queries for files.
- The system will list available offers from other peers.
- Select an offer, and the file will be transferred.
We present a file transfer scenario involving three nodes arranged in a linear topology: [Node1] → [Node2] → [Node3]. In this setup, Node 1 requests a PDF file that is available on Node 3. Since they are not directly connected, Node 2 serves as an intermediary, forwarding the file from Node 3 to Node 1.
To demonstrate the system’s robustness, the Wi-Fi connection of the intermediate node is intentionally disconnected during the transfer, triggering the error-handling mechanisms.
Node 1:
Node 2:
Node 3:







