bugfixes and public ip change detection
This commit is contained in:
@@ -207,7 +207,7 @@ impl DiscoveryContext {
|
||||
true
|
||||
}
|
||||
|
||||
pub async fn protocol_process_no_nat(&self) {
|
||||
pub async fn protocol_process_no_nat(&self) -> Result<(), String> {
|
||||
let (node_b, external1_dial_info) = {
|
||||
let inner = self.inner.lock();
|
||||
(
|
||||
@@ -226,7 +226,7 @@ impl DiscoveryContext {
|
||||
RoutingDomain::PublicInternet,
|
||||
external1_dial_info,
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
// Attempt a UDP port mapping via all available and enabled mechanisms
|
||||
else if let Some(external_mapped_dial_info) = self.try_port_mapping().await {
|
||||
@@ -235,19 +235,20 @@ impl DiscoveryContext {
|
||||
RoutingDomain::PublicInternet,
|
||||
external_mapped_dial_info,
|
||||
DialInfoClass::Mapped,
|
||||
);
|
||||
)?;
|
||||
} else {
|
||||
// Add public dial info with Blocked dialinfo class
|
||||
self.routing_table.register_dial_info(
|
||||
RoutingDomain::PublicInternet,
|
||||
external1_dial_info,
|
||||
DialInfoClass::Blocked,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
self.upgrade_network_class(NetworkClass::InboundCapable);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn protocol_process_nat(&self) -> bool {
|
||||
pub async fn protocol_process_nat(&self) -> Result<bool, String> {
|
||||
let (node_b, external1_dial_info, external1, protocol_type, address_type) = {
|
||||
let inner = self.inner.lock();
|
||||
(
|
||||
@@ -266,11 +267,11 @@ impl DiscoveryContext {
|
||||
RoutingDomain::PublicInternet,
|
||||
external_mapped_dial_info,
|
||||
DialInfoClass::Mapped,
|
||||
);
|
||||
)?;
|
||||
self.upgrade_network_class(NetworkClass::InboundCapable);
|
||||
|
||||
// No more retries
|
||||
return true;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// Port mapping was not possible, let's see what kind of NAT we have
|
||||
@@ -286,10 +287,10 @@ impl DiscoveryContext {
|
||||
RoutingDomain::PublicInternet,
|
||||
external1_dial_info,
|
||||
DialInfoClass::FullConeNAT,
|
||||
);
|
||||
)?;
|
||||
self.upgrade_network_class(NetworkClass::InboundCapable);
|
||||
|
||||
return true;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// No, we are restricted, determine what kind of restriction
|
||||
@@ -301,7 +302,7 @@ impl DiscoveryContext {
|
||||
{
|
||||
None => {
|
||||
// If we can't get an external address, allow retry
|
||||
return false;
|
||||
return Ok(false);
|
||||
}
|
||||
Some(v) => v,
|
||||
};
|
||||
@@ -312,7 +313,7 @@ impl DiscoveryContext {
|
||||
self.upgrade_network_class(NetworkClass::OutboundOnly);
|
||||
|
||||
// No more retries
|
||||
return true;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// If we're going to end up as a restricted NAT of some sort
|
||||
@@ -329,19 +330,19 @@ impl DiscoveryContext {
|
||||
RoutingDomain::PublicInternet,
|
||||
external1_dial_info,
|
||||
DialInfoClass::AddressRestrictedNAT,
|
||||
);
|
||||
)?;
|
||||
} else {
|
||||
// Didn't get a reply from a non-default port, which means we are also port restricted
|
||||
self.routing_table.register_dial_info(
|
||||
RoutingDomain::PublicInternet,
|
||||
external1_dial_info,
|
||||
DialInfoClass::PortRestrictedNAT,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
self.upgrade_network_class(NetworkClass::InboundCapable);
|
||||
|
||||
// Allow another retry because sometimes trying again will get us Full Cone NAT instead
|
||||
false
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +380,7 @@ impl Network {
|
||||
};
|
||||
if res {
|
||||
// No NAT
|
||||
context.protocol_process_no_nat().await;
|
||||
context.protocol_process_no_nat().await?;
|
||||
|
||||
// No more retries
|
||||
break;
|
||||
@@ -387,7 +388,7 @@ impl Network {
|
||||
}
|
||||
|
||||
// There is -some NAT-
|
||||
if context.protocol_process_nat().await {
|
||||
if context.protocol_process_nat().await? {
|
||||
// We either got dial info or a network class without one
|
||||
break;
|
||||
}
|
||||
@@ -435,7 +436,7 @@ impl Network {
|
||||
}
|
||||
|
||||
// No NAT
|
||||
context.protocol_process_no_nat().await;
|
||||
context.protocol_process_no_nat().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -237,7 +237,7 @@ impl WebsocketProtocolHandler {
|
||||
if tls {
|
||||
let connector = TlsConnector::default();
|
||||
let tls_stream = connector
|
||||
.connect(domain, tcp_stream)
|
||||
.connect(domain.to_string(), tcp_stream)
|
||||
.await
|
||||
.map_err(map_to_string)
|
||||
.map_err(logthru_net!(error))?;
|
||||
|
@@ -300,7 +300,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
di.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
static_public = true;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
di.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
// Add static public dialinfo if it's configured
|
||||
@@ -329,7 +329,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
pdi.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
|
||||
// See if this public address is also a local interface address we haven't registered yet
|
||||
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
|
||||
@@ -345,7 +345,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
DialInfo::udp_from_socketaddr(pdi_addr),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
static_public = true;
|
||||
@@ -412,7 +412,7 @@ impl Network {
|
||||
|
||||
// Resolve static public hostnames
|
||||
let global_socket_addrs = split_url
|
||||
.host
|
||||
.host_port(80)
|
||||
.to_socket_addrs()
|
||||
.await
|
||||
.map_err(map_to_string)
|
||||
@@ -427,7 +427,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
pdi.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
static_public = true;
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
@@ -444,7 +444,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
pdi,
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
registered_addresses.insert(gsa.ip());
|
||||
@@ -468,7 +468,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
local_di.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
static_public = true;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
local_di,
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
if static_public {
|
||||
@@ -544,7 +544,7 @@ impl Network {
|
||||
|
||||
// Resolve static public hostnames
|
||||
let global_socket_addrs = split_url
|
||||
.host
|
||||
.host_port(443)
|
||||
.to_socket_addrs()
|
||||
.await
|
||||
.map_err(map_to_string)
|
||||
@@ -559,7 +559,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
pdi.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
static_public = true;
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
@@ -576,7 +576,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
pdi,
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
registered_addresses.insert(gsa.ip());
|
||||
@@ -643,7 +643,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
di.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
static_public = true;
|
||||
}
|
||||
// Register interface dial info
|
||||
@@ -651,7 +651,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
di.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
registered_addresses.insert(socket_address.to_ip_addr());
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ impl Network {
|
||||
RoutingDomain::PublicInternet,
|
||||
pdi.clone(),
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
static_public = true;
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
@@ -692,7 +692,7 @@ impl Network {
|
||||
RoutingDomain::LocalNetwork,
|
||||
pdi,
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user