2021-12-14 14:48:33 +00:00
|
|
|
use super::*;
|
2023-02-14 02:12:27 +00:00
|
|
|
use routing_table::tasks::bootstrap::BOOTSTRAP_TXT_VERSION_0;
|
2021-12-14 14:48:33 +00:00
|
|
|
|
|
|
|
impl RoutingTable {
|
2022-11-11 02:53:45 +00:00
|
|
|
pub(crate) async fn debug_info_txtrecord(&self) -> String {
|
2022-05-17 20:55:53 +00:00
|
|
|
let mut out = String::new();
|
|
|
|
|
|
|
|
let gdis = self.dial_info_details(RoutingDomain::PublicInternet);
|
|
|
|
if gdis.is_empty() {
|
|
|
|
out += "No TXT Record\n";
|
2022-05-16 15:52:48 +00:00
|
|
|
} else {
|
2022-05-28 14:07:57 +00:00
|
|
|
let mut short_urls = Vec::new();
|
|
|
|
let mut some_hostname = Option::<String>::None;
|
2022-05-17 20:55:53 +00:00
|
|
|
for gdi in gdis {
|
2022-05-28 14:07:57 +00:00
|
|
|
let (short_url, hostname) = gdi.dial_info.to_short().await;
|
|
|
|
if let Some(h) = &some_hostname {
|
|
|
|
if h != &hostname {
|
|
|
|
return format!(
|
|
|
|
"Inconsistent hostnames for dial info: {} vs {}",
|
|
|
|
some_hostname.unwrap(),
|
|
|
|
hostname
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
some_hostname = Some(hostname);
|
|
|
|
}
|
|
|
|
|
|
|
|
short_urls.push(short_url);
|
2022-05-16 15:52:48 +00:00
|
|
|
}
|
2022-05-28 14:07:57 +00:00
|
|
|
if some_hostname.is_none() || short_urls.is_empty() {
|
|
|
|
return "No dial info for bootstrap host".to_owned();
|
|
|
|
}
|
|
|
|
short_urls.sort();
|
|
|
|
short_urls.dedup();
|
2022-05-17 20:55:53 +00:00
|
|
|
|
2023-02-13 21:12:46 +00:00
|
|
|
let valid_envelope_versions = VALID_ENVELOPE_VERSIONS.map(|x| x.to_string()).join(",");
|
|
|
|
let node_ids = self
|
|
|
|
.unlocked_inner
|
|
|
|
.node_ids()
|
|
|
|
.iter()
|
|
|
|
.map(|x| x.to_string())
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
.join(",");
|
2022-05-28 14:07:57 +00:00
|
|
|
out += "TXT Record:\n";
|
|
|
|
out += &format!(
|
2023-02-13 21:12:46 +00:00
|
|
|
"{}|{}|{}|{}|",
|
2023-02-14 02:12:27 +00:00
|
|
|
BOOTSTRAP_TXT_VERSION_0,
|
2023-02-13 21:12:46 +00:00
|
|
|
valid_envelope_versions,
|
|
|
|
node_ids,
|
2022-05-28 14:07:57 +00:00
|
|
|
some_hostname.unwrap()
|
|
|
|
);
|
2023-05-29 19:24:57 +00:00
|
|
|
out += &short_urls.join(",");
|
2022-05-17 20:55:53 +00:00
|
|
|
out += "\n";
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
2022-05-17 20:55:53 +00:00
|
|
|
out
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
2022-05-17 20:55:53 +00:00
|
|
|
|
2023-05-29 19:24:57 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-11-11 02:53:45 +00:00
|
|
|
pub(crate) fn debug_info_dialinfo(&self) -> String {
|
2022-05-17 20:55:53 +00:00
|
|
|
let ldis = self.dial_info_details(RoutingDomain::LocalNetwork);
|
|
|
|
let gdis = self.dial_info_details(RoutingDomain::PublicInternet);
|
|
|
|
let mut out = String::new();
|
|
|
|
|
|
|
|
out += "Local Network Dial Info Details:\n";
|
|
|
|
for (n, ldi) in ldis.iter().enumerate() {
|
|
|
|
out += &format!(" {:>2}: {:?}\n", n, ldi);
|
|
|
|
}
|
|
|
|
out += "Public Internet Dial Info Details:\n";
|
|
|
|
for (n, gdi) in gdis.iter().enumerate() {
|
|
|
|
out += &format!(" {:>2}: {:?}\n", n, gdi);
|
|
|
|
}
|
2022-07-05 23:47:25 +00:00
|
|
|
|
2022-08-31 01:21:16 +00:00
|
|
|
out += "LocalNetwork PeerInfo:\n";
|
|
|
|
out += &format!(
|
|
|
|
" {:#?}\n",
|
|
|
|
self.get_own_peer_info(RoutingDomain::LocalNetwork)
|
|
|
|
);
|
|
|
|
|
|
|
|
out += "PublicInternet PeerInfo:\n";
|
|
|
|
out += &format!(
|
|
|
|
" {:#?}\n",
|
|
|
|
self.get_own_peer_info(RoutingDomain::PublicInternet)
|
|
|
|
);
|
2022-07-05 23:47:25 +00:00
|
|
|
|
2022-05-17 20:55:53 +00:00
|
|
|
out
|
|
|
|
}
|
|
|
|
|
2023-03-14 00:59:57 +00:00
|
|
|
pub(crate) fn debug_info_entries(&self, min_state: BucketEntryState) -> String {
|
2022-06-25 14:57:33 +00:00
|
|
|
let inner = self.inner.read();
|
2022-10-09 18:59:01 +00:00
|
|
|
let inner = &*inner;
|
2022-12-17 01:07:28 +00:00
|
|
|
let cur_ts = get_aligned_timestamp();
|
2021-12-14 14:48:33 +00:00
|
|
|
|
|
|
|
let mut out = String::new();
|
|
|
|
|
2023-02-14 02:12:27 +00:00
|
|
|
out += &format!("Entries: {}\n", inner.bucket_entry_count());
|
|
|
|
for ck in &VALID_CRYPTO_KINDS {
|
2023-03-14 00:59:57 +00:00
|
|
|
let mut b = 0;
|
2023-02-14 02:12:27 +00:00
|
|
|
let blen = inner.buckets[ck].len();
|
|
|
|
while b < blen {
|
|
|
|
let filtered_entries: Vec<(&PublicKey, &Arc<BucketEntry>)> = inner.buckets[ck][b]
|
|
|
|
.entries()
|
|
|
|
.filter(|e| {
|
|
|
|
let state = e.1.with(inner, |_rti, e| e.state(cur_ts));
|
|
|
|
state >= min_state
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
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!(
|
2023-05-29 19:24:57 +00:00
|
|
|
" {} [{}] {}\n",
|
2023-02-14 02:12:27 +00:00
|
|
|
e.0.encode(),
|
|
|
|
match state {
|
|
|
|
BucketEntryState::Reliable => "R",
|
|
|
|
BucketEntryState::Unreliable => "U",
|
|
|
|
BucketEntryState::Dead => "D",
|
2023-05-29 19:24:57 +00:00
|
|
|
},
|
|
|
|
e.1.with(inner, |_rti, e| {
|
|
|
|
e.peer_stats()
|
|
|
|
.latency
|
|
|
|
.as_ref()
|
|
|
|
.map(|l| {
|
|
|
|
format!(
|
|
|
|
"{:.2}ms",
|
|
|
|
timestamp_to_secs(l.average.as_u64()) * 1000.0
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| "???.??ms".to_string())
|
|
|
|
})
|
2023-02-14 02:12:27 +00:00
|
|
|
);
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-14 02:12:27 +00:00
|
|
|
b += 1;
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out
|
|
|
|
}
|
|
|
|
|
2023-02-26 03:02:13 +00:00
|
|
|
pub(crate) fn debug_info_entry(&self, node_ref: NodeRef) -> String {
|
2021-12-14 14:48:33 +00:00
|
|
|
let mut out = String::new();
|
2023-02-26 03:02:13 +00:00
|
|
|
out += &node_ref.operate(|_rt, e| format!("{:#?}\n", e));
|
2021-12-14 14:48:33 +00:00
|
|
|
out
|
|
|
|
}
|
|
|
|
|
2022-11-11 02:53:45 +00:00
|
|
|
pub(crate) fn debug_info_buckets(&self, min_state: BucketEntryState) -> String {
|
2022-06-25 14:57:33 +00:00
|
|
|
let inner = self.inner.read();
|
2022-10-09 18:59:01 +00:00
|
|
|
let inner = &*inner;
|
2022-12-17 01:07:28 +00:00
|
|
|
let cur_ts = get_aligned_timestamp();
|
2021-12-14 14:48:33 +00:00
|
|
|
|
|
|
|
let mut out = String::new();
|
|
|
|
const COLS: usize = 16;
|
|
|
|
out += "Buckets:\n";
|
2023-02-14 02:12:27 +00:00
|
|
|
for ck in &VALID_CRYPTO_KINDS {
|
2023-03-14 00:59:57 +00:00
|
|
|
out += &format!(" {}:\n", ck);
|
2023-02-14 02:12:27 +00:00
|
|
|
let rows = inner.buckets[ck].len() / COLS;
|
|
|
|
let mut r = 0;
|
|
|
|
let mut b = 0;
|
|
|
|
while r < rows {
|
|
|
|
let mut c = 0;
|
2023-03-14 00:59:57 +00:00
|
|
|
out += format!(" {:>3}: ", b).as_str();
|
2023-02-14 02:12:27 +00:00
|
|
|
while c < COLS {
|
|
|
|
let mut cnt = 0;
|
|
|
|
for e in inner.buckets[ck][b].entries() {
|
|
|
|
if e.1.with(inner, |_rti, e| e.state(cur_ts) >= min_state) {
|
|
|
|
cnt += 1;
|
|
|
|
}
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
2023-02-14 02:12:27 +00:00
|
|
|
out += format!("{:>3} ", cnt).as_str();
|
|
|
|
b += 1;
|
|
|
|
c += 1;
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
2023-02-14 02:12:27 +00:00
|
|
|
out += "\n";
|
|
|
|
r += 1;
|
2021-12-14 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out
|
|
|
|
}
|
|
|
|
}
|