This project is a lightweight BitTorrent client implemented in Go.
It can download files from peers using a .torrent file — demonstrating how the BitTorrent protocol works under the hood: parsing torrent metadata, connecting to peers, and downloading verified pieces.
The goal is educational clarity and simplicity rather than a full-featured production client.
- Parses
.torrentfiles - Connects to peers discovered via tracker
- Downloads file pieces concurrently
- Verifies each piece using SHA-1 hashes
- Assembles the complete file from verified pieces
- Simple, minimal entry point with no CLI flags
- Go 1.23+
- Internet connection
- A valid
.torrentfile
git clone https://github.com/onahvictor/torrent-client.git
cd torrent-clientgo build -o torrent-client ./cmdThe client takes two arguments:
- Path to the
.torrentfile - Output directory for the downloaded file
Example:
./torrent-client ./testdata/example.torrent ./downloads-
Open the torrent file
- Reads and parses the
.torrentmetadata (announce URL, info hash, piece hashes, etc.).
- Reads and parses the
-
Announce to tracker
- Contacts the tracker to get a list of available peers.
-
Handshake with peers
- Performs the BitTorrent handshake to confirm they share the same torrent.
-
Download pieces
- Requests and downloads file pieces concurrently from multiple peers.
-
Verify and assemble
- Verifies each piece using SHA-1 hash and assembles the final file once all pieces are complete.
Opening torrent file: example.torrent
Connecting to tracker...
Found 8 peers
Downloading piece 4/256
Piece 4 verified ✅
Download complete: ./downloads/example.iso
| Concept | Description |
|---|---|
| Torrent file | A metadata file describing the files and trackers for the torrent |
| Tracker | A server that helps peers discover each other |
| Peer | Another client sharing the same torrent |
| Piece | A fixed-size chunk of the full file |
| Info hash | Unique identifier for the torrent content |
- Add support for flags (e.g.,
-torrent,-out) - Add DHT and magnet link support
- Implement upload (seeding)
- Handle multi-file torrents
- Improve download progress display