23#include "util/rats_export.h"
25#include "subsystems/dht_service.h"
30#include <condition_variable>
36#include <unordered_set>
44 uint16_t dht_port = 0;
45 std::string bind_address =
"";
46 std::string data_dir =
"";
47 bool enable_ipv4 =
true;
48 bool enable_ipv6 =
true;
49 std::string discovery_key =
"";
51 std::chrono::milliseconds search_interval{30000};
56 std::chrono::milliseconds announce_interval{600000};
61 bool discover_external_ip =
true;
63 std::chrono::milliseconds stun_timeout{3000};
78 DhtClient*
dht_client()
override {
return dht_ ? dht_.get() : dht6_.get(); }
93 void probe_external_ip();
94 void on_peers(
const std::vector<Address>& peers,
const InfoHash& info_hash);
98 std::unique_ptr<DhtClient> make_client(AddressFamily family);
101 template <
typename Fn>
102 void for_each_client(Fn fn) {
104 if (dht6_) fn(*dht6_);
110 std::unique_ptr<DhtClient> dht_;
111 std::unique_ptr<DhtClient> dht6_;
114 std::atomic<bool> running_{
false};
115 std::atomic<bool> recover_pending_{
false};
116 std::mutex wait_mutex_;
117 std::condition_variable wake_;
119 std::mutex dialed_mutex_;
120 std::unordered_set<Address> 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::vector< HostEndpoint > bootstrap_nodes
empty → default internet nodes
std::vector< HostEndpoint > stun_servers
empty → built-in public defaults