From e4238b6830c44c3ebf8da30082f5f27d9fb5162a Mon Sep 17 00:00:00 2001 From: qima Date: Tue, 15 Jun 2021 18:35:42 +0800 Subject: [PATCH] fix: new node after section split retry with MIN_ADULT_AGE --- src/routing/bootstrap/join.rs | 13 ++++++++++++- src/routing/core/messaging/handling/mod.rs | 15 +++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/routing/bootstrap/join.rs b/src/routing/bootstrap/join.rs index 30f44fa15c..81204a7025 100644 --- a/src/routing/bootstrap/join.rs +++ b/src/routing/bootstrap/join.rs @@ -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; @@ -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 diff --git a/src/routing/core/messaging/handling/mod.rs b/src/routing/core/messaging/handling/mod.rs index de48b28a03..20c9280d7f 100644 --- a/src/routing/core/messaging/handling/mod.rs +++ b/src/routing/core/messaging/handling/mod.rs @@ -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.