From 4a14cabeeb60b3dff20a0bbd1cc86ec6a14b3ad8 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 24 Jun 2023 18:40:19 -0400 Subject: [PATCH] handle unreachable --- veilid-core/src/network_manager/send_data.rs | 39 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/veilid-core/src/network_manager/send_data.rs b/veilid-core/src/network_manager/send_data.rs index 02de25c5..16613e98 100644 --- a/veilid-core/src/network_manager/send_data.rs +++ b/veilid-core/src/network_manager/send_data.rs @@ -66,9 +66,10 @@ impl NetworkManager { ) } NodeContactMethod::Unreachable => { - return Ok(NetworkResult::no_connection_other( - "Can't send to this node", - )); + network_result_try!( + this.send_data_ncm_unreachable(target_node_ref, data) + .await? + ) } }; @@ -113,6 +114,38 @@ impl NetworkManager { ))) } + /// Send data using NodeContactMethod::Unreachable + async fn send_data_ncm_unreachable( + &self, + target_node_ref: NodeRef, + data: Vec, + ) -> EyreResult> { + // Try to send data to the last socket we've seen this peer on + let Some(connection_descriptor) = target_node_ref.last_connection() else { + return Ok(NetworkResult::no_connection_other( + "Node is not reachable and has no existing connection", + )); + }; + + if self + .net() + .send_data_to_existing_connection(connection_descriptor, data) + .await? + .is_some() + { + return Ok(NetworkResult::no_connection_other( + "failed to send to existing connection", + )); + } + + // Update timestamp for this last connection since we just sent to it + target_node_ref.set_last_connection(connection_descriptor, get_aligned_timestamp()); + + Ok(NetworkResult::value(SendDataKind::Existing( + connection_descriptor, + ))) + } + /// Send data using NodeContactMethod::SignalReverse async fn send_data_ncm_signal_reverse( &self,