libFenrir/src/config/mod.rs
Luca Fulchir aff1c313f5
Cleanup & incomplete tests
Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
2023-06-10 14:42:24 +02:00

63 lines
1.8 KiB
Rust

//!
//! Configuration to initialize the Fenrir networking library
use crate::{
connection::handshake::HandshakeID,
enc::{
asym::{KeyExchangeKind, KeyID, PrivKey, PubKey},
hkdf::HkdfKind,
sym::CipherKind,
},
};
use ::std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
num::NonZeroUsize,
option::Option,
vec,
};
/// Main config for libFenrir
#[derive(Clone, Debug)]
pub struct Config {
/// number of threads that libFenrir will use
pub threads: Option<NonZeroUsize>,
/// List of ipv4 or ipv6 UDP inet socket to listen on
/// If empty, libFenrir will listen on a random UDP port on `0.0.0.0`
pub listen: Vec<SocketAddr>,
/// List of DNS resolvers to use
pub resolvers: Vec<SocketAddr>,
/// Supported handshakes
pub handshakes: Vec<HandshakeID>,
/// Supported key exchanges
pub key_exchanges: Vec<KeyExchangeKind>,
/// Supported Hkdfs
pub hkdfs: Vec<HkdfKind>,
/// Supported Ciphers
pub ciphers: Vec<CipherKind>,
/// list of public/private keys
pub keys: Vec<(KeyID, PrivKey, PubKey)>,
}
impl Default for Config {
fn default() -> Self {
Config {
threads: None,
listen: vec![
// ipv4 random port
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0),
// ipv6 random port
SocketAddr::new(
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)),
0,
),
],
resolvers: Vec::new(),
handshakes: [HandshakeID::DirectorySynchronized].to_vec(),
key_exchanges: [KeyExchangeKind::X25519DiffieHellman].to_vec(),
hkdfs: [HkdfKind::Sha3].to_vec(),
ciphers: [CipherKind::XChaCha20Poly1305].to_vec(),
keys: Vec::new(),
}
}
}