#bittorrent #dht #kademlia #hash

mtorrent-dht

Asynchronous implementation of Distributed Hash Table (DHT) for the BitTorrent protocol

7 releases

Uses new Rust 2024

0.3.8 Nov 28, 2025
0.3.7 Nov 17, 2025
0.3.6 Oct 5, 2025
0.3.4 Sep 26, 2025

#6 in #kademlia


Used in 2 crates

Apache-2.0

245KB
6K SLoC

CI Crates.io Version docs.rs codecov

mtorrent-dht

Asynchronous implementation of Kademlia-based Distributed Hash Table (DHT) for the BitTorrent protocol. Based on Tokio and used as part of the mtorrent client.

Example usage:

use mtorrent_dht as dht;

// Create the UDP socket for DHT:
let socket = UdpSocket::bind(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, local_port)).await?;

// Set up the DHT stack:
let (outgoing_msgs_sink, incoming_msgs_source, io_driver) = dht::setup_udp(socket);
let (client, server, router) =
    dht::setup_queries(outgoing_msgs_sink, incoming_msgs_source, max_concurrent_queries);
let processor = dht::Processor::new(config_dir, client);

// Run the DHT system:
tokio::join!(io_driver.run(), router.run(), processor.run(server, cmd_receiver));

Dependencies

~16–30MB
~327K SLoC