rlibtorrent

A BitTorrent engine for Rust

One crate covers the protocol, peers, trackers, DHT and storage. Inside rbittorrent, it finished first in all 20 races against qBittorrent, Deluge and rTorrent.

examples/embed-daemon/src/main.rs
use rlibtorrent_daemon::{
    ControlListen, Listen, Mechanisms, WebListen, start,
};

let started = start(
    Listen::default(),
    &checkpoints,
    ControlListen::default(),
    WebListen::default(),
    None,
    Mechanisms::default(),
)
.await?;
println!("engine embedded in-process:");
println!("  peer-wire listener: {}", started.local_addr());
println!("  control surface:    {}", started.control_addr());

let report = started.stop().await?;
20/20races finished firstthe other 3 clients won none
2.3×faster than rTorrentfull download, SSD · no tracker delay
20/20races uploaded the most in the first 60 sthe other 3 clients won none
12×less memorythan qBittorrent, 50 GiB download

Race results

Measured inside rbittorrent. Each number is the middle of 5 runs.

Seeders

  • 2 × qBittorrent

One torrent

  • 1 GiB private torrent
  • Trackerdelay 0 or 5 s

4 clients, started together

  • rbittorrent
  • qBittorrent
  • Deluge
  • rTorrent

One race at real speedSSD · no tracker delay, run 1 of 5

1.3 s
  • rbittorrent1.34 s
  • rTorrent2.92 s
  • qBittorrent6.71 s
  • Deluge18.5 s

Finished first in all 20 races

Races won of 20

  • rbittorrent20
  • Deluge0
  • qBittorrent0
  • rTorrent0

SSD · no tracker delay

  • rbittorrent1.34 s
  • rTorrent3.14 s
  • qBittorrent8.17 s
  • Deluge18.5 s1 of 5 runs

SSD · 5 s tracker delay

  • rbittorrent8.22 s
  • rTorrent16.3 s
  • qBittorrentdid not finish in 60 s-
  • Delugedid not finish in 60 s-

HDD · no tracker delay

  • rbittorrent31.5 s
  • qBittorrent37.9 s
  • rTorrent40 s4 of 5 runs
  • Delugedid not finish in 60 s-

HDD · 5 s tracker delay

  • rbittorrent15.4 s
  • rTorrent26.8 s
  • qBittorrentdid not finish in 60 s-
  • Delugedid not finish in 60 s-

Time to download every piece and check it.

Uploaded the most in all 20 races

Races won of 20

  • rbittorrent20
  • Deluge0
  • qBittorrent0
  • rTorrent0

SSD · no tracker delay

  • rbittorrent73%
  • rTorrent21%
  • Deluge1%
  • qBittorrent0.5%

SSD · 5 s tracker delay

  • rbittorrent100%
  • qBittorrent0%
  • Deluge0%
  • rTorrent0%

HDD · no tracker delay

  • rbittorrent67%
  • qBittorrent21%
  • rTorrent10%
  • Deluge3.2%

HDD · 5 s tracker delay

  • rbittorrent100%
  • qBittorrent0%
  • Deluge0%
  • rTorrent0%

Share of all the data the clients uploaded to each other in the first 60 s.

Registration

SSD · no tracker delay

  • rbittorrent2.2 ms
  • rTorrent2.7 ms
  • Deluge0.26 s4 of 5 runs
  • qBittorrent1.2 s

SSD · 5 s tracker delay

  • rbittorrent7.01 s
  • rTorrent14.4 s
  • qBittorrentnot let in within 60 s-
  • Delugenot let in within 60 s-

HDD · 5 s tracker delay

  • rbittorrent7.02 s
  • rTorrent14.6 s
  • qBittorrentnot let in within 60 s-
  • Delugenot let in within 60 s-

Time from fetching the torrent until the tracker let the client in.

How we tested

Adding a torrent, step by step

Adding a torrent took 4.87 ms, start to finish. The engine's own steps, in colour, took 2.38 ms. Median of 5 runs on the SSD.

waits for the add queue: 0.74 ms checks the request and the disk room: 0.3 ms the engine adds the torrent: 2.31 ms the product writes its records: 0.39 ms hands the first announce to the engine: 0.06 ms publishes the new torrent to the UI: 1.06 ms 0 ms 1 ms 2 ms 3 ms 4 ms
  • waits for the add queue: 0.74 ms
  • checks the request and the disk room: 0.3 ms
  • the engine adds the torrent: 2.31 ms
  • the product writes its records: 0.39 ms
  • hands the first announce to the engine: 0.06 ms
  • publishes the new torrent to the UI: 1.06 ms

