Skip to content

About

Simple, robust, BitTorrent's Mainline DHT implementation

Resources

Stars

15 stars

Watchers

2 watching

Forks

Repository files navigation

n0-mainline

Simple, robust, BitTorrent's Mainline DHT implementation.

This is an iroh-flavored fork of nuhvi/dht: it is a support crate for iroh and integrates with the iroh ecosystem (e.g. iroh-base keys, async UDP via noq-udp). It does not depend on the iroh crate itself, so it can be used standalone. It does however require noq-udp for its socket layer.

The main purpose for which iroh uses n0-mainline is endpoint address lookup via BEP_0044.

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 n0_mainline::{Dht, Mode};

let dht = Dht::client().await.unwrap();

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 n0_mainline::{Dht, Mode};

let dht = Dht::builder().mode(Mode::Server).build()?; // or Dht::server()?

Supported BEPs:

Rate limiting

The server implementation has no rate-limiting, you can run your own request filter 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.

Client and server modes

Nodes start in client mode and do not automatically switch to server mode. If you know your node is publicly reachable and will be long running, enable server mode with Dht::builder().mode(Mode::Server).build(). You can also provide a known public IPv4 address with .public_ip(ip) to derive the node ID from that address.

Reported public addresses are observations from other nodes, not proof of inbound reachability.

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.

About

Simple, robust, BitTorrent's Mainline DHT implementation

Resources

Stars

15 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages