Skip to content

Commit 320a1cd

Browse files
folexmxinden
andauthored
protocols/kad: Add Kademlia::get_closest_local_peers (#2436)
Co-authored-by: Max Inden <[email protected]>
1 parent a26b6ab commit 320a1cd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

protocols/kad/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
- Derive `Serialize`, `Deserialize` for `store::record::Key` (see [PR 2408])
1010

11+
- Add `get_closest_local_peers` to `Kademlia` (see [PR 2436])
12+
1113
[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339
1214
[PR 2411]: https://github.com/libp2p/rust-libp2p/pull/2411
1315
[PR 2408]: https://github.com/libp2p/rust-libp2p/pull/2408
16+
[PR 2436]: https://github.com/libp2p/rust-libp2p/pull/2436
1417

1518
# 0.33.0 [2021-11-16]
1619

protocols/kad/src/behaviour.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,14 @@ where
667667
self.queries.add_iter_closest(target.clone(), peers, inner)
668668
}
669669

670+
/// Returns closest peers to the given key; takes peers from local routing table only.
671+
pub fn get_closest_local_peers<'a, K: Clone>(
672+
&'a mut self,
673+
key: &'a kbucket::Key<K>,
674+
) -> impl Iterator<Item = kbucket::Key<PeerId>> + 'a {
675+
self.kbuckets.closest_keys(key)
676+
}
677+
670678
/// Performs a lookup for a record in the DHT.
671679
///
672680
/// The result of this operation is delivered in a

0 commit comments

Comments
 (0)