Skip to content

Commit

Permalink
fix(kad): correctly handle NoKnownPeers error when bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-frb committed Apr 30, 2024
1 parent e5c072c commit 7aba7ef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
See [PR 4934](https://github.com/libp2p/rust-libp2p/pull/4934).
- Add periodic and automatic bootstrap.
See [PR 4838](https://github.com/libp2p/rust-libp2p/pull/4838).
See [PR 5349](https://github.com/libp2p/rust-libp2p/pull/5349).
- Make it mandatory to provide protocol names when creating a `kad::Config`.
Deprecate `kad::Config::default()`, replaced by `kad::Config::new(StreamProtocol)`.
See [PR 5122](https://github.com/libp2p/rust-libp2p/pull/5122).
Expand Down
3 changes: 2 additions & 1 deletion protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ where
/// This parameter is used to call [`Behaviour::bootstrap`] periodically and automatically
/// to ensure a healthy routing table.
pub fn bootstrap(&mut self) -> Result<QueryId, NoKnownPeers> {
self.bootstrap_status.on_started();
let local_key = *self.kbuckets.local_key();
let info = QueryInfo::Bootstrap {
peer: *local_key.preimage(),
Expand All @@ -939,9 +940,9 @@ where
};
let peers = self.kbuckets.closest_keys(&local_key).collect::<Vec<_>>();
if peers.is_empty() {
self.bootstrap_status.on_finish();
Err(NoKnownPeers())
} else {
self.bootstrap_status.on_started();
let inner = QueryInner::new(info);
Ok(self.queries.add_iter_closest(local_key, peers, inner))
}
Expand Down

0 comments on commit 7aba7ef

Please sign in to comment.