use std::time::Duration;
use serde::{Deserialize, Serialize};
use crate::{NetBenchReport, PathKind};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConnectionStage {
PreparingAddress,
QuicHandshakeStarted,
QuicHandshakeCompleted {
elapsed: Duration,
},
ControlStreamOpened,
ClientHelloSent,
ServerHelloReceived {
version: u16,
},
PathObserved {
path: PathKind,
},
DirectPathSelected {
elapsed: Duration,
},
RelayFallback {
waited: Duration,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ConnectionInfo {
pub connect_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 timed_out: 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 {
Connecting,
ConnectionStage(ConnectionStage),
Connected(ConnectionInfo),
LatencyStarted,
LatencySample(LatencySample),
LossStarted,
LossSample(LossSample),
DownloadWarmupStarted,
DownloadStarted,
DownloadSample(ThroughputSample),
UploadWarmupStarted,
UploadStarted,
UploadSample(ThroughputSample),
Finished(NetBenchReport),
}