From 296d50b9ff32a9d7bdbb6d0cb31e8b3f1d64f65b Mon Sep 17 00:00:00 2001 From: lxien Date: Thu, 20 Aug 2026 17:04:21 +0800 Subject: [PATCH] chore: cargo fmt --- server/src/dashboard/routes.rs | 18 ++++++++++----- server/src/main.rs | 2 +- server/src/metrics/mem.rs | 6 ++++- server/src/metrics/mod.rs | 2 +- server/src/service/ingress.rs | 5 ++++- server/src/service/mod.rs | 8 ++----- server/src/service/session_registry.rs | 5 ++++- server/src/tunnel/gw.rs | 5 +---- server/src/tunnel/http.rs | 31 +++++++++++++------------- server/src/tunnel/mod.rs | 8 +++---- 10 files changed, 50 insertions(+), 40 deletions(-) diff --git a/server/src/dashboard/routes.rs b/server/src/dashboard/routes.rs index 523a22b..cbc85d6 100644 --- a/server/src/dashboard/routes.rs +++ b/server/src/dashboard/routes.rs @@ -1,9 +1,9 @@ use super::model::{ - ApiResponse, ClientInfo, Page, TunnelInfo, TunnelTrafficPoint, TunnelTrafficResp, SystemConfig, - SystemInfo, SystemStatus, + ApiResponse, ClientInfo, Page, SystemConfig, SystemInfo, SystemStatus, TunnelInfo, + TunnelTrafficPoint, TunnelTrafficResp, }; use super::DashState; -use crate::metrics::{TunnelTrafficHistory, TrafficWindow}; +use crate::metrics::{TrafficWindow, TunnelTrafficHistory}; use axum::body::Body; use axum::extract::{Path, Query, State}; use axum::http::{header, HeaderMap, HeaderValue, Request, StatusCode}; @@ -241,7 +241,11 @@ async fn get_client( ) -> Result>, StatusCode> { let session_id = urlencoding_decode(&session_id); let snap = state.svc.dashboard_snapshot().await; - match snap.clients.into_iter().find(|c| c.session_id == session_id) { + match snap + .clients + .into_iter() + .find(|c| c.session_id == session_id) + { Some(c) => Ok(Json(ApiResponse::ok(c))), None => Err(StatusCode::NOT_FOUND), } @@ -305,7 +309,11 @@ async fn tunnel_traffic( Query(q): Query, ) -> Result>, StatusCode> { let name = urlencoding_decode(&name); - match state.svc.metrics().tunnel_traffic(&name, traffic_window(&q)) { + match state + .svc + .metrics() + .tunnel_traffic(&name, traffic_window(&q)) + { Some(hist) => Ok(Json(ApiResponse::ok(traffic_resp(hist)))), None => Err(StatusCode::NOT_FOUND), } diff --git a/server/src/main.rs b/server/src/main.rs index befb72a..4d24325 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -2,8 +2,8 @@ mod access; mod control; mod dashboard; mod metrics; -mod tunnel; mod service; +mod tunnel; use anyhow::Result; use clap::Parser; diff --git a/server/src/metrics/mem.rs b/server/src/metrics/mem.rs index 557e786..c4ffd12 100644 --- a/server/src/metrics/mem.rs +++ b/server/src/metrics/mem.rs @@ -149,7 +149,11 @@ impl MemMetrics { g.tunnels.get(name).map(|p| to_tunnel_snapshot(name, p)) } - pub fn tunnel_traffic(&self, name: &str, window: TrafficWindow) -> Option { + pub fn tunnel_traffic( + &self, + name: &str, + window: TrafficWindow, + ) -> Option { let g = self.state.lock().expect("metrics lock"); let p = g.tunnels.get(name)?; Some(match window { diff --git a/server/src/metrics/mod.rs b/server/src/metrics/mod.rs index 53fc35f..788de46 100644 --- a/server/src/metrics/mod.rs +++ b/server/src/metrics/mod.rs @@ -4,7 +4,7 @@ mod hour_counter; mod mem; mod traits; -pub use mem::{MemMetrics, TunnelTrafficHistory, TrafficWindow}; +pub use mem::{MemMetrics, TrafficWindow, TunnelTrafficHistory}; pub use traits::ServerMetrics; pub const RESERVE_DAYS: usize = 7; diff --git a/server/src/service/ingress.rs b/server/src/service/ingress.rs index 8d5563c..9caed72 100644 --- a/server/src/service/ingress.rs +++ b/server/src/service/ingress.rs @@ -73,7 +73,10 @@ impl Service { } } - pub(super) async fn run_kcp(self: Arc, mut listener: kcp_tokio::KcpListener) -> Result<()> { + pub(super) async fn run_kcp( + self: Arc, + mut listener: kcp_tokio::KcpListener, + ) -> Result<()> { loop { let (stream, peer) = transport::accept_kcp(&mut listener).await?; tracing::debug!(%peer, transport = "kcp", "incoming connection"); diff --git a/server/src/service/mod.rs b/server/src/service/mod.rs index 3ce0619..8c69a30 100644 --- a/server/src/service/mod.rs +++ b/server/src/service/mod.rs @@ -99,9 +99,7 @@ impl Service { let gw = Arc::clone(gw); let access = Arc::clone(&this.access); let shutdown = Arc::clone(&gw_shutdown); - set.spawn( - async move { run_http_gw_listener(bind, port, gw, access, shutdown).await }, - ); + set.spawn(async move { run_http_gw_listener(bind, port, gw, access, shutdown).await }); } if let Some(ref gw) = this.https_gw { @@ -110,9 +108,7 @@ impl Service { let gw = Arc::clone(gw); let access = Arc::clone(&this.access); let shutdown = Arc::clone(&gw_shutdown); - set.spawn(async move { - run_https_gw_listener(bind, port, gw, access, shutdown).await - }); + set.spawn(async move { run_https_gw_listener(bind, port, gw, access, shutdown).await }); } if this.cfg.quic_enabled() { diff --git a/server/src/service/session_registry.rs b/server/src/service/session_registry.rs index 392d8e1..ee5a493 100644 --- a/server/src/service/session_registry.rs +++ b/server/src/service/session_registry.rs @@ -152,7 +152,10 @@ impl Service { c.push_data_conn(stream).await; Ok(()) } - None => Err(anyhow!("unknown session_id for data conn: {}", nw.session_id)), + None => Err(anyhow!( + "unknown session_id for data conn: {}", + nw.session_id + )), } } } diff --git a/server/src/tunnel/gw.rs b/server/src/tunnel/gw.rs index f645b6e..12f29ab 100644 --- a/server/src/tunnel/gw.rs +++ b/server/src/tunnel/gw.rs @@ -121,10 +121,7 @@ pub fn normalize_host(host: &str) -> String { .to_ascii_lowercase() } -pub fn build_domains( - domains: &[String], - root_domain: &str, -) -> anyhow::Result> { +pub fn build_domains(domains: &[String], root_domain: &str) -> anyhow::Result> { let root = normalize_host(root_domain); let entries: Vec = domains .iter() diff --git a/server/src/tunnel/http.rs b/server/src/tunnel/http.rs index b7f532b..c984bcb 100644 --- a/server/src/tunnel/http.rs +++ b/server/src/tunnel/http.rs @@ -1,6 +1,6 @@ use super::gw::{ build_domains, expand_locations, normalize_host, route_basic_auth_ok, route_user_from_headers, - HttpRoute, HttpGw, + HttpGw, HttpRoute, }; use crate::access::{prepare_ingress, AccessPolicy}; use crate::control::Control; @@ -42,21 +42,20 @@ impl HttpTunnel { for domain in &domains { for location in &locations { - gw - .register( - domain, - HttpRoute { - tunnel_name: name.clone(), - control: Arc::downgrade(&control), - location: location.clone(), - host_header_rewrite: rewrite.clone(), - basic_auth_user: basic_auth_user.clone(), - basic_auth_password: basic_auth_password.clone(), - route_by_http_user: route_by_http_user.clone(), - limiter: limiter.clone(), - }, - ) - .await?; + gw.register( + domain, + HttpRoute { + tunnel_name: name.clone(), + control: Arc::downgrade(&control), + location: location.clone(), + host_header_rewrite: rewrite.clone(), + basic_auth_user: basic_auth_user.clone(), + basic_auth_password: basic_auth_password.clone(), + route_by_http_user: route_by_http_user.clone(), + limiter: limiter.clone(), + }, + ) + .await?; } } diff --git a/server/src/tunnel/mod.rs b/server/src/tunnel/mod.rs index 8048ae2..da7336f 100644 --- a/server/src/tunnel/mod.rs +++ b/server/src/tunnel/mod.rs @@ -1,13 +1,13 @@ +mod gw; mod http; mod https; mod manager; mod tcp; mod udp; -mod gw; +pub use gw::HttpGw; pub use http::{run_http_gw_listener, HttpTunnel}; -pub use https::{run_https_gw_listener, HttpsTunnel, HttpsGw}; -pub use manager::{format_local_addr, TunnelManager, TunnelSummary, RegisteredTunnel}; +pub use https::{run_https_gw_listener, HttpsGw, HttpsTunnel}; +pub use manager::{format_local_addr, RegisteredTunnel, TunnelManager, TunnelSummary}; pub use tcp::TcpTunnel; pub use udp::UdpTunnel; -pub use gw::HttpGw;