refactor attachment
This commit is contained in:
@@ -51,7 +51,7 @@ pub struct LowLevelPortInfo {
|
||||
pub type RoutingTableEntryFilter<'t> =
|
||||
Box<dyn FnMut(&RoutingTableInner, DHTKey, Option<Arc<BucketEntry>>) -> bool + Send + 't>;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
pub struct RoutingTableHealth {
|
||||
/// Number of reliable (responsive) entries in the routing table
|
||||
pub reliable_entry_count: usize,
|
||||
@@ -60,9 +60,9 @@ pub struct RoutingTableHealth {
|
||||
/// Number of dead (always unresponsive) entries in the routing table
|
||||
pub dead_entry_count: usize,
|
||||
/// If PublicInternet network class is valid yet
|
||||
pub public_internet_network_class_valid: bool, xxx do this and add to attachment calculation
|
||||
pub public_internet_ready: bool,
|
||||
/// If LocalNetwork network class is valid yet
|
||||
pub local_network_network_class_valid: bool,
|
||||
pub local_network_ready: bool,
|
||||
}
|
||||
|
||||
pub(super) struct RoutingTableUnlockedInner {
|
||||
@@ -78,7 +78,7 @@ pub(super) struct RoutingTableUnlockedInner {
|
||||
kick_queue: Mutex<BTreeSet<usize>>,
|
||||
/// Background process for computing statistics
|
||||
rolling_transfers_task: TickTask<EyreReport>,
|
||||
/// Backgroup process to purge dead routing table entries when necessary
|
||||
/// Background process to purge dead routing table entries when necessary
|
||||
kick_buckets_task: TickTask<EyreReport>,
|
||||
/// Background process to get our initial routing table
|
||||
bootstrap_task: TickTask<EyreReport>,
|
||||
|
@@ -318,10 +318,8 @@ impl RoutingTableInner {
|
||||
4 => 16,
|
||||
5 => 8,
|
||||
6 => 4,
|
||||
7 => 4,
|
||||
8 => 4,
|
||||
9 => 4,
|
||||
_ => 4,
|
||||
7 => 2,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -718,24 +716,45 @@ impl RoutingTableInner {
|
||||
// Routing Table Health Metrics
|
||||
|
||||
pub fn get_routing_table_health(&self) -> RoutingTableHealth {
|
||||
let mut health = RoutingTableHealth::default();
|
||||
let mut reliable_entry_count: usize = 0;
|
||||
let mut unreliable_entry_count: usize = 0;
|
||||
let mut dead_entry_count: usize = 0;
|
||||
|
||||
let cur_ts = get_aligned_timestamp();
|
||||
for bucket in &self.buckets {
|
||||
for (_, v) in bucket.entries() {
|
||||
match v.with(self, |_rti, e| e.state(cur_ts)) {
|
||||
BucketEntryState::Reliable => {
|
||||
health.reliable_entry_count += 1;
|
||||
reliable_entry_count += 1;
|
||||
}
|
||||
BucketEntryState::Unreliable => {
|
||||
health.unreliable_entry_count += 1;
|
||||
unreliable_entry_count += 1;
|
||||
}
|
||||
BucketEntryState::Dead => {
|
||||
health.dead_entry_count += 1;
|
||||
dead_entry_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
health
|
||||
|
||||
let public_internet_ready = matches!(
|
||||
self.get_network_class(RoutingDomain::PublicInternet)
|
||||
.unwrap_or_default(),
|
||||
NetworkClass::Invalid
|
||||
);
|
||||
let local_network_ready = matches!(
|
||||
self.get_network_class(RoutingDomain::LocalNetwork)
|
||||
.unwrap_or_default(),
|
||||
NetworkClass::Invalid
|
||||
);
|
||||
|
||||
RoutingTableHealth {
|
||||
reliable_entry_count,
|
||||
unreliable_entry_count,
|
||||
dead_entry_count,
|
||||
public_internet_ready,
|
||||
local_network_ready,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn touch_recent_peer(&mut self, node_id: DHTKey, last_connection: ConnectionDescriptor) {
|
||||
|
Reference in New Issue
Block a user