Skip to content

Commit

Permalink
protocols/kad: Kademlia::kbuckets include all
Browse files Browse the repository at this point in the history
Instead of only returning non-empty kbuckets via `Kademlia::kbuckets`,
return empty ones as well.

Doing so enables consumers to (1) reason about each and every bucket and
(2) depend on a stable order of the buckets.
  • Loading branch information
mxinden committed Jul 27, 2020
1 parent 8a08f72 commit eafeee2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Next

- Include empty buckets in `Kademlia::kbuckets`.


# 0.21.0 [2020-07-01]

- Remove `KademliaEvent::Discovered`
Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ where
}
}

/// Returns an iterator over all non-empty buckets in the routing table.
/// Returns an iterator over all buckets in the routing table.
pub fn kbuckets(&mut self)
-> impl Iterator<Item = kbucket::KBucketRef<kbucket::Key<PeerId>, Addresses>>
{
self.kbuckets.iter().filter(|b| !b.is_empty())
self.kbuckets.iter()
}

/// Returns the k-bucket for the distance to the given key.
Expand Down

0 comments on commit eafeee2

Please sign in to comment.