Expand description
Correlated clock probes and a bounded interpolation delay. All times are supplied explicitly, making jitter/loss/reorder behavior testable offline.
A transport must validate the enclosing connection/session before delivering a reply. Nonces correlate probes, not sessions. All local timestamps below are microseconds in the same caller-owned monotonic time domain; server timestamps use the server’s domain. Neither domain is a wall clock.
use ferravex_net::clock::{ClientClock, ClockAge, ClockSampleIgnored, TickUnwrapper};
let mut clock = ClientClock::default();
let (nonce, client_us) = clock.probe(1_000_000).unwrap();
let pending = clock.diagnostics(1_050_000, 64);
let probe = pending.pending_probes.into_iter().flatten().next().unwrap();
assert_eq!(probe.age, ClockAge::AgeMicros(50_000));
// After validating the reply's outer session, pass its four timestamps.
clock.observe_detailed(nonce, client_us, 11_050_000, 11_051_000,
640, 1_101_000).unwrap();
let diagnostics = clock.diagnostics(1_201_000, 64);
assert_eq!(diagnostics.sample_age, ClockAge::AgeMicros(100_000));
assert!((diagnostics.rtt_seconds.unwrap() - 0.1).abs() < 1e-9);
assert!((diagnostics.offset_seconds.unwrap() - 10.0).abs() < 1e-9);
assert_eq!(diagnostics.render_delay_ticks, 6);
let estimated = clock.estimated_tick(1_201_000, 64).unwrap();
let render = clock.render_tick(1_201_000, 64).unwrap();
assert!((render - (estimated - 6.0)).abs() < 1e-9);
assert_eq!(clock.observe_detailed(nonce, client_us, 11_050_000, 11_051_000,
640, 1_101_000),
Err(ClockSampleIgnored::ProbeNotRetained));
// At reconnect, discard old-session traffic/history and reset both clocks.
let mut ticks = TickUnwrapper::default();
ticks.observe(640);
ticks.reset();
clock.reset();
assert_eq!(clock.diagnostics(0, 64).sample_age, ClockAge::Unknown);
assert_eq!(ticks.observe(2), Some(2));
// A new local/server time origin and lower tick can now establish the anchor.
let (nonce, sent) = clock.probe(0).unwrap();
assert!(clock.observe(nonce, sent, 50_000, 51_000, 2, 101_000));
assert!(clock.render_tick(101_000, 64).is_some());Structs§
- Client
Clock - Four-slot correlated clock estimator. See the module recipe for transport, time-domain, render sampling and reconnect responsibilities.
- Clock
Diagnostics - Allocation-free, read-only diagnostics at an explicitly supplied time/rate.
RTT and offset share
sample_age, measured since the last accepted local receive.Nonemeans unknown, whileSome(0.0)is a valid zero estimate. - Pending
Clock Probe - A retained probe, including expired probes (inspection never consumes them).
Only
AgeMicros(age)withage > 5_000_000establishes expiry; invalid or preceding inspection times establish neither freshness nor expiry. - Tick
Unwrapper
Enums§
- Clock
Age - Age relative to a supplied local timestamp. This reports age, not a freshness policy: the caller chooses how old an accepted estimate may be. No method can detect timestamps from a different domain that happen to be ordered.
- Clock
Sample Ignored - Why a reply was ignored. The first failing check is reported, in timestamp, correlation, expiry, anchor ordering, estimator, then tick-overflow order. Every rejection preserves the entire clock, including retained probes.