Skip to content

πŸš€ A BitTorrent client that implements core functionalities of the BitTorrent protocol, including file parsing, tracker communication, and peer-to-peer file downloading.πŸŒπŸ“

License

Notifications You must be signed in to change notification settings

Abdulrahman295/BitTorrent-Client

Repository files navigation

BitTorrent Client

Bittorrent Logo

πŸš€ A BitTorrent client that implements core functionalities of the BitTorrent protocol, including file parsing, tracker communication, and peer-to-peer file downloading.πŸŒπŸ“

C++ BitTorrent License

πŸ“‘ Table of Contents

✨ Features

  • 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.

βš™οΈ Architecture

Architecture Diagram

β˜‘οΈ Prerequisites

To build and run this project, you need:

  • C++23 compatible compiler
  • CMake (version 3.13 or higher)

πŸ—ΊοΈ Installation

  1. Clone this repo:
git clone https://github.com/Abdulrahman295/BitTorrent-Client.git
  1. Build the project:
cmake . -B build
cmake --build build

πŸ’‘ Usage

Decode Command

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"}

Info Command

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

Peers Command

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

Handshake Command

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 Piece Command

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 Command

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.

πŸ“° License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

πŸš€ A BitTorrent client that implements core functionalities of the BitTorrent protocol, including file parsing, tracker communication, and peer-to-peer file downloading.πŸŒπŸ“

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages