Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix(bootstrap): avoid duplicate GetSectionRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Mar 3, 2021
1 parent a8a184c commit 84327e2
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/routing/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sn_messaging::{
DstLocation, MessageType, WireMsg,
};
use std::{
collections::{BTreeMap, VecDeque},
collections::{BTreeMap, HashSet, VecDeque},
mem,
net::SocketAddr,
};
Expand Down Expand Up @@ -137,7 +137,11 @@ impl<'a> State<'a> {
mut bootstrap_addrs: Vec<SocketAddr>,
relocate_details: Option<&SignedRelocateDetails>,
) -> Result<(Prefix, bls::PublicKey, BTreeMap<XorName, SocketAddr>)> {
// Avoid sending more than one request to the same peer.
let mut used_addrs = HashSet::new();

loop {
used_addrs.extend(bootstrap_addrs.iter().copied());
self.send_get_section_request(mem::take(&mut bootstrap_addrs), relocate_details)
.await?;

Expand All @@ -156,12 +160,19 @@ impl<'a> State<'a> {
);
return Ok((prefix, key, elders));
}
GetSectionResponse::Redirect(new_bootstrap_addrs) => {
info!(
"Bootstrapping redirected to another set of peers: {:?}",
new_bootstrap_addrs,
);
bootstrap_addrs = new_bootstrap_addrs.to_vec();
GetSectionResponse::Redirect(mut new_bootstrap_addrs) => {
// Ignore already used addresses
new_bootstrap_addrs.retain(|addr| !used_addrs.contains(addr));

if new_bootstrap_addrs.is_empty() {
debug!("Bootstrapping redirected to the same set of peers we already contacted - ignoring");
} else {
info!(
"Bootstrapping redirected to another set of peers: {:?}",
new_bootstrap_addrs,
);
bootstrap_addrs = new_bootstrap_addrs;
}
}
GetSectionResponse::SectionInfoUpdate(error) => {
error!("Infrastructure error: {:?}", error);
Expand Down

0 comments on commit 84327e2

Please sign in to comment.