From 6590b76263d6fa7b99b57b8b1d1b07c6cd7919c5 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 19 May 2024 12:28:06 -0400 Subject: [PATCH] correctly handle local interface address changes closes #350 --- veilid-core/src/network_manager/native/mod.rs | 20 +++++++++++++++---- .../src/routing_table/tasks/bootstrap.rs | 6 +++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/veilid-core/src/network_manager/native/mod.rs b/veilid-core/src/network_manager/native/mod.rs index 728ce936..5b168292 100644 --- a/veilid-core/src/network_manager/native/mod.rs +++ b/veilid-core/src/network_manager/native/mod.rs @@ -109,6 +109,8 @@ struct NetworkInner { listener_states: BTreeMap>>, /// Preferred local addresses for protocols/address combinations for outgoing connections preferred_local_addresses: BTreeMap<(ProtocolType, AddressType), SocketAddr>, + /// The list of stable interface addresses we have last seen + stable_interface_addresses_at_startup: Vec, } struct NetworkUnlockedInner { @@ -155,6 +157,7 @@ impl Network { tls_acceptor: None, listener_states: BTreeMap::new(), preferred_local_addresses: BTreeMap::new(), + stable_interface_addresses_at_startup: Vec::new(), } } @@ -170,7 +173,7 @@ impl Network { connection_manager, interfaces: NetworkInterfaces::new(), update_network_class_task: TickTask::new(1), - network_interfaces_task: TickTask::new(5), + network_interfaces_task: TickTask::new(1), upnp_task: TickTask::new(1), igd_manager: igd_manager::IGDManager::new(config.clone()), } @@ -339,13 +342,14 @@ impl Network { pub fn get_stable_interface_addresses(&self) -> Vec { let addrs = self.unlocked_inner.interfaces.stable_addresses(); - let addrs: Vec = addrs + let mut addrs: Vec = addrs .into_iter() .filter(|addr| { let address = Address::from_ip_addr(*addr); address.is_local() || address.is_global() }) .collect(); + addrs.sort(); addrs } @@ -361,7 +365,11 @@ impl Network { return Ok(false); } - self.inner.lock().needs_public_dial_info_check = true; + let mut inner = self.inner.lock(); + let new_stable_interface_addresses = self.get_stable_interface_addresses(); + if new_stable_interface_addresses != inner.stable_interface_addresses_at_startup { + inner.network_needs_restart = true; + } Ok(true) } @@ -708,8 +716,11 @@ impl Network { // determine if we have ipv4/ipv6 addresses { let mut inner = self.inner.lock(); + + let stable_interface_addresses = self.get_stable_interface_addresses(); + inner.enable_ipv4 = false; - for addr in self.get_stable_interface_addresses() { + for addr in stable_interface_addresses.iter().copied() { if addr.is_ipv4() { log_net!(debug "enable address {:?} as ipv4", addr); inner.enable_ipv4 = true; @@ -724,6 +735,7 @@ impl Network { } } } + inner.stable_interface_addresses_at_startup = stable_interface_addresses; } // Build our protocol config to share it with other nodes diff --git a/veilid-core/src/routing_table/tasks/bootstrap.rs b/veilid-core/src/routing_table/tasks/bootstrap.rs index 3f8b9215..4b1ce1cd 100644 --- a/veilid-core/src/routing_table/tasks/bootstrap.rs +++ b/veilid-core/src/routing_table/tasks/bootstrap.rs @@ -287,9 +287,9 @@ impl RoutingTable { Ok(NodeContactMethod::Direct(v)) => v, Ok(v) => { log_rtab!(warn "invalid contact method for bootstrap, ignoring peer: {:?}", v); - let _ = routing_table - .network_manager() - .get_node_contact_method(nr.clone()); + // let _ = routing_table + // .network_manager() + // .get_node_contact_method(nr.clone()); return; } Err(e) => {