High-performance open BitTorrent tracker (UDP, HTTP, WebTorrent)
Find a file
Joakim Frostegård 38c7c51689 Run cargo update
Updating aho-corasick v0.7.18 -> v0.7.19
    Updating anyhow v1.0.58 -> v1.0.65
    Updating arc-swap v1.5.0 -> v1.5.1
    Updating async-trait v0.1.56 -> v0.1.57
    Updating axum v0.5.13 -> v0.5.16
    Updating axum-core v0.2.7 -> v0.2.8
    Updating base64ct v1.5.1 -> v1.5.2
    Updating block-buffer v0.10.2 -> v0.10.3
    Updating bumpalo v3.10.0 -> v3.11.0
    Updating bytes v1.2.0 -> v1.2.1
    Updating concurrent-queue v1.2.3 -> v1.2.4
    Updating console v0.15.0 -> v0.15.1
    Updating constant_time_eq v0.2.3 -> v0.2.4
    Updating cpufeatures v0.2.2 -> v0.2.5
    Updating crossbeam v0.8.1 -> v0.8.2
    Updating crossbeam-channel v0.5.5 -> v0.5.6
    Updating crossbeam-deque v0.8.1 -> v0.8.2
    Updating crossbeam-epoch v0.9.9 -> v0.9.10
    Updating crossbeam-queue v0.3.5 -> v0.3.6
    Updating crossbeam-utils v0.8.10 -> v0.8.11
    Updating digest v0.10.3 -> v0.10.5
      Adding dirs v4.0.0
      Adding dirs-sys v0.3.7
      Adding dotenvy v0.15.3
    Updating either v1.7.0 -> v1.8.0
    Updating event-listener v2.5.2 -> v2.5.3
    Updating fastrand v1.7.0 -> v1.8.0
    Updating flume v0.10.13 -> v0.10.14
    Updating form_urlencoded v1.0.1 -> v1.1.0
    Updating futures v0.3.21 -> v0.3.24
    Updating futures-channel v0.3.21 -> v0.3.24
    Updating futures-core v0.3.21 -> v0.3.24
    Updating futures-executor v0.3.21 -> v0.3.24
    Updating futures-io v0.3.21 -> v0.3.24
    Updating futures-macro v0.3.21 -> v0.3.24
    Updating futures-rustls v0.22.1 -> v0.22.2
    Updating futures-sink v0.3.21 -> v0.3.24
    Updating futures-task v0.3.21 -> v0.3.24
    Updating futures-util v0.3.21 -> v0.3.24
    Updating generic-array v0.14.5 -> v0.14.6
    Updating hashlink v0.8.0 -> v0.8.1
    Updating hdrhistogram v7.5.0 -> v7.5.1
    Updating headers v0.3.7 -> v0.3.8
    Updating httparse v1.7.1 -> v1.8.0
    Updating idna v0.2.3 -> v0.3.0
    Updating itertools v0.10.3 -> v0.10.4
    Updating itoa v1.0.2 -> v1.0.3
    Updating js-sys v0.3.58 -> v0.3.60
    Updating libc v0.2.126 -> v0.2.132
    Updating libm v0.2.2 -> v0.2.5
    Updating lock_api v0.4.7 -> v0.4.8
    Removing matches v0.1.9
    Updating miniz_oxide v0.5.3 -> v0.5.4
    Updating once_cell v1.13.0 -> v1.14.0
    Updating paste v1.0.7 -> v1.0.9
    Updating percent-encoding v2.1.0 -> v2.2.0
    Updating pin-project v1.0.11 -> v1.0.12
    Updating pin-project-internal v1.0.11 -> v1.0.12
    Updating plotters v0.3.2 -> v0.3.4
    Updating plotters-svg v0.3.2 -> v0.3.3
    Updating proc-macro2 v1.0.40 -> v1.0.43
    Updating quote v1.0.20 -> v1.0.21
    Updating rand_core v0.6.3 -> v0.6.4
    Updating redox_syscall v0.2.13 -> v0.2.16
      Adding redox_users v0.4.3
    Updating rustls-pemfile v1.0.0 -> v1.0.1
    Updating ryu v1.0.10 -> v1.0.11
    Updating serde v1.0.139 -> v1.0.144
    Updating serde_bytes v0.11.6 -> v0.11.7
    Updating serde_derive v1.0.139 -> v1.0.144
    Updating serde_json v1.0.82 -> v1.0.85
      Adding sha1 v0.10.5
    Updating sha2 v0.10.2 -> v0.10.6
    Updating simple_logger v2.2.0 -> v2.3.0
    Updating socket2 v0.4.4 -> v0.4.7
    Updating sqlformat v0.1.8 -> v0.2.0
    Updating sqlx v0.6.0 -> v0.6.2
    Updating sqlx-core v0.6.0 -> v0.6.2
    Updating sqlx-macros v0.6.0 -> v0.6.2
    Updating sqlx-rt v0.6.0 -> v0.6.2
    Updating syn v1.0.98 -> v1.0.99
    Updating thiserror v1.0.31 -> v1.0.35
    Updating thiserror-impl v1.0.31 -> v1.0.35
    Updating time v0.3.11 -> v0.3.14
    Updating tokio v1.20.0 -> v1.21.1
    Updating tracing v0.1.35 -> v0.1.36
    Updating tracing-core v0.1.28 -> v0.1.29
    Updating unicode-ident v1.0.2 -> v1.0.4
    Updating unicode-normalization v0.1.21 -> v0.1.22
    Updating unicode-segmentation v1.9.0 -> v1.10.0
    Updating unicode-width v0.1.9 -> v0.1.10
    Updating unicode-xid v0.2.3 -> v0.2.4
    Updating url v2.2.2 -> v2.3.1
    Updating urlencoding v2.1.0 -> v2.1.2
    Updating wasm-bindgen v0.2.81 -> v0.2.83
    Updating wasm-bindgen-backend v0.2.81 -> v0.2.83
    Updating wasm-bindgen-macro v0.2.81 -> v0.2.83
    Updating wasm-bindgen-macro-support v0.2.81 -> v0.2.83
    Updating wasm-bindgen-shared v0.2.81 -> v0.2.83
    Updating web-sys v0.3.58 -> v0.3.60
    Updating zeroize v1.5.6 -> v1.5.7
