fix(irtt): use effective RTT for latency fallback

This commit is contained in:
Nils Andreas Svee committed 2026-10-14 11:12:50 +07:00
1 parent 3eab999aa5
commit 441720811e
4 files changed
+13 -1

No files matched your search

+1
View File
@@ -289,6 +289,7 @@ mod tests {
}, },
started_at: received_at, started_at: received_at,
observed_at: received_at, observed_at: received_at,
round_trip: None,
one_way: Some(OneWayLatency { one_way: Some(OneWayLatency {
uplink: SignedDuration::from_millis(up_time as i64), uplink: SignedDuration::from_millis(up_time as i64),
downlink: SignedDuration::from_millis(down_time as i64), downlink: SignedDuration::from_millis(down_time as i64),
+2
View File
@@ -326,6 +326,7 @@ impl IcmpEngine {
stream: probe.stream, stream: probe.stream,
started_at: probe.sent_at, started_at: probe.sent_at,
observed_at, observed_at,
round_trip: None,
one_way: None, one_way: None,
}) })
} }
@@ -385,6 +386,7 @@ impl IcmpEngine {
stream: probe.stream, stream: probe.stream,
started_at: probe.sent_at, started_at: probe.sent_at,
observed_at, observed_at,
round_trip: None,
one_way: Some(OneWayLatency { one_way: Some(OneWayLatency {
uplink: SignedDuration::from_millis(uplink_ms), uplink: SignedDuration::from_millis(uplink_ms),
downlink: SignedDuration::from_millis(downlink_ms), downlink: SignedDuration::from_millis(downlink_ms),
+3
View File
@@ -255,6 +255,7 @@ impl IrttEngine {
sent_at, sent_at,
received_at, received_at,
one_way, one_way,
rtt,
.. ..
} => { } => {
let Some(stream) = stream else { let Some(stream) = stream else {
@@ -265,6 +266,8 @@ impl IrttEngine {
stream, stream,
started_at: sent_at.mono, started_at: sent_at.mono,
observed_at: received_at.mono, observed_at: received_at.mono,
round_trip: i64::try_from(rtt.effective.as_nanos())
.ok().map(SignedDuration::from_nanos),
one_way: one_way.and_then(map_one_way), one_way: one_way.and_then(map_one_way),
}; };
+7 -1
View File
@@ -121,6 +121,9 @@ pub struct MeasurementObservation {
/// Local monotonic time at which the result was observed. /// Local monotonic time at which the result was observed.
pub observed_at: Instant, pub observed_at: Instant,
/// Measured round-trip latency when it differs from elapsed local time.
pub round_trip: Option<SignedDuration>,
/// Directional timing, when the measurement mechanism can provide it. /// Directional timing, when the measurement mechanism can provide it.
pub one_way: Option<OneWayLatency>, pub one_way: Option<OneWayLatency>,
} }
@@ -131,7 +134,10 @@ impl MeasurementObservation {
} }
pub fn rtt_ms(&self) -> f64 { pub fn rtt_ms(&self) -> f64 {
self.rtt().as_secs_f64() * 1000.0 self.round_trip
.map(SignedDuration::as_secs_f64)
.unwrap_or_else(|| self.rtt().as_secs_f64())
* 1000.0
} }
} }