rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

Ability to query Kademlia peers via behaviour API

Open nazar-pc opened this issue 1 year ago • 3 comments

Description

Right now there are methods for adding and removing addresses, but no direct API to query addresses. There is get_closest_local_peers that returns PeerIds, but not corresponding addresses. There is find_closest, but it is private.

Motivation

I need to be able to implement a mechanism similar to Kademlia's iterative lookups, but outside Kademlia. get_closest_local_peers is exactly what I need there, except I also need peer addresses to in order to respond to a query.

Requirements

  1. get_closest_local_peers to return something like KadPeer at the minimum
  2. Ability to query addresses more directly would probably be nice as well
  3. Possibly making find_closest public as it seems to be doing the same thing as get_closest_local_peers except it also contains addresses and filters out source peer, which is exactly what I need

Open questions

Not sure what would be the desired API here yet, hence provided a few potential options

Are you planning to do it yourself in a pull request ?

Maybe

nazar-pc avatar Oct 07 '24 17:10 nazar-pc

Hey! It sounds like you might be looking for Behaviour::get_closest_peers, no?

https://github.com/libp2p/rust-libp2p/blob/93ad28c4cce236b1657241ba623ea30077565afd/protocols/kad/src/behaviour.rs#L730-L739

dariusc93 avatar Oct 07 '24 17:10 dariusc93

No, I specifically want to query local Kademlia view, not doing iterative network lookups. I'll be doing network lookups on a different level in a slightly different way.

nazar-pc avatar Oct 07 '24 17:10 nazar-pc

Yes, it makes sense that the addresses stored in the kbuckets are accessible through an API 👍🏻

guillaumemichel avatar Oct 09 '24 11:10 guillaumemichel