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

Commit 88723b0

Browse files
maqiYoga07
authored andcommitted
fix: make JoinRequest be handled properly by AE after section split
1 parent 5912ece commit 88723b0

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/routing/core/anti_entropy.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,23 @@ pub(crate) fn process(
4444
.cmp_by_position(&dest_info.dest_section_pk, section.chain().last_key())
4545
{
4646
info!("Anti-Entropy: Source's knowledge of our key is outdated, send them an update.");
47-
let chain = section
47+
let chain = if let Ok(chain) = section
4848
.chain()
49-
.get_proof_chain_to_current(&dest_info.dest_section_pk)?;
49+
.get_proof_chain_to_current(&dest_info.dest_section_pk)
50+
{
51+
chain
52+
} else {
53+
trace!(
54+
"Cannot find section_key {:?} within the chain",
55+
dest_info.dest_section_pk
56+
);
57+
// In case a new node is trying to bootstrap from us, not being its matching section.
58+
// Reply with empty actions with false flag to send back a JoinResponse::Redirect.
59+
if let Variant::JoinRequest(_) = msg.variant {
60+
return Ok((actions, false));
61+
}
62+
section.chain().clone()
63+
};
5064
let section_auth = section.section_signed_authority_provider();
5165
let variant = Variant::SectionKnowledge {
5266
src_info: (section_auth.clone(), chain),

src/routing/core/messaging/handling/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,33 @@ impl Core {
7272
trace!("Useful message from {:?}: {:?}", sender, msg);
7373
let (entropy_commands, shall_be_handled) =
7474
self.check_for_entropy(&msg, dest_info.clone()).await?;
75+
let no_ae_commands = entropy_commands.is_empty();
7576
commands.extend(entropy_commands);
7677
if shall_be_handled {
7778
info!("Entropy check passed. Handling useful msg!");
7879
commands.extend(self.handle_useful_message(sender, msg, dest_info).await?);
80+
} else if no_ae_commands {
81+
// For the case of receiving a JoinRequest not matching our prefix.
82+
let sender_name = msg.src.name();
83+
let sender_addr = if let Some(addr) = sender {
84+
addr
85+
} else {
86+
error!("JoinRequest from {:?} without address", sender_name);
87+
return Ok(commands);
88+
};
89+
let section_auth = self
90+
.network
91+
.closest(&sender_name)
92+
.unwrap_or_else(|| self.section.authority_provider());
93+
let variant = Variant::JoinResponse(Box::new(JoinResponse::Redirect(
94+
section_auth.clone(),
95+
)));
96+
trace!("Sending {:?} to {}", variant, sender_name);
97+
commands.push(self.send_direct_message(
98+
(sender_name, sender_addr),
99+
variant,
100+
section_auth.section_key(),
101+
)?);
79102
}
80103
}
81104
MessageStatus::Untrusted => {

0 commit comments

Comments
 (0)