pub struct DhtRoutingOptimizer {
pub stale_threshold_secs: u64,
pub target_bucket_fill: usize,
pub k_bucket_capacity: usize,
}Expand description
Analyzes Kademlia routing table snapshots and emits remediation suggestions.
§Example
use ipfrs_network::dht_optimizer::{DhtRoutingOptimizer, RoutingEntry};
let optimizer = DhtRoutingOptimizer::new(600, 8);
let entries = vec![
RoutingEntry::new("peer-1", 5, 1_700_000_000, 12.0, true),
RoutingEntry::new("peer-2", 5, 1_700_000_010, 18.5, true),
];
let report = optimizer.optimize(&entries, 1_700_000_600);
assert!(!report.has_issues());Fields§
§stale_threshold_secs: u64Seconds of inactivity before a peer is considered stale.
target_bucket_fill: usizeTarget number of responsive peers per bucket.
k_bucket_capacity: usizeMaximum number of entries allowed per bucket (Kademlia k).
Implementations§
Source§impl DhtRoutingOptimizer
impl DhtRoutingOptimizer
Sourcepub fn new(stale_threshold_secs: u64, target_bucket_fill: usize) -> Self
pub fn new(stale_threshold_secs: u64, target_bucket_fill: usize) -> Self
Creates a new optimizer with the given thresholds.
§Arguments
stale_threshold_secs– seconds without a response before a peer is labelled stale (default:DEFAULT_STALE_THRESHOLD_SECS).target_bucket_fill– desired number of responsive entries per bucket (default:DEFAULT_TARGET_BUCKET_FILL).
Sourcepub fn analyze_bucket(
&self,
entries: &[RoutingEntry],
now_secs: u64,
) -> BucketAnalysis
pub fn analyze_bucket( &self, entries: &[RoutingEntry], now_secs: u64, ) -> BucketAnalysis
Analyzes a slice of entries that all belong to the same bucket.
The bucket_index field of the returned BucketAnalysis is taken
from the first entry; callers should ensure all entries share the same
bucket index (as guaranteed by optimize).
§Health classification order
- Saturated —
entry_count > k_bucket_capacity - Stale — any non-responsive entries present
- Sparse —
responsive_count < target_bucket_fill - Healthy — otherwise
Sourcepub fn optimize(
&self,
all_entries: &[RoutingEntry],
now_secs: u64,
) -> OptimizationReport
pub fn optimize( &self, all_entries: &[RoutingEntry], now_secs: u64, ) -> OptimizationReport
Analyzes all routing entries and returns a full OptimizationReport.
§Algorithm
- Group entries by
bucket_index. - Run
analyze_bucketon each group. - For each bucket produce recommendations:
- Stale entries: emit
PingPeer(orEvictPeerif age > 2×stale_threshold_secs), capped atMAX_PINGS_PER_BUCKETper bucket. - Sparse bucket: emit
RefreshBucket.
- Stale entries: emit
- Collate bucket-health counts and return the report.
Sourcepub fn top_latency_peers<'a>(
&self,
entries: &'a [RoutingEntry],
n: usize,
) -> Vec<&'a RoutingEntry>
pub fn top_latency_peers<'a>( &self, entries: &'a [RoutingEntry], n: usize, ) -> Vec<&'a RoutingEntry>
Returns the n responsive peers with the highest latency, sorted
descending. These are candidates for replacement by lower-latency
peers discovered during bucket refresh.
Sourcepub fn coverage_score(&self, entries: &[RoutingEntry]) -> f64
pub fn coverage_score(&self, entries: &[RoutingEntry]) -> f64
Returns the fraction of the 256 possible Kademlia bucket indices that have at least one responsive entry.
Returns 0.0 for an empty entry list.
Trait Implementations§
Source§impl Clone for DhtRoutingOptimizer
impl Clone for DhtRoutingOptimizer
Source§fn clone(&self) -> DhtRoutingOptimizer
fn clone(&self) -> DhtRoutingOptimizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DhtRoutingOptimizer
impl Debug for DhtRoutingOptimizer
Auto Trait Implementations§
impl Freeze for DhtRoutingOptimizer
impl RefUnwindSafe for DhtRoutingOptimizer
impl Send for DhtRoutingOptimizer
impl Sync for DhtRoutingOptimizer
impl Unpin for DhtRoutingOptimizer
impl UnsafeUnpin for DhtRoutingOptimizer
impl UnwindSafe for DhtRoutingOptimizer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more