Skip to content

DistributedShenanigans/bittorrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💾 Peer-to-Peer File Sharing with BitTorrent

Implement a simplified BitTorrent-style file sharing protocol. Each peer stores and exchanges file chunks.

Validation Checklist:

  • Upload a file and download it completely using chunk exchange
  • Log peer join/leave and chunk ownership updates
  • Visualize download progress per peer

BitTorrent Architecture

BitTorrent Architecture

Running the System

1. Start the Tracker

python -m tracker.server

This starts the tracker on port 8080.

Check it's running with:

curl http://localhost:8080/health
# → {"status": "ok"}

2. Start the Seeder(s)

python -m seed.seed \
  -t path/to/your-file.torrent \
  -p 6881

This will:

  • Parse the .torrent
  • Announce to the tracker
  • Serve pieces to requesting peers

3. Run the Client

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)

Project Structure

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)

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages