PROJECT NOTES · RUST
How BitTorrent works
A look at the ideas behind peer-to-peer file sharing and my RustBitTorrent client.
View RustBitTorrent on GitHubSharing in pieces
BitTorrent moves a file as many small pieces instead of asking one server to send the whole thing. A torrent’s metadata describes the content and its pieces. As a client downloads pieces, it can also share verified pieces with other clients.
That group of participating clients is called a swarm. Each client can download from several peers and contribute pieces to others, so the work is distributed across the swarm.
From metadata to peers
- Read the torrent metadata. The client learns what is being shared and how the data is divided into pieces.
- Discover peers. A tracker can introduce the client to other participants in the swarm.
- Exchange pieces. The client requests pieces from connected peers while advertising the pieces it already has.
- Verify the data. Piece hashes let the client check received data against the metadata before keeping or sharing it.
- Assemble the download. Once all required pieces are available and verified, they can be written back in order.
Building RustBitTorrent
RustBitTorrent is my BitTorrent client implementation in Rust. Building a client brings together several useful systems concepts: parsing structured metadata, making network requests, coordinating asynchronous work, and checking data integrity.
The benchmark output below shows a run with peers connected, verified data accumulating, and transfer speed being reported. It makes the client’s progress visible while a download is underway.
Explore the code
For the implementation details and current state of the project, visit the repository.
Open the GitHub repository