From d527c4c8e76b09b2a07c7d13e1464ed37d5daa30 Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 3 Mar 2023 17:17:23 -0500 Subject: [PATCH] xfer --- .vscode/launch.json | 16 +++++++++++--- veilid-core/src/routing_table/mod.rs | 12 +++++++--- .../src/routing_table/routing_table_inner.rs | 22 ++++++++++++++----- veilid-core/src/veilid_api/types.rs | 7 +++++- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1156a811..ca85eff4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,21 +9,31 @@ "request": "attach", "name": "Attach to veilid-server", "program": "${workspaceFolder}/target/debug/veilid-server", - "pid": "${command:pickMyProcess}" + "pid": "${command:pickMyProcess}", + "sourceLanguages": [ + "rust" + ] }, { "type": "lldb", "request": "attach", "name": "Attach to veilid-cli", "program": "${workspaceFolder}/target/debug/veilid-cli", - "pid": "${command:pickMyProcess}" + "pid": "${command:pickMyProcess}", + "sourceLanguages": [ + "rust" + ] }, { "type": "lldb", "request": "attach", "name": "Attach to veilid-flutter example", "program": "${workspaceFolder}/veilid-flutter/example/build/linux/x64/debug/bundle/veilid_example", - "pid": "${command:pickMyProcess}" + "pid": "${command:pickMyProcess}", + "sourceLanguages": [ + "rust", + "dart" + ] }, { "type": "lldb", diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index 746444c5..c72d1f67 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -344,11 +344,19 @@ impl RoutingTable { }; // Reconstruct all entries + let inner = &mut *self.inner.write(); + let mut all_entries: Vec> = Vec::with_capacity(all_entry_bytes.len()); for entry_bytes in all_entry_bytes { let entryinner = from_rkyv(entry_bytes).wrap_err("failed to deserialize bucket entry")?; - all_entries.push(Arc::new(BucketEntry::new_with_inner(entryinner))); + let entry = Arc::new(BucketEntry::new_with_inner(entryinner)); + + // Keep strong reference in table + all_entries.push(entry.clone()); + + // Keep all entries in weak table too + inner.all_entries.insert(entry); } // Validate serialized bucket map @@ -364,8 +372,6 @@ impl RoutingTable { } // Recreate buckets - let inner = &mut *self.inner.write(); - for (k, v) in serialized_bucket_map { let buckets = inner.buckets.get_mut(&k).unwrap(); diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index 39039f03..2da59280 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -413,17 +413,25 @@ impl RoutingTableInner { } /// Build the counts of entries per routing domain and crypto kind and cache them + /// Only considers entries that have valid signed node info pub fn refresh_cached_entry_counts(&mut self) -> EntryCounts { self.live_entry_count.clear(); let cur_ts = get_aligned_timestamp(); self.with_entries_mut(cur_ts, BucketEntryState::Unreliable, |rti, entry| { entry.with_inner(|e| { - if let Some(rd) = e.best_routing_domain(rti, RoutingDomainSet::all()) { - for crypto_kind in e.crypto_kinds() { - rti.live_entry_count - .entry((rd, crypto_kind)) - .and_modify(|x| *x += 1) - .or_insert(1); + // Tally per routing domain and crypto kind + for rd in RoutingDomain::all() { + if let Some(sni) = e.signed_node_info(rd) { + // Only consider entries that have valid signed node info in this domain + if sni.has_any_signature() { + // Tally + for crypto_kind in e.crypto_kinds() { + rti.live_entry_count + .entry((rd, crypto_kind)) + .and_modify(|x| *x += 1) + .or_insert(1); + } + } } } }); @@ -433,6 +441,7 @@ impl RoutingTableInner { } /// Return the last cached entry counts + /// Only considers entries that have valid signed node info pub fn cached_entry_counts(&self) -> EntryCounts { self.live_entry_count.clone() } @@ -681,6 +690,7 @@ impl RoutingTableInner { let bucket_entry = self.unlocked_inner.calculate_bucket_index(&first_node_id); let bucket = self.get_bucket_mut(bucket_entry); let new_entry = bucket.add_new_entry(first_node_id.value); + self.all_entries.insert(new_entry.clone()); self.unlocked_inner.kick_queue.lock().insert(bucket_entry); // Update the other bucket entries with the remaining node ids diff --git a/veilid-core/src/veilid_api/types.rs b/veilid-core/src/veilid_api/types.rs index 034e8aac..57bfd6d1 100644 --- a/veilid-core/src/veilid_api/types.rs +++ b/veilid-core/src/veilid_api/types.rs @@ -27,7 +27,6 @@ pub type ValueSeqNum = u32; /// FOURCC code #[derive( Copy, - Debug, Default, Clone, Hash, @@ -61,6 +60,12 @@ impl fmt::Display for FourCC { write!(f, "{}", String::from_utf8_lossy(&self.0)) } } +impl fmt::Debug for FourCC { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + write!(f, "{}", String::from_utf8_lossy(&self.0)) + } +} + impl FromStr for FourCC { type Err = VeilidAPIError; fn from_str(s: &str) -> Result {