From b2dbff36112eddfcae28505b52d6a6ad20040203 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Sat, 4 Feb 2023 18:39:25 +0900 Subject: [PATCH] make clippy happy (kinda) --- tuic-client/src/socks5.rs | 10 +++++++--- tuic-quinn/src/lib.rs | 2 +- tuic-server/src/server.rs | 8 +++----- tuic/src/model/mod.rs | 6 ++++++ tuic/src/protocol/authenticate.rs | 1 + tuic/src/protocol/connect.rs | 1 + tuic/src/protocol/dissociate.rs | 1 + tuic/src/protocol/heartbeat.rs | 5 ++--- tuic/src/protocol/mod.rs | 4 +++- tuic/src/protocol/packet.rs | 1 + 10 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tuic-client/src/socks5.rs b/tuic-client/src/socks5.rs index c14ef47..51fd00e 100644 --- a/tuic-client/src/socks5.rs +++ b/tuic-client/src/socks5.rs @@ -243,7 +243,7 @@ impl Server { if frag != 0 { Err(IoError::new( ErrorKind::Other, - format!("fragmented packet is not supported"), + "fragmented packet is not supported", ))?; } @@ -282,8 +282,12 @@ impl Server { } pub async fn recv_pkt(pkt: Bytes, addr: Address, assoc_id: u16) -> Result<(), Error> { - let sessions = SERVER.get().unwrap().udp_sessions.lock(); - let Some(assoc_socket) = sessions.get(&assoc_id) else { unreachable!() }; + let assoc_socket = { + let sessions = SERVER.get().unwrap().udp_sessions.lock(); + let Some(assoc_socket) = sessions.get(&assoc_id) else { unreachable!() }; + assoc_socket.clone() + }; + assoc_socket.send(pkt, 0, addr).await?; Ok(()) } diff --git a/tuic-quinn/src/lib.rs b/tuic-quinn/src/lib.rs index 29057ba..bd86fa0 100644 --- a/tuic-quinn/src/lib.rs +++ b/tuic-quinn/src/lib.rs @@ -316,7 +316,7 @@ impl Connect { match &self.model { Side::Client(model) => { let Header::Connect(conn) = model.header() else { unreachable!() }; - &conn.addr() + conn.addr() } Side::Server(model) => model.addr(), } diff --git a/tuic-server/src/server.rs b/tuic-server/src/server.rs index 892693f..8847248 100644 --- a/tuic-server/src/server.rs +++ b/tuic-server/src/server.rs @@ -131,7 +131,7 @@ impl Server { loop { let conn = self.ep.accept().await.unwrap(); - tokio::spawn(Connection::new( + tokio::spawn(Connection::handle( conn, self.token.clone(), self.udp_relay_ipv6, @@ -161,8 +161,9 @@ struct Connection { max_concurrent_bi_streams: Arc, } +#[allow(clippy::too_many_arguments)] impl Connection { - async fn new( + async fn handle( conn: Connecting, token: Arc<[u8]>, udp_relay_ipv6: bool, @@ -310,7 +311,6 @@ impl Connection { Err(err) => { eprintln!("{err}"); self.close(); - return; } } } @@ -350,7 +350,6 @@ impl Connection { Err(err) => { eprintln!("{err}"); self.close(); - return; } } } @@ -386,7 +385,6 @@ impl Connection { Err(err) => { eprintln!("{err}"); self.close(); - return; } } } diff --git a/tuic/src/model/mod.rs b/tuic/src/model/mod.rs index 9e66fe1..c65e6cb 100644 --- a/tuic/src/model/mod.rs +++ b/tuic/src/model/mod.rs @@ -40,6 +40,7 @@ impl Connection where B: AsRef<[u8]>, { + #[allow(clippy::new_without_default)] pub fn new() -> Self { let task_associate_count = Counter::new(); @@ -174,6 +175,7 @@ where .send_packet(assoc_id, addr, max_pkt_size) } + #[allow(clippy::too_many_arguments)] fn recv_packet( &mut self, sessions: Arc>, @@ -189,6 +191,7 @@ where }) } + #[allow(clippy::too_many_arguments)] fn recv_packet_unrestricted( &mut self, sessions: Arc>, @@ -215,6 +218,7 @@ where Dissociate::::new(assoc_id) } + #[allow(clippy::too_many_arguments)] fn insert( &mut self, assoc_id: u16, @@ -270,6 +274,7 @@ where ) } + #[allow(clippy::too_many_arguments)] fn recv_packet( &self, sessions: Arc>>, @@ -283,6 +288,7 @@ where Packet::::new(sessions, assoc_id, pkt_id, frag_total, frag_id, size, addr) } + #[allow(clippy::too_many_arguments)] fn insert( &mut self, assoc_id: u16, diff --git a/tuic/src/protocol/authenticate.rs b/tuic/src/protocol/authenticate.rs index 9879241..7c86ae7 100644 --- a/tuic/src/protocol/authenticate.rs +++ b/tuic/src/protocol/authenticate.rs @@ -23,6 +23,7 @@ impl Authenticate { Self::TYPE_CODE } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { 32 } diff --git a/tuic/src/protocol/connect.rs b/tuic/src/protocol/connect.rs index 6139c83..6f00984 100644 --- a/tuic/src/protocol/connect.rs +++ b/tuic/src/protocol/connect.rs @@ -25,6 +25,7 @@ impl Connect { Self::TYPE_CODE } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.addr.len() } diff --git a/tuic/src/protocol/dissociate.rs b/tuic/src/protocol/dissociate.rs index 86caa19..eb29754 100644 --- a/tuic/src/protocol/dissociate.rs +++ b/tuic/src/protocol/dissociate.rs @@ -23,6 +23,7 @@ impl Dissociate { Self::TYPE_CODE } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { 2 } diff --git a/tuic/src/protocol/heartbeat.rs b/tuic/src/protocol/heartbeat.rs index dd8143a..ec665b3 100644 --- a/tuic/src/protocol/heartbeat.rs +++ b/tuic/src/protocol/heartbeat.rs @@ -17,13 +17,12 @@ impl Heartbeat { Self::TYPE_CODE } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { 0 } } impl From for () { - fn from(_: Heartbeat) -> Self { - () - } + fn from(_: Heartbeat) -> Self {} } diff --git a/tuic/src/protocol/mod.rs b/tuic/src/protocol/mod.rs index 3ade4cb..a675def 100644 --- a/tuic/src/protocol/mod.rs +++ b/tuic/src/protocol/mod.rs @@ -53,6 +53,7 @@ impl Header { } } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { 2 + match self { Self::Authenticate(auth) => auth.len(), @@ -106,12 +107,13 @@ impl Address { } } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { 1 + match self { Address::None => 0, Address::DomainAddress(addr, _) => 1 + addr.len() + 2, Address::SocketAddress(addr) => match addr { - SocketAddr::V4(_) => 1 * 4 + 2, + SocketAddr::V4(_) => 4 + 2, SocketAddr::V6(_) => 2 * 8 + 2, }, } diff --git a/tuic/src/protocol/packet.rs b/tuic/src/protocol/packet.rs index d9c6a5d..f6703c7 100644 --- a/tuic/src/protocol/packet.rs +++ b/tuic/src/protocol/packet.rs @@ -64,6 +64,7 @@ impl Packet { Self::TYPE_CODE } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { Self::len_without_addr() + self.addr.len() }