use std::time::Duration;
use serde::{Deserialize, Serialize};
use crate::{NetBenchReport, PathKind};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FlowStage {
ControlStreamReady,
ClientHelloSent,
ServerHelloReceived {
version: u16,
},
PathObserved {
path: PathKind,
},
DirectPathSelected {
elapsed: Duration,
},
RelayRetained {
waited: Duration,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FlowInfo {
pub negotiation_time: Duration,
pub path: PathKind,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LatencySample {
pub sequence: u64,
pub rtt: Duration,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LossSample {
pub sent: u64,
pub received: u64,
pub outstanding: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ThroughputDirection {
Download,
Upload,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ThroughputSample {
pub direction: ThroughputDirection,
pub elapsed: Duration,
pub received_bytes: u64,
pub interval_bps: f64,
}
#[allow(
clippy::large_enum_variant,
reason = "the public API intentionally exposes Finished(NetBenchReport)"
)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum NetBenchEvent {
FlowStage(FlowStage),
Ready(FlowInfo),
LatencyStarted,
LatencySample(LatencySample),
LossStarted,
LossSample(LossSample),
DownloadWarmupStarted,
DownloadStarted,
DownloadSample(ThroughputSample),
UploadWarmupStarted,
UploadStarted,
UploadSample(ThroughputSample),
Finished(NetBenchReport),
}