From d355f8d005d4a45b1250066bc6726c4294cdf69a Mon Sep 17 00:00:00 2001 From: Razvan Dimescu Date: Sat, 21 Mar 2026 16:54:03 +0200 Subject: [PATCH] fix rustfmt formatting Co-Authored-By: Claude Opus 4.6 --- src/ctx.rs | 6 ++---- src/lan.rs | 33 ++++++++++++++++++++++----------- src/proxy.rs | 7 ++++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/ctx.rs b/src/ctx.rs index d555fad..1a2f424 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -11,12 +11,12 @@ use crate::cache::DnsCache; use crate::config::ZoneMap; use crate::forward::forward_query; use crate::header::ResultCode; +use crate::lan::PeerStore; use crate::override_store::OverrideStore; use crate::packet::DnsPacket; use crate::query_log::{QueryLog, QueryLogEntry}; use crate::question::QueryType; use crate::record::DnsRecord; -use crate::lan::PeerStore; use crate::service_store::ServiceStore; use crate::stats::{QueryPath, ServerStats}; use crate::system_dns::ForwardingRule; @@ -70,9 +70,7 @@ pub async fn handle_query( && (qname.ends_with(&ctx.proxy_tld_suffix) || qname == ctx.proxy_tld) { // Resolve .numa: local services → 127.0.0.1, LAN peers → peer IP - let service_name = qname - .strip_suffix(&ctx.proxy_tld_suffix) - .unwrap_or(&qname); + let service_name = qname.strip_suffix(&ctx.proxy_tld_suffix).unwrap_or(&qname); let resolve_ip = { let local = ctx.services.lock().unwrap(); if local.lookup(service_name).is_some() { diff --git a/src/lan.rs b/src/lan.rs index f693f71..1cc1484 100644 --- a/src/lan.rs +++ b/src/lan.rs @@ -27,8 +27,7 @@ impl PeerStore { pub fn update(&mut self, host: IpAddr, services: &[(String, u16)]) { let now = Instant::now(); for (name, port) in services { - self.peers - .insert(name.to_lowercase(), (host, *port, now)); + self.peers.insert(name.to_lowercase(), (host, *port, now)); } } @@ -44,11 +43,17 @@ impl PeerStore { pub fn list(&mut self) -> Vec<(String, IpAddr, u16, u64)> { let now = Instant::now(); - self.peers.retain(|_, (_, _, seen)| now.duration_since(*seen) < self.timeout); + self.peers + .retain(|_, (_, _, seen)| now.duration_since(*seen) < self.timeout); self.peers .iter() .map(|(name, (ip, port, seen))| { - (name.clone(), *ip, *port, now.duration_since(*seen).as_secs()) + ( + name.clone(), + *ip, + *port, + now.duration_since(*seen).as_secs(), + ) }) .collect() } @@ -81,7 +86,10 @@ pub async fn start_lan_discovery(ctx: Arc, config: &LanConfig) { let multicast_group: Ipv4Addr = match config.multicast_group.parse() { Ok(g) => g, Err(e) => { - warn!("LAN: invalid multicast group {}: {}", config.multicast_group, e); + warn!( + "LAN: invalid multicast group {}: {}", + config.multicast_group, e + ); return; } }; @@ -89,13 +97,19 @@ pub async fn start_lan_discovery(ctx: Arc, config: &LanConfig) { let interval = Duration::from_secs(config.broadcast_interval_secs); let local_ip = detect_lan_ip().unwrap_or(Ipv4Addr::LOCALHOST); - info!("LAN discovery on {}:{}, local IP {}", multicast_group, port, local_ip); + info!( + "LAN discovery on {}:{}, local IP {}", + multicast_group, port, local_ip + ); // Create socket with SO_REUSEADDR for multicast let std_socket = match create_multicast_socket(multicast_group, port) { Ok(s) => s, Err(e) => { - warn!("LAN: could not bind multicast socket: {} — LAN discovery disabled", e); + warn!( + "LAN: could not bind multicast socket: {} — LAN discovery disabled", + e + ); return; } }; @@ -178,10 +192,7 @@ pub async fn start_lan_discovery(ctx: Arc, config: &LanConfig) { } } -fn create_multicast_socket( - group: Ipv4Addr, - port: u16, -) -> std::io::Result { +fn create_multicast_socket(group: Ipv4Addr, port: u16) -> std::io::Result { use std::net::SocketAddrV4; let addr = SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port); diff --git a/src/proxy.rs b/src/proxy.rs index af9ca5c..414a53e 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -273,9 +273,10 @@ pre .str {{ color: #d48a5a }} .path_and_query() .map(|pq| pq.as_str()) .unwrap_or("/"); - let target_uri: hyper::Uri = format!("http://{}:{}{}", target_host, target_port, path_and_query) - .parse() - .unwrap(); + let target_uri: hyper::Uri = + format!("http://{}:{}{}", target_host, target_port, path_and_query) + .parse() + .unwrap(); // Check for upgrade request (WebSocket, etc.) let is_upgrade = req.headers().get(hyper::header::UPGRADE).is_some();