use std::time::Duration;
#[derive(Clone, Debug)]
pub struct ShapeConfig {
pub name: Option<String>,
pub listener_addr: Option<std::net::SocketAddr>,
pub strategy: ShapingStrategy,
pub scope: ShapingScope,
pub fanout: usize,
pub frame_size: usize,
pub high_lane_capacity: usize,
pub low_lane_capacity: usize,
pub max_frame_size: usize,
pub max_connections: u16,
pub max_connections_per_ip: u16,
pub reuse_listener_port: bool,
}
impl Default for ShapeConfig {
fn default() -> Self {
Self {
name: None,
listener_addr: None,
strategy: ShapingStrategy::Constant {
interval: Duration::from_secs(1),
},
scope: ShapingScope::Global,
fanout: 3,
frame_size: 256,
high_lane_capacity: 256,
low_lane_capacity: 1024,
max_frame_size: 1024 * 1024,
max_connections: 64,
max_connections_per_ip: 8,
reuse_listener_port: false,
}
}
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub enum ShapingStrategy {
Constant {
interval: Duration,
},
Poisson {
rate: f64,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ShapingScope {
Global,
PerConnection {
randomize: bool,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Lane {
High,
Low,
}