A minimal (standard & UNIX libraries only!) Bittorrent client implementation in C. Download .torrent files with one terminal command.
This program is being developed as a side-project of mine to explore networking & memory management in C. It is by no means production ready and only meant as an educational tool.
It includes:
- The world's worst Bencode parser.
- A low level networking api that can send & receive data from TCP sockets.
- A partial HTTP 1.0 implementation.
- A multi-threaded torrent part downloader & validator.
- A CLI argument parser.
I have tried to keep the source code as clean and minimal as possible so it should be quite readable for anyone who wants to take a look at the code. I am also planning on making a blog post write-up once the project is finished.
Development status
- Bencode parser
- Parsing of bencode strings, ints
- Parsing of bencode dicts, lists, simple bencode files
- Parsing of .torrent files
- TCP client
- Implement connect, close, send receive functions
- Able to ping-pong a echo server
- HTTP client
- DNS lookup to get server IPs from hostnames
- HTTP GET Able to get HTTP 200 HTML data from example.com Query parameters unsupported for now
- HTTP POST
- Core torrent stuff
- Parse a torrent file and extract the info hashes
- Connect to a tracker, retrieve list of peers
- Downloading from peers
- Complete Bittorrent handshake
- Parse downloadable data from peer using bitfields
- Pipelining
- Assemble file and validate using the hash
- Cleanup
- CLI interface with help command
- Unit tests & better error handling
- Improve readme
- I am following this great article by Jesse Li who did something similar in Go.
- Initial inspiration for this project came from a Rust video by Jon Gjengset: implementing a bittorrent client using the (paid) Build your own BitTorrent course at codecrafters.io
- SHA1 implementation copied from Steve Reid
A CLI interface is planned but not available yet.
Only buildable on linux systems due to reliance on standard C UNIX networking api's.
No build system required, Build manually using the build.sh
bash script.
Please don't submit issues / merge requests while still in development.