From c7c78b1b9f597f489cdf4423a3a426a28a79a714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Cig=C3=A1nek?= Date: Fri, 26 Apr 2019 10:44:53 +0200 Subject: [PATCH] Minor fix in sending RoutingMessage as unestablished Also move send_signed_message_to_peer from Relocated back to Node, as it is only used there. --- src/states/common/not_established.rs | 12 +++++++++--- src/states/common/relocated.rs | 28 +--------------------------- src/states/node.rs | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/states/common/not_established.rs b/src/states/common/not_established.rs index 6f2f295aa5..745ccb433f 100644 --- a/src/states/common/not_established.rs +++ b/src/states/common/not_established.rs @@ -71,11 +71,17 @@ pub trait NotEstablished: Bootstrapped { // Get PublicId of the proxy node let proxy_pub_id = match routing_msg.src { Authority::Client { + ref client_id, ref proxy_node_name, - .. - } => *self.get_proxy_public_id(proxy_node_name)?, + } => { + if self.name() != client_id.name() { + return Ok(()); + } + + *self.get_proxy_public_id(proxy_node_name)? + } _ => { - error!("{} Source should be client if our state is Client", self); + error!("{} - Source should be client in this state", self); return Err(RoutingError::InvalidSource); } }; diff --git a/src/states/common/relocated.rs b/src/states/common/relocated.rs index 9cffb5a5ce..47f892deb7 100644 --- a/src/states/common/relocated.rs +++ b/src/states/common/relocated.rs @@ -13,7 +13,7 @@ use crate::{ error::RoutingError, event::Event, id::PublicId, - messages::{MessageContent, SignedMessage}, + messages::MessageContent, outbox::EventBox, peer_manager::{ConnectionInfoPreparedResult, Peer, PeerManager, PeerState}, routing_table::Authority, @@ -24,7 +24,6 @@ use crate::{ }; use log::LogLevel; use safe_crypto::SharedSecretKey; -use std::collections::BTreeSet; /// Common functionality for node states post-relocation. pub trait Relocated: Bootstrapped { @@ -425,31 +424,6 @@ pub trait Relocated: Bootstrapped { } } - // Filter, then convert the message to a `Hop` and serialise. - // Send this byte string. - fn send_signed_message_to_peer( - &mut self, - signed_msg: SignedMessage, - target: &PublicId, - route: u8, - sent_to: BTreeSet, - ) -> Result<(), RoutingError> { - if !self.crust_service().is_connected(target) { - trace!("{} Not connected to {:?}. Dropping peer.", self, target); - self.disconnect_peer(target); - return Ok(()); - } - - if self.filter_outgoing_routing_msg(signed_msg.routing_message(), target, route) { - return Ok(()); - } - - let priority = signed_msg.priority(); - let bytes = self.to_hop_bytes(signed_msg, route, sent_to)?; - self.send_or_drop(target, bytes, priority); - Ok(()) - } - fn add_to_routing_table(&mut self, pub_id: &PublicId, outbox: &mut EventBox) { match self.peer_mgr_mut().add_to_routing_table(pub_id) { Err(error) => { diff --git a/src/states/node.rs b/src/states/node.rs index ddfeb89ded..2b6add505d 100644 --- a/src/states/node.rs +++ b/src/states/node.rs @@ -1548,6 +1548,31 @@ impl Node { Ok(()) } + // Filter, then convert the message to a `Hop` and serialise. + // Send this byte string. + fn send_signed_message_to_peer( + &mut self, + signed_msg: SignedMessage, + target: &PublicId, + route: u8, + sent_to: BTreeSet, + ) -> Result<(), RoutingError> { + if !self.crust_service().is_connected(target) { + trace!("{} Not connected to {:?}. Dropping peer.", self, target); + self.disconnect_peer(target); + return Ok(()); + } + + if self.filter_outgoing_routing_msg(signed_msg.routing_message(), target, route) { + return Ok(()); + } + + let priority = signed_msg.priority(); + let bytes = self.to_hop_bytes(signed_msg, route, sent_to)?; + self.send_or_drop(target, bytes, priority); + Ok(()) + } + // Wraps the signed message in a `HopMessage` and sends it on. // // In the case that the `pub_id` is unknown, an ack is sent and the message dropped.