A minimal BitTorrent client implemented from scratch in Java.
This project demonstrates how peer-to-peer file sharing works internally by implementing the core BitTorrent protocol,
including tracker communication, peer connections, piece downloading, and file reconstruction.
This project was done with help of Codecrafters.io they provided the tracker behavior and peers to connect with.
- Parse and decode
.torrentfiles (bencode format) - Communicate with HTTP trackers to retrieve peer lists
- Establish TCP connections with peers
- Perform BitTorrent handshake
- Exchange protocol messages:
- choke / unchoke
- interested / not interested
- have
- bitfield
- request
- piece
- Download torrent data in pieces
- Verify piece integrity using SHA-1 hashes
- Reconstruct original files from downloaded pieces
- Support multi-file torrents
BitTorrent splits the entire torrent payload into fixed-size pieces.
The client:
- Parses the
.torrentfile - Contacts the tracker to get peers
- Connects to peers via TCP
- Requests pieces from peers
- Verifies each piece using SHA-1
- Writes verified data to disk
- Reconstructs the original file(s)
Peers exchange pieces independently of file boundaries.
Check this Notion notebook for more explanation: BitTorrent Client Notebook