DHT Kademlia implementation. More...
#include <dht.h>
Public Member Functions | |
| DhtClient (int port=DHT_PORT, const std::string &bind_address="", const std::string &data_directory="") | |
| Constructor. | |
| ~DhtClient () | |
| Destructor. | |
| bool | start () |
| Start the DHT client. | |
| void | stop () |
| Stop the DHT client. | |
| void | shutdown_immediate () |
| Trigger immediate shutdown of all background threads. | |
| bool | bootstrap (const std::vector< Peer > &bootstrap_nodes) |
| Bootstrap the DHT with known nodes. | |
| bool | find_peers (const InfoHash &info_hash, PeerDiscoveryCallback callback) |
| Find peers for a specific info hash. | |
| bool | announce_peer (const InfoHash &info_hash, uint16_t port=0, PeerDiscoveryCallback callback=nullptr) |
| Announce that this node is a peer for a specific info hash. | |
| void | cancel_search (const InfoHash &info_hash) |
| Cancel an active search or announce for a specific info hash Should be called when a torrent is removed to clean up DHT state. | |
| const NodeId & | get_node_id () const |
| Get our node ID. | |
| size_t | get_routing_table_size () const |
| Get number of nodes in routing table. | |
| size_t | get_pending_ping_verifications_count () const |
| Get number of pending ping verifications. | |
| bool | is_search_active (const InfoHash &info_hash) const |
| Check if a search is currently active for an info hash. | |
| bool | is_announce_active (const InfoHash &info_hash) const |
| Check if an announce is currently active for an info hash. | |
| size_t | get_active_searches_count () const |
| Get number of active searches. | |
| size_t | get_active_announces_count () const |
| Get number of active announces. | |
| bool | is_running () const |
| Check if DHT is running. | |
| void | set_spider_mode (bool enable) |
| Enable spider mode In spider mode: | |
| bool | is_spider_mode () const |
| Check if spider mode is enabled. | |
| void | set_spider_announce_callback (SpiderAnnounceCallback callback) |
| Set callback for announce_peer requests (spider mode) Called when other peers announce they have a torrent. | |
| void | set_spider_ignore (bool ignore) |
| Set spider ignore mode - when true, incoming requests are not processed Similar to rate limiting in the original spider implementation. | |
| bool | is_spider_ignoring () const |
| Check if spider ignore mode is enabled. | |
| void | spider_walk () |
| Trigger a single spider walk iteration Sends find_node to a random node from the spider pool Should be called from external loop at desired frequency. | |
| size_t | get_spider_pool_size () const |
| Get the size of the spider node pool. | |
| size_t | get_spider_visited_count () const |
| Get the number of visited nodes in spider mode. | |
| void | clear_spider_state () |
| Clear spider state (pool and visited nodes) Useful for resetting the spider walk. | |
| bool | save_routing_table () |
| Save routing table to disk. | |
| bool | load_routing_table () |
| Load routing table from disk. | |
| void | set_data_directory (const std::string &directory) |
| Set data directory for persistence. | |
Static Public Member Functions | |
| static std::vector< Peer > | get_default_bootstrap_nodes () |
| Get default BitTorrent DHT bootstrap nodes. | |
| librats::DhtClient::DhtClient | ( | int | port = DHT_PORT, |
| const std::string & | bind_address = "", |
||
| const std::string & | data_directory = "" |
||
| ) |
Constructor.
| port | The UDP port to bind to (default: 6881) |
| bind_address | The interface IP address to bind to (empty for all interfaces) |
| librats::DhtClient::~DhtClient | ( | ) |
Destructor.
| bool librats::DhtClient::announce_peer | ( | const InfoHash & | info_hash, |
| uint16_t | port = 0, |
||
| PeerDiscoveryCallback | callback = nullptr |
||
| ) |
Announce that this node is a peer for a specific info hash.
| info_hash | The info hash to announce |
| port | The port to announce (0 for DHT port) |
| callback | Optional callback to receive discovered peers during traversal |
| bool librats::DhtClient::bootstrap | ( | const std::vector< Peer > & | bootstrap_nodes | ) |
Bootstrap the DHT with known nodes.
| bootstrap_nodes | Vector of bootstrap nodes |
| void librats::DhtClient::cancel_search | ( | const InfoHash & | info_hash | ) |
Cancel an active search or announce for a specific info hash Should be called when a torrent is removed to clean up DHT state.
| info_hash | The info hash to cancel search for |
| void librats::DhtClient::clear_spider_state | ( | ) |
Clear spider state (pool and visited nodes) Useful for resetting the spider walk.
| bool librats::DhtClient::find_peers | ( | const InfoHash & | info_hash, |
| PeerDiscoveryCallback | callback | ||
| ) |
Find peers for a specific info hash.
| info_hash | The info hash to search for |
| callback | Callback to receive discovered peers |
| size_t librats::DhtClient::get_active_announces_count | ( | ) | const |
Get number of active announces.
| size_t librats::DhtClient::get_active_searches_count | ( | ) | const |
Get number of active searches.
|
static |
Get default BitTorrent DHT bootstrap nodes.
|
inline |
| size_t librats::DhtClient::get_pending_ping_verifications_count | ( | ) | const |
Get number of pending ping verifications.
| size_t librats::DhtClient::get_routing_table_size | ( | ) | const |
Get number of nodes in routing table.
| size_t librats::DhtClient::get_spider_pool_size | ( | ) | const |
Get the size of the spider node pool.
| size_t librats::DhtClient::get_spider_visited_count | ( | ) | const |
Get the number of visited nodes in spider mode.
| bool librats::DhtClient::is_announce_active | ( | const InfoHash & | info_hash | ) | const |
Check if an announce is currently active for an info hash.
| info_hash | The info hash to check |
|
inline |
| bool librats::DhtClient::is_search_active | ( | const InfoHash & | info_hash | ) | const |
Check if a search is currently active for an info hash.
| info_hash | The info hash to check |
|
inline |
|
inline |
| bool librats::DhtClient::load_routing_table | ( | ) |
Load routing table from disk.
| bool librats::DhtClient::save_routing_table | ( | ) |
Save routing table to disk.
| void librats::DhtClient::set_data_directory | ( | const std::string & | directory | ) |
Set data directory for persistence.
| directory | Directory path |
| void librats::DhtClient::set_spider_announce_callback | ( | SpiderAnnounceCallback | callback | ) |
Set callback for announce_peer requests (spider mode) Called when other peers announce they have a torrent.
| callback | The callback to invoke |
| void librats::DhtClient::set_spider_ignore | ( | bool | ignore | ) |
Set spider ignore mode - when true, incoming requests are not processed Similar to rate limiting in the original spider implementation.
| ignore | true to ignore incoming requests, false to process them |
| void librats::DhtClient::set_spider_mode | ( | bool | enable | ) |
Enable spider mode In spider mode:
| enable | true to enable spider mode, false to disable |
| void librats::DhtClient::shutdown_immediate | ( | ) |
Trigger immediate shutdown of all background threads.
| void librats::DhtClient::spider_walk | ( | ) |
Trigger a single spider walk iteration Sends find_node to a random node from the spider pool Should be called from external loop at desired frequency.
| bool librats::DhtClient::start | ( | ) |
Start the DHT client.
| void librats::DhtClient::stop | ( | ) |
Stop the DHT client.