2022-09-18 14:05:28 +02:00
.github GitHub CI: add transfer test for non-TLS WebTorrent 2022-07-19 17:12:39 +02:00
aquatic Update crate descriptions 2022-06-27 22:44:45 +02:00
aquatic_common Use regular (ahash) IndexMap for PeerMaps 2022-08-06 16:53:49 +02:00
aquatic_http Use regular (ahash) IndexMap for PeerMaps 2022-08-06 16:53:49 +02:00
aquatic_http_load_test Exit with error message on unrecognized config keys 2022-07-05 11:26:46 +02:00
aquatic_http_private Use regular (ahash) IndexMap for PeerMaps 2022-08-06 16:53:49 +02:00
aquatic_http_protocol http protocol: implement Error for RequestParseError 2022-08-01 14:42:22 +02:00
aquatic_toml_config aquatic_toml_config: fix dependency declaration for publishing 2022-03-26 11:53:04 +01:00
aquatic_toml_config_derive Bump version to 0.2.0 for all aquatic crates 2022-03-26 11:39:37 +01:00
aquatic_udp udp: in Peer, replace PeerStatus with is_seeder bool 2022-08-06 18:14:12 +02:00
aquatic_udp_bench udp: add optional peers per torrent statistics 2022-08-06 13:56:19 +02:00
aquatic_udp_load_test Exit with error message on unrecognized config keys 2022-07-05 11:26:46 +02:00
aquatic_udp_protocol Bump version to 0.2.0 for all aquatic crates 2022-03-26 11:39:37 +01:00
aquatic_ws Use regular (ahash) IndexMap for PeerMaps 2022-08-06 16:53:49 +02:00
aquatic_ws_load_test Exit with error message on unrecognized config keys 2022-07-05 11:26:46 +02:00
aquatic_ws_protocol Update simd-json to version 0.6.0 2022-07-18 18:47:28 +02:00
docker Update warning in aquatic_ws.Dockerfile 2022-08-01 14:19:28 +02:00
documents README and architecture svg: rename request worker to swarm worker 2022-07-04 12:00:45 +02:00
scripts Switch to thin LTO; add Cargo profile release-debug 2022-04-04 12:32:42 +02:00
.dockerignore Add "documents" to .dockerignore 2022-07-23 17:50:54 +02:00
.gitignore work on http_private, including parsing announce requests 2022-04-02 13:32:36 +02:00
Cargo.lock Run cargo update 2022-09-18 14:05:28 +02:00
Cargo.toml GitHub CI: speed up test compilation 2022-07-19 16:40:02 +02:00
deny.toml add some allowed licences to deny.toml 2020-07-21 01:53:43 +02:00
LICENSE Decide to use Apache 2.0 license, add file and update Cargo.toml's 2020-04-20 16:54:43 +02:00
README.md Update README 2022-08-01 15:05:06 +02:00
TODO.md Update TODO 2022-08-06 14:56:00 +02:00

