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

Commit

Permalink
Merge d2118c6 into 22574f4
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jun 15, 2021
2 parents 22574f4 + d2118c6 commit bd54fc4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
37 changes: 32 additions & 5 deletions src/routing/bootstrap/join.rs
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,16 @@ 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 Expand Up @@ -338,16 +348,33 @@ impl<'a> Join<'a> {
| JoinResponse::Rejected(JoinRejectionReason::JoinsDisallowed) => {
return Ok((join_response, sender, dest_info));
}
JoinResponse::Retry(ref section_auth)
| JoinResponse::Redirect(ref section_auth) => {
JoinResponse::Retry(ref section_auth) => {
if !section_auth.prefix.matches(&destination) {
error!("Invalid JoinResponse bad prefix: {:?}", join_response);
error!(
"Invalid JoinResponse::Retry bad prefix: {:?}",
join_response
);
continue;
}

if section_auth.elders.is_empty() {
error!(
"Invalid JoinResponse::Retry, empty list of Elders: {:?}",
join_response
);
continue;
}

if !verify_message(&routing_msg, None) {
continue;
}

return Ok((join_response, sender, dest_info));
}
JoinResponse::Redirect(ref section_auth) => {
if section_auth.elders.is_empty() {
error!(
"Invalid JoinResponse, empty list of Elders: {:?}",
"Invalid JoinResponse::Redirect, empty list of Elders: {:?}",
join_response
);
continue;
Expand Down
10 changes: 4 additions & 6 deletions src/routing/bootstrap/mod.rs
Expand Up @@ -30,12 +30,10 @@ async fn send_message(comm: &Comm, message: MessageType, recipients: Vec<(XorNam
Ok(SendStatus::MinDeliveryGroupSizeFailed(recipients)) => {
error!("Failed to send message {:?} to {:?}", message, recipients)
}
Err(err) => {
error!(
"Failed to send message {:?} to {:?}: {:?}",
message, recipients, err
)
}
Err(err) => error!(
"Failed to send message {:?} to {:?}: {:?}",
message, recipients, err
),
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/routing/core/messaging/handling/mod.rs
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 bd54fc4

Please sign in to comment.