debugging
This commit is contained in:
@@ -38,6 +38,7 @@ pub struct BucketEntry {
|
||||
|
||||
impl BucketEntry {
|
||||
pub(super) fn new() -> Self {
|
||||
let now = get_timestamp();
|
||||
Self {
|
||||
ref_count: 0,
|
||||
min_max_version: None,
|
||||
@@ -45,7 +46,7 @@ impl BucketEntry {
|
||||
dial_info_entries: VecDeque::new(),
|
||||
stats_accounting: StatsAccounting::new(),
|
||||
peer_stats: PeerStats {
|
||||
time_added: get_timestamp(),
|
||||
time_added: now,
|
||||
last_seen: None,
|
||||
ping_stats: PingStats::default(),
|
||||
latency: None,
|
||||
@@ -250,8 +251,9 @@ impl BucketEntry {
|
||||
}
|
||||
pub(super) fn check_dead(&self, cur_ts: u64) -> bool {
|
||||
// if we have not heard from the node at all for the duration of the unreliable ping span
|
||||
// a node is not dead if we haven't heard from it yet
|
||||
match self.peer_stats.last_seen {
|
||||
None => true,
|
||||
None => false,
|
||||
Some(ts) => {
|
||||
cur_ts.saturating_sub(ts) >= (UNRELIABLE_PING_SPAN_SECS as u64 * 1000000u64)
|
||||
}
|
||||
@@ -353,6 +355,11 @@ impl BucketEntry {
|
||||
self.stats_accounting.add_up(bytes);
|
||||
self.peer_stats.ping_stats.in_flight += 1;
|
||||
self.peer_stats.ping_stats.last_pinged = Some(ts);
|
||||
// if we haven't heard from this node yet and it's our first attempt at contacting it
|
||||
// then we set the last_seen time
|
||||
if self.peer_stats.last_seen.is_none() {
|
||||
self.peer_stats.last_seen = Some(ts);
|
||||
}
|
||||
}
|
||||
pub(super) fn ping_rcvd(&mut self, ts: u64, bytes: u64) {
|
||||
self.stats_accounting.add_down(bytes);
|
||||
@@ -383,8 +390,13 @@ impl BucketEntry {
|
||||
self.peer_stats.ping_stats.consecutive_pongs = 0;
|
||||
self.peer_stats.ping_stats.first_consecutive_pong_time = None;
|
||||
}
|
||||
pub(super) fn question_sent(&mut self, _ts: u64, bytes: u64) {
|
||||
pub(super) fn question_sent(&mut self, ts: u64, bytes: u64) {
|
||||
self.stats_accounting.add_up(bytes);
|
||||
// if we haven't heard from this node yet and it's our first attempt at contacting it
|
||||
// then we set the last_seen time
|
||||
if self.peer_stats.last_seen.is_none() {
|
||||
self.peer_stats.last_seen = Some(ts);
|
||||
}
|
||||
}
|
||||
pub(super) fn question_rcvd(&mut self, ts: u64, bytes: u64) {
|
||||
self.stats_accounting.add_down(bytes);
|
||||
|
114
veilid-core/src/routing_table/debug.rs
Normal file
114
veilid-core/src/routing_table/debug.rs
Normal file
@@ -0,0 +1,114 @@
|
||||
use super::*;
|
||||
|
||||
impl RoutingTable {
|
||||
pub fn debug_info_nodeinfo(&self) -> String {
|
||||
let mut out = String::new();
|
||||
let inner = self.inner.lock();
|
||||
out += "Routing Table Info:\n";
|
||||
|
||||
out += &format!(" Node Id: {}\n", inner.node_id.encode());
|
||||
out += &format!(" Stats Accounting: {:#?}\n\n", inner.stats_accounting);
|
||||
out += &format!(" Transfer Stats: {:#?}\n\n", inner.transfer_stats);
|
||||
|
||||
out
|
||||
}
|
||||
pub fn debug_info_dialinfo(&self) -> String {
|
||||
let ldis = self.local_dial_info();
|
||||
let gdis = self.global_dial_info();
|
||||
let mut out = String::new();
|
||||
|
||||
out += "Local Dial Info:\n";
|
||||
for (n, ldi) in ldis.iter().enumerate() {
|
||||
out += &format!(" {:>2}: {:?}\n", n, ldi);
|
||||
}
|
||||
out += "Global Dial Info:\n";
|
||||
for (n, gdi) in gdis.iter().enumerate() {
|
||||
out += &format!(" {:>2}: {:?}\n", n, gdi);
|
||||
}
|
||||
out
|
||||
}
|
||||
pub fn debug_info_entries(&self, limit: usize, min_state: BucketEntryState) -> String {
|
||||
let inner = self.inner.lock();
|
||||
let cur_ts = get_timestamp();
|
||||
|
||||
let mut out = String::new();
|
||||
|
||||
let blen = inner.buckets.len();
|
||||
let mut b = 0;
|
||||
let mut cnt = 0;
|
||||
out += &format!("Entries: {}\n", inner.bucket_entry_count);
|
||||
while b < blen {
|
||||
if inner.buckets[b].entries().len() > 0 {
|
||||
out += &format!(" Bucket #{}:\n", b);
|
||||
for e in inner.buckets[b].entries() {
|
||||
let state = e.1.state(cur_ts);
|
||||
if state >= min_state {
|
||||
out += &format!(
|
||||
" {} [{}]\n",
|
||||
e.0.encode(),
|
||||
match state {
|
||||
BucketEntryState::Reliable => "R",
|
||||
BucketEntryState::Unreliable => "U",
|
||||
BucketEntryState::Dead => "D",
|
||||
}
|
||||
);
|
||||
|
||||
cnt += 1;
|
||||
if cnt >= limit {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if cnt >= limit {
|
||||
break;
|
||||
}
|
||||
}
|
||||
b += 1;
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn debug_info_entry(&self, node_id: DHTKey) -> String {
|
||||
let mut out = String::new();
|
||||
out += &format!("Entry {:?}:\n", node_id);
|
||||
if let Some(nr) = self.lookup_node_ref(node_id) {
|
||||
out += &nr.operate(|e| format!("{:#?}\n", e));
|
||||
} else {
|
||||
out += "Entry not found\n";
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn debug_info_buckets(&self, min_state: BucketEntryState) -> String {
|
||||
let inner = self.inner.lock();
|
||||
let cur_ts = get_timestamp();
|
||||
|
||||
let mut out = String::new();
|
||||
const COLS: usize = 16;
|
||||
let rows = inner.buckets.len() / COLS;
|
||||
let mut r = 0;
|
||||
let mut b = 0;
|
||||
out += "Buckets:\n";
|
||||
while r < rows {
|
||||
let mut c = 0;
|
||||
out += format!(" {:>3}: ", b).as_str();
|
||||
while c < COLS {
|
||||
let mut cnt = 0;
|
||||
for e in inner.buckets[b].entries() {
|
||||
if e.1.state(cur_ts) >= min_state {
|
||||
cnt += 1;
|
||||
}
|
||||
}
|
||||
out += format!("{:>3} ", cnt).as_str();
|
||||
b += 1;
|
||||
c += 1;
|
||||
}
|
||||
out += "\n";
|
||||
r += 1;
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
mod bucket;
|
||||
mod bucket_entry;
|
||||
mod debug;
|
||||
mod dial_info_entry;
|
||||
mod find_nodes;
|
||||
mod node_ref;
|
||||
@@ -15,6 +16,7 @@ use alloc::collections::VecDeque;
|
||||
use alloc::str::FromStr;
|
||||
use bucket::*;
|
||||
pub use bucket_entry::*;
|
||||
pub use debug::*;
|
||||
pub use dial_info_entry::*;
|
||||
pub use find_nodes::*;
|
||||
use futures_util::stream::{FuturesUnordered, StreamExt};
|
||||
@@ -354,38 +356,6 @@ impl RoutingTable {
|
||||
*self.inner.lock() = Self::new_inner(self.network_manager());
|
||||
}
|
||||
|
||||
// debugging info
|
||||
pub fn debug_info(&self, min_state: BucketEntryState) -> String {
|
||||
let inner = self.inner.lock();
|
||||
let cur_ts = get_timestamp();
|
||||
|
||||
let mut out = String::new();
|
||||
const COLS: usize = 16;
|
||||
let rows = inner.buckets.len() / COLS;
|
||||
let mut r = 0;
|
||||
let mut b = 0;
|
||||
out += "Buckets:\n";
|
||||
while r < rows {
|
||||
let mut c = 0;
|
||||
out += format!(" {:>3}: ", b).as_str();
|
||||
while c < COLS {
|
||||
let mut cnt = 0;
|
||||
for e in inner.buckets[b].entries() {
|
||||
if e.1.state(cur_ts) >= min_state {
|
||||
cnt += 1;
|
||||
}
|
||||
}
|
||||
out += format!("{:>3} ", cnt).as_str();
|
||||
b += 1;
|
||||
c += 1;
|
||||
}
|
||||
out += "\n";
|
||||
r += 1;
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
// Just match address and port to help sort dialinfoentries for buckets
|
||||
// because inbound connections will not have dialinfo associated with them
|
||||
// but should have ip addresses if they have changed
|
||||
@@ -590,7 +560,6 @@ impl RoutingTable {
|
||||
for p in res.peers {
|
||||
// if our own node if is in the list then ignore it, as we don't add ourselves to our own routing table
|
||||
if p.node_id.key == node_id {
|
||||
// however, it is useful to note when
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user