aquatic: high-performance open BitTorrent tracker

CargoBuildAndTest Test HTTP, UDP and WSS file transfer

High-performance open BitTorrent tracker, consisting of sub-implementations for different protocols:

Name Protocol OS requirements
aquatic_udp BitTorrent over UDP Unix-like (using mio)
aquatic_http BitTorrent over HTTP with TLS (rustls) Linux 5.8+ (using glommio)
aquatic_ws WebTorrent over TLS (rustls, optional) Linux 5.8+ (using glommio)

Features at a glance:

  • Multithreaded design for handling large amounts of traffic
  • All data is stored in-memory (no database needed)
  • IPv4 and IPv6 support, with separate swarms
  • Supports forbidding/allowing info hashes
  • Built-in TLS support (no reverse proxy needed)
  • Automated CI testing of full file transfers

Known users:

Usage

Compiling

  • Install Rust with rustup (latest stable release is recommended)
  • Install cmake with your package manager (e.g., apt-get install cmake)
  • Clone this git repository and enter the directory
  • Build the implementations that you are interested in:
# Tell Rust to enable support for all CPU extensions present on current CPU
# except for those relating to AVX-512. This is necessary for aquatic_ws and
# recommended for the other implementations.
. ./scripts/env-native-cpu-without-avx-512

cargo build --release -p aquatic_udp
cargo build --release -p aquatic_http
cargo build --release -p aquatic_ws

Configuring

Generate configuration files. They come with comments and differ between protocols.

./target/release/aquatic_udp -p > "aquatic-udp-config.toml"
./target/release/aquatic_http -p > "aquatic-http-config.toml"
./target/release/aquatic_ws -p > "aquatic-ws-config.toml"

Make adjustments to the files. You will likely want to adjust address (listening address) under the network section.

Note that both aquatic_http and aquatic_ws require configuring certificate and private key files to run over TLS (which is optional for aquatic_ws). More details are available in the respective configuration files.

Workers

To increase performance, number of worker threads can be increased. The sum of socket_workers and swarm_workers should equal the total number of CPU cores that you want to use. Recommended proportions:

aquatic_udp aquatic_ws
CPU cores 2-5 6-9 10-15 >=16 2-11 12-19 >=20
Swarm workers 1 2 3 4 1 2 3
Socket workers 1-4 4-7 7-12 >=12 1-10 10-17 >=17

Access control

Access control by info hash is supported for all protocols. The relevant part of configuration is:

