Module sc_network::discovery

source ·
Expand description

Discovery mechanisms of Substrate.

The DiscoveryBehaviour struct implements the NetworkBehaviour trait of libp2p and is responsible for discovering other nodes that are part of the network.

Substrate uses the following mechanisms in order to discover nodes that are part of the network:

  • Bootstrap nodes. These are hard-coded node identities and addresses passed in the constructor of the DiscoveryBehaviour. You can also call add_known_address later to add an entry.

  • mDNS. Discovers nodes on the local network by broadcasting UDP packets.

  • Kademlia random walk. Once connected, we perform random Kademlia FIND_NODE requests on the configured Kademlia DHTs in order for nodes to propagate to us their view of the network. This is performed automatically by the DiscoveryBehaviour.

Additionally, the DiscoveryBehaviour is also capable of storing and loading value in the configured DHTs.

§Usage

The DiscoveryBehaviour generates events of type DiscoveryOut, most notably DiscoveryOut::Discovered that is generated whenever we discover a node. Only the identity of the node is returned. The node’s addresses are stored within the DiscoveryBehaviour and can be queried through the NetworkBehaviour trait.

Important: In order for the discovery mechanism to work properly, there needs to be an active mechanism that asks nodes for the addresses they are listening on. Whenever we learn of a node’s address, you must call add_self_reported_address.

Structs§

Enums§

Constants§