This project aims to simulate the BitTorrent protocol, a peer-to-peer (P2P) file-sharing protocol, using MPI (Message Passing Interface). The BitTorrent protocol enables decentralized sharing and downloading of files over the "internet". By dividing files into smaller segments, BitTorrent allows users to simultaneously download and upload segments, optimizing file transfer speeds and reducing dependency on centralized servers.
This simulation replicates key components of the BitTorrent protocol:
-
File Segmentation:
- Files are divided into fixed-size segments.
- Each segment is protected by a cryptographic hash for integrity verification (for this simulation we will work just with hashes and as a response we will get an ACK but not the segment itself)
-
Peer-to-Peer Communication:
- Peers exchange file segments using MPI-based message passing.
- Roles (seed, peer) are dynamically assigned based on file availability.
-
Swarm Coordination:
- The system mimics the interaction between peers in a swarm to efficiently upload and download file segments.
-
Tracker Simulation:
- A central tracker coordinates the initial communication, managing lists of peers and seeds available for each file.
- After the tracker collected all the data (files and segment hashes for each file owned by each peer), starts a loop that manages requests from any peer, there are 4 types of requests
- Request (R)- when the peer need all the information about the file and swarm for the file
- Update (U)- when the peer needs to update the swarm
- Download (D)- The peer signals to the tracker about finishing downloading the file, tracker marks the client as seed.
- Finish (F) - The peer signals that it is done with the downloading part, tracker marks the peer as done.
To make the downloading a little more efficient the client will try to download from a different peer or seed every time. The main idea is that we update our swarm of seeds and peers every 10 downloaded segments.
- So the first 0 - 5 segments will be downloaded from the peers, cause the segments are lower in the order and the chance that the peers will have the is higher than the other 5 - 10. The other 5 will be downloaded from the seeds.
- The seeds and peers will be chosen randomly from the given swar
- If the response is NACK (this will happen just in the peers cases) then the second attempt will be to a seed.
Compile and execute the project using MPI commands (in the nr of processes u have to include the tracker and the peers):
- mpicc -o bit_sim tema2.c
- mpirun -np [number_of_processes] ./bit_sim