diff --git a/traffic_core/src/daemon.rs b/traffic_core/src/daemon.rs index b907705..5630fbf 100644 --- a/traffic_core/src/daemon.rs +++ b/traffic_core/src/daemon.rs @@ -150,12 +150,12 @@ fn docker_events_loop(cfg: &Config, state: &Arc>) -> anyh fn wait_for_interface(cfg: &Config, container_name: &str, timeout_secs: u64) -> bool { let start = Instant::now(); while start.elapsed() < Duration::from_secs(timeout_secs.max(1)) { - if let Ok(target) = docker::discover_target(cfg) { - if target.container_name == container_name { - let transport = build_transport(target.container_pid, &target.container_name); - if iface::detect_interface_with_transport(cfg, transport.as_ref()).is_ok() { - return true; - } + if let Ok(target) = docker::discover_target(cfg) + && target.container_name == container_name + { + let transport = build_transport(target.container_pid, &target.container_name); + if iface::detect_interface_with_transport(cfg, transport.as_ref()).is_ok() { + return true; } } diff --git a/traffic_core/src/firewall.rs b/traffic_core/src/firewall.rs index 08ab2df..8a70b69 100644 --- a/traffic_core/src/firewall.rs +++ b/traffic_core/src/firewall.rs @@ -532,9 +532,10 @@ pub fn antitorrent_drop_counter(cfg: &Config) -> anyhow::Result { if let Some(v) = parse_counter_json(&raw)? { - return Ok(Some(v)); + Ok(Some(v)) + } else { + Ok(None) } - return Ok(None); } Err(e) => { let msg = e.to_string(); @@ -543,9 +544,10 @@ pub fn antitorrent_drop_counter(cfg: &Config) -> anyhow::Result anyhow::Result { Self::acquire_timeout(path, Duration::from_secs(0)) } @@ -42,9 +43,9 @@ impl FileLock { match OpenOptions::new().create_new(true).write(true).open(p) { Ok(mut file) => { file.write_all(std::process::id().to_string().as_bytes())?; - return Ok(Self { + Ok(Self { path: path.to_string(), - }); + }) } Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { let stale = is_stale_lock(p)?; @@ -52,13 +53,14 @@ impl FileLock { let _ = fs::remove_file(p); let mut file = OpenOptions::new().create_new(true).write(true).open(p)?; file.write_all(std::process::id().to_string().as_bytes())?; - return Ok(Self { + Ok(Self { path: path.to_string(), - }); + }) + } else { + anyhow::bail!("lock already exists: {path}"); } - anyhow::bail!("lock already exists: {path}"); } - Err(e) => return Err(e.into()), + Err(e) => Err(e.into()), } } } diff --git a/traffic_core/src/status.rs b/traffic_core/src/status.rs index 32a5b8a..cf8b788 100644 --- a/traffic_core/src/status.rs +++ b/traffic_core/src/status.rs @@ -56,7 +56,9 @@ pub fn print_status(cfg: &Config) -> anyhow::Result<()> { } println!("WireGuard clients:"); - println!(" IP State Latest handshake RX TX Endpoint"); + println!( + " IP State Latest handshake RX TX Public key Endpoint" + ); match wg::discover_peer_runtime( target.container_pid, &target.container_name, @@ -87,13 +89,13 @@ pub fn print_status(cfg: &Config) -> anyhow::Result<()> { let tx = format_bytes(rp.transfer_tx_bytes.unwrap_or(0)); let ep = rp.endpoint.clone().unwrap_or_else(|| "-".to_string()); println!( - " {:<11} {:<8} {:<19} {:<9} {:<9} {}", - ip, state, hs, rx, tx, ep + " {:<11} {:<8} {:<19} {:<9} {:<9} {:<44} {}", + ip, state, hs, rx, tx, rp.public_key, ep ); } else { println!( - " {:<11} {:<8} {:<19} {:<9} {:<9} -", - ip, "offline", "never", "0B", "0B" + " {:<11} {:<8} {:<19} {:<9} {:<9} {:<44} -", + ip, "offline", "never", "0B", "0B", "-" ); } } @@ -427,6 +429,7 @@ fn print_swap_status(cfg: &Config) { " fstab_exclusive: {}", if s.fstab_exclusive { "yes" } else { "no" } ); + println!(" fstab_swap_entries: {}", s.fstab_swap_entries.len()); println!( " swappiness_current: {}", s.current_swappiness @@ -556,11 +559,11 @@ fn parse_tc_filter_hits(raw: &str) -> BTreeMap { let hits = parse_sent_packets(t).unwrap_or(0); out.insert(ip, hits); } - } else if t.contains(" success ") || t.starts_with("success ") { - if let Some(ip) = current_ip.clone() { - let hits = parse_success_packets(t).unwrap_or(0); - out.insert(ip, hits); - } + } else if (t.contains(" success ") || t.starts_with("success ")) + && let Some(ip) = current_ip.clone() + { + let hits = parse_success_packets(t).unwrap_or(0); + out.insert(ip, hits); } } out diff --git a/traffic_core/src/swap.rs b/traffic_core/src/swap.rs index a169db1..7b597a4 100644 --- a/traffic_core/src/swap.rs +++ b/traffic_core/src/swap.rs @@ -69,8 +69,7 @@ pub fn inspect_swap(cfg: &Config) -> anyhow::Result { let fstab_swap_entries = read_fstab_swap_entries("/etc/fstab")?; let expected_line = render_fstab_line(&desired_path, cfg.swap.priority); let fstab_exclusive = fstab_swap_entries.len() == 1 - && normalize_ws(&fstab_swap_entries[0]) - == normalize_ws(&expected_line.trim_end().to_string()); + && normalize_ws(&fstab_swap_entries[0]) == normalize_ws(expected_line.trim_end()); let current_swappiness = read_current_swappiness().ok(); let persisted_swappiness = read_persisted_swappiness()?; diff --git a/traffic_core/src/wg.rs b/traffic_core/src/wg.rs index 6d3b1a6..abbf9b9 100644 --- a/traffic_core/src/wg.rs +++ b/traffic_core/src/wg.rs @@ -90,10 +90,10 @@ fn parse_allowed_ips(raw: &str, peer_cidr: &str) -> anyhow::Result> { if pfx != "32" { continue; } - if let Ok(v4) = ip.parse::() { - if config::ip_in_cidr(v4, peer_cidr)? { - out.push(Peer { ipv4: v4 }); - } + if let Ok(v4) = ip.parse::() + && config::ip_in_cidr(v4, peer_cidr)? + { + out.push(Peer { ipv4: v4 }); } } } @@ -115,10 +115,10 @@ fn parse_fallback_wg_show(raw: &str, peer_cidr: &str) -> anyhow::Result() { - if config::ip_in_cidr(v4, peer_cidr)? { - out.push(Peer { ipv4: v4 }); - } + if let Ok(v4) = ip.parse::() + && config::ip_in_cidr(v4, peer_cidr)? + { + out.push(Peer { ipv4: v4 }); } } } @@ -308,9 +308,7 @@ mod tests { "wg show all dump", Err(anyhow::anyhow!("wg broken")), )]); - let err = discover_peer_runtime_with_transport(&transport, "10.8.1.0/24") - .err() - .expect("err"); + let err = discover_peer_runtime_with_transport(&transport, "10.8.1.0/24").expect_err("err"); assert!(err.to_string().contains("wg show all dump failed")); } }