From a1585a3db53ee59fe941622d698638322b585267 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 4 Nov 2026 22:15:18 +0100 Subject: hop delays --- src/swarm/stats.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/swarm/stats.rs') diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs index 74076a4..de63962 100644 --- a/src/swarm/stats.rs +++ b/src/swarm/stats.rs @@ -59,7 +59,7 @@ pub(crate) struct Propagation { } impl Propagation { - fn record(&mut self, delay_ms: i64) { + pub(crate) fn record(&mut self, delay_ms: i64) { if delay_ms < 0 { self.ahead += 1; } @@ -73,6 +73,20 @@ impl Propagation { self.sum_ms += delay_ms; } + /// The bound of the bucket by which `quantile` of the delays came: None if beyond + /// the last bound, or none came. + pub(crate) fn within(&self, quantile: f64) -> Option { + let wanted = (self.count as f64 * quantile).ceil() as u64; + let mut seen = 0; + for (bound, count) in self.buckets() { + seen += count; + if seen >= wanted && seen > 0 { + return bound; + } + } + None + } + /// Each bucket's upper bound (None for the last) and count. pub(crate) fn buckets(&self) -> impl Iterator, u64)> + '_ { PROPAGATION_BUCKETS_MS -- cgit v1.3.1