libp2p / go-libp2p-kad-dht

A Kademlia DHT implementation on go-libp2p
https://github.com/libp2p/specs/tree/master/kad-dht
MIT License
521 stars 223 forks source link

Use a random peer ID for lookup check #967

Closed xinaxu closed 5 months ago

xinaxu commented 6 months ago

This fixes #966

guillaumemichel commented 6 months ago

In the rust-libp2p implementation, only requesting for the recipient key will trigger an empty response. If any other key is requested, the node should answer with nodes from its routing table. So requesting any other key should allow go-libp2p-kad-dht nodes to add rust-libp2p nodes to their routing table.

* _we are starting a new DHT out of thin air_

* rust-libp2p starts and has 0 peers.

* go-libp2p-kad-dht do FindPeer on rust-libp2p to check if it is a valid node, rust-libp2p has no peer in bucket yet and returns nothing.

In this case, rust-libp2p would add go-libp2p-kad-dht in its routing table after the failed check is performed. When rust-libp2p buckets will refresh (e.g after 10 minutes), it will ping go-libp2p-kad-dht, which will learn again about rust-libp2p, and check it again. This time, rust-libp2p will be able to answer with the go-libp2p-kad-dht peer id.

I agree with @Jorropo that generating a new random key every time is too expensive.

guillaumemichel commented 6 months ago

Alternatively, we could run the lookupCheck only if the nodes has a non-empty routing table, or at least 5 (?) nodes in its routing table. The node shouldn't be picky if it doesn't have any peers yet.

guillaumemichel commented 5 months ago

Closing as https://github.com/libp2p/go-libp2p-kad-dht/issues/966 is now resolved