diff --git a/Earthfile b/Earthfile index c8d569ac..ce1fa058 100644 --- a/Earthfile +++ b/Earthfile @@ -6,7 +6,7 @@ ARG --global debian = bookworm IMPORT github.com/earthly/lib/rust:a49d2a0f4028cd15666d19904f8fc5fbd0b9ba87 AS lib-rust install-build-dependencies: - FROM rust:1.88.0-$debian + FROM rust:1.89.0-$debian WORKDIR /lightway RUN dpkg --add-architecture arm64 RUN apt-get update -qq diff --git a/lightway-client/src/io/inside/tun.rs b/lightway-client/src/io/inside/tun.rs index aad4ee22..184bdac4 100644 --- a/lightway-client/src/io/inside/tun.rs +++ b/lightway-client/src/io/inside/tun.rs @@ -59,10 +59,10 @@ impl InsideIORecv for Tun { // Update source IP from server DNS ip to TUN DNS ip if let Some(ip_config) = ip_config { let packet = Ipv4Packet::new(pkt.as_ref()); - if let Some(packet) = packet { - if packet.get_source() == ip_config.dns_ip { - ipv4_update_source(pkt.as_mut(), self.dns_ip); - } + if let Some(packet) = packet + && packet.get_source() == ip_config.dns_ip + { + ipv4_update_source(pkt.as_mut(), self.dns_ip); }; } @@ -83,10 +83,10 @@ impl InsideIOSendCallback> for Tun { // Update source IP from server DNS ip to TUN DNS ip if let Some(ip_config) = state.ip_config { let packet = Ipv4Packet::new(buf.as_ref()); - if let Some(packet) = packet { - if packet.get_source() == ip_config.dns_ip { - ipv4_update_source(buf.as_mut(), self.dns_ip); - } + if let Some(packet) = packet + && packet.get_source() == ip_config.dns_ip + { + ipv4_update_source(buf.as_mut(), self.dns_ip); }; } diff --git a/lightway-client/src/lib.rs b/lightway-client/src/lib.rs index dbc32319..62d62aa5 100644 --- a/lightway-client/src/lib.rs +++ b/lightway-client/src/lib.rs @@ -280,13 +280,10 @@ async fn handle_events( conn.lock().unwrap().inside_io(inside_io.clone()); - if enable_encoding_when_online { - if let Err(e) = conn.lock().unwrap().set_encoding(true) { - tracing::error!( - "Error encoutered when trying to toggle encoding. {}", - e - ); - } + if enable_encoding_when_online + && let Err(e) = conn.lock().unwrap().set_encoding(true) + { + tracing::error!("Error encoutered when trying to toggle encoding. {}", e); } } } @@ -369,10 +366,10 @@ pub async fn inside_io_task( // Update TUN device DNS IP address to server provided DNS address let packet = Ipv4Packet::new(buf.as_ref()); - if let Some(packet) = packet { - if packet.get_destination() == tun_dns_ip { - ipv4_update_destination(buf.as_mut(), ip_config.dns_ip); - } + if let Some(packet) = packet + && packet.get_destination() == tun_dns_ip + { + ipv4_update_destination(buf.as_mut(), ip_config.dns_ip); }; } @@ -525,14 +522,13 @@ fn validate_client_config( )); } - if let Some(inside_pkt_codec_config) = &config.inside_pkt_codec_config { - if inside_pkt_codec_config.enable_encoding_at_connect - && matches!(config.mode, ClientConnectionMode::Stream(_)) - { - return Err(anyhow!( - "inside pkt encoding should not be enabled with TCP" - )); - } + if let Some(inside_pkt_codec_config) = &config.inside_pkt_codec_config + && inside_pkt_codec_config.enable_encoding_at_connect + && matches!(config.mode, ClientConnectionMode::Stream(_)) + { + return Err(anyhow!( + "inside pkt encoding should not be enabled with TCP" + )); } Ok(()) diff --git a/lightway-client/src/routing_table.rs b/lightway-client/src/routing_table.rs index 3be430d3..9476cfcc 100644 --- a/lightway-client/src/routing_table.rs +++ b/lightway-client/src/routing_table.rs @@ -273,13 +273,13 @@ impl RoutingTable { } } - if let Some(route) = &self.server_route { - if let Err(e) = self.route_manager.delete(route) { - warn!( - "Failed to delete server route during drop: {}, error: {}", - route, e - ); - } + if let Some(route) = &self.server_route + && let Err(e) = self.route_manager.delete(route) + { + warn!( + "Failed to delete server route during drop: {}, error: {}", + route, e + ); } } pub async fn initialize_routing_table( diff --git a/lightway-core/src/borrowed_bytesmut.rs b/lightway-core/src/borrowed_bytesmut.rs index 44a45bea..7cc72599 100644 --- a/lightway-core/src/borrowed_bytesmut.rs +++ b/lightway-core/src/borrowed_bytesmut.rs @@ -131,7 +131,7 @@ mod immutable_bytesmut { Self { orig, mutable } } - pub fn as_borrowed_bytesmut(&mut self) -> BorrowedBytesMut { + pub fn as_borrowed_bytesmut(&mut self) -> BorrowedBytesMut<'_> { BorrowedBytesMut::from(&mut self.mutable) } } diff --git a/lightway-core/src/connection.rs b/lightway-core/src/connection.rs index 503c55d9..f9c86cd2 100644 --- a/lightway-core/src/connection.rs +++ b/lightway-core/src/connection.rs @@ -558,10 +558,10 @@ impl Connection { } } - if matches!(new_state, State::LinkUp) { - if let ConnectionMode::Client { auth_method, .. } = &self.mode { - self.authenticate(auth_method.clone())?; - } + if matches!(new_state, State::LinkUp) + && let ConnectionMode::Client { auth_method, .. } = &self.mode + { + self.authenticate(auth_method.clone())?; }; Ok(()) } @@ -859,11 +859,11 @@ impl Connection { // This should be enabled only for client for now. // But since we enable PMTU check only on client, there is no direct // check for client/server - if let Some(pmtud) = self.pmtud.as_ref() { - if let Some((mps, _)) = pmtud.maximum_packet_sizes() { - let tcp_mss = mps - (IPV4_HEADER_SIZE + TCP_HEADER_SIZE); - tcp_clamp_mss(pkt.as_mut(), tcp_mss as _); - } + if let Some(pmtud) = self.pmtud.as_ref() + && let Some((mps, _)) = pmtud.maximum_packet_sizes() + { + let tcp_mss = mps - (IPV4_HEADER_SIZE + TCP_HEADER_SIZE); + tcp_clamp_mss(pkt.as_mut(), tcp_mss as _); } match self.inside_plugins.do_ingress(pkt) { diff --git a/lightway-core/src/context.rs b/lightway-core/src/context.rs index 2971ea4b..c2064a4b 100644 --- a/lightway-core/src/context.rs +++ b/lightway-core/src/context.rs @@ -312,7 +312,7 @@ impl ServerContext { &self, protocol_version: Version, outside_io: OutsideIOSendCallbackArg, - ) -> Result, ContextError> { + ) -> Result, ContextError> { Ok(ServerConnectionBuilder::new( self, protocol_version, diff --git a/lightway-server/src/connection_manager.rs b/lightway-server/src/connection_manager.rs index 7b49f639..d55e0483 100644 --- a/lightway-server/src/connection_manager.rs +++ b/lightway-server/src/connection_manager.rs @@ -167,11 +167,11 @@ async fn handle_events(mut stream: EventStream, conn: Weak) { #[instrument(level = "trace", skip_all)] async fn handle_stale(conn: Weak) { tokio::time::sleep(CONNECTION_STALE_AGE).await; - if let Some(conn) = conn.upgrade() { - if !matches!(conn.state(), State::Online) { - metrics::connection_stale_closed(); - let _ = conn.disconnect(); - } + if let Some(conn) = conn.upgrade() + && !matches!(conn.state(), State::Online) + { + metrics::connection_stale_closed(); + let _ = conn.disconnect(); }; } diff --git a/lightway-server/src/io/outside/udp/cmsg.rs b/lightway-server/src/io/outside/udp/cmsg.rs index 45da6f56..e5cd1a8b 100644 --- a/lightway-server/src/io/outside/udp/cmsg.rs +++ b/lightway-server/src/io/outside/udp/cmsg.rs @@ -22,7 +22,7 @@ impl Buffer { /// /// `control_len` must have been set to the number of bytes of the /// buffer which have been initialized. - pub(crate) unsafe fn iter(&self, control_len: LibcControlLen) -> Iter { + pub(crate) unsafe fn iter(&self, control_len: LibcControlLen) -> Iter<'_, N> { // Build a `msghdr` so we can use the `CMSG_*` functionality in // libc. We will only use the `CMSG_*` macros which only use // the `msg_control*` fields. @@ -123,7 +123,7 @@ impl BufferMut { /// /// Note that this is not mentioned in /// . - pub(crate) fn builder(&mut self) -> BufferBuilder { + pub(crate) fn builder(&mut self) -> BufferBuilder<'_, N> { // Build a `msghdr` so we can use the `CMSG_*` functionality in // libc. We will only use the `CMSG_*` macros which only use // the `msg_control*` fields.