libp2p / go-libp2p

libp2p implementation in Go
MIT License
5.97k stars 1.05k forks source link

FindPeer Design Review #784

Open aschmahmann opened 4 years ago

aschmahmann commented 4 years ago

There are a few upcoming changes to the DHT and we'd like to nail down what the contract and expectations are for the FindPeer query to make sure they are met from a performance and security standpoint without adding too much complexity.

Questions for the upcoming design review include:

Existing implementation approaches

Current go-libp2p-kad-dht approach:

libp2p/go-libp2p-kad-dht#436:

aschmahmann commented 4 years ago

Some results from this design review:

1) Once signed peer records land FindPeer should effectively run GetClosestPeers and return the best of all the records found 2) Add a FindPeerAsync function that returns a channel of peer records as we find them, but otherwise continues the query 3) Change FindPeer to not rely on the FindPeer DHT message since that message should only return DHT server nodes (i.e. nodes in the routing table), but currently returns DHT client nodes also in order to make their addresses findable

Hopefully landing 1 should be doable without any massive changes, and if so then should push 2 and 3 further down the road.

aschmahmann commented 4 years ago

@aarshkshah1992 asked in #779 about whether FindProviders should also not shortcut as FindPeer has been decided not to.

Shortcutting can lead to two issues: 1) We only learn about old addresses/provider records due to caching inside of Kad (or an attacker giving you a set of bogus provider records) and therefore can't find some content that's really popular

It's possible that the DHT improvements will yield a full search not being much more expensive than shortcutting. If, after benchmarking, the results are close I'd definitely be pro removing the shortcutting by default since we have FindProvidesAsync and the query is cancellable via context.

@Stebalien @jacobheun does this analysis make sense to you and seem like a reasonable plan forward? It's a pretty minimal implementation change (famous last words 😛) which we can revisit once we've got better data about how valuable the shortcuts could be.