π A BitTorrent client that implements core functionalities of the BitTorrent protocol, including file parsing, tracker communication, and peer-to-peer file downloading.ππ
-
Parse .torrent Files: Reads and interprets .torrent files, extracting metadata such as tracker URLs, file sizes, piece lengths, and hash values for data integrity.
-
Tracker Communication: Communicates with trackers to announce the client's presence and obtain a list of peers available for downloading the file.
-
BitTorrent Protocol: Implements the BitTorrent protocol, allowing the client to connect to peers, perform handshakes, and exchange pieces of the file.
-
Multi-threaded Downloading: Supports downloading pieces from multiple peers simultaneously, optimizing the download speed and efficiency.
-
Piece Selection: Allows downloading of specific pieces of a file.
-
Piece Verification: Ensures data integrity by verifying downloaded pieces against the hash values provided in the .torrent file.
To build and run this project, you need:
- C++23 compatible compiler
- CMake (version 3.13 or higher)
- Clone this repo:
git clone https://github.com/Abdulrahman295/BitTorrent-Client.git
- Build the project:
cmake . -B build
cmake --build build
Decode bencoded values, supporting four data types: strings, integers, arrays, and dictionaries.
./bittorrent decode <bencoded values>
Example:
./bittorrent decode '5:hello'
# Output: "hello"
./bittorrent decode 'i3e'
# Output: 3
./bittorrent decode 'l4:spam4:eggse'
# Output: ["spam", "eggs"]
./bittorrent decode 'd3:cow3:moo4:spam4:eggse'
# Output: {"cow": "moo", "spam": "eggs"}
Parse a torrent file and calculate info and piece hashes.
./bittorrent info <torrent file>
Example:
./bittorrent info sample.torrent
# Output:
# Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
# Length: 92063
# Info Hash: d69f91e6b2ae4c542468d1073a71d4ea13879a7f
# Piece Length: 32768
# Piece Hashes:
# e876f67a2a8886e8f36b136726c30fa29703022d
# 6e2275e604a0766656736e81ff10b55204ad8d35
Discover peers' IP addresses from a torrent file.
./bittorrent peers <torrent file>
Example:
./bittorrent peers sample.torrent
# Output:
# 178.62.82.89:51470
# 165.232.33.77:51467
# 178.62.85.20:51489
Establish a TCP connection with a peer.
./bittorrent handshake <torrent file> <peer_ip>:<peer_port>
Example:
./bittorrent handshake sample.torrent 178.62.82.89:51470
# Output: Peer ID: 0102030405060708090a0b0c0d0e0f1011121314
Download specific pieces of the torrent file.
download_piece -o <output file> <torrent file> <piece_index>
Example:
./bittorrent download_piece -o /tmp/test-piece-0 sample.torrent 0
# Output: Piece 0 downloaded to /tmp/test-piece-0.
Download the entire file and save it to disk.
download -o <output file> <torrent file>
Example:
./bittorrent download -o /tmp/test.txt sample.torrent
# Output: Downloaded sample.torrent to /tmp/test.txt.
This project is licensed under the MIT License. See the LICENSE
file for more details.