use std::time::Duration;
use peashape::{ShapeConfig, ShapingStrategy};
#[derive(Clone, Debug)]
pub struct NodeConfig {
pub name: Option<String>,
pub listener_addr: Option<std::net::SocketAddr>,
pub cover: CoverStrategy,
pub fanout: usize,
pub message_size: usize,
pub app_outbox_capacity: usize,
pub relay_outbox_capacity: usize,
pub dedup_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 NodeConfig {
fn default() -> Self {
Self {
name: None,
listener_addr: None,
cover: CoverStrategy::Constant {
interval: Duration::from_secs(1),
},
fanout: 3,
message_size: 256,
app_outbox_capacity: 256,
relay_outbox_capacity: 1024,
dedup_capacity: 4096,
max_frame_size: 1024 * 1024,
max_connections: 64,
max_connections_per_ip: 8,
reuse_listener_port: false,
}
}
}
impl NodeConfig {
pub(crate) fn to_shape_config(&self) -> ShapeConfig {
ShapeConfig {
name: self.name.clone(),
listener_addr: self.listener_addr,
strategy: match self.cover {
CoverStrategy::Constant { interval } => ShapingStrategy::Constant { interval },
CoverStrategy::Poisson { rate } => ShapingStrategy::Poisson { rate },
},
scope: peashape::ShapingScope::Global,
fanout: self.fanout,
frame_size: self.message_size,
high_lane_capacity: self.app_outbox_capacity,
low_lane_capacity: self.relay_outbox_capacity,
max_frame_size: self.max_frame_size,
max_connections: self.max_connections,
max_connections_per_ip: self.max_connections_per_ip,
reuse_listener_port: self.reuse_listener_port,
..ShapeConfig::default()
}
}
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub enum CoverStrategy {
Constant {
interval: Duration,
},
Poisson {
rate: f64,
},
}