From 0589e6dc31053ef991feb60c1fdbdc5febf5595d Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 1 Apr 2024 14:34:12 -0400 Subject: [PATCH] add entries debug command filter by capability --- veilid-core/src/routing_table/debug.rs | 29 ++++++++++++++++++++++---- veilid-core/src/veilid_api/debug.rs | 14 ++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/veilid-core/src/routing_table/debug.rs b/veilid-core/src/routing_table/debug.rs index 3e2e02b3..86341f98 100644 --- a/veilid-core/src/routing_table/debug.rs +++ b/veilid-core/src/routing_table/debug.rs @@ -104,7 +104,11 @@ impl RoutingTable { out } - pub(crate) fn debug_info_entries(&self, min_state: BucketEntryState) -> String { + pub(crate) fn debug_info_entries( + &self, + min_state: BucketEntryState, + capabilities: Vec, + ) -> String { let inner = self.inner.read(); let inner = &*inner; let cur_ts = get_aligned_timestamp(); @@ -117,25 +121,30 @@ impl RoutingTable { let routing_domain = ec.0 .0; let crypto_kind = ec.0 .1; let count = ec.1; - out += &format!(" {:?}:{}: {}\n", routing_domain, crypto_kind, count); + out += &format!("{:?}: {}: {}\n", routing_domain, crypto_kind, count); } for ck in &VALID_CRYPTO_KINDS { + let mut filtered_total = 0; let mut b = 0; let blen = inner.buckets[ck].len(); while b < blen { let filtered_entries: Vec<(&PublicKey, &Arc)> = inner.buckets[ck][b] .entries() .filter(|e| { + let cap_match = e.1.with(inner, |_rti, e| { + e.has_capabilities(RoutingDomain::PublicInternet, &capabilities) + }); let state = e.1.with(inner, |_rti, e| e.state(cur_ts)); - state >= min_state + state >= min_state && cap_match }) .collect(); + filtered_total += filtered_entries.len(); if !filtered_entries.is_empty() { out += &format!("{} Bucket #{}:\n", ck, b); for e in filtered_entries { let state = e.1.with(inner, |_rti, e| e.state(cur_ts)); out += &format!( - " {} [{}] {}\n", + " {} [{}] {} [{}]\n", e.0.encode(), match state { BucketEntryState::Reliable => "R", @@ -153,12 +162,24 @@ impl RoutingTable { ) }) .unwrap_or_else(|| "???.??ms".to_string()) + }), + e.1.with(inner, |_rti, e| { + if let Some(ni) = e.node_info(RoutingDomain::PublicInternet) { + ni.capabilities() + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(",") + } else { + "???".to_owned() + } }) ); } } b += 1; } + out += &format!("{} Filtered Total: {}\n", ck, filtered_total); } out diff --git a/veilid-core/src/veilid_api/debug.rs b/veilid-core/src/veilid_api/debug.rs index ddd7b6cc..48b3fcc2 100644 --- a/veilid-core/src/veilid_api/debug.rs +++ b/veilid-core/src/veilid_api/debug.rs @@ -676,17 +676,24 @@ impl VeilidAPI { let args: Vec = args.split_whitespace().map(|s| s.to_owned()).collect(); let mut min_state = BucketEntryState::Unreliable; + let mut capabilities = vec![]; for arg in args { if let Some(ms) = get_bucket_entry_state(&arg) { min_state = ms; } else { - apibail_invalid_argument!("debug_entries", "unknown", arg); + for cap in arg.split(',') { + if let Ok(capfcc) = FourCC::from_str(cap) { + capabilities.push(capfcc); + } else { + apibail_invalid_argument!("debug_entries", "unknown", arg); + } + } } } // Dump routing table entries let routing_table = self.network_manager()?.routing_table(); - Ok(routing_table.debug_info_entries(min_state)) + Ok(routing_table.debug_info_entries(min_state, capabilities)) } async fn debug_entry(&self, args: String) -> VeilidAPIResult { @@ -1917,7 +1924,7 @@ impl VeilidAPI { Ok(r#"buckets [dead|reliable] dialinfo peerinfo [routingdomain] -entries [dead|reliable] +entries [dead|reliable] [] entry nodeinfo config [insecure] [configkey [new value]] @@ -1959,6 +1966,7 @@ record list -------------------------------------------------------------------- is: VLD0:GsgXCRPrzSK6oBNgxhNpm-rTYFd02R0ySx6j9vbQBG4 * also , , , + is: a list of FourCC codes: ROUT,SGNL,RLAY,DIAL,DHTV,DHTW,APPM etc. is: dot path like network.protocol.udp.enabled is: * direct: [+][]