diff --git a/clash_lib/src/app/api/middlewares/auth.rs b/clash_lib/src/app/api/middlewares/auth.rs index 639d49bfc..807d7ebf8 100644 --- a/clash_lib/src/app/api/middlewares/auth.rs +++ b/clash_lib/src/app/api/middlewares/auth.rs @@ -52,11 +52,9 @@ where S: Service, Response = Response> + Send + 'static, S::Future: Send + 'static, { - type Response = S::Response; - type Error = S::Error; - type Future = BoxFuture<'static, Result>; + type Response = S::Response; fn poll_ready( &mut self, diff --git a/clash_lib/src/app/dispatcher/dispatcher_impl.rs b/clash_lib/src/app/dispatcher/dispatcher_impl.rs index 23e6bb0f8..52cb517c1 100644 --- a/clash_lib/src/app/dispatcher/dispatcher_impl.rs +++ b/clash_lib/src/app/dispatcher/dispatcher_impl.rs @@ -103,7 +103,7 @@ impl Dispatcher { sess } } - crate::session::SocksAddr::Domain(_, _) => sess, + crate::session::SocksAddr::Domain(..) => sess, } } else { sess @@ -287,7 +287,7 @@ impl Dispatcher { sess } } - crate::session::SocksAddr::Domain(_, _) => sess, + crate::session::SocksAddr::Domain(..) => sess, } } else { sess @@ -597,7 +597,7 @@ impl Drop for OutboundHandleMap { "dropping inner outbound handle map that has {} sessions", self.0.len() ); - for (_, (recv_handle, send_handle, _, _)) in self.0.drain() { + for (_, (recv_handle, send_handle, ..)) in self.0.drain() { recv_handle.abort(); send_handle.abort(); } diff --git a/clash_lib/src/app/dispatcher/tracked.rs b/clash_lib/src/app/dispatcher/tracked.rs index 26bff4028..72ae8d4c7 100644 --- a/clash_lib/src/app/dispatcher/tracked.rs +++ b/clash_lib/src/app/dispatcher/tracked.rs @@ -325,6 +325,7 @@ where T: Sink + Unpin, { type Error = std::io::Error; + fn poll_ready( self: Pin<&mut Self>, cx: &mut std::task::Context<'_>, diff --git a/clash_lib/src/app/dns/resolver.rs b/clash_lib/src/app/dns/resolver.rs index 1dc581ae4..00603c783 100644 --- a/clash_lib/src/app/dns/resolver.rs +++ b/clash_lib/src/app/dns/resolver.rs @@ -479,6 +479,7 @@ impl ClashResolver for Resolver { .map(|ip| ip.map(net::IpAddr::from)), } } + async fn resolve_v4( &self, host: &str, diff --git a/clash_lib/src/app/dns/system.rs b/clash_lib/src/app/dns/system.rs index 9611ae1e2..a0f35aa5d 100644 --- a/clash_lib/src/app/dns/system.rs +++ b/clash_lib/src/app/dns/system.rs @@ -51,6 +51,7 @@ impl ClashResolver for SystemResolver { }) .choose(&mut rand::thread_rng())) } + async fn resolve_v6( &self, host: &str, diff --git a/clash_lib/src/app/remote_content_manager/http_client.rs b/clash_lib/src/app/remote_content_manager/http_client.rs index fc9f63eb9..b0ccf2793 100644 --- a/clash_lib/src/app/remote_content_manager/http_client.rs +++ b/clash_lib/src/app/remote_content_manager/http_client.rs @@ -19,10 +19,10 @@ use crate::{ pub struct LocalConnector(pub AnyOutboundHandler, pub ThreadSafeDNSResolver); impl Service for LocalConnector { - type Response = BoxedChainedStream; type Error = std::io::Error; type Future = Pin> + Send>>; + type Response = BoxedChainedStream; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) diff --git a/clash_lib/src/app/remote_content_manager/providers/fetcher.rs b/clash_lib/src/app/remote_content_manager/providers/fetcher.rs index 915aa92f7..8a1d549c5 100644 --- a/clash_lib/src/app/remote_content_manager/providers/fetcher.rs +++ b/clash_lib/src/app/remote_content_manager/providers/fetcher.rs @@ -58,6 +58,7 @@ where on_update: on_update.map(|f| Arc::new(Mutex::new(f))), } } + pub fn name(&self) -> &str { self.name.as_str() } diff --git a/clash_lib/src/app/remote_content_manager/providers/proxy_provider/plain_provider.rs b/clash_lib/src/app/remote_content_manager/providers/proxy_provider/plain_provider.rs index 74ab45061..f6cd61283 100644 --- a/clash_lib/src/app/remote_content_manager/providers/proxy_provider/plain_provider.rs +++ b/clash_lib/src/app/remote_content_manager/providers/proxy_provider/plain_provider.rs @@ -52,15 +52,19 @@ impl Provider for PlainProvider { fn name(&self) -> &str { &self.name } + fn vehicle_type(&self) -> ProviderVehicleType { ProviderVehicleType::Compatible } + fn typ(&self) -> ProviderType { ProviderType::Proxy } + async fn initialize(&self) -> std::io::Result<()> { Ok(()) } + async fn update(&self) -> std::io::Result<()> { Ok(()) } diff --git a/clash_lib/src/app/remote_content_manager/providers/rule_provider/provider.rs b/clash_lib/src/app/remote_content_manager/providers/rule_provider/provider.rs index b65c08dd8..ca69f6b9d 100644 --- a/clash_lib/src/app/remote_content_manager/providers/rule_provider/provider.rs +++ b/clash_lib/src/app/remote_content_manager/providers/rule_provider/provider.rs @@ -167,6 +167,7 @@ impl RuleProvider for RuleProviderImpl { } } } + fn behavior(&self) -> RuleSetBehavior { self.behavior } @@ -177,12 +178,15 @@ impl Provider for RuleProviderImpl { fn name(&self) -> &str { self.fetcher.name() } + fn vehicle_type(&self) -> ProviderVehicleType { self.fetcher.vehicle_type() } + fn typ(&self) -> ProviderType { ProviderType::Rule } + async fn initialize(&self) -> std::io::Result<()> { let ele = self.fetcher.initial().await.map_err(map_io_error)?; debug!("initializing rule provider {}", self.name()); @@ -191,6 +195,7 @@ impl Provider for RuleProviderImpl { } Ok(()) } + async fn update(&self) -> std::io::Result<()> { let (ele, same) = self.fetcher.update().await.map_err(map_io_error)?; debug!("rule provider {} updated. same? {}", self.name(), same); diff --git a/clash_lib/src/app/router/rules/geoip.rs b/clash_lib/src/app/router/rules/geoip.rs index 3feb1ae36..63ea42782 100644 --- a/clash_lib/src/app/router/rules/geoip.rs +++ b/clash_lib/src/app/router/rules/geoip.rs @@ -38,9 +38,10 @@ impl RuleMatcher for GeoIP { false } }, - crate::session::SocksAddr::Domain(_, _) => false, + crate::session::SocksAddr::Domain(..) => false, } } + fn target(&self) -> &str { self.target.as_str() } diff --git a/clash_lib/src/app/router/rules/ipcidr.rs b/clash_lib/src/app/router/rules/ipcidr.rs index 08ec83be2..179e2eaf8 100644 --- a/clash_lib/src/app/router/rules/ipcidr.rs +++ b/clash_lib/src/app/router/rules/ipcidr.rs @@ -29,10 +29,11 @@ impl RuleMatcher for IpCidr { true => self.ipnet.contains(&sess.source.ip()), false => match &sess.destination { SocksAddr::Ip(ip) => self.ipnet.contains(&ip.ip()), - SocksAddr::Domain(_, _) => false, + SocksAddr::Domain(..) => false, }, } } + fn target(&self) -> &str { self.target.as_str() } diff --git a/clash_lib/src/common/http.rs b/clash_lib/src/common/http.rs index 2a177b2cc..692ed4d8a 100644 --- a/clash_lib/src/common/http.rs +++ b/clash_lib/src/common/http.rs @@ -21,10 +21,10 @@ use crate::{ pub struct LocalConnector(pub ThreadSafeDNSResolver); impl Service for LocalConnector { - type Response = AnyStream; type Error = std::io::Error; type Future = Pin> + Send>>; + type Response = AnyStream; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) diff --git a/clash_lib/src/proxy/http/inbound/connector.rs b/clash_lib/src/proxy/http/inbound/connector.rs index 0fd7b8705..6c6d0eaa7 100644 --- a/clash_lib/src/proxy/http/inbound/connector.rs +++ b/clash_lib/src/proxy/http/inbound/connector.rs @@ -30,10 +30,10 @@ impl Connector { } impl tower::Service for Connector { - type Response = AnyStream; type Error = ProxyError; type Future = Pin> + Send>>; + type Response = AnyStream; fn poll_ready( &mut self, diff --git a/clash_lib/src/proxy/http/inbound/proxy.rs b/clash_lib/src/proxy/http/inbound/proxy.rs index 47a2f2d98..2e1be85e1 100644 --- a/clash_lib/src/proxy/http/inbound/proxy.rs +++ b/clash_lib/src/proxy/http/inbound/proxy.rs @@ -107,11 +107,9 @@ struct ProxyService { } impl Service> for ProxyService { - type Response = Response; - type Error = ProxyError; - type Future = BoxFuture<'static, Result>; + type Response = Response; fn poll_ready( &mut self, diff --git a/clash_lib/src/proxy/shadowsocks/datagram.rs b/clash_lib/src/proxy/shadowsocks/datagram.rs index ed4220bc6..0e0434788 100644 --- a/clash_lib/src/proxy/shadowsocks/datagram.rs +++ b/clash_lib/src/proxy/shadowsocks/datagram.rs @@ -175,7 +175,7 @@ impl Stream for OutboundDatagramShadowsocks { debug!("recv udp packet from remote ss server: {:?}", rv); match rv { - Ok((n, src, _, _)) => Poll::Ready(Some(UdpPacket { + Ok((n, src, ..)) => Poll::Ready(Some(UdpPacket { data: buf.filled()[..n].to_vec(), src_addr: src.into(), dst_addr: SocksAddr::any_ipv4(), diff --git a/clash_lib/src/proxy/shadowsocks/shadow_tls/utils.rs b/clash_lib/src/proxy/shadowsocks/shadow_tls/utils.rs index 2a262c968..3181f3bb1 100644 --- a/clash_lib/src/proxy/shadowsocks/shadow_tls/utils.rs +++ b/clash_lib/src/proxy/shadowsocks/shadow_tls/utils.rs @@ -142,7 +142,7 @@ pub(crate) fn support_tls13(frame: &[u8]) -> bool { } let mut cursor = std::io::Cursor::new(&frame[SESSION_ID_LEN_IDX..]); macro_rules! read_ok { - ($res: expr) => { + ($res:expr) => { match $res { Ok(r) => r, Err(_) => { diff --git a/clash_lib/src/proxy/socks/inbound/datagram.rs b/clash_lib/src/proxy/socks/inbound/datagram.rs index c69bc9ec8..1e45427e3 100644 --- a/clash_lib/src/proxy/socks/inbound/datagram.rs +++ b/clash_lib/src/proxy/socks/inbound/datagram.rs @@ -40,8 +40,8 @@ impl Encoder<(Bytes, SocksAddr)> for Socks5UDPCodec { } impl Decoder for Socks5UDPCodec { - type Item = (SocksAddr, BytesMut); type Error = std::io::Error; + type Item = (SocksAddr, BytesMut); fn decode( &mut self, diff --git a/clash_lib/src/proxy/tuic/compat.rs b/clash_lib/src/proxy/tuic/compat.rs index c79a6e6c9..25d97c063 100644 --- a/clash_lib/src/proxy/tuic/compat.rs +++ b/clash_lib/src/proxy/tuic/compat.rs @@ -11,6 +11,7 @@ use super::TuicDatagramOutbound; impl Sink for TuicDatagramOutbound { type Error = std::io::Error; + fn poll_ready( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -19,6 +20,7 @@ impl Sink for TuicDatagramOutbound { .poll_ready_unpin(cx) .map_err(|v| new_io_error(&format!("{v:?}"))) } + fn start_send( mut self: Pin<&mut Self>, item: UdpPacket, @@ -27,6 +29,7 @@ impl Sink for TuicDatagramOutbound { .start_send_unpin(item) .map_err(|v| new_io_error(&format!("{v:?}"))) } + fn poll_flush( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -35,6 +38,7 @@ impl Sink for TuicDatagramOutbound { .poll_flush_unpin(cx) .map_err(|v| new_io_error(&format!("{v:?}"))) } + fn poll_close( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -47,6 +51,7 @@ impl Sink for TuicDatagramOutbound { impl Stream for TuicDatagramOutbound { type Item = UdpPacket; + fn poll_next( mut self: Pin<&mut Self>, cx: &mut Context<'_>, diff --git a/clash_lib/src/proxy/tuic/handle_task.rs b/clash_lib/src/proxy/tuic/handle_task.rs index 33acd35a1..72d323349 100644 --- a/clash_lib/src/proxy/tuic/handle_task.rs +++ b/clash_lib/src/proxy/tuic/handle_task.rs @@ -185,6 +185,7 @@ impl TuicConnection { self.inner.collect_garbage(gc_lifetime); Ok(()) } + /// Tasks triggered by timer /// Won't return unless occurs error pub async fn cyclical_tasks( diff --git a/clash_lib/src/proxy/tuic/mod.rs b/clash_lib/src/proxy/tuic/mod.rs index ffb478c9f..c6815b8e1 100644 --- a/clash_lib/src/proxy/tuic/mod.rs +++ b/clash_lib/src/proxy/tuic/mod.rs @@ -119,6 +119,7 @@ impl OutboundHandler for Handler { std::io::Error::new(std::io::ErrorKind::Other, e.to_string()) }) } + async fn connect_datagram( &self, sess: &Session, diff --git a/clash_lib/src/proxy/tuic/types.rs b/clash_lib/src/proxy/tuic/types.rs index 027a7afc7..3306be2b0 100644 --- a/clash_lib/src/proxy/tuic/types.rs +++ b/clash_lib/src/proxy/tuic/types.rs @@ -126,6 +126,7 @@ impl TuicConnection { None => Ok(()), } } + #[allow(clippy::too_many_arguments)] fn new( conn: QuinnConnection, @@ -161,6 +162,7 @@ impl TuicConnection { conn } + async fn init( self: Arc, zero_rtt_accepted: Option, diff --git a/clash_lib/src/proxy/vmess/vmess_impl/cipher.rs b/clash_lib/src/proxy/vmess/vmess_impl/cipher.rs index 55553c9e2..20f7c28d3 100644 --- a/clash_lib/src/proxy/vmess/vmess_impl/cipher.rs +++ b/clash_lib/src/proxy/vmess/vmess_impl/cipher.rs @@ -15,6 +15,7 @@ impl VmessSecurity { pub fn overhead_len(&self) -> usize { 16 } + #[inline(always)] pub fn nonce_len(&self) -> usize { 12 diff --git a/clash_lib/src/session.rs b/clash_lib/src/session.rs index 42992d3dd..88162d3f0 100644 --- a/clash_lib/src/session.rs +++ b/clash_lib/src/session.rs @@ -34,8 +34,8 @@ impl Display for SocksAddr { pub struct SocksAddrType; impl SocksAddrType { - pub const V4: u8 = 0x1; pub const DOMAIN: u8 = 0x3; + pub const V4: u8 = 0x1; pub const V6: u8 = 0x4; } @@ -97,7 +97,7 @@ impl SocksAddr { pub fn is_domain(&self) -> bool { match self { SocksAddr::Ip(_) => false, - SocksAddr::Domain(_, _) => true, + SocksAddr::Domain(..) => true, } } @@ -111,7 +111,7 @@ impl SocksAddr { pub fn must_into_socket_addr(self) -> SocketAddr { match self { SocksAddr::Ip(addr) => addr, - SocksAddr::Domain(_, _) => panic!("not a socket address"), + SocksAddr::Domain(..) => panic!("not a socket address"), } } @@ -344,7 +344,7 @@ impl TryFrom for SocketAddr { fn try_from(s: SocksAddr) -> Result { match s { SocksAddr::Ip(ip) => Ok(ip), - SocksAddr::Domain(_, _) => { + SocksAddr::Domain(..) => { Err(io::Error::new(io::ErrorKind::Other, "cannot convert")) } } diff --git a/rustfmt.toml b/rustfmt.toml index f8cb1f1c6..056190ea2 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,10 +1,17 @@ -error_on_line_overflow = false +edition = "2021" +reorder_modules = true +reorder_impl_items = true +reorder_imports = true format_strings = true +format_code_in_doc_comments = true +format_macro_matchers = true +condense_wildcard_suffixes = true normalize_comments = true -imports_granularity = "Crate" -reorder_modules = true -max_width = 85 -# enum_discrim_align_threshold = 20 use_try_shorthand = true wrap_comments = true -edition = "2021" +use_field_init_shorthand = true +error_on_line_overflow = false +tab_spaces = 4 +enum_discrim_align_threshold = 20 +max_width = 85 +imports_granularity = "Crate"