From 823db3adf25fba3e0ef7889c356b27f94db862ea Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 16 Jul 2023 00:21:19 -0400 Subject: [PATCH] reverse connect fix --- veilid-core/src/network_manager/mod.rs | 25 ++++++++++++--------- veilid-core/src/rpc_processor/rpc_signal.rs | 6 ++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index 807ec42d..6578fb1a 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -676,7 +676,11 @@ impl NetworkManager { // Process a received signal #[instrument(level = "trace", skip(self), err)] - pub async fn handle_signal(&self, signal_info: SignalInfo) -> EyreResult> { + pub async fn handle_signal( + &self, + connection_descriptor: ConnectionDescriptor, + signal_info: SignalInfo, + ) -> EyreResult> { match signal_info { SignalInfo::ReverseConnect { receipt, peer_info } => { let routing_table = self.routing_table(); @@ -697,6 +701,10 @@ impl NetworkManager { } }; + // Restrict reverse connection to same protocol as inbound signal + let peer_nr = peer_nr + .filtered_clone(NodeRefFilter::from(connection_descriptor.protocol_type())); + // Make a reverse connection to the peer and send the receipt to it rpc.rpc_call_return_receipt(Destination::direct(peer_nr), receipt) .await @@ -1038,16 +1046,11 @@ impl NetworkManager { }; if let Some(relay_nr) = some_relay_nr { - // Force sequencing if this came in sequenced. - // The sender did the prefer/ensure calculation when it did get_contact_method, - // so we don't need to do it here. - let relay_nr = if connection_descriptor.remote().protocol_type().is_ordered() { - let mut relay_nr = relay_nr.clone(); - relay_nr.set_sequencing(Sequencing::EnsureOrdered); - relay_nr - } else { - relay_nr - }; + // Ensure the protocol is forwarded exactly as is + // Address type is allowed to change if connectivity is better + let relay_nr = relay_nr.filtered_clone( + NodeRefFilter::new().with_protocol_type(connection_descriptor.protocol_type()), + ); // Relay the packet to the desired destination log_net!("relaying {} bytes to {}", data.len(), relay_nr); diff --git a/veilid-core/src/rpc_processor/rpc_signal.rs b/veilid-core/src/rpc_processor/rpc_signal.rs index b24a4efe..3226ae00 100644 --- a/veilid-core/src/rpc_processor/rpc_signal.rs +++ b/veilid-core/src/rpc_processor/rpc_signal.rs @@ -52,8 +52,8 @@ impl RPCProcessor { // Can't allow anything other than direct packets here, as handling reverse connections // or anything like via signals over private routes would deanonymize the route - match &msg.header.detail { - RPCMessageHeaderDetail::Direct(_) => {} + let connection_descriptor = match &msg.header.detail { + RPCMessageHeaderDetail::Direct(d) => d.connection_descriptor, RPCMessageHeaderDetail::SafetyRouted(_) | RPCMessageHeaderDetail::PrivateRouted(_) => { return Ok(NetworkResult::invalid_message("signal must be direct")); } @@ -73,7 +73,7 @@ impl RPCProcessor { let network_manager = self.network_manager(); let signal_info = signal.destructure(); network_manager - .handle_signal(signal_info) + .handle_signal(connection_descriptor, signal_info) .await .map_err(RPCError::network) }