Skip to main content

Module latency_predictor

Module latency_predictor 

Source
Expand description

Peer Latency Predictor

Predicts future peer latency using exponentially-weighted moving average (EWMA) and trend detection. Tracks per-peer RTT samples, computes jitter via EWMA of squared deviations, and provides conservative predicted RTT estimates.

§Features

  • EWMA-based latency smoothing with configurable alpha factor
  • EWMA-based variance (jitter) tracking with configurable beta factor
  • Trend detection (Improving / Stable / Degrading) from rolling EWMA history
  • Stale peer eviction based on configurable timeout
  • Best-peer ranking by predicted RTT

§Example

use ipfrs_network::latency_predictor::{
    LatencySample, PeerLatencyPredictor, PredictorConfig,
};

let config = PredictorConfig::default();
let mut predictor = PeerLatencyPredictor::new(config);

predictor.record_sample(LatencySample {
    peer_id: "peer-a".to_string(),
    rtt_ms: 42.0,
    timestamp_secs: 1_000,
});

let predicted = predictor.predict("peer-a");
assert!(predicted.is_some());

Structs§

LatencySample
A single RTT measurement for a peer.
PeerLatencyPredictor
Tracks per-peer RTT samples and provides latency predictions.
PeerLatencyState
Per-peer latency tracking state.
PredictorConfig
Configuration for PeerLatencyPredictor.
PredictorStats
Aggregated statistics snapshot for a PeerLatencyPredictor.

Enums§

TrendDirection
Direction of latency trend inferred from recent EWMA history.