refactor for routing domains
This commit is contained in:
@@ -38,7 +38,7 @@ struct NetworkInner {
|
||||
network_needs_restart: bool,
|
||||
protocol_config: Option<ProtocolConfig>,
|
||||
static_public_dialinfo: ProtocolTypeSet,
|
||||
network_class: Option<NetworkClass>,
|
||||
network_class: [Option<NetworkClass>; RoutingDomain::count()],
|
||||
join_handles: Vec<MustJoinHandle<()>>,
|
||||
stop_source: Option<StopSource>,
|
||||
udp_port: u16,
|
||||
@@ -98,7 +98,7 @@ impl Network {
|
||||
public_dial_info_check_punishment: None,
|
||||
protocol_config: None,
|
||||
static_public_dialinfo: ProtocolTypeSet::empty(),
|
||||
network_class: None,
|
||||
network_class: [None, None],
|
||||
join_handles: Vec::new(),
|
||||
stop_source: None,
|
||||
udp_port: 0u16,
|
||||
@@ -715,7 +715,8 @@ impl Network {
|
||||
if !detect_address_changes {
|
||||
let mut inner = self.inner.lock();
|
||||
if !inner.static_public_dialinfo.is_empty() {
|
||||
inner.network_class = Some(NetworkClass::InboundCapable);
|
||||
inner.network_class[RoutingDomain::PublicInternet as usize] =
|
||||
Some(NetworkClass::InboundCapable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,9 +797,9 @@ impl Network {
|
||||
inner.doing_public_dial_info_check
|
||||
}
|
||||
|
||||
pub fn get_network_class(&self) -> Option<NetworkClass> {
|
||||
pub fn get_network_class(&self, routing_domain: RoutingDomain) -> Option<NetworkClass> {
|
||||
let inner = self.inner.lock();
|
||||
inner.network_class
|
||||
inner.network_class[routing_domain as usize]
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
@@ -861,9 +862,13 @@ impl Network {
|
||||
|
||||
// If we need to figure out our network class, tick the task for it
|
||||
if detect_address_changes {
|
||||
let network_class = self.get_network_class().unwrap_or(NetworkClass::Invalid);
|
||||
let public_internet_network_class = self
|
||||
.get_network_class(RoutingDomain::PublicInternet)
|
||||
.unwrap_or(NetworkClass::Invalid);
|
||||
let needs_public_dial_info_check = self.needs_public_dial_info_check();
|
||||
if network_class == NetworkClass::Invalid || needs_public_dial_info_check {
|
||||
if public_internet_network_class == NetworkClass::Invalid
|
||||
|| needs_public_dial_info_check
|
||||
{
|
||||
let routing_table = self.routing_table();
|
||||
let rth = routing_table.get_routing_table_health();
|
||||
|
||||
|
@@ -124,7 +124,7 @@ impl DiscoveryContext {
|
||||
let inbound_dial_info_entry_filter =
|
||||
RoutingTable::make_inbound_dial_info_entry_filter(dial_info_filter.clone());
|
||||
let disallow_relays_filter = move |e: &BucketEntryInner| {
|
||||
if let Some(n) = e.node_info() {
|
||||
if let Some(n) = e.node_info(RoutingDomain::PublicInternet) {
|
||||
n.relay_peer_info.is_none()
|
||||
} else {
|
||||
false
|
||||
@@ -583,7 +583,8 @@ impl Network {
|
||||
let (protocol_config, existing_network_class, tcp_same_port) = {
|
||||
let inner = self.inner.lock();
|
||||
let protocol_config = inner.protocol_config.unwrap_or_default();
|
||||
let existing_network_class = inner.network_class;
|
||||
let existing_network_class =
|
||||
inner.network_class[RoutingDomain::PublicInternet as usize];
|
||||
let tcp_same_port = if protocol_config.inbound.contains(ProtocolType::TCP)
|
||||
&& protocol_config.inbound.contains(ProtocolType::WS)
|
||||
{
|
||||
@@ -815,14 +816,15 @@ impl Network {
|
||||
|
||||
// Is the network class different?
|
||||
if existing_network_class != new_network_class {
|
||||
self.inner.lock().network_class = new_network_class;
|
||||
self.inner.lock().network_class[RoutingDomain::PublicInternet as usize] =
|
||||
new_network_class;
|
||||
changed = true;
|
||||
log_net!(debug "network class changed to {:?}", new_network_class);
|
||||
log_net!(debug "PublicInternet network class changed to {:?}", new_network_class);
|
||||
}
|
||||
} else if existing_network_class.is_some() {
|
||||
// Network class could not be determined
|
||||
routing_table.clear_dial_info_details(RoutingDomain::PublicInternet);
|
||||
self.inner.lock().network_class = None;
|
||||
self.inner.lock().network_class[RoutingDomain::PublicInternet as usize] = None;
|
||||
changed = true;
|
||||
log_net!(debug "network class cleared");
|
||||
}
|
||||
@@ -834,7 +836,9 @@ impl Network {
|
||||
}
|
||||
} else {
|
||||
// Send updates to everyone
|
||||
network_manager.send_node_info_updates(true).await;
|
||||
network_manager
|
||||
.send_node_info_updates(RoutingDomain::PublicInternet, true)
|
||||
.await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user