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

Commit

Permalink
fix: only send to client directly when it belongs to self section
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and Yoga07 committed Apr 27, 2021
1 parent aaebeb7 commit b8ddc1b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/routing/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Comm {
.send_message(msg, recipient)
.await
.map_err(|err| {
error!("{}", err);
error!("Sending to {:?} failed with {}", recipient, err);
SendError
})
}
Expand Down
15 changes: 9 additions & 6 deletions src/routing/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ impl Core {
}

fn handle_user_message(&mut self, msg: &Message, content: Bytes) -> Result<Vec<Command>> {
trace!("handle user message {:?}", msg);
if let DstLocation::EndUser(end_user) = msg.dst() {
let recipients = match end_user {
EndUser::AllClients(public_key) => {
Expand All @@ -1099,8 +1100,10 @@ impl Core {
}
};
if recipients.is_empty() {
trace!("Cannot route user message, recipient list empty: {:?}", msg);
return Err(Error::CannotRoute);
};
trace!("sending user message {:?} to client {:?}", msg, recipients);
return Ok(vec![Command::SendMessage {
recipients,
delivery_group_size: 1,
Expand Down Expand Up @@ -2092,8 +2095,9 @@ impl Core {
}

trace!(
"relay {:?} to {:?} (proof_chain: {:?})",
"relay {:?} to first {:?} of {:?} (proof_chain: {:?})",
msg,
dg_size,
targets,
msg.proof_chain().ok()
);
Expand All @@ -2106,12 +2110,11 @@ impl Core {

#[allow(unused)]
pub fn check_key_status(&self, bls_pk: &bls::PublicKey) -> Result<(), TargetSectionError> {
let elders_candidates = self.section.promote_and_demote_elders(&self.node.name());
// Whenever there is EldersInfo change candidate, it is considered as having ongoing DKG.
if !self
.section
.promote_and_demote_elders(&self.node.name())
.is_empty()
{
if !elders_candidates.is_empty() {
trace!("Non empty elder candidates {:?}", elders_candidates);
trace!("Current erlders_info {:?}", self.section.elders_info());
return Err(TargetSectionError::DkgInProgress);
}
if !self.section.chain().has_key(bls_pk) {
Expand Down
5 changes: 5 additions & 0 deletions src/routing/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ impl Dispatcher {
.await
.is_err()
{
trace!(
"Lost connection to client {:?} when sending message {:?}",
recipient,
message
);
self.send_event(Event::ClientLost(*recipient)).await;
}
}
Expand Down
43 changes: 26 additions & 17 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,24 +357,33 @@ impl Routing {
public_key,
}) = itinerary.dst
{
let socket_addr = self
.dispatcher
.core
.lock()
.await
.get_socket_addr(socket_id)
.copied();

if let Some(socket_addr) = socket_addr {
return self
.send_message_to_client(socket_addr, ClientMessage::from(content)?)
.await;
let name = XorName::from(public_key);
if self.our_prefix().await.matches(&name) {
let socket_addr = self
.dispatcher
.core
.lock()
.await
.get_socket_addr(socket_id)
.copied();

if let Some(socket_addr) = socket_addr {
debug!(
"Sending client msg of {:?} to {:?}",
public_key, socket_addr
);
return self
.send_message_to_client(socket_addr, ClientMessage::from(content)?)
.await;
} else {
debug!(
"Could not find socketaddr corresponding to socket_id {:?} and public_key {:?}",
socket_id, public_key
);
debug!("Sending user message instead.. (Command::SendUserMessage)");
}
} else {
debug!(
"Could not find socketaddr corresponding to socket_id {:?} and public_key {:?}",
socket_id, public_key
);
debug!("Sending user message instead.. (Command::SendUserMessage)");
debug!("Relaying message with sending user message (Command::SendUserMessage)");
}
}
let command = Command::SendUserMessage {
Expand Down

0 comments on commit b8ddc1b

Please sign in to comment.