Skip to content

Commit

Permalink
Use defensive programming
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Dec 3, 2023
1 parent 9c7b8e8 commit 75889e1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2084,12 +2084,19 @@ where
}

fn maybe_bootstrap(&mut self) {
if self.current_automated_bootstrap.is_none() {
match self.bootstrap() {
Ok(query_id) => self.current_automated_bootstrap = Some(query_id),
Err(_) => self.current_automated_bootstrap = None,
}
if self.current_automated_bootstrap.is_some() {
return;
}

let query_id = match self.bootstrap() {
Ok(id) => id,
Err(e) => {
tracing::warn!("skipping automated bootstrap: {e}");
return;
}
};

self.current_automated_bootstrap = Some(query_id);
}

/// Preloads a new [`Handler`] with requests that are waiting to be sent to the newly connected peer.
Expand Down

0 comments on commit 75889e1

Please sign in to comment.