rqbit - bittorrent client in Rust

Overview

rqbit - bittorrent client in Rust

rqbit is a bittorrent client written in Rust.

Motivation

First of all, I love Rust. The project was created purely for the fun of the process of writing code in Rust.

I was not satisfied with my regular bittorrent client, and was wondering how much work would it be to create a new one from scratch.

Got it to the point where it downloads torrents reliably and pretty fast, and I was using for a few months myself. It works good enough for me, and at the moment of writing this I'm not planning to extend it further.

So in short, it's not "feature complete", but rather "good enough for my use-cases".

Open sourced it just in case anyone might find it useful and/or wants to contribute.

Build

Just a regular Rust binary build process.

cargo build --release

Usage quick start

Assuming you are downloading to ~/Downloads

rqbit 'magnet:?....' ~/Downloads

or

rqbit /some/file.torrent ~/Downloads

Useful options

-v

Increase verbosity. Possible values: trace, debug, info, warn, error.

--list

Will print the contents of the torrent file or the magnet link.

--overwrite

If you want to resume downloading a file that already exists, you'll need to add this option.

--peer-connect-timeout=10s

This will increase the default peer connect timeout. The default one is 2 seconds, and it's sometimes not enough.

-r / --filename-re

Use a regex here to select files by their names.

Features and missing features

Some supported features

  • Sequential downloading (the default and only option)
  • Resume downloading file(s) if they already exist on disk
  • Selective downloading using a regular expression for filename
  • DHT support. Allows magnet links to work, and makes more peers available.
  • HTTP API

Code features

  • Serde-based bencode serializer/deserializer
  • Custom code for binary protocol serialization/deserialization. And for everything else too :)
  • Supports several SHA1 implementations, as this seems to be the biggest performance bottleneck. Default is openssl as it's the fastest in my benchmarks.
  • In theory, the libraries that rqbit is made of are re-usable.
  • No unsafe

Bugs, missing features and other caveats

Below points are all easily fixable, PRs welcome.

  • The CLI support only one mode of operation: download one torrent to a given folder.
  • If you try to run multiple instances, there's some port conflicts (already listening on port). This happens because DHT stores persistence information on disk, and that includes the port it last listened on. So all instances try to listen on the same port. Which means we need to add support for managing multiple torrents rather than trying to run the client multiple times. Or at least add a switch like --disable-dht-persistence.
  • HTTP API is rudimentary, mostly for looking at stats. E.g. you can't add a torrent through it.
  • Only supports BitTorrent V1 over TCP
  • As this was created for personal needs, and for educational purposes, documentation, commit message quality etc. leave a lot to be desired.
  • Doesn't survive switching networks, i.e. doesn't reconnect to a peer once the TCP connection is closed.

Code organization

  • crates/rqbit - main binary
  • crates/librqbit - main library
  • crates/librqbit-core - torrent utils
  • crates/bencode - bencode serializing/deserializing
  • crates/buffers - wrappers around binary buffers
  • crates/clone_to_owned - a trait to make something owned
  • crates/sha1w - wrappers around sha1 libraries
  • crates/peer_binary_protocol - the protocol to talk to peers
  • crates/dht - Distributed Hash Table implementation

HTTP API

By default it listens on http://127.0.0.1:3030.

curl -s 'http://127.0.0.1:3030/'

{
    "apis": {
        "GET /": "list all available APIs",
        "GET /dht/stats": "DHT stats",
        "GET /dht/table": "DHT routing table",
        "GET /torrents": "List torrents (default torrent is 0)",
        "GET /torrents/{index}": "Torrent details",
        "GET /torrents/{index}/haves": "The bitfield of have pieces",
        "GET /torrents/{index}/stats": "Torrent stats"
    }
}
Comments
  • Can't build without OpenSSL

    Can't build without OpenSSL

    It doesn't seem to be possible to build without OpenSSL. cargo build --no-default-features --features sha1-rust doesn't seem to get rid of the OpenSSL dependency.

    opened by SoniEx2 8
  • Update: add sub_folder in AddTorrentOptions

    Update: add sub_folder in AddTorrentOptions

    Add sub folder in options, it will download to target/sub/, Example:

    curl -d '/path/to/torrent' 'http://127.0.0.1:3030/torrents?output_folder=target&sub_folder=sub'
    
    opened by pcmid 1
  • Completely change the CLI so that we have a server and a client.

    Completely change the CLI so that we have a server and a client.

    This is a breaking change.

    Adds support for "rqbit server" command and "rqbit download" commands. Previous functionality is part of "rqbit download".

    "rqbit download" tries to connect to the server if it's already running, and if it's not starts one within the process.

    opened by ikatson 0
  • Support for downloading / managing multiple torrents at once.

    Support for downloading / managing multiple torrents at once.

    I have this branch to make it possible to download multiple torrents at once.

    @Lesiuk it probably conflicts a bit with your PR #2, mostly as things are moved around. As we haven't yet settled on the performance regressions from #2 I want to merge this in as there's some quality of life improvements here.

    To download multiple torrents at once, you can't do it yet with the CLI (that would probably require a breaking CLI change, or split into some client-server mode), but here's the trick for now

    1. start rqbit as usual to download one torrent

    2. In another terminal run this to start downloading another torrent using the same rqbit process

      curl -d 'magnet:?...' http://127.0.0.1:3030/torrents

    opened by ikatson 0
  • HTTP API is unresponsive in the beginning

    HTTP API is unresponsive in the beginning

    Right after starting the HTTP API it blocks on something for a few seconds, not sure on what exactly. Either doesn't connect or after sending the request it blocks.

    Reproduce with:

    • run rqbit
    • try to curl http://127.0.0.1:3030 right away
    opened by ikatson 0
  • Very rarely freezes when almost downloaded

    Very rarely freezes when almost downloaded

    Sometimes (very very rearely) when downloading a torrent there's 100% CPU usage and rqbit locks up when near completion (like 99.*% downloaded by that time).

    Saving here not to forget.

    opened by ikatson 0
