From 94a8a31b254aaab9a5691b627f693483956d2d1f Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 7 Dec 2021 21:55:45 -0500 Subject: [PATCH] don't error out --- .../network/public_dialinfo_discovery.rs | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/veilid-core/src/intf/native/network/public_dialinfo_discovery.rs b/veilid-core/src/intf/native/network/public_dialinfo_discovery.rs index 85d22117..9e651ff9 100644 --- a/veilid-core/src/intf/native/network/public_dialinfo_discovery.rs +++ b/veilid-core/src/intf/native/network/public_dialinfo_discovery.rs @@ -27,11 +27,12 @@ impl Network { &self, protocol_address_type: ProtocolAddressType, ignore_node: Option, - ) -> Result<(SocketAddr, NodeRef), String> { + ) -> Option<(SocketAddr, NodeRef)> { let routing_table = self.routing_table(); let peers = routing_table.get_fast_nodes_of_type(protocol_address_type); if peers.is_empty() { - return Err(format!("no peers of type '{:?}'", protocol_address_type)); + trace!("no peers of type '{:?}'", protocol_address_type); + return None; } for peer in peers { if let Some(ignore_node) = ignore_node { @@ -40,10 +41,11 @@ impl Network { } } if let Some(sa) = self.request_public_address(peer.clone()).await { - return Ok((sa, peer)); + return Some((sa, peer)); } } - Err("no peers responded with an external address".to_owned()) + trace!("no peers responded with an external address"); + None } fn get_interface_addresses( @@ -115,9 +117,16 @@ impl Network { // Loop for restricted NAT retries loop { // Get our external address from some fast node, call it node B - let (external1, node_b) = self + let (external1, node_b) = match self .discover_external_address(ProtocolAddressType::UDPv4, None) - .await?; + .await + { + None => { + // If we can't get an external address, exit but don't throw an error so we can try again later + return Ok(()); + } + Some(v) => v, + }; let external1_dial_info = DialInfo::udp_from_socketaddr(external1); // If our local interface list contains external1 then there is no NAT in place @@ -185,12 +194,19 @@ impl Network { // No, we are restricted, determine what kind of restriction // Get our external address from some fast node, that is not node B, call it node D - let (external2, node_d) = self + let (external2, node_d) = match self .discover_external_address( ProtocolAddressType::UDPv4, Some(node_b.node_id()), ) - .await?; + .await + { + None => { + // If we can't get an external address, exit but don't throw an error so we can try again later + return Ok(()); + } + Some(v) => v, + }; // If we have two different external addresses, then this is a symmetric NAT if external2 != external1 { // Symmetric NAT is outbound only, no public dial info will work