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

Commit

Permalink
fix(bootstrap): require GetSectionResponse to match our destination, …
Browse files Browse the repository at this point in the history
…not name
  • Loading branch information
madadam committed Mar 3, 2021
1 parent 84327e2 commit 4f484f1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/routing/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> State<'a> {
self.send_get_section_request(mem::take(&mut bootstrap_addrs), relocate_details)
.await?;

let (response, sender) = self.receive_get_section_response().await?;
let (response, sender) = self.receive_get_section_response(relocate_details).await?;

match response {
GetSectionResponse::Success(SectionInfo {
Expand Down Expand Up @@ -188,10 +188,9 @@ impl<'a> State<'a> {
) -> Result<()> {
debug!("{} Sending GetSectionQuery to {:?}", self.node, recipients);

let destination = match relocate_details {
Some(details) => *details.destination(),
None => self.node.name(),
};
let destination = relocate_details
.map(|details| *details.destination())
.unwrap_or_else(|| self.node.name());

let message = SectionInfoMsg::GetSectionQuery(destination);

Expand All @@ -203,7 +202,14 @@ impl<'a> State<'a> {
Ok(())
}

async fn receive_get_section_response(&mut self) -> Result<(GetSectionResponse, SocketAddr)> {
async fn receive_get_section_response(
&mut self,
relocate_details: Option<&SignedRelocateDetails>,
) -> Result<(GetSectionResponse, SocketAddr)> {
let destination = relocate_details
.map(|details| *details.destination())
.unwrap_or_else(|| self.node.name());

while let Some((message, sender)) = self.recv_rx.next().await {
match message {
MessageType::SectionInfo(SectionInfoMsg::GetSectionResponse(response)) => {
Expand All @@ -213,7 +219,7 @@ impl<'a> State<'a> {
continue;
}
GetSectionResponse::Success(SectionInfo { prefix, .. })
if !prefix.matches(&self.node.name()) =>
if !prefix.matches(&destination) =>
{
error!("Invalid GetSectionResponse::Success: bad prefix");
continue;
Expand Down

0 comments on commit 4f484f1

Please sign in to comment.