Skip to main content

Crate mtorrent_dht

Crate mtorrent_dht 

Source
Expand description

Complete implementation of Kademlia-based Distributed Hash Table (DHT) used in the BitTorrent protocol.

Example usage:

use mtorrent_dht as dht;

let (cmd_sender, cmd_receiver) = dht::setup_commands();

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

// Set up the DHT stack that consists of 3 layers:
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));

// now send commands to the `cmd_sender` from a different task or runtime

Structs§

CommandSource
Command receiver used internally by the DHT code.
InboundQueries
Server for receiving incoming queries from different nodes.
IoDriver
Actor that reads and writes UDP packets, and encodes/decodes DHT messages.
MessageChannelReceiver
MessageChannelSender
OutboundQueries
Client for sending outgoing queries to different nodes.
Processor
Actor that maintains the routing table, responds to incoming queries, keeps track of discovered peers, and handles commands from the user.
QueryRouter
Actor that routes queries between crate::Processor and crate::IoDriver, performs retries and matches requests and responses.

Enums§

Command
Command from the user to the DHT system.

Functions§

setup_commands
Set up a channel for the user commands to the DHT system.
setup_queries
Create the layer that facilitates inbound and outbound transactions (queries).
setup_udp
Create the networking layer that handles low-level I/O.

Type Aliases§

CommandSink
Sender of commands to the DHT system.