Implement a simplified BitTorrent-style file sharing protocol. Each peer stores and exchanges file chunks.
- Upload a file and download it completely using chunk exchange
- Log peer join/leave and chunk ownership updates
- Visualize download progress per peer
python -m tracker.serverThis starts the tracker on port 8080.
Check it's running with:
curl http://localhost:8080/health
# → {"status": "ok"}python -m seed.seed \
-t path/to/your-file.torrent \
-p 6881This will:
- Parse the .torrent
- Announce to the tracker
- Serve pieces to requesting peers
To download the file using the BitTorrent client:
python -m client.main \
-t path/to/your-file.torrent \
-o path/to/output-file \
-p 6889-t– path to the .torrent file-o– where to save the downloaded file (optional)-p– port to announce to tracker (should differ from seeder)
bittorrent/
├── handshake/
│ └── handshake.py # Peer-to-peer handshake logic
├── leech/
│ └── leech.py # Leech (downloading peer) implementation
├── msg/
│ └── message.py # BitTorrent message definitions and handling
├── p2p/
│ └── p2p.py # Core integration of P2P logic
├── seed/
│ └── seed.py # Seeder (uploading peer) implementation
├── torrentfile/
│ └── torrentfile.py # .torrent parsing and file download helpers
├── tracker/
│ ├── server.py # FastAPI tracker server (announce endpoint)
│ └── models.py # Data models for requests and peer info
├── utils/
│ ├── bitfield.py # Efficient bitfield structure for piece availability
│ └── encoding.py # Peer host/port serialization (compact format)
└── main.py # Project entry point (CLI or orchestrator)