diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index eb5ff7d1309..b9616cc2074 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -8,9 +8,12 @@ - Derive `Serialize`, `Deserialize` for `store::record::Key` (see [PR 2408]) +- Add `get_closest_local_peers` to `Kademlia` (see [PR 2436]) + [PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339 [PR 2411]: https://github.com/libp2p/rust-libp2p/pull/2411 [PR 2408]: https://github.com/libp2p/rust-libp2p/pull/2408 +[PR 2436]: https://github.com/libp2p/rust-libp2p/pull/2436 # 0.33.0 [2021-11-16] diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 335e2eba8e1..b213f964bda 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -667,6 +667,14 @@ where self.queries.add_iter_closest(target.clone(), peers, inner) } + /// Returns closest peers to the given key; takes peers from local routing table only. + pub fn get_closest_local_peers<'a, K: Clone>( + &'a mut self, + key: &'a kbucket::Key, + ) -> impl Iterator> + 'a { + self.kbuckets.closest_keys(key) + } + /// Performs a lookup for a record in the DHT. /// /// The result of this operation is delivered in a