Crates

30 crates in all. The rlibtorrent crate brings 19 of them.

What a caller touches7

rlibtorrentapiwebapidaemoncapiqbtrss

The engine4

sessiondriverpeer-sessionstorage

The protocol5

typesbencodemetainfomagnetpeer-wire

The network8

trackerdhtdiscoverytransportutpmseportmaphttp

Labs and tools5

laboracle-libtorrentoracle-rqbitoracle-transmissionxtask

Beyond BitTorrent1

rlibusenet
What each crate does

rlibtorrent

The front door. Re-exports the engine so a consumer depends on ONE name instead of nineteen; holds no behaviour of its own (ADR-0031).

rlibtorrent-types

Hashes, digests, Merkle arithmetic, and the parse budgets every other crate is held to.

rlibtorrent-bencode

The bencode parser and canonical encoder, with raw-span preservation so an info hash is taken over the bytes as received.

rlibtorrent-metainfo

.torrent files: v1, v2 (BEP 52), hybrid, path sanitisation, and torrent creation.

rlibtorrent-magnet

Magnet links, including hybrid btih plus btmh topics.

rlibtorrent-peer-wire

The peer protocol on the wire: handshake, framing, and the BEP 6/9/10/11 extensions.

rlibtorrent-peer-session

What a connection is allowed to do: the state machine, availability, and the request pipeline.

rlibtorrent-storage

Torrent offsets to file ranges, the storage backend contract, and the resume checkpoint.

rlibtorrent-session

The policy engine: piece picking, choking, queueing, share limits, and categories.

rlibtorrent-tracker

HTTP and BEP 15 UDP announces, BEP 12 tiers, and the SSRF policy an announce is held to.

rlibtorrent-dht

BEP 5 with BEP 32 IPv6, routing table and lookups, socketless so a caller owns the UDP.

rlibtorrent-discovery

Where candidate peers come from, and the policy deciding which sources a torrent may use.

rlibtorrent-transport

TCP, SOCKS5, and the dial path every outbound connection shares.

rlibtorrent-utp

uTP and LEDBAT congestion control.

rlibtorrent-mse

Message Stream Encryption.

rlibtorrent-portmap

UPnP and NAT-PMP port mapping.

rlibtorrent-http

The HTTP client, its TLS trust decisions, and the SSRF policy shared with the tracker.

rlibtorrent-driver

The coordinator: the one place sockets, storage, discovery and the session meet.

rlibtorrent-api

The native control and event surface, its wire codec, and the delta stream.

rlibtorrent-webapi

The qBittorrent-compatible Web API contract, sans-io: no framework, no socket.

rlibtorrent-daemon

The executable, and the only crate that binds the Web API to a real HTTP transport.

rlibtorrent-capi

The C ABI, and the generated header a C or C++ caller links against.

rlibtorrent-qbt

Reading a real qBittorrent profile, read-only.

lab/rlibtorrent-lab

The deterministic lab: virtual clock, seeded RNG, bounded runner, scripted peers.

lab/oracle-libtorrent

Two pinned libtorrent builds (2.0.14 and 1.2.20) driven as subprocess oracles.

lab/oracle-rqbit, lab/oracle-transmission

Two further independent implementations to differ against.

rlibtorrent-rss

RSS and Atom feeds, and the auto-download rules that turn articles into torrents.

LunarWerxs/rlibusenet

Usenet, its own repository since ENG-12 (2026-09-18): NZB reading, article fetching, yEnc, PAR2, unpack and the job pipeline; this engine consumes it pinned by rev.

xtask

The evidence machine: the ledger, the milestone state machine, and verify.

Testing

15fuzz targets, covering every parser
4reference engines: libtorrent 2.0.14 and 1.2.20, rqbit and Transmission
1 labwith a virtual clock and scripted peers, so any failure replays exactly
20races on our test PC, inside rbittorrent

Examples

Each one runs with cargo run.

examples/embed-daemon

The daemon, embedded in your own binary.

examples/parse-and-build-torrent

Build a .torrent, parse it back, derive a magnet link.

examples/seed-and-download

Two engines in one process: one seeds, one downloads.

Commercial use

Building rlibtorrent into a product or service you sell needs a licence. See what it's worth and how the licence works.