savoirfairelinux / opendht

OpenDHT: a C++17 Distributed Hash Table implementation
GNU General Public License v3.0
1.03k stars 172 forks source link

Peer Discovery in C lib - dht_runner_bootstrap and multicast/last known nodes #590

Closed ghenry closed 2 years ago

ghenry commented 2 years ago

Hi all,

https://github.com/savoirfairelinux/opendht/wiki/Running-a-node-in-your-program#joining-an-existing-network

What options are there for broadcasting locally on the same subnets etc or loading a list of known notes?

Thanks, Gavin.

aberaud commented 2 years ago

Hi,

To enable automatic discovery of DHT nodes on the same network with multicast, use the peer_discovery and peer_publish options. Run the dhtrunner with dht_runner_run_config instead of dht_runner_run:


dht_runner_config config;
dht_runner_config_default(&config);

config.peer_discovery = true;
config.peer_publish = true;

dht_runner* runner = dht_runner_new();
dht_runner_run_config(runner, 4222, &config);

This feature can be enabled when using dhtnode with the -D flag: https://github.com/savoirfairelinux/opendht/wiki/Running-a-node-with-dhtnode#running-dhtnode-directly

There is also a generic standalone dht::PeerDiscovery class allowing to perform multicast local service discovery independently from the DHT. This class is internally used by the DhtRunner when enabling peer_discovery/peer_publish: https://github.com/savoirfairelinux/opendht/wiki/Peer-discovery

Currently, this class is not exposed by the C binding.