use std::path::{Path, PathBuf};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct NetworkConfig {
pub interface: String,
pub socket_num: u16,
pub max_buffer_size: usize,
pub max_name_size: usize,
}
impl NetworkConfig {
pub fn default(interface: impl Into<String>) -> Self {
NetworkConfig {
interface: interface.into(),
socket_num: 25_000,
max_buffer_size: 10_000,
max_name_size: 100,
}
}
pub fn set_socket_num(mut self, socket_num: impl Into<u16>) -> NetworkConfig {
self.socket_num = socket_num.into();
self
}
pub fn set_max_buffer_size(mut self, max_buffer_size: usize) -> NetworkConfig {
self.max_buffer_size = max_buffer_size;
self
}
pub fn set_max_name_size(mut self, max_name_size: usize) -> NetworkConfig {
self.max_name_size = max_name_size;
self
}
}
pub use NetworkConfig as TcpConfig;
pub use NetworkConfig as UdpConfig;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct QuicConfig {
pub network_cfg: NetworkConfig,
pub cert_path: PathBuf,
pub key_path: PathBuf,
}
impl Default for QuicConfig {
fn default() -> Self {
QuicConfig {
network_cfg: NetworkConfig {
interface: "lo".into(),
socket_num: 25_000,
max_buffer_size: 10_000,
max_name_size: 100,
},
cert_path: Path::new("target").join("cert.pem"),
key_path: Path::new("target").join("priv_key.pem"),
}
}
}
impl QuicConfig {
pub fn new(interface: impl Into<String>) -> Self {
QuicConfig {
network_cfg: NetworkConfig {
interface: interface.into(),
socket_num: 25_000,
max_buffer_size: 10_000,
max_name_size: 100,
},
cert_path: Path::new("target").join("cert.pem"),
key_path: Path::new("target").join("priv_key.pem"),
}
}
}