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

Commit

Permalink
fix: respond with GetSectionResponse::Redirect on missing pk set
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Mar 3, 2021
1 parent 4f484f1 commit 69a1fb8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
7 changes: 6 additions & 1 deletion src/messages/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
use bls_dkg::key_gen::message::Message as DkgMessage;
use bytes::Bytes;
use hex_fmt::HexFmt;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::{
collections::VecDeque,
Expand Down Expand Up @@ -184,10 +185,14 @@ impl Debug for Variant {
.field("elders_info", elders_info)
.field("member_info", member_info)
.finish(),
Self::Sync { section, .. } => f
Self::Sync { section, network } => f
.debug_struct("Sync")
.field("elders_info", section.elders_info())
.field("section_key", section.chain().last_key())
.field(
"other_prefixes",
&format_args!("({:b})", network.prefixes().format(", ")),
)
.finish(),
Self::Relocate(payload) => write!(f, "Relocate({:?})", payload),
Self::RelocatePromise(payload) => write!(f, "RelocatePromise({:?})", payload),
Expand Down
41 changes: 18 additions & 23 deletions src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,19 @@ impl Approved {
SectionInfoMsg::GetSectionQuery(name) => {
debug!("Received GetSectionQuery({}) from {}", name, sender);

let response = if self.section.prefix().matches(&name) {
if let Ok(pk_set) = self.public_key_set() {
GetSectionResponse::Success(SectionInfo {
prefix: self.section.elders_info().prefix,
pk_set,
elders: self
.section
.elders_info()
.peers()
.map(|peer| (*peer.name(), *peer.addr()))
.collect(),
})
} else {
GetSectionResponse::SectionInfoUpdate(TargetSectionError::NoSectionPkSet)
}
let response = if let (true, Ok(pk_set)) =
(self.section.prefix().matches(&name), self.public_key_set())
{
GetSectionResponse::Success(SectionInfo {
prefix: self.section.elders_info().prefix,
pk_set,
elders: self
.section
.elders_info()
.peers()
.map(|peer| (*peer.name(), *peer.addr()))
.collect(),
})
} else {
// If we are elder, we should know a section that is closer to `name` that us.
// Otherwise redirect to our elders.
Expand Down Expand Up @@ -891,28 +889,25 @@ impl Approved {
dst_key: Option<bls::PublicKey>,
bounced_msg: Message,
) -> Option<Command> {
trace!(
"Received BouncedUntrustedMessage({:?}) from {:?}...",
bounced_msg,
sender
);
let span = trace_span!("Received BouncedUntrustedMessage", ?bounced_msg, %sender);
let _span_guard = span.enter();

if let Some(dst_key) = dst_key {
let resend_msg = match bounced_msg.extend_proof_chain(&dst_key, self.section.chain()) {
Ok(msg) => msg,
Err(err) => {
trace!("...extending proof failed, discarding: {:?}", err);
trace!("extending proof failed, discarding: {:?}", err);
return None;
}
};

trace!(" ...resending with extended proof");
trace!("resending with extended proof");
Some(Command::send_message_to_node(
sender.addr(),
resend_msg.to_bytes(),
))
} else {
trace!(" ...missing dst key, discarding");
trace!("missing dst key, discarding");
None
}
}
Expand Down

0 comments on commit 69a1fb8

Please sign in to comment.