Skip to content

A simple torrent client written in rust that can be used to download torrent files

Notifications You must be signed in to change notification settings

arjav0703/bittorrent-rust

Repository files navigation

Bittorrent CLI Client (WIP)

A simple command-line interface (CLI) Bittorrent client written in Rust. This client allows you to download files using the Bittorrent protocol directly from the terminal.

Supported commands:

  • info <.torrent file>le>: Displays information about the torrent file.
  • download_piece -o <.torrent file> lt;piece index>: Downloads a specific piece of the torrent and saves it to the output file.
  • decode ue>: Decodes a Bencode-encoded value and displays the result.
  • peers <.torrent file>le>: Lists the peers associated with the torrent file.
  • handshake <.torrent file> eer_port>: Performs a handshake with peers for the given torrent file.
  • download -o <.torrent file>ent file>: Downloads the entire torrent and saves it to the output file.
  • magnet_parse nk>: Parses a magnet link and displays its components.
  • magnet_handshake nk> : Performs a handshake with peer from the given magnet link and prints the peer ID.

Installation

  1. Make sure you have Rust installed. You can install Rust using rustup.
  2. Clone this repository:
    git clone https://github.com/arjav0703/bittorrent-rust.git
      cd bittorrent-rust
  3. Build the project:
    cargo build --release
  4. The compiled binary will be located in the target/release directory.
    target/release/bittorrent-client
    
    

Example Commands

Install the program with the above steps and run the following example commands:

  1. Decode a bencoded value:
    # A Dictionary
    ./target/release/bittorrent-client decode  "d3:cati1e4:spam3:fooe"
  2. Display torrent info:
    ./target/release/bittorrent-client info ./sample.torrent
  3. List peers:
    ./target/release/bittorrent-client peers ./sample.torrent
  4. Download a specific piece:
    ./target/release/bittorrent-client download_piece -o piece_0.bin ./sample.torrent 0
  5. Perform a handshake with a peer:
    ./target/release/bittorrent-client handshake ./sample.torrent
  6. Download the entire torrent:
    ./target/release/bittorrent-client download -o output_file.bin ./sample.torrent
  7. Parse a magnet link:
    ./target/release/bittorrent-client magnet_parse "magnet:?xt=urn:btih:ad42ce8109f54c99613ce38f9b4d87e70f24a165&dn=magnet1.gif&tr=http%3A%2F%2Fbittorrent-test-tracker.codecrafters.io%2Fannounceannounce"
  8. Perform a handshake using a magnet link:
    ./target/release/bittorrent-client magnet_handshake "magnet:?xt=urn:btih:ad42ce8109f54c99613ce38f9b4d87e70f24a165&dn=magnet1.gif&tr=http%3A%2F%2Fbittorrent-test-tracker.codecrafters.io%2Fannounceannounce"