fix bugs and lints
This commit is contained in:
@@ -487,11 +487,11 @@ impl Network {
|
||||
//////////////////////////////////////////
|
||||
pub fn get_network_class(&self) -> Option<NetworkClass> {
|
||||
let inner = self.inner.lock();
|
||||
return inner.network_class;
|
||||
inner.network_class
|
||||
}
|
||||
|
||||
pub fn reset_network_class(&self) {
|
||||
let inner = self.inner.lock();
|
||||
let mut inner = self.inner.lock();
|
||||
inner.network_class = None;
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ struct DiscoveryContextInner {
|
||||
node_b: Option<NodeRef>,
|
||||
}
|
||||
|
||||
struct DiscoveryContext {
|
||||
pub struct DiscoveryContext {
|
||||
routing_table: RoutingTable,
|
||||
net: Network,
|
||||
inner: Arc<Mutex<DiscoveryContextInner>>,
|
||||
@@ -43,10 +43,10 @@ impl DiscoveryContext {
|
||||
|
||||
///////
|
||||
// Utilities
|
||||
xxxx continue converting to async safe inner
|
||||
|
||||
// Pick the best network class we have seen so far
|
||||
pub fn upgrade_network_class(&self, network_class: NetworkClass) {
|
||||
let inner = self.inner.lock();
|
||||
let mut inner = self.inner.lock();
|
||||
|
||||
if let Some(old_nc) = inner.network_class {
|
||||
if network_class < old_nc {
|
||||
@@ -137,7 +137,7 @@ xxxx continue converting to async safe inner
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
async fn try_port_mapping(&mut self) -> Option<DialInfo> {
|
||||
async fn try_port_mapping(&self) -> Option<DialInfo> {
|
||||
//xxx
|
||||
None
|
||||
}
|
||||
@@ -161,25 +161,30 @@ xxxx continue converting to async safe inner
|
||||
///////
|
||||
// Per-protocol discovery routines
|
||||
|
||||
pub fn protocol_begin(&mut self, protocol_type: ProtocolType, address_type: AddressType) {
|
||||
pub fn protocol_begin(&self, protocol_type: ProtocolType, address_type: AddressType) {
|
||||
// Get our interface addresses
|
||||
self.intf_addrs = Some(self.get_local_addresses(protocol_type, address_type));
|
||||
self.protocol_type = Some(protocol_type);
|
||||
self.address_type = Some(address_type);
|
||||
self.low_level_protocol_type = Some(match protocol_type {
|
||||
let intf_addrs = self.get_local_addresses(protocol_type, address_type);
|
||||
|
||||
let mut inner = self.inner.lock();
|
||||
inner.intf_addrs = Some(intf_addrs);
|
||||
inner.protocol_type = Some(protocol_type);
|
||||
inner.address_type = Some(address_type);
|
||||
inner.low_level_protocol_type = Some(match protocol_type {
|
||||
ProtocolType::UDP => ProtocolType::UDP,
|
||||
ProtocolType::TCP => ProtocolType::TCP,
|
||||
ProtocolType::WS => ProtocolType::TCP,
|
||||
ProtocolType::WSS => ProtocolType::TCP,
|
||||
});
|
||||
self.external1_dial_info = None;
|
||||
self.external1 = None;
|
||||
self.node_b = None;
|
||||
inner.external1_dial_info = None;
|
||||
inner.external1 = None;
|
||||
inner.node_b = None;
|
||||
}
|
||||
|
||||
pub async fn protocol_get_external_address_1(&mut self) -> bool {
|
||||
let protocol_type = self.protocol_type.unwrap();
|
||||
let address_type = self.address_type.unwrap();
|
||||
pub async fn protocol_get_external_address_1(&self) -> bool {
|
||||
let (protocol_type, address_type) = {
|
||||
let inner = self.inner.lock();
|
||||
(inner.protocol_type.unwrap(), inner.address_type.unwrap())
|
||||
};
|
||||
|
||||
// Get our external address from some fast node, call it node B
|
||||
let (external1, node_b) = match self
|
||||
@@ -194,20 +199,22 @@ xxxx continue converting to async safe inner
|
||||
};
|
||||
let external1_dial_info = self.make_dial_info(external1, protocol_type);
|
||||
|
||||
self.external1_dial_info = Some(external1_dial_info);
|
||||
self.external1 = Some(external1);
|
||||
self.node_b = Some(node_b);
|
||||
let mut inner = self.inner.lock();
|
||||
inner.external1_dial_info = Some(external1_dial_info);
|
||||
inner.external1 = Some(external1);
|
||||
inner.node_b = Some(node_b);
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
pub async fn protocol_process_no_nat(&mut self) {
|
||||
let node_b = self.node_b.as_ref().unwrap().clone();
|
||||
let external1_dial_info = self.external1_dial_info.as_ref().unwrap().clone();
|
||||
let external1 = self.external1.unwrap();
|
||||
let protocol_type = self.protocol_type.unwrap();
|
||||
let address_type = self.address_type.unwrap();
|
||||
let intf_addrs = self.intf_addrs.as_ref().unwrap();
|
||||
pub async fn protocol_process_no_nat(&self) {
|
||||
let (node_b, external1_dial_info) = {
|
||||
let inner = self.inner.lock();
|
||||
(
|
||||
inner.node_b.as_ref().unwrap().clone(),
|
||||
inner.external1_dial_info.as_ref().unwrap().clone(),
|
||||
)
|
||||
};
|
||||
|
||||
// Do a validate_dial_info on the external address from a redirected node
|
||||
if self
|
||||
@@ -240,13 +247,17 @@ xxxx continue converting to async safe inner
|
||||
self.upgrade_network_class(NetworkClass::InboundCapable);
|
||||
}
|
||||
|
||||
pub async fn protocol_process_nat(&mut self) -> bool {
|
||||
let node_b = self.node_b.as_ref().unwrap().clone();
|
||||
let external1_dial_info = self.external1_dial_info.as_ref().unwrap().clone();
|
||||
let external1 = self.external1.unwrap();
|
||||
let protocol_type = self.protocol_type.unwrap();
|
||||
let address_type = self.address_type.unwrap();
|
||||
let intf_addrs = self.intf_addrs.as_ref().unwrap();
|
||||
pub async fn protocol_process_nat(&self) -> bool {
|
||||
let (node_b, external1_dial_info, external1, protocol_type, address_type) = {
|
||||
let inner = self.inner.lock();
|
||||
(
|
||||
inner.node_b.as_ref().unwrap().clone(),
|
||||
inner.external1_dial_info.as_ref().unwrap().clone(),
|
||||
inner.external1.unwrap(),
|
||||
inner.protocol_type.unwrap(),
|
||||
inner.address_type.unwrap(),
|
||||
)
|
||||
};
|
||||
|
||||
// Attempt a UDP port mapping via all available and enabled mechanisms
|
||||
if let Some(external_mapped_dial_info) = self.try_port_mapping().await {
|
||||
@@ -337,7 +348,7 @@ xxxx continue converting to async safe inner
|
||||
impl Network {
|
||||
pub async fn update_ipv4_protocol_dialinfo(
|
||||
&self,
|
||||
context: &mut DiscoveryContext,
|
||||
context: &DiscoveryContext,
|
||||
protocol_type: ProtocolType,
|
||||
) -> Result<(), String> {
|
||||
let mut retry_count = {
|
||||
@@ -357,17 +368,22 @@ impl Network {
|
||||
}
|
||||
|
||||
// If our local interface list contains external1 then there is no NAT in place
|
||||
if context
|
||||
.intf_addrs
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains(&context.external1.as_ref().unwrap())
|
||||
{
|
||||
// No NAT
|
||||
context.protocol_process_no_nat().await;
|
||||
let res = {
|
||||
let inner = context.inner.lock();
|
||||
inner
|
||||
.intf_addrs
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains(inner.external1.as_ref().unwrap())
|
||||
};
|
||||
if res {
|
||||
// No NAT
|
||||
context.protocol_process_no_nat().await;
|
||||
|
||||
// No more retries
|
||||
break;
|
||||
// No more retries
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// There is -some NAT-
|
||||
@@ -388,7 +404,7 @@ impl Network {
|
||||
|
||||
pub async fn update_ipv6_protocol_dialinfo(
|
||||
&self,
|
||||
context: &mut DiscoveryContext,
|
||||
context: &DiscoveryContext,
|
||||
protocol_type: ProtocolType,
|
||||
) -> Result<(), String> {
|
||||
// Start doing ipv6 protocol
|
||||
@@ -401,18 +417,21 @@ impl Network {
|
||||
}
|
||||
|
||||
// If our local interface list doesn't contain external1 then there is an Ipv6 NAT in place
|
||||
if !context
|
||||
.intf_addrs
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains(&context.external1.as_ref().unwrap())
|
||||
{
|
||||
// IPv6 NAT is not supported today
|
||||
log_net!(warn
|
||||
"IPv6 NAT is not supported for external address: {}",
|
||||
context.external1.unwrap()
|
||||
);
|
||||
return Ok(());
|
||||
let inner = context.inner.lock();
|
||||
if !inner
|
||||
.intf_addrs
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains(inner.external1.as_ref().unwrap())
|
||||
{
|
||||
// IPv6 NAT is not supported today
|
||||
log_net!(warn
|
||||
"IPv6 NAT is not supported for external address: {}",
|
||||
inner.external1.unwrap()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// No NAT
|
||||
@@ -424,37 +443,32 @@ impl Network {
|
||||
pub async fn update_network_class_task_routine(self, _l: u64, _t: u64) -> Result<(), String> {
|
||||
log_net!("updating network class");
|
||||
|
||||
let protocol_config = self
|
||||
.inner
|
||||
.lock()
|
||||
.protocol_config
|
||||
.clone()
|
||||
.unwrap_or_default();
|
||||
let protocol_config = self.inner.lock().protocol_config.unwrap_or_default();
|
||||
|
||||
let context = DiscoveryContext::new(self.routing_table(), self.clone());
|
||||
|
||||
if protocol_config.inbound.contains(ProtocolType::UDP) {
|
||||
self.update_ipv4_protocol_dialinfo(&mut context, ProtocolType::UDP)
|
||||
self.update_ipv4_protocol_dialinfo(&context, ProtocolType::UDP)
|
||||
.await?;
|
||||
self.update_ipv6_protocol_dialinfo(&mut context, ProtocolType::UDP)
|
||||
self.update_ipv6_protocol_dialinfo(&context, ProtocolType::UDP)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if protocol_config.inbound.contains(ProtocolType::TCP) {
|
||||
self.update_ipv4_protocol_dialinfo(&mut context, ProtocolType::TCP)
|
||||
self.update_ipv4_protocol_dialinfo(&context, ProtocolType::TCP)
|
||||
.await?;
|
||||
self.update_ipv6_protocol_dialinfo(&mut context, ProtocolType::TCP)
|
||||
self.update_ipv6_protocol_dialinfo(&context, ProtocolType::TCP)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if protocol_config.inbound.contains(ProtocolType::WS) {
|
||||
self.update_ipv4_protocol_dialinfo(&mut context, ProtocolType::WS)
|
||||
self.update_ipv4_protocol_dialinfo(&context, ProtocolType::WS)
|
||||
.await?;
|
||||
self.update_ipv6_protocol_dialinfo(&mut context, ProtocolType::WS)
|
||||
self.update_ipv6_protocol_dialinfo(&context, ProtocolType::WS)
|
||||
.await?;
|
||||
}
|
||||
|
||||
self.inner.lock().network_class = context.network_class;
|
||||
self.inner.lock().network_class = context.inner.lock().network_class;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -331,17 +331,16 @@ impl Network {
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
if !local_dial_info_list.contains(&pdi)
|
||||
&& self.with_interface_addresses(|ip_addrs| {
|
||||
for ip_addr in ip_addrs {
|
||||
if pdi_addr.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
// 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| {
|
||||
for ip_addr in ip_addrs {
|
||||
if pdi_addr.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
{
|
||||
}
|
||||
false
|
||||
});
|
||||
if !local_dial_info_list.contains(&pdi) && is_interface_address {
|
||||
routing_table.register_dial_info(
|
||||
RoutingDomain::LocalNetwork,
|
||||
DialInfo::udp_from_socketaddr(pdi_addr),
|
||||
@@ -432,16 +431,15 @@ impl Network {
|
||||
static_public = true;
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
if !registered_addresses.contains(&gsa.ip())
|
||||
&& self.with_interface_addresses(|ip_addrs| {
|
||||
for ip_addr in ip_addrs {
|
||||
if gsa.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
|
||||
for ip_addr in ip_addrs {
|
||||
if gsa.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
{
|
||||
}
|
||||
false
|
||||
});
|
||||
if !registered_addresses.contains(&gsa.ip()) && is_interface_address {
|
||||
routing_table.register_dial_info(
|
||||
RoutingDomain::LocalNetwork,
|
||||
pdi,
|
||||
@@ -496,12 +494,11 @@ impl Network {
|
||||
trace!("starting wss listeners");
|
||||
|
||||
let routing_table = self.routing_table();
|
||||
let (listen_address, url, enable_local_peer_scope) = {
|
||||
let (listen_address, url) = {
|
||||
let c = self.config.get();
|
||||
(
|
||||
c.network.protocol.wss.listen_address.clone(),
|
||||
c.network.protocol.wss.url.clone(),
|
||||
c.network.enable_local_peer_scope,
|
||||
)
|
||||
};
|
||||
|
||||
@@ -566,16 +563,15 @@ impl Network {
|
||||
static_public = true;
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
if !registered_addresses.contains(&gsa.ip())
|
||||
&& self.with_interface_addresses(|ip_addrs| {
|
||||
for ip_addr in ip_addrs {
|
||||
if gsa.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
|
||||
for ip_addr in ip_addrs {
|
||||
if gsa.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
{
|
||||
}
|
||||
false
|
||||
});
|
||||
if !registered_addresses.contains(&gsa.ip()) && is_interface_address {
|
||||
routing_table.register_dial_info(
|
||||
RoutingDomain::LocalNetwork,
|
||||
pdi,
|
||||
@@ -683,22 +679,21 @@ impl Network {
|
||||
static_public = true;
|
||||
|
||||
// See if this public address is also a local interface address
|
||||
if self.with_interface_addresses(|ip_addrs| {
|
||||
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
|
||||
for ip_addr in ip_addrs {
|
||||
if pdi_addr.ip() == *ip_addr {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}) {
|
||||
});
|
||||
if is_interface_address {
|
||||
routing_table.register_dial_info(
|
||||
RoutingDomain::LocalNetwork,
|
||||
pdi,
|
||||
DialInfoClass::Direct,
|
||||
);
|
||||
}
|
||||
|
||||
static_public = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user