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 May 2, 2024
1 parent a91c48f commit ec9898f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
See [PR 5148](https://github.com/libp2p/rust-libp2p/pull/5148).
- Derive `Copy` for `kbucket::key::Key<T>`.
See [PR 5317](https://github.com/libp2p/rust-libp2p/pull/5317).
- Fix periodic bootstrap not handling correctly `NoKnownPeers` error.
See [PR 5349](https://github.com/libp2p/rust-libp2p/pull/5349).

## 0.45.3

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 ec9898f

Please sign in to comment.