mtorrent_dht/lib.rs
1//! Complete implementation of Kademlia-based Distributed Hash Table (DHT) used in the BitTorrent
2//! protocol.
3//!
4//! Example usage:
5//! ```no_run
6//! use mtorrent_dht as dht;
7//! # use tokio::net::UdpSocket;
8//! # use std::net::*;
9//!
10//! # let local_port = 6881;
11//! # let max_concurrent_queries = Some(100);
12//! # let config_dir = std::env::current_dir().unwrap();
13//! let (cmd_sender, cmd_receiver) = dht::setup_commands();
14//!
15//! # tokio::task::spawn_local(async move {
16//! // Create the UDP socket for DHT:
17//! let socket = UdpSocket::bind(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, local_port)).await.unwrap();
18//!
19//! // Set up the DHT stack that consists of 3 layers:
20//! let (outgoing_msgs_sink, incoming_msgs_source, io_driver) = dht::setup_udp(socket);
21//! let (client, server, router) =
22//! dht::setup_queries(outgoing_msgs_sink, incoming_msgs_source, max_concurrent_queries);
23//! let processor = dht::Processor::new(config_dir, client);
24//!
25//! // Run the DHT system:
26//! tokio::join!(io_driver.run(), router.run(), processor.run(server, cmd_receiver));
27//! # });
28//!
29//! // now send commands to the `cmd_sender` from a different task or runtime
30//! ```
31
32mod cmds;
33mod config;
34mod error;
35mod kademlia;
36mod msgs;
37mod peers;
38mod processor;
39mod queries;
40mod tasks;
41mod u160;
42mod udp;
43
44pub use cmds::*;
45pub use processor::Processor;
46pub use queries::*;
47pub use udp::*;