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 runtimeStructs§
- Command
Source - Command receiver used internally by the DHT code.
- Inbound
Queries - Server for receiving incoming queries from different nodes.
- IoDriver
- Actor that reads and writes UDP packets, and encodes/decodes DHT messages.
- Message
Channel Receiver - Message
Channel Sender - Outbound
Queries - 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.
- Query
Router - Actor that routes queries between
crate::Processorandcrate::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§
- Command
Sink - Sender of commands to the DHT system.