peer table thresholds

This commit is contained in:
John Smith
2022-03-24 10:14:50 -04:00
parent ac0280e0b6
commit c276dd7796
10 changed files with 184 additions and 47 deletions

View File

@@ -60,6 +60,13 @@ struct RoutingTableInner {
self_transfer_stats: TransferStatsDownUp,
}
#[derive(Clone, Debug, Default)]
pub struct RoutingTableHealth {
pub reliable_entry_count: usize,
pub unreliable_entry_count: usize,
pub dead_entry_count: usize,
}
struct RoutingTableUnlockedInner {
// Background processes
rolling_transfers_task: TickTask,
@@ -743,4 +750,29 @@ impl RoutingTable {
e.question_lost(ts);
})
}
//////////////////////////////////////////////////////////////////////
// Routing Table Health Metrics
pub fn get_routing_table_health(&self) -> RoutingTableHealth {
let mut health = RoutingTableHealth::default();
let cur_ts = intf::get_timestamp();
let inner = self.inner.lock();
for bucket in &inner.buckets {
for entry in bucket.entries() {
match entry.1.state(cur_ts) {
BucketEntryState::Reliable => {
health.reliable_entry_count += 1;
}
BucketEntryState::Unreliable => {
health.unreliable_entry_count += 1;
}
BucketEntryState::Dead => {
health.dead_entry_count += 1;
}
}
}
}
health
}
}