From f59c4509ea7e0c0e8b1088138a6eb5297844b112 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 30 Sep 2023 22:42:06 -0400 Subject: [PATCH] rework public address detection timing --- veilid-core/src/network_manager/native/mod.rs | 21 +++++++++++++++---- veilid-core/src/routing_table/mod.rs | 4 +++- .../src/routing_table/routing_table_inner.rs | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/veilid-core/src/network_manager/native/mod.rs b/veilid-core/src/network_manager/native/mod.rs index 072bbdcc..ead28274 100644 --- a/veilid-core/src/network_manager/native/mod.rs +++ b/veilid-core/src/network_manager/native/mod.rs @@ -1017,14 +1017,27 @@ impl Network { let routing_table = self.routing_table(); let rth = routing_table.get_routing_table_health(); - // Need at least two entries to do this - if rth.unreliable_entry_count + rth.reliable_entry_count >= 2 { + // We want at least two live entries per crypto kind before we start doing this (bootstrap) + let mut has_at_least_two = true; + for ck in VALID_CRYPTO_KINDS { + if rth + .live_entry_counts + .get(&(RoutingDomain::PublicInternet, ck)) + .copied() + .unwrap_or_default() + < 2 + { + has_at_least_two = false; + break; + } + } + + if has_at_least_two { self.unlocked_inner.update_network_class_task.tick().await?; } } - // If we aren't resetting the network already, - // check our network interfaces to see if they have changed + // Check our network interfaces to see if they have changed if !self.needs_restart() { self.unlocked_inner.network_interfaces_task.tick().await?; } diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index 45823b14..2b7f9e6d 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -71,12 +71,14 @@ pub type SerializedBucketMap = BTreeMap; #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct RoutingTableHealth { - /// Number of reliable (responsive) entries in the routing table + /// Number of reliable (long-term responsive) entries in the routing table pub reliable_entry_count: usize, /// Number of unreliable (occasionally unresponsive) entries in the routing table pub unreliable_entry_count: usize, /// Number of dead (always unresponsive) entries in the routing table pub dead_entry_count: usize, + /// Number of live (responsive) entries in the routing table per RoutingDomain and CryptoKind + pub live_entry_counts: BTreeMap<(RoutingDomain, CryptoKind), usize>, /// If PublicInternet network class is valid yet pub public_internet_ready: bool, /// If LocalNetwork network class is valid yet diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index 0ec1224a..02b77754 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -925,10 +925,13 @@ impl RoutingTableInner { NetworkClass::Invalid ); + let live_entry_counts = self.cached_entry_counts(); + RoutingTableHealth { reliable_entry_count, unreliable_entry_count, dead_entry_count, + live_entry_counts, public_internet_ready, local_network_ready, }