use crate::{primitives::Str, profile::Profile, tunnel::TunnelPoolConfig};
use alloc::{string::String, vec::Vec};
use core::net::{Ipv4Addr, Ipv6Addr};
#[derive(Clone, PartialEq, Eq)]
pub struct ExploratoryConfig {
pub inbound_len: Option<usize>,
pub inbound_count: Option<usize>,
pub outbound_len: Option<usize>,
pub outbound_count: Option<usize>,
}
impl From<Option<ExploratoryConfig>> for TunnelPoolConfig {
fn from(value: Option<ExploratoryConfig>) -> Self {
let default_config = TunnelPoolConfig::default();
match value {
None => default_config,
Some(config) => TunnelPoolConfig {
name: Str::from("exploratory"),
num_inbound: config.inbound_count.unwrap_or(default_config.num_inbound),
num_inbound_hops: config.inbound_len.unwrap_or(default_config.num_inbound_hops),
num_outbound: config.outbound_count.unwrap_or(default_config.num_outbound),
num_outbound_hops: config.outbound_len.unwrap_or(default_config.num_outbound_hops),
},
}
}
}
#[derive(Clone, PartialEq, Eq)]
pub struct Ntcp2Config {
pub ipv4: bool,
pub ipv4_host: Option<Ipv4Addr>,
pub ipv6: bool,
pub ipv6_host: Option<Ipv6Addr>,
pub iv: [u8; 16],
pub key: [u8; 32],
pub port: u16,
pub publish: bool,
pub ml_kem: Option<usize>,
pub disable_pq: bool,
}
#[derive(Clone, PartialEq, Eq)]
pub struct Ssu2Config {
pub disable_pq: bool,
pub intro_key: [u8; 32],
pub ipv4: bool,
pub ipv4_host: Option<Ipv4Addr>,
pub ipv4_mtu: Option<usize>,
pub ipv6: bool,
pub ipv6_host: Option<Ipv6Addr>,
pub ipv6_mtu: Option<usize>,
pub port: u16,
pub publish: bool,
pub static_key: [u8; 32],
pub ml_kem: Option<String>,
}
#[derive(Debug, Clone)]
pub struct I2cpConfig {
pub port: u16,
pub host: String,
}
#[derive(Debug, Clone)]
pub struct SamConfig {
pub tcp_port: u16,
pub udp_port: u16,
pub host: String,
}
#[derive(Default, Debug, Clone)]
pub struct MetricsConfig {
pub port: u16,
}
#[derive(Default, Debug, Clone)]
pub struct TransitConfig {
pub max_tunnels: Option<usize>,
}
#[derive(Debug, Clone)]
pub struct BandwidthConfig {
pub bandwidth: usize,
pub share_ratio: f64,
}
impl Default for BandwidthConfig {
fn default() -> Self {
Self {
bandwidth: 1000 * 1000,
share_ratio: 0.9,
}
}
}
#[derive(Default)]
pub struct Config {
pub allow_local: bool,
pub caps: Option<String>,
pub exploratory: Option<ExploratoryConfig>,
pub floodfill: bool,
pub bandwidth: Option<BandwidthConfig>,
pub i2cp_config: Option<I2cpConfig>,
pub insecure_tunnels: bool,
pub metrics: Option<MetricsConfig>,
pub net_id: Option<u8>,
pub ntcp2: Option<Ntcp2Config>,
pub profiles: Vec<(String, Profile)>,
pub refresh_interval: Option<usize>,
pub router_info: Option<Vec<u8>>,
pub routers: Vec<Vec<u8>>,
pub samv3_config: Option<SamConfig>,
pub signing_key: Option<[u8; 32]>,
pub ssu2: Option<Ssu2Config>,
pub static_key: Option<[u8; 32]>,
pub transit: Option<TransitConfig>,
}