Releases(v2.1.5)
Owner
Igor Katson
Igor Katson
BitTorrent peer ID registry/parser/(soon) encoder for Rust

BitTorrent peer ID registry/parser/(soon) encoder By convention, BitTorrent clients identify themselves and their versions in peer IDs they send to tr

TORRENTDYNE 3 Oct 16, 2023
A multi-functional lightweight BitTorrent Tracker

Torrust-Axum Tracker Project Description Torrust-Axum Tracker is a lightweight but incredibly powerful and feature-rich BitTorrent Tracker made using

Jasper 55 Apr 21, 2023
Acts as an IRC server and a nostr client. Connect with your IRC client using your nostr private key as the password.

nostr-irc Acts as an IRC server and a nostr client. Connect with your IRC client using your nostr private key as the password. Experimental code, use

null 11 Dec 26, 2022
FTP client for Rust

rust-ftp FTP client for Rust Documentation rust-ftp Installation Usage License Contribution Development environment Installation FTPS support is achie

Matt McCoy 155 Nov 12, 2022
NNTP client for Rust

rust-nntp NNTP Client for Rust Usage extern crate nntp; use nntp::{Article, NNTPStream}; fn main() { let mut nntp_stream = match NNTPStream::connec

Matt McCoy 13 Jan 22, 2022
POP3 client for Rust

rust-pop3 POP3 Client for Rust This client has SSL support. SSL is configured using an SSLContext that is passed into the connect method of a POP3Stre

Matt McCoy 26 Dec 19, 2022
A STOMP client in Rust. Compatible with RabbitMQ, ActiveMQ.

stomp-rs stomp-rs provides a full STOMP 1.2 client implementation for the Rust programming language. This allows programs written in Rust to interact

Zack Slayton 84 Dec 4, 2022
Rust client for NATS, the cloud native messaging system.

A Rust client for the NATS messaging system. Status Motivation Rust may be the most interesting new language the NATS ecosystem has seen. We believe t

NATS - The Cloud Native Messaging System 651 Jan 3, 2023
Simple project to test grpc between ruby (client) and rust (server)

grpc-example Simple project to test grpc between ruby (client) and rust (server). Usage To simplify a lot this project uses docker and docker compose

Bruno Arueira 2 Oct 14, 2021
A rust client and structures to interact with the Clever-Cloud API.

Clever-Cloud Software Development Kit - Rust edition This crate provides structures and client to interact with the Clever-Cloud API. Status This crat

Clever Cloud 6 Jun 3, 2022
Third party Google DNS client for rust.

google-dns-rs Documentation Install Add the following line to your Cargo.toml file: google-dns-rs = "0.3.0" Usage use google_dns_rs::api::{Dns, DoH, R

Eduardo Stuart 2 Nov 13, 2021
A ddns client written in Rust.

ddns-rs ready for use with one cloudflare A/AAAA record ?? A ddns client written in Rust. Features get public ip cloudflare (A or AAAA record) toml co

Ric Li 1 Oct 25, 2022
Rust client for apache iotdb.

Apache IoTDB Apache IoTDB (Database for Internet of Things) is an IoT native database with high performance for data management and analysis, deployab

Mark Liu 7 Aug 4, 2022
Rust client for Kubernetes

Rust client for Kubernetes API.

null 244 Dec 17, 2022
A Rust based DNS client, server, and resolver

Trust-DNS A Rust based DNS client, server, and Resolver, built to be safe and secure from the ground up. This repo consists of multiple crates: Librar

Benjamin Fry 2.7k Dec 30, 2022
An online version of the popular game four in a row, written in Rust on the server side and Flutter + Dart on the client.

Four in a Row - Server An online version of the popular game four in a row, written in Rust on the server side and Flutter + Dart on the client. Downl

Filippo OrrĂ¹ 8 Sep 16, 2022
A minimalist socket-based client/server in Rust to illustrate a tutorial

The basics of unix sockets This repository serves as a reference for this tutorial blogpost How to run Install Rust and Cargo, and then do: cargo run

Emmanuel Bosquet 4 Dec 4, 2022
Rust Verbio SpeechCenter Client

The CLI client allows you to launch a single file to the server. It also allows you to use either a grammar or a language model.

Verbio Technologies 3 Sep 16, 2022
Fast Discord RPC Client written in Rust

Discord RPC Client Examples Big image, small image, details and one button discordrpc -c 942151169185316874 -d 'untypeable nickname' --button-1-text '

Oskar 10 Jan 1, 2023