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

Commit

Permalink
fix: relocated allowed to join with own age
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and dirvine committed Apr 6, 2021
1 parent f1c6945 commit 018a9b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/routing/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,28 +1260,31 @@ impl Core {
(MIN_ADULT_AGE, None, None)
};

// During the first section, node shall use ranged age to avoid too many nodes got
// relocated at the same time. After the first section got split, later on nodes shall
// only start with age of MIN_ADULT_AGE
if self.section.prefix().is_empty() {
if peer.age() < FIRST_SECTION_MIN_AGE || peer.age() > FIRST_SECTION_MAX_AGE {
// Age differentiate only applies to the new node.
if join_request.relocate_payload.is_none() {
// During the first section, node shall use ranged age to avoid too many nodes got
// relocated at the same time. After the first section got split, later on nodes shall
// only start with age of MIN_ADULT_AGE
if self.section.prefix().is_empty() {
if peer.age() < FIRST_SECTION_MIN_AGE || peer.age() > FIRST_SECTION_MAX_AGE {
debug!(
"Ignoring JoinRequest from {} - first-section node having wrong age {:?}",
peer,
peer.age(),
);
return Ok(vec![]);
} else {
age = peer.age();
}
} 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 {} - first-section node having wrong age {:?}",
"Ignoring JoinRequest from {} - non-first-section node having wrong age {:?}",
peer,
peer.age(),
);
return Ok(vec![]);
} else {
age = peer.age();
}
} else if peer.age() != MIN_ADULT_AGE && join_request.relocate_payload.is_none() {
// 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![]);
}

// Requires the node name matches the age.
Expand Down
2 changes: 1 addition & 1 deletion src/section/member_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const MIN_ADULT_AGE: u8 = MIN_AGE + 1;
/// During the first section, nodes can start at a range of age to avoid too many nodes having the
/// same time get relocated at the same time.
/// Defines the lower bound of this range.
pub const FIRST_SECTION_MIN_AGE: u8 = MIN_AGE + 2;
pub const FIRST_SECTION_MIN_AGE: u8 = MIN_ADULT_AGE + 1;
/// Defines the higher bound of this range.
pub const FIRST_SECTION_MAX_AGE: u8 = 100;

Expand Down

0 comments on commit 018a9b8

Please sign in to comment.