24#include "subsystems/dht_service.h"
29#include <condition_variable>
35#include <unordered_set>
73 DhtClient*
dht_client()
override {
return dht_ ? dht_.get() : dht6_.get(); }
88 void probe_external_ip();
89 void on_peers(
const std::vector<Address>& peers,
const InfoHash& info_hash);
93 std::unique_ptr<DhtClient> make_client(AddressFamily family);
96 template <
typename Fn>
97 void for_each_client(Fn fn) {
99 if (dht6_) fn(*dht6_);
105 std::unique_ptr<DhtClient> dht_;
106 std::unique_ptr<DhtClient> dht6_;
109 std::atomic<bool> running_{
false};
110 std::atomic<bool> recover_pending_{
false};
111 std::mutex wait_mutex_;
112 std::condition_variable wake_;
114 std::mutex dialed_mutex_;
115 std::unordered_set<std::string> dialed_;
InfoHash discovery_hash() const
uint16_t dht_port_v6() const
IPv6 DHT UDP port (0 if not running)
std::string external_address() const
Our external (public) IP currently used to derive the DHT node id, learned via STUN at startup or in-...
DhtDiscovery(Config config)
static InfoHash hash_for_key(const std::string &key)
Map an application key to a stable 20-byte discovery hash (SHA-1).
uint16_t dht_port() const
IPv4 DHT UDP port (0 if not running)
DhtClient * dht_client() override
DhtService: hand out the live Kademlia node so siblings (e.g.
void attach(NodeContext &ctx) override
A pluggable network subsystem.
The narrow contract a subsystem needs from the node — and nothing more.
std::string data_dir
routing-table persistence dir (empty = cwd). Set to the node's data_dir to co-locate state.
bool enable_ipv4
run the IPv4 Kademlia network
uint16_t dht_port
0 = ephemeral
std::chrono::milliseconds announce_interval
std::chrono::milliseconds search_interval
bool enable_ipv6
run the IPv6 Kademlia network (BEP 32)
std::vector< Address > stun_servers
empty → built-in public defaults
bool discover_external_ip
Probe a STUN server once at startup to learn our public IP and seed the DHT node id per BEP 42.
std::vector< Address > bootstrap_nodes
empty → default internet nodes
std::string discovery_key
app namespace
std::chrono::milliseconds stun_timeout