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

Commit

Permalink
fix: new node after section split retry with MIN_ADULT_AGE
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and bochaco committed Jun 15, 2021
1 parent 22574f4 commit e4238b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/routing/bootstrap/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
peer::PeerUtils,
routing::comm::{Comm, ConnectionEvent},
section::{SectionAuthorityProviderUtils, SectionUtils},
FIRST_SECTION_MAX_AGE, FIRST_SECTION_MIN_AGE,
FIRST_SECTION_MAX_AGE, FIRST_SECTION_MIN_AGE, MIN_ADULT_AGE,
};
use futures::future;
use rand::seq::IteratorRandom;
Expand Down Expand Up @@ -181,6 +181,17 @@ impl<'a> Join<'a> {
}

if prefix.matches(&self.node.name()) {
// After section split, new node must join with the age of MIN_ADULT_AGE.
if !prefix.is_empty() && self.node.age() != MIN_ADULT_AGE
{
let new_keypair =
ed25519::gen_keypair(&prefix.range_inclusive(), MIN_ADULT_AGE);
let new_name = ed25519::name(&new_keypair.public);

info!("Setting Node name to {}", new_name);
self.node = Node::new(new_keypair, self.node.addr);
}

info!(
"Newer Join response for our prefix {:?} from {:?}",
section_auth, sender
Expand Down
15 changes: 9 additions & 6 deletions src/routing/core/messaging/handling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,15 @@ impl Core {
}
} else if peer.age() != MIN_ADULT_AGE {
// After section split, new node has to join with age of MIN_ADULT_AGE.
debug!(
"Ignoring JoinRequest from {} - non-first-section node having wrong age {:?}",
peer,
peer.age(),
);
return Ok(vec![]);
let variant = Variant::JoinResponse(Box::new(JoinResponse::Retry(
self.section.authority_provider().clone(),
)));
trace!("New node after section split must join with age of MIN_ADULT_AGE. Sending {:?} to {}", variant, peer);
return Ok(vec![self.send_direct_message(
(*peer.name(), *peer.addr()),
variant,
*self.section.chain().last_key(),
)?]);
}

// Requires the node name matches the age.
Expand Down

0 comments on commit e4238b6

Please sign in to comment.