use std::fmt;
use std::net::IpAddr;
use std::time::Duration;
use gossip::auth::ClusterKey;
use ipnet::IpNet;
use crate::clock::{ClockDrift, NodeId, MAX_CLOCK_DRIFT};
use super::persistence::SNAPSHOT_INTERVAL;
mod builders;
pub(super) const DEFAULT_BULK_SEND_RATE: usize = 32 * 1024 * 1024;
pub(crate) const MIN_BULK_SEND_RATE: usize = 1024 * 1024;
pub(super) const DEFAULT_SOCKET_BUFFER_SIZE: usize = 8 * 1024 * 1024;
pub(super) const DEFAULT_MAX_PEERS: usize = 1024;
pub(super) const DEFAULT_MAX_CONCURRENT_BULK_DUMPS: usize = 4;
pub const MAX_NETS: usize = 8;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[non_exhaustive]
pub enum ConfigError {
TooManyNets,
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConfigError::TooManyNets => write!(f, "at most {MAX_NETS} networks are supported"),
}
}
}
impl std::error::Error for ConfigError {}
#[derive(Clone)]
#[non_exhaustive]
pub struct Config {
pub port: u16,
pub listen_addr: IpAddr,
pub nets: [Option<IpNet>; MAX_NETS],
pub remote_interval: u32,
pub remote_fanout: usize,
pub cluster_key: Option<ClusterKey>,
pub insecure_no_key: bool,
pub node_id: Option<NodeId>,
pub encrypt: bool,
pub reconcile_interval: Duration,
pub bulk_send_rate: Option<usize>,
pub recv_buffer_size: Option<usize>,
pub send_buffer_size: Option<usize>,
pub freshness_window: Duration,
pub max_peers: usize,
pub max_concurrent_bulk_dumps: usize,
pub snapshot_interval: Duration,
pub max_clock_drift: ClockDrift,
pub coalesce_window: Duration,
}
impl fmt::Debug for Config {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Config")
.field("port", &self.port)
.field("listen_addr", &self.listen_addr)
.field("nets", &self.nets)
.field("remote_interval", &self.remote_interval)
.field("remote_fanout", &self.remote_fanout)
.field(
"cluster_key",
&self.cluster_key.as_ref().map(|_| "<redacted>"),
)
.field("insecure_no_key", &self.insecure_no_key)
.field("node_id", &self.node_id)
.field("encrypt", &self.encrypt)
.field("reconcile_interval", &self.reconcile_interval)
.field("bulk_send_rate", &self.bulk_send_rate)
.field("recv_buffer_size", &self.recv_buffer_size)
.field("send_buffer_size", &self.send_buffer_size)
.field("freshness_window", &self.freshness_window)
.field("max_peers", &self.max_peers)
.field("max_concurrent_bulk_dumps", &self.max_concurrent_bulk_dumps)
.field("snapshot_interval", &self.snapshot_interval)
.field("max_clock_drift", &self.max_clock_drift)
.field("coalesce_window", &self.coalesce_window)
.finish()
}
}
impl Default for Config {
fn default() -> Self {
Config {
port: 0,
listen_addr: "127.0.0.1".parse().unwrap(),
nets: [None; MAX_NETS],
remote_interval: 6,
remote_fanout: 2,
cluster_key: None,
insecure_no_key: false,
node_id: None,
encrypt: false,
reconcile_interval: Duration::from_secs(1),
bulk_send_rate: Some(DEFAULT_BULK_SEND_RATE),
recv_buffer_size: Some(DEFAULT_SOCKET_BUFFER_SIZE),
send_buffer_size: Some(DEFAULT_SOCKET_BUFFER_SIZE),
freshness_window: gossip::replay::FRESHNESS_WINDOW_DEFAULT,
max_peers: DEFAULT_MAX_PEERS,
max_concurrent_bulk_dumps: DEFAULT_MAX_CONCURRENT_BULK_DUMPS,
snapshot_interval: SNAPSHOT_INTERVAL,
max_clock_drift: MAX_CLOCK_DRIFT,
coalesce_window: Duration::ZERO,
}
}
}