[access_list]
# Access list mode. Available modes are allow, deny and off.
mode = "off"
# Path to access list file consisting of newline-separated hex-encoded info hashes.
path = ""

The file is read on start and when the program receives SIGUSR1. If initial parsing fails, the program exits. Later failures result in in emitting of an error-level log message, while successful updates of the access list result in emitting of an info-level log message.

Running

If you're running aquatic_http or aquatic_ws, please make sure locked memory limits are sufficient:

  • If you're using a systemd service file, add LimitMEMLOCK=65536000 to it
  • Otherwise, add the following lines to /etc/security/limits.conf, and then log out and back in:
*    hard    memlock    65536
*    soft    memlock    65536

Once done, start the application:

./target/release/aquatic_udp -c "aquatic-udp-config.toml"
./target/release/aquatic_http -c "aquatic-http-config.toml"
./target/release/aquatic_ws -c "aquatic-ws-config.toml"

If your server is pointed to by domain example.com and you configured the tracker to run on port 3000, people can now use it by adding its URL to their torrent files or magnet links:

Implementation Announce URL
aquatic_udp udp://example.com:3000
aquatic_http https://example.com:3000/announce
aquatic_ws wss://example.com:3000

Details on implementations

aquatic_udp: UDP BitTorrent tracker

Implements:

  • BEP 015: UDP BitTorrent tracker protocol (more details). Exceptions:
    • Doesn't care about IP addresses sent in announce requests. The packet source IP is always used.
    • Doesn't track the number of torrent downloads (0 is always sent).

This is the most mature of the implementations. I consider it ready for production use.

Performance

UDP BitTorrent tracker throughput comparison

More details are available here. Please note that request workers have been renamed to swarm workers.

Optimisation attempts that didn't work out

  • Using glommio
  • Using io-uring
  • Using zerocopy + vectored sends for responses
  • Using sendmmsg

aquatic_http: HTTP BitTorrent tracker

Implements:

  • BEP 003: HTTP BitTorrent protocol (more details). Exceptions:
    • Only runs over TLS
    • Doesn't track the number of torrent downloads (0 is always sent)
    • Only compact responses are supported
  • BEP 023: Compact HTTP responses
  • BEP 007: IPv6 support
  • BEP 048: HTTP scrape support. Notes:
    • Doesn't allow full scrapes, i.e. of all registered info hashes

aquatic_http has not been tested as much as aquatic_udp but likely works fine in production.

Running behind a reverse proxy is currently not supported due to the difficulties of determining the originating IP address without knowing the exact setup.

Performance

HTTP BitTorrent tracker throughput comparison

More details are available here. Please note that request workers have been renamed to swarm workers.

aquatic_ws: WebTorrent tracker

Aims for compatibility with WebTorrent clients. Notes:

  • Doesn't track the number of torrent downloads (0 is always sent).
  • Doesn't allow full scrapes, i.e. of all registered info hashes

aquatic_ws has not been tested as much as aquatic_udp but likely works fine in production.

Running behind a reverse proxy is supported, as long as IPv4 requests are proxied to IPv4 requests, and IPv6 requests to IPv6 requests.

Performance

WebTorrent tracker throughput comparison

More details are available here. Please note that request workers have been renamed to swarm workers.

Load testing

There are load test binaries for all protocols. They use a CLI structure similar to the trackers and support generation and loading of configuration files.

To run, first start the tracker that you want to test. Then run the corresponding load test binary:

./scripts/run-load-test-udp.sh
./scripts/run-load-test-http.sh
./scripts/run-load-test-ws.sh

To fairly compare HTTP performance to opentracker, set keep_alive to false in aquatic_http settings.

Architectural overview

Architectural overview of aquatic

Copyright (c) 2020-2022 Joakim Frostegård

Distributed under Apache 2.0 license (details in LICENSE file.)

Trivia

The tracker is called aquatic because it thrives under a torrent of bits ;-)