Files
fips/src/bin/fips.rs
T
Johnathan Corgan 4f8107be83 Add --wait flag and ip link debug output
- Add --wait / -w command-line flag for debugger attachment
- When --wait is set, daemon blocks after init with thread::park()
- Add ip link show output after TUN device creation for debugging
2026-01-30 00:46:17 +00:00

134 lines
3.8 KiB
Rust

//! FIPS daemon binary
//!
//! Loads configuration and creates the top-level node instance.
use fips::{Config, Node};
use tracing::{error, info, warn, Level};
use tracing_subscriber::{fmt, EnvFilter};
fn parse_args() -> bool {
std::env::args().any(|arg| arg == "--wait" || arg == "-w")
}
#[tokio::main(flavor = "current_thread")]
async fn main() {
let wait_mode = parse_args();
// Initialize logging
let filter = EnvFilter::builder()
.with_default_directive(Level::INFO.into())
.from_env_lossy();
fmt()
.with_env_filter(filter)
.with_target(true)
.init();
info!("FIPS starting");
// Load configuration
info!("Loading configuration");
let (config, loaded_paths) = match Config::load() {
Ok(result) => result,
Err(e) => {
error!("Failed to load configuration: {}", e);
std::process::exit(1);
}
};
if loaded_paths.is_empty() {
info!("No config files found, using defaults");
} else {
for path in &loaded_paths {
info!(path = %path.display(), "Loaded config file");
}
}
// Log identity status
if config.has_identity() {
info!("Using configured identity");
} else {
warn!("No identity configured, generating ephemeral keypair");
}
// Create node
info!("Creating node");
let mut node = match Node::new(config) {
Ok(node) => node,
Err(e) => {
error!("Failed to create node: {}", e);
std::process::exit(1);
}
};
// Log node information
info!(
state = %node.state(),
leaf_only = node.is_leaf_only(),
"Node created"
);
info!(" npub: {}", node.npub());
info!(" node_id: {}", hex::encode(node.node_id().as_bytes()));
info!(" address: {}", node.identity().address());
// Initialize TUN interface
info!(
tun_state = %node.tun_state(),
"TUN interface"
);
if node.tun_state() != fips::TunState::Disabled {
info!(
name = node.config().tun.name(),
mtu = node.config().tun.mtu(),
"Initializing TUN device"
);
match node.init_tun().await {
Ok(true) => {
let device = node.tun_device().unwrap();
info!(
name = device.name(),
mtu = device.mtu(),
address = %device.address(),
"TUN device active"
);
// Show interface details for debugging
let output = std::process::Command::new("ip")
.args(["link", "show", device.name()])
.output();
match output {
Ok(out) => {
if out.status.success() {
info!("ip link show {}:\n{}", device.name(),
String::from_utf8_lossy(&out.stdout));
}
}
Err(e) => {
warn!("Failed to run ip link: {}", e);
}
}
}
Ok(false) => {
info!("TUN disabled");
}
Err(e) => {
error!("Failed to initialize TUN: {}", e);
warn!("Continuing without TUN interface");
}
}
}
info!("FIPS initialized successfully");
// TODO: Start event loop, transports, etc.
if wait_mode {
info!("Running in wait mode (--wait). Press Ctrl+C to exit.");
info!("Attach debugger with: sudo ./scripts/lldb-attach-fips.sh");
// Block forever (until signal)
std::thread::park();
} else {
info!("No transports configured, nothing to do");
}
}