mirror of
https://github.com/jmcorgan/fips.git
synced 2026-08-09 00:04:54 +00:00
Split cache.rs and config.rs into directory modules, create utils/
Module reorganization for three large single-file modules: cache.rs (792 lines) split into cache/ directory: - cache/mod.rs: CacheError, CacheStats, re-exports - cache/entry.rs: CacheEntry with TTL/LRU tracking - cache/coord_cache.rs: CoordCache (address-to-coordinate mappings) - cache/route_cache.rs: RouteCache + CachedCoords (discovery routes) - Added 22 new tests filling coverage gaps across all submodules config.rs (1318 lines) split into config/ directory: - config/mod.rs: ConfigError, IdentityConfig, Config struct with file loading/merge logic, all 24 integration tests - config/node.rs: NodeConfig + 9 subsection structs (Limits, RateLimit, Retry, Cache, Discovery, Tree, Bloom, Session, Buffers) - config/transport.rs: TransportInstances<T>, TransportsConfig, UdpConfig - config/peer.rs: ConnectPolicy, PeerAddress, PeerConfig DnsConfig and TunConfig moved to upper/config.rs to co-locate with the upper layer components they configure (TUN interface, DNS responder). index.rs moved to utils/index.rs as cross-cutting infrastructure that serves both node and peer layers.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//! Upper layer configuration types.
|
||||
//!
|
||||
//! Configuration for the IPv6 adaptation layer components: TUN interface
|
||||
//! and DNS responder.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Default TUN device name.
|
||||
const DEFAULT_TUN_NAME: &str = "fips0";
|
||||
|
||||
/// Default TUN MTU (IPv6 minimum).
|
||||
const DEFAULT_TUN_MTU: u16 = 1280;
|
||||
|
||||
/// Default DNS responder bind address.
|
||||
const DEFAULT_DNS_BIND_ADDR: &str = "127.0.0.1";
|
||||
|
||||
/// Default DNS responder port.
|
||||
const DEFAULT_DNS_PORT: u16 = 5354;
|
||||
|
||||
/// Default DNS record TTL in seconds (5 minutes).
|
||||
const DEFAULT_DNS_TTL: u32 = 300;
|
||||
|
||||
/// DNS responder configuration (`dns.*`).
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct DnsConfig {
|
||||
/// Enable DNS responder (`dns.enabled`).
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub enabled: bool,
|
||||
|
||||
/// Bind address (`dns.bind_addr`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub bind_addr: Option<String>,
|
||||
|
||||
/// Port (`dns.port`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub port: Option<u16>,
|
||||
|
||||
/// Record TTL in seconds (`dns.ttl`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub ttl: Option<u32>,
|
||||
}
|
||||
|
||||
impl DnsConfig {
|
||||
/// Get the bind address (default: 127.0.0.1).
|
||||
pub fn bind_addr(&self) -> &str {
|
||||
self.bind_addr.as_deref().unwrap_or(DEFAULT_DNS_BIND_ADDR)
|
||||
}
|
||||
|
||||
/// Get the port (default: 5354).
|
||||
pub fn port(&self) -> u16 {
|
||||
self.port.unwrap_or(DEFAULT_DNS_PORT)
|
||||
}
|
||||
|
||||
/// Get the TTL in seconds (default: 300).
|
||||
pub fn ttl(&self) -> u32 {
|
||||
self.ttl.unwrap_or(DEFAULT_DNS_TTL)
|
||||
}
|
||||
}
|
||||
|
||||
/// TUN interface configuration (`tun.*`).
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct TunConfig {
|
||||
/// Enable TUN interface (`tun.enabled`).
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub enabled: bool,
|
||||
|
||||
/// Device name (`tun.name`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// MTU (`tun.mtu`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub mtu: Option<u16>,
|
||||
}
|
||||
|
||||
impl TunConfig {
|
||||
/// Get the device name (default: "fips0").
|
||||
pub fn name(&self) -> &str {
|
||||
self.name.as_deref().unwrap_or(DEFAULT_TUN_NAME)
|
||||
}
|
||||
|
||||
/// Get the MTU (default: 1280).
|
||||
pub fn mtu(&self) -> u16 {
|
||||
self.mtu.unwrap_or(DEFAULT_TUN_MTU)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
//! responder (.fips domain resolution), and ICMPv6 handling (error
|
||||
//! signaling and neighbor discovery).
|
||||
|
||||
pub mod config;
|
||||
pub mod dns;
|
||||
pub mod icmp;
|
||||
pub mod tun;
|
||||
|
||||
Reference in New Issue
Block a user