A simple BitTorrent client written in C++.
This project demonstrates how BitTorrent works internally by implementing the core parts of the protocol:
- Reading
.torrentfiles - Communicating with trackers
- Discovering peers
- Performing peer handshakes
- Downloading files piece-by-piece
This is not a production-ready torrent client. It is intended for learning, experimentation, and understanding distributed file sharing.
- Parse
.torrentfiles - Contact HTTP trackers
- Discover peers
- Perform BitTorrent handshakes
- Download single-file torrents
- Works on Linux, macOS, and Windows (via WSL)
You do not need to manually install compilers or libraries.
The provided setup scripts automatically install everything required:
- C++ compiler
- CMake
- libcurl
- OpenSSL
You do not need to modify these files to use the project.
BitTorrent/
├── src/ # C++ source code
├── include/ # Header files
├── build/ # Build output (created automatically)
├── sample.torrent # Example torrent file
├── setup.sh # Setup script for Linux/macOS
├── setup.ps1 # Setup script for Windows (WSL)
├── CMakeLists.txt
└── README.md
- Open a terminal
- Navigate into the project directory
- Run:
chmod +x setup.sh
./setup.shThis will:
- Install required dependencies
- Build the project
This project relies on Linux libraries. On Windows, it runs inside WSL (Windows Subsystem for Linux) automatically.
- Open PowerShell
- Navigate into the project directory
- Run:
.\setup.ps1If WSL is not installed, the script will clearly tell you how to install it.
The setup script will:
- Install required dependencies
- Build the project
After setup, the compiled executable is located at:
build/bt_main
./build/bt_main info sample.torrentDisplays:
- File name
- File size
- Piece length
- Number of pieces
- Tracker URL
./build/bt_main peers sample.torrentDisplays a list of peers (ip:port) currently sharing the file.
./build/bt_main handshake sample.torrent <ip:port>Example:
./build/bt_main handshake sample.torrent 165.232.35.114:51443This confirms successful communication with a peer.
./build/bt_main download -o out.bin sample.torrent- Downloads the full file described by the torrent
- Saves it as
out.bin - Pieces are downloaded sequentially
- This is a command-line application
- There is no graphical interface
- Download speed may be slower than popular torrent clients
- Only single-file torrents are supported
- This project is meant for learning and experimentation
This project is provided for educational purposes only. Use responsibly.