use std::time::Duration;
use crate::transport::packet_data::MAX_DATA_SIZE;
pub(crate) const MSS: usize = MAX_DATA_SIZE;
pub(crate) const TARGET: Duration = Duration::from_millis(60);
pub(crate) const MAX_GAIN_DIVISOR: u32 = 16;
pub(crate) const BASE_HISTORY_SIZE: usize = 10;
pub(crate) const DELAY_FILTER_SIZE: usize = 4;
pub(crate) const DEFAULT_SSTHRESH: usize = 1_048_576;
pub(crate) const SLOWDOWN_INTERVAL_MULTIPLIER: u32 = 9;
pub(crate) const SLOWDOWN_DELAY_RTTS: u32 = 2;
pub(crate) const SLOWDOWN_FREEZE_RTTS: u32 = 2;
pub(crate) const SLOWDOWN_REDUCTION_FACTOR: usize = 4;
pub(crate) const PATH_CHANGE_RTT_THRESHOLD: f64 = 1.5;
pub(crate) const RTT_SCALING_BYTES_PER_MS: usize = 1024;
#[derive(Debug, Clone)]
pub struct LedbatConfig {
pub initial_cwnd: usize,
pub min_cwnd: usize,
pub max_cwnd: usize,
pub ssthresh: usize,
pub enable_slow_start: bool,
pub delay_exit_threshold: f64,
pub randomize_ssthresh: bool,
pub enable_periodic_slowdown: bool,
pub min_ssthresh: Option<usize>,
}
impl Default for LedbatConfig {
fn default() -> Self {
Self {
initial_cwnd: 38_000, min_cwnd: 2_848, max_cwnd: 1_000_000_000, ssthresh: DEFAULT_SSTHRESH, enable_slow_start: true, delay_exit_threshold: 0.75, randomize_ssthresh: true, enable_periodic_slowdown: true, min_ssthresh: None, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_target_delay_is_60ms() {
assert_eq!(
TARGET,
Duration::from_millis(60),
"LEDBAT++ TARGET should be 60ms"
);
}
#[test]
fn test_slow_start_exit_threshold_is_75_percent() {
let config = LedbatConfig::default();
assert!(
(config.delay_exit_threshold - 0.75).abs() < 0.01,
"LEDBAT++ delay_exit_threshold should be 0.75, got {}",
config.delay_exit_threshold
);
}
}