don't error out

This commit is contained in:
John Smith 2021-12-07 21:55:45 -05:00
parent b77f0dbcec
commit 94a8a31b25

View File

@ -27,11 +27,12 @@ impl Network {
&self,
protocol_address_type: ProtocolAddressType,
ignore_node: Option<DHTKey>,
) -> 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