This commit is contained in:
John Smith
2023-05-12 20:13:04 -04:00
parent ab2434dfd3
commit cb899b44ea
12 changed files with 448 additions and 68 deletions

View File

@@ -2,28 +2,6 @@ use super::*;
use routing_table::tasks::bootstrap::BOOTSTRAP_TXT_VERSION_0;
impl RoutingTable {
pub(crate) fn debug_info_nodeinfo(&self) -> String {
let mut out = String::new();
let inner = self.inner.read();
out += "Routing Table Info:\n";
out += &format!(" Node Ids: {}\n", self.unlocked_inner.node_ids());
out += &format!(
" Self Latency Stats Accounting: {:#?}\n\n",
inner.self_latency_stats_accounting
);
out += &format!(
" Self Transfer Stats Accounting: {:#?}\n\n",
inner.self_transfer_stats_accounting
);
out += &format!(
" Self Transfer Stats: {:#?}\n\n",
inner.self_transfer_stats
);
out
}
pub(crate) async fn debug_info_txtrecord(&self) -> String {
let mut out = String::new();
@@ -71,14 +49,34 @@ impl RoutingTable {
node_ids,
some_hostname.unwrap()
);
for short_url in short_urls {
out += &format!(",{}", short_url);
}
out += &short_urls.join(",");
out += "\n";
}
out
}
pub(crate) fn debug_info_nodeinfo(&self) -> String {
let mut out = String::new();
let inner = self.inner.read();
out += "Routing Table Info:\n";
out += &format!(" Node Ids: {}\n", self.unlocked_inner.node_ids());
out += &format!(
" Self Latency Stats Accounting: {:#?}\n\n",
inner.self_latency_stats_accounting
);
out += &format!(
" Self Transfer Stats Accounting: {:#?}\n\n",
inner.self_transfer_stats_accounting
);
out += &format!(
" Self Transfer Stats: {:#?}\n\n",
inner.self_transfer_stats
);
out
}
pub(crate) fn debug_info_dialinfo(&self) -> String {
let ldis = self.dial_info_details(RoutingDomain::LocalNetwork);
let gdis = self.dial_info_details(RoutingDomain::PublicInternet);

View File

@@ -115,7 +115,7 @@ impl RouteSpecStore {
dr
};
let update = VeilidUpdate::Route(VeilidStateRoute {
let update = VeilidUpdate::RouteChange(VeilidRouteChange {
dead_routes,
dead_remote_routes,
});

View File

@@ -0,0 +1,18 @@
use super::*;
impl StorageManager {
pub(crate) async fn debug_local_records(&self) -> String {
let inner = self.inner.lock().await;
let Some(local_record_store) = &inner.local_record_store else {
return "not initialized".to_owned();
};
local_record_store.debug_records()
}
pub(crate) async fn debug_remote_records(&self) -> String {
let inner = self.inner.lock().await;
let Some(remote_record_store) = &inner.remote_record_store else {
return "not initialized".to_owned();
};
remote_record_store.debug_records()
}
}

View File

@@ -1,3 +1,4 @@
mod debug;
mod get_value;
mod keys;
mod record_store;

View File

@@ -516,4 +516,35 @@ where
}
self.purge_dead_records(false).await;
}
pub(super) fn debug_records(&self) -> String {
// Dump fields in an abbreviated way
let mut out = String::new();
out += "Record Index:\n";
for (rik, rec) in &self.record_index {
out += &format!(
" {} @ {} len={}\n",
rik.key.to_string(),
rec.last_touched().as_u64(),
rec.record_data_size()
);
}
out += &format!("Subkey Cache Count: {}\n", self.subkey_cache.len());
out += &format!(
"Subkey Cache Total Size: {}\n",
self.subkey_cache_total_size
);
out += &format!("Total Storage Space: {}\n", self.total_storage_space);
out += &format!("Dead Records: {}\n", self.dead_records.len());
for dr in &self.dead_records {
out += &format!(" {}\n", dr.0.key.to_string());
}
out += &format!("Changed Records: {}\n", self.changed_records.len());
for cr in &self.changed_records {
out += &format!(" {}\n", cr.key.to_string());
}
out
}
}

View File

@@ -874,6 +874,39 @@ impl VeilidAPI {
}
}
async fn debug_record_list(&self, args: Vec<String>) -> Result<String, VeilidAPIError> {
// <local|remote>
let storage_manager = self.storage_manager()?;
let scope = get_debug_argument_at(&args, 1, "debug_record_list", "scope", get_string)?;
let out = match scope.as_str() {
"local" => {
let mut out = format!("Local Records:\n");
out += &storage_manager.debug_local_records().await;
out
}
"remote" => {
let mut out = format!("Remote Records:\n");
out += &storage_manager.debug_remote_records().await;
out
}
_ => "Invalid scope\n".to_owned(),
};
return Ok(out);
}
async fn debug_record(&self, args: String) -> Result<String, VeilidAPIError> {
let args: Vec<String> = args.split_whitespace().map(|s| s.to_owned()).collect();
let command = get_debug_argument_at(&args, 0, "debug_record", "command", get_string)?;
if command == "list" {
self.debug_record_list(args).await
} else {
Ok(">>> Unknown command\n".to_owned())
}
}
pub async fn debug_help(&self, _args: String) -> Result<String, VeilidAPIError> {
Ok(r#">>> Debug commands:
help
@@ -897,6 +930,7 @@ impl VeilidAPI {
list
import <blob>
test <route>
record list <local|remote>
<destination> is:
* direct: <node>[+<safety>][<modifiers>]
@@ -953,6 +987,8 @@ impl VeilidAPI {
self.debug_restart(rest).await
} else if arg == "route" {
self.debug_route(rest).await
} else if arg == "record" {
self.debug_record(rest).await
} else {
Err(VeilidAPIError::generic("Unknown debug command"))
}

View File

@@ -96,7 +96,7 @@ pub struct VeilidStateNetwork {
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize,
)]
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct VeilidStateRoute {
pub struct VeilidRouteChange {
pub dead_routes: Vec<RouteId>,
pub dead_remote_routes: Vec<RouteId>,
}
@@ -130,7 +130,7 @@ pub enum VeilidUpdate {
Attachment(VeilidStateAttachment),
Network(VeilidStateNetwork),
Config(VeilidStateConfig),
Route(VeilidStateRoute),
RouteChange(VeilidRouteChange),
ValueChange(VeilidValueChange),
Shutdown,
}