#bittorrent #dht #kademlia #torrent

mainline

Simple, robust, BitTorrent's Mainline DHT implementation

24 releases (14 stable)

new 4.1.0 Nov 29, 2024
4.0.0 Sep 27, 2023
3.0.0 Sep 27, 2024
2.0.1 Jun 24, 2024
0.6.1 Nov 27, 2023

#181 in Network programming

Download history 1437/week @ 2024-08-09 1366/week @ 2024-08-16 859/week @ 2024-08-23 1269/week @ 2024-08-30 889/week @ 2024-09-06 967/week @ 2024-09-13 706/week @ 2024-09-20 1686/week @ 2024-09-27 978/week @ 2024-10-04 1116/week @ 2024-10-11 1694/week @ 2024-10-18 1483/week @ 2024-10-25 2761/week @ 2024-11-01 2038/week @ 2024-11-08 2303/week @ 2024-11-15 2244/week @ 2024-11-22

9,651 downloads per month
Used in 4 crates

MIT license

225KB
5K SLoC

Mainline

Simple, robust, BitTorrent's Mainline DHT implementation.

This library is focused on being the best and simplest Rust client for Mainline, especially focused on reliable and fast time-to-first-response.

It should work as a routing / storing node as well, and has been running in production for many months without an issue. However if you are running your separate (read: small) DHT, or otherwise facing unusual DoS attack, you should consider implementing rate limiting.

API Docs

Getting started

Check the Examples.

Features

Client

Running as a client, means you can store and query for values on the DHT, but not accept any incoming requests.

use mainline::Dht;

let dht = Dht::client(); // or `Dht::default();`

Supported BEPs:

This implementation also includes measures against Vertical Sybil Attacks.

Server

Running as a server is the same as a client, but you also respond to incoming requests and serve as a routing and storing node, supporting the general routing of the DHT, and contributing to the storage capacity of the DHT.

use mainline::Dht;

let dht = Dht::server(); // or `Dht::builder::server().build();` for more control.

Supported BEPs:

Rate limiting

The default server implementation has no rate-limiting, you can run your own custom server and apply your custom rate-limiting. However, that limit/block will only apply after parsing incoming messages, and it won't affect handling incoming responses.

Acknowledgment

This implementation was possible thanks to Webtorrent's Bittorrent-dht as a reference, and Rustydht-lib that saved me a lot of time, especially at the serialization and deserialization of Bencode messages.

Dependencies

~3.5–5MB
~99K SLoC