Skip to content

sehbeygi79/P2P-File-Sharing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P2P File Sharing System

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.

📌 Features

  • 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

Communication Protocol

1. Discovery Phase

A peer broadcasts a query (file name) to its neighbors. Duplicate queries are avoided using (sequence_number, host_id) tuples.

discovery_packet

2. Offer Phase

Peers respond with a list of matching files if they have them.

offer_packet

3. Ack Phase

The requester selects one of the offers and sends an acknowledgment.

ack_packet

4. Metadata Transfer

Metadata of the file (e.g., file size) is sent first.

metadata_packet

5. Data Transfer

Finally, the raw file chunks are transferred peer-to-peer. Intermediate peers forward packets if needed.

protocol

Execution

1. Configure Topology

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.

2. Prepare Repository Folders

Inside the project’s root directory, the repository/ folder must contain:

  • tx/ → files you want to share
  • rx/ → files you will receive

3. Run the Peer

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.

Demo

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:

demo2

Node 2:

demo3

Node 3:

demo4

About

A simple peer-to-peer (P2P) file sharing system for distributed P2P communication, inspired by Gnutella.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages