From f1e96842bba33cfe81b1026dee47d5dcdd864320 Mon Sep 17 00:00:00 2001 From: e1732a364fed <75717694+e1732a364fed@users.noreply.github.com> Date: Thu, 1 Jan 2099 00:00:00 +0000 Subject: [PATCH] improve code by clippy --- README.md | 2 +- rucimp/src/net/http.rs | 2 +- src/map/network/mod.rs | 7 ++++--- src/map/stdio.rs | 2 +- src/net/dns.rs | 3 ++- src/net/tun/mod.rs | 3 +-- src/net/tun/route.rs | 2 ++ 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6587ce42..50316c73 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ o2node-.->collector - [x] http_filter, websocket(including early data) - [x] h2, grpc - [x] quic -- [x] ip relay protocol test1 +- [x] ip relay protocol (test1) - [ ] tcp/ip netstack (smoltcp) - [ ] ss?, vmess? diff --git a/rucimp/src/net/http.rs b/rucimp/src/net/http.rs index 311cd090..8ca7d954 100644 --- a/rucimp/src/net/http.rs +++ b/rucimp/src/net/http.rs @@ -65,7 +65,7 @@ pub fn match_request_http_header<'a, T: 'a + std::fmt::Debug>( //debug!("checking {r:?}"); if c.authority != given_host { - if given_host == "" { + if given_host.is_empty() { let hh = r .headers() .get("host") diff --git a/src/map/network/mod.rs b/src/map/network/mod.rs index cf8740d9..8b5bc9b8 100644 --- a/src/map/network/mod.rs +++ b/src/map/network/mod.rs @@ -6,7 +6,6 @@ pub mod accept; pub mod echo; use macro_map::*; -use parking_lot::Mutex; use tokio::sync::mpsc::Receiver; use tracing::debug; use tracing::info; @@ -105,6 +104,7 @@ impl Map for Direct { } } +#[cfg(feature = "tun")] #[derive(Clone, Debug, Default)] enum AutoRouteState { #[default] @@ -127,7 +127,8 @@ pub struct BindDialer { #[cfg(feature = "tun")] pub out_auto_route: Option, - auto_route_state: Arc>, + #[cfg(feature = "tun")] + auto_route_state: Arc>, } impl Name for BindDialer { @@ -190,8 +191,8 @@ impl BindDialer { match r { Ok(c) => { + #[cfg(feature = "tun")] if let Some(a) = &bind_a { - #[cfg(feature = "tun")] if let Network::IP = a.network { if let Some(c) = &self.in_auto_route { let mut mg = self.auto_route_state.lock(); diff --git a/src/map/stdio.rs b/src/map/stdio.rs index 003d90f7..6d20d2d1 100644 --- a/src/map/stdio.rs +++ b/src/map/stdio.rs @@ -55,7 +55,7 @@ impl fmt::Display for HexSlice<'_> { for byte in self.0 { write!(f, "{:02X}", byte)?; } - write!(f, "\n")?; + writeln!(f)?; Ok(()) } } diff --git a/src/net/dns.rs b/src/net/dns.rs index 3166d4ec..2122ccaf 100644 --- a/src/net/dns.rs +++ b/src/net/dns.rs @@ -32,9 +32,10 @@ pub fn get_sys_dns() -> Vec { } } - return vec![]; + vec![] } +#[allow(unused)] pub fn set_sys_dns(list: Vec<&str>) -> std::io::Result<()> { #[cfg(target_os = "linux")] { diff --git a/src/net/tun/mod.rs b/src/net/tun/mod.rs index 489aa723..6c3c5cdc 100644 --- a/src/net/tun/mod.rs +++ b/src/net/tun/mod.rs @@ -1,3 +1,4 @@ +#[allow(unused)] pub mod route; use anyhow::Context; @@ -47,8 +48,6 @@ where "tun: create_bind succeed" ); - // let dev = crate::net::helpers::PrintWrapper::from(Box::new(dev)); - Ok(Box::new(dev)) } diff --git a/src/net/tun/route.rs b/src/net/tun/route.rs index 80ad100e..f30d42eb 100644 --- a/src/net/tun/route.rs +++ b/src/net/tun/route.rs @@ -27,6 +27,7 @@ pub struct OutAutoRouteParams { const DEFAULT_ROUTER_IP: &str = "192.168.0.1"; const DEFAULT_ORIGINAL_DEV_NAME: &str = "enp0s1"; +#[allow(unused)] pub fn out_auto_route(params: &OutAutoRouteParams) -> anyhow::Result<()> { #[cfg(target_os = "linux")] { @@ -60,6 +61,7 @@ iptables -t nat -I POSTROUTING -o {original_dev_name} -j MASQUERADE"#, Ok(()) } +#[allow(unused)] pub fn out_down_route(params: &OutAutoRouteParams) -> anyhow::Result<()> { #[cfg(target_os = "linux")] {