This commit is contained in:
John Smith
2022-08-27 12:54:09 -04:00
parent 39ddb6534a
commit 4e8c1d5b4a
4 changed files with 94 additions and 37 deletions

View File

@@ -48,6 +48,10 @@ struct NetworkInner {
enable_ipv4: bool,
enable_ipv6_global: bool,
enable_ipv6_local: bool,
// public dial info check
needs_public_dial_info_check: bool,
doing_public_dial_info_check: bool,
public_dial_info_check_punishment: Option<Box<dyn FnOnce() + Send + 'static>>,
// udp
bound_first_udp: BTreeMap<u16, Option<(socket2::Socket, socket2::Socket)>>,
inbound_udp_protocol_handlers: BTreeMap<SocketAddr, RawUdpProtocolHandler>,
@@ -89,6 +93,9 @@ impl Network {
NetworkInner {
network_started: false,
network_needs_restart: false,
needs_public_dial_info_check: false,
doing_public_dial_info_check: false,
public_dial_info_check_punishment: None,
protocol_config: None,
static_public_dialinfo: ProtocolTypeSet::empty(),
network_class: None,
@@ -770,17 +777,30 @@ impl Network {
}
//////////////////////////////////////////
pub fn set_needs_public_dial_info_check(
&self,
punishment: Option<Box<dyn FnOnce() + Send + 'static>>,
) {
let mut inner = self.inner.lock();
inner.needs_public_dial_info_check = true;
inner.public_dial_info_check_punishment = punishment;
}
fn needs_public_dial_info_check(&self) -> bool {
let inner = self.inner.lock();
inner.needs_public_dial_info_check
}
pub fn doing_public_dial_info_check(&self) -> bool {
let inner = self.inner.lock();
inner.doing_public_dial_info_check
}
pub fn get_network_class(&self) -> Option<NetworkClass> {
let inner = self.inner.lock();
inner.network_class
}
#[instrument(level = "debug", skip_all)]
pub fn reset_network_class(&self) {
let mut inner = self.inner.lock();
inner.network_class = None;
}
//////////////////////////////////////////
#[instrument(level = "trace", skip(self), err)]
@@ -842,7 +862,8 @@ 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);
if network_class == NetworkClass::Invalid {
let needs_public_dial_info_check = self.needs_public_dial_info_check();
if network_class == NetworkClass::Invalid || needs_public_dial_info_check {
let routing_table = self.routing_table();
let rth = routing_table.get_routing_table_health();

View File

@@ -605,16 +605,13 @@ impl Network {
}
#[instrument(level = "trace", skip(self), err)]
pub async fn update_network_class_task_routine(
self,
pub async fn do_public_dial_info_check(
&self,
stop_token: StopToken,
_l: u64,
_t: u64,
) -> EyreResult<()> {
// Ensure we aren't trying to update this without clearing it first
let old_network_class = self.inner.lock().network_class;
assert_eq!(old_network_class, None);
// Figure out if we can optimize TCP/WS checking since they are often on the same port
let protocol_config = self.inner.lock().protocol_config.unwrap_or_default();
let tcp_same_port = if protocol_config.inbound.contains(ProtocolType::TCP)
&& protocol_config.inbound.contains(ProtocolType::WS)
@@ -823,6 +820,26 @@ impl Network {
network_manager.send_node_info_updates(true).await;
}
if !changed {}
Ok(())
}
#[instrument(level = "trace", skip(self), err)]
pub async fn update_network_class_task_routine(
self,
stop_token: StopToken,
l: u64,
t: u64,
) -> EyreResult<()> {
// Note that we are doing the public dial info check
self.inner.lock().doing_public_dial_info_check = true;
// Do the public dial info check
let out = self.do_public_dial_info_check(stop_token, l, t);
// Done with public dial info check
self.inner.lock().doing_public_dial_info_check = false;
out
}
}