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

Commit

Permalink
Minor fix in sending RoutingMessage as unestablished
Browse files Browse the repository at this point in the history
Also move send_signed_message_to_peer from Relocated back to Node, as it is only used there.
  • Loading branch information
madadam committed Apr 26, 2019
1 parent 1c19d70 commit c7c78b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
12 changes: 9 additions & 3 deletions src/states/common/not_established.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
28 changes: 1 addition & 27 deletions src/states/common/relocated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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<XorName>,
) -> 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) => {
Expand Down
25 changes: 25 additions & 0 deletions src/states/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<XorName>,
) -> 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.
Expand Down

0 comments on commit c7c78b1

Please sign in to comment.