From ea8a6af67ec556625e1ab9019a7ae16198a7a8a4 Mon Sep 17 00:00:00 2001 From: ExpressVPN Automation Bot <143369453+expressvpn-iat-bot@users.noreply.github.com> Date: Fri, 21 Feb 2025 01:55:57 +0000 Subject: [PATCH 1/4] [auto] Update Rust toolchain to 1.85.0 --- Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index faa39c3..b5780ec 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.84.1-$debian + FROM rust:1.85.0-$debian WORKDIR /lightway RUN dpkg --add-architecture arm64 RUN apt-get update -qq From 4cdb863ce3288dcf5020f190a3cc1c7d0f8deac0 Mon Sep 17 00:00:00 2001 From: Mariappan Ramasamy <142216110+kp-mariappan-ramasamy@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:53:52 +0800 Subject: [PATCH 2/4] cargo: fmt needed for rustc 1.85.0 --- lightway-core/src/wire/data_frag.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightway-core/src/wire/data_frag.rs b/lightway-core/src/wire/data_frag.rs index 22071b9..7dbc6a9 100644 --- a/lightway-core/src/wire/data_frag.rs +++ b/lightway-core/src/wire/data_frag.rs @@ -55,7 +55,7 @@ impl OffsetAndMoreFragments { } else { 0 }; - Self(mf_bit | offset as u16 >> Self::OFFSET_SHIFT) + Self(mf_bit | (offset as u16 >> Self::OFFSET_SHIFT)) } fn into_parts(self) -> (usize, bool) { From 033cf0e55cf30ac00781fbb4b7913f73be4dd199 Mon Sep 17 00:00:00 2001 From: Mariappan Ramasamy <142216110+kp-mariappan-ramasamy@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:51:46 +0800 Subject: [PATCH 3/4] cargo: move package properties to workspace --- Cargo.toml | 6 ++++++ lightway-app-utils/Cargo.toml | 8 ++++---- lightway-client/Cargo.toml | 8 ++++---- lightway-core/Cargo.toml | 8 ++++---- lightway-core/fuzz/Cargo.toml | 6 +++--- lightway-server/Cargo.toml | 8 ++++---- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6afc7e2..5d61012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,12 @@ resolver = "2" lto = true debug = 1 +[workspace.package] +repository = "https://github.com/expressvpn/lightway" +edition = "2021" +authors = ["lightway-developers@expressvpn.com"] +license = "AGPL-3.0-only" + [workspace.lints.rust] unsafe_code = "deny" unsafe_op_in_unsafe_fn = "deny" diff --git a/lightway-app-utils/Cargo.toml b/lightway-app-utils/Cargo.toml index b9dbcc1..df8da5a 100644 --- a/lightway-app-utils/Cargo.toml +++ b/lightway-app-utils/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "lightway-app-utils" version = "0.1.0" -edition = "2021" -repository = "https://github.com/expressvpn/lightway" -authors = ["lightway-developers@expressvpn.com"] -license = "AGPL-3.0-only" +repository.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/lightway-client/Cargo.toml b/lightway-client/Cargo.toml index a5c6d38..5ce0334 100644 --- a/lightway-client/Cargo.toml +++ b/lightway-client/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "lightway-client" version = "0.1.0" -edition = "2021" -repository = "https://github.com/expressvpn/lightway" -authors = ["lightway-developers@expressvpn.com"] -license = "AGPL-3.0-only" +repository.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/lightway-core/Cargo.toml b/lightway-core/Cargo.toml index 910d68c..d4037be 100644 --- a/lightway-core/Cargo.toml +++ b/lightway-core/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "lightway-core" version = "0.1.0" -edition = "2021" -repository = "https://github.com/expressvpn/lightway" -authors = ["lightway-developers@expressvpn.com"] -license = "AGPL-3.0-only" +repository.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/lightway-core/fuzz/Cargo.toml b/lightway-core/fuzz/Cargo.toml index dd29936..85e90e4 100644 --- a/lightway-core/fuzz/Cargo.toml +++ b/lightway-core/fuzz/Cargo.toml @@ -2,9 +2,9 @@ name = "lightway-core-fuzz" version = "0.0.0" publish = false -edition = "2021" -authors = ["lightway-developers@expressvpn.com"] -license = "GPL-2.0-only" +edition.workspace = true +authors.workspace = true +license.workspace = true [package.metadata] cargo-fuzz = true diff --git a/lightway-server/Cargo.toml b/lightway-server/Cargo.toml index 0227417..8b5bec3 100644 --- a/lightway-server/Cargo.toml +++ b/lightway-server/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "lightway-server" version = "0.1.0" -repository = "https://github.com/expressvpn/lightway" -edition = "2021" -authors = ["lightway-developers@expressvpn.com"] -license = "AGPL-3.0-only" +repository.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 009d756a1bd38c6839ff22687a8c0bc9f62ac5c3 Mon Sep 17 00:00:00 2001 From: Mariappan Ramasamy <142216110+kp-mariappan-ramasamy@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:57:47 +0800 Subject: [PATCH 4/4] cargo: update rust edition to 2024 Rest of the changes are format changes in 2024 edition --- Cargo.toml | 4 +-- lightway-app-utils/examples/udprelay.rs | 2 +- lightway-app-utils/src/args/duration.rs | 2 +- lightway-app-utils/src/iouring.rs | 14 ++++------ lightway-app-utils/src/lib.rs | 4 +-- lightway-app-utils/src/metrics.rs | 2 +- lightway-client/src/args.rs | 2 +- lightway-client/src/io/inside/tun.rs | 6 ++-- lightway-client/src/io/outside/udp.rs | 2 +- lightway-client/src/keepalive.rs | 2 +- lightway-client/src/lib.rs | 16 +++++------ lightway-client/src/main.rs | 4 +-- lightway-core/src/builder_predicates.rs | 12 ++------ lightway-core/src/connection.rs | 6 ++-- lightway-core/src/connection/builders.rs | 9 +++--- lightway-core/src/connection/dplpmtud.rs | 10 +++---- lightway-core/src/connection/io_adapter.rs | 4 +-- lightway-core/src/context.rs | 13 +++++---- lightway-core/src/context/server_auth.rs | 2 +- lightway-core/src/lib.rs | 8 +++--- lightway-core/src/metrics.rs | 2 +- lightway-core/src/packet.rs | 2 +- lightway-core/src/utils.rs | 2 +- lightway-core/src/wire.rs | 24 ++++++++-------- lightway-core/tests/connection.rs | 6 ++-- lightway-server/src/auth.rs | 2 +- lightway-server/src/connection_manager.rs | 2 +- .../src/connection_manager/connection_map.rs | 2 +- lightway-server/src/io/inside/tun.rs | 2 +- lightway-server/src/io/outside/tcp.rs | 6 ++-- lightway-server/src/io/outside/udp.rs | 4 +-- lightway-server/src/io/outside/udp/cmsg.rs | 28 +++++++++++-------- lightway-server/src/lib.rs | 8 +++--- lightway-server/src/main.rs | 6 ++-- lightway-server/src/metrics.rs | 2 +- 35 files changed, 109 insertions(+), 113 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d61012..febb033 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ "lightway-server", ] -resolver = "2" +resolver = "3" [profile.release] lto = true @@ -16,7 +16,7 @@ debug = 1 [workspace.package] repository = "https://github.com/expressvpn/lightway" -edition = "2021" +edition = "2024" authors = ["lightway-developers@expressvpn.com"] license = "AGPL-3.0-only" diff --git a/lightway-app-utils/examples/udprelay.rs b/lightway-app-utils/examples/udprelay.rs index 26d0282..bd89bed 100644 --- a/lightway-app-utils/examples/udprelay.rs +++ b/lightway-app-utils/examples/udprelay.rs @@ -3,7 +3,7 @@ use self::channel::Channel; use lightway_app_utils::IOUring; use anyhow::Result; -use async_channel::{bounded, Receiver, Sender}; +use async_channel::{Receiver, Sender, bounded}; use bytes::BytesMut; use clap::Parser; use lightway_core::IOCallbackResult; diff --git a/lightway-app-utils/src/args/duration.rs b/lightway-app-utils/src/args/duration.rs index a9b52ce..2de5443 100644 --- a/lightway-app-utils/src/args/duration.rs +++ b/lightway-app-utils/src/args/duration.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use serde_with::{serde_as, DisplayFromStr}; +use serde_with::{DisplayFromStr, serde_as}; /// Wrapper for compatibility with both clap and twelf at the same time #[serde_as] diff --git a/lightway-app-utils/src/iouring.rs b/lightway-app-utils/src/iouring.rs index 0f61545..d96108d 100644 --- a/lightway-app-utils/src/iouring.rs +++ b/lightway-app-utils/src/iouring.rs @@ -1,12 +1,12 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use bytes::{BufMut, Bytes, BytesMut}; use lightway_core::IOCallbackResult; use thiserror::Error; use crate::metrics; use io_uring::{ - cqueue::Entry as CEntry, opcode, squeue::Entry as SEntry, types::Fixed, Builder, IoUring, - SubmissionQueue, Submitter, + Builder, IoUring, SubmissionQueue, Submitter, cqueue::Entry as CEntry, opcode, + squeue::Entry as SEntry, types::Fixed, }; use std::{ os::fd::{AsRawFd, RawFd}, @@ -16,7 +16,7 @@ use std::{ }; use tokio::{ io::AsyncReadExt, - sync::{mpsc, Mutex}, + sync::{Mutex, mpsc}, }; use tokio_eventfd::EventFd; @@ -124,11 +124,7 @@ enum SlotIdx { impl SlotIdx { fn from_user_data(u: u64) -> Self { let u = u as isize; - if u < 0 { - Self::Rx(!u) - } else { - Self::Tx(u) - } + if u < 0 { Self::Rx(!u) } else { Self::Tx(u) } } fn idx(&self) -> usize { diff --git a/lightway-app-utils/src/lib.rs b/lightway-app-utils/src/lib.rs index 4e48b6c..7f37385 100644 --- a/lightway-app-utils/src/lib.rs +++ b/lightway-app-utils/src/lib.rs @@ -16,7 +16,7 @@ mod tun; #[cfg(feature = "tokio")] pub use connection_ticker::{ - connection_ticker_cb, ConnectionTicker, ConnectionTickerState, ConnectionTickerTask, Tickable, + ConnectionTicker, ConnectionTickerState, ConnectionTickerTask, Tickable, connection_ticker_cb, }; #[cfg(feature = "tokio")] pub use dplpmtud_timer::{DplpmtudTimer, DplpmtudTimerTask}; @@ -33,4 +33,4 @@ pub use tun::{Tun, TunConfig, TunDirect}; #[cfg(feature = "io-uring")] mod metrics; mod utils; -pub use utils::{validate_configuration_file_path, Validate}; +pub use utils::{Validate, validate_configuration_file_path}; diff --git a/lightway-app-utils/src/metrics.rs b/lightway-app-utils/src/metrics.rs index 00d3bd4..ce336da 100644 --- a/lightway-app-utils/src/metrics.rs +++ b/lightway-app-utils/src/metrics.rs @@ -1,4 +1,4 @@ -use metrics::{counter, Counter}; +use metrics::{Counter, counter}; use std::sync::LazyLock; static METRIC_TUN_IOURING_RX_ERR: LazyLock = diff --git a/lightway-client/src/args.rs b/lightway-client/src/args.rs index d7fa50c..176e542 100644 --- a/lightway-client/src/args.rs +++ b/lightway-client/src/args.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use bytesize::ByteSize; use clap::Parser; use lightway_app_utils::args::{Cipher, ConnectionType, Duration, LogLevel}; diff --git a/lightway-client/src/io/inside/tun.rs b/lightway-client/src/io/inside/tun.rs index 189c767..2b8ce1a 100644 --- a/lightway-client/src/io/inside/tun.rs +++ b/lightway-client/src/io/inside/tun.rs @@ -9,11 +9,11 @@ use pnet::packet::ipv4::Ipv4Packet; use lightway_app_utils::{Tun as AppUtilsTun, TunConfig}; use lightway_core::{ - ipv4_update_destination, ipv4_update_source, IOCallbackResult, InsideIOSendCallback, - InsideIpConfig, + IOCallbackResult, InsideIOSendCallback, InsideIpConfig, ipv4_update_destination, + ipv4_update_source, }; -use crate::{io::inside::InsideIO, ConnectionState}; +use crate::{ConnectionState, io::inside::InsideIO}; pub struct Tun { tun: AppUtilsTun, diff --git a/lightway-client/src/io/outside/udp.rs b/lightway-client/src/io/outside/udp.rs index 112059d..08435ae 100644 --- a/lightway-client/src/io/outside/udp.rs +++ b/lightway-client/src/io/outside/udp.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use async_trait::async_trait; use std::{net::SocketAddr, sync::Arc}; use tokio::net::UdpSocket; diff --git a/lightway-client/src/keepalive.rs b/lightway-client/src/keepalive.rs index e19da50..fac69e7 100644 --- a/lightway-client/src/keepalive.rs +++ b/lightway-client/src/keepalive.rs @@ -235,7 +235,7 @@ mod tests { use more_asserts::*; use std::collections::VecDeque; use test_case::test_case; - use tokio::sync::{mpsc, oneshot, Mutex as TokioMutex}; + use tokio::sync::{Mutex as TokioMutex, mpsc, oneshot}; #[derive(Copy, Clone, Debug)] enum FixtureEvent { diff --git a/lightway-client/src/lib.rs b/lightway-client/src/lib.rs index da83047..550a12f 100644 --- a/lightway-client/src/lib.rs +++ b/lightway-client/src/lib.rs @@ -2,27 +2,27 @@ mod debug; pub mod io; pub mod keepalive; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use bytes::BytesMut; use bytesize::ByteSize; use futures::future::OptionFuture; use keepalive::Keepalive; use lightway_app_utils::{ - args::Cipher, connection_ticker_cb, ConnectionTicker, ConnectionTickerState, DplpmtudTimer, - EventStream, EventStreamCallback, TunConfig, + ConnectionTicker, ConnectionTickerState, DplpmtudTimer, EventStream, EventStreamCallback, + TunConfig, args::Cipher, connection_ticker_cb, }; use lightway_core::{ - ipv4_update_destination, ipv4_update_source, BuilderPredicates, ClientContextBuilder, - ClientIpConfig, Connection, ConnectionError, ConnectionType, Event, EventCallback, - IOCallbackResult, InsideIpConfig, OutsidePacket, State, + BuilderPredicates, ClientContextBuilder, ClientIpConfig, Connection, ConnectionError, + ConnectionType, Event, EventCallback, IOCallbackResult, InsideIpConfig, OutsidePacket, State, + ipv4_update_destination, ipv4_update_source, }; // re-export so client app does not need to depend on lightway-core #[cfg(feature = "debug")] pub use lightway_core::enable_tls_debug; pub use lightway_core::{ - AuthMethod, PluginFactoryError, PluginFactoryList, RootCertificate, Version, MAX_INSIDE_MTU, - MAX_OUTSIDE_MTU, + AuthMethod, MAX_INSIDE_MTU, MAX_OUTSIDE_MTU, PluginFactoryError, PluginFactoryList, + RootCertificate, Version, }; use pnet::packet::ipv4::Ipv4Packet; diff --git a/lightway-client/src/main.rs b/lightway-client/src/main.rs index 10cca5f..2aaf780 100644 --- a/lightway-client/src/main.rs +++ b/lightway-client/src/main.rs @@ -1,12 +1,12 @@ use std::path::PathBuf; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::CommandFactory; use lightway_core::{Event, EventCallback}; use twelf::Layer; use lightway_app_utils::{ - args::ConnectionType, validate_configuration_file_path, TunConfig, Validate, + TunConfig, Validate, args::ConnectionType, validate_configuration_file_path, }; use lightway_client::*; diff --git a/lightway-core/src/builder_predicates.rs b/lightway-core/src/builder_predicates.rs index c2abbe6..4edb511 100644 --- a/lightway-core/src/builder_predicates.rs +++ b/lightway-core/src/builder_predicates.rs @@ -8,11 +8,7 @@ pub trait BuilderPredicates: Sized { where F: FnOnce(Self) -> Self, { - if cond { - func(self) - } else { - self - } + if cond { func(self) } else { self } } /// When `cond` is True call fallible `func` on `Self` @@ -20,11 +16,7 @@ pub trait BuilderPredicates: Sized { where F: FnOnce(Self) -> Result, { - if cond { - func(self) - } else { - Ok(self) - } + if cond { func(self) } else { Ok(self) } } /// When `maybe` is Some(_) call `func` on `Self` and the contained value diff --git a/lightway-core/src/connection.rs b/lightway-core/src/connection.rs index 8577f12..e8c1d55 100644 --- a/lightway-core/src/connection.rs +++ b/lightway-core/src/connection.rs @@ -21,13 +21,13 @@ use wolfssl::{ErrorKind, IOCallbackResult, ProtocolVersion}; use crate::max_dtls_mtu; use crate::{ + ConnectionType, IPV4_HEADER_SIZE, InsideIOSendCallbackArg, PluginResult, SessionId, + TCP_HEADER_SIZE, Version, context::{ScheduleTickCb, ServerAuthArg, ServerAuthHandle, ServerAuthResult}, metrics, plugin::PluginList, utils::tcp_clamp_mss, wire::{self, AuthMethod}, - ConnectionType, InsideIOSendCallbackArg, PluginResult, SessionId, Version, IPV4_HEADER_SIZE, - TCP_HEADER_SIZE, }; use crate::context::ip_pool::{ClientIpConfigArg, ServerIpPoolArg}; @@ -936,7 +936,7 @@ impl Connection { ref mut pending_session_id, .. } => { - let new_session_id = rng.lock().unwrap().gen(); + let new_session_id = rng.lock().unwrap().r#gen(); self.session.io_cb_mut().set_session_id(new_session_id); diff --git a/lightway-core/src/connection/builders.rs b/lightway-core/src/connection/builders.rs index 53eeafe..7a55338 100644 --- a/lightway-core/src/connection/builders.rs +++ b/lightway-core/src/connection/builders.rs @@ -8,14 +8,13 @@ use thiserror::Error; use wolfssl::Tls13SecretCallbacksArg; use crate::{ - connection::{dplpmtud, fragment_map::FragmentMap, key_update, EventCallbackArg}, + AuthMethod, BuilderPredicates, ClientContext, Connection, ConnectionType, MAX_OUTSIDE_MTU, + MIN_OUTSIDE_MTU, OutsideIOSendCallbackArg, ServerContext, ServerIpPoolArg, Version, + connection::{EventCallbackArg, dplpmtud, fragment_map::FragmentMap, key_update}, context::ServerAuthArg, dtls_required_outside_mtu, max_dtls_outside_mtu, plugin::PluginFactoryError, wire::SessionId, - AuthMethod, BuilderPredicates, ClientContext, Connection, ConnectionType, - OutsideIOSendCallbackArg, ServerContext, ServerIpPoolArg, Version, MAX_OUTSIDE_MTU, - MIN_OUTSIDE_MTU, }; use super::{ConnectionError, ConnectionMode, NewConnectionArgs, PluginList}; @@ -283,7 +282,7 @@ impl<'a, AppState: Send + 'static> ServerConnectionBuilder<'a, AppState> { let auth = ctx.auth.clone(); let ip_pool = ctx.ip_pool.clone(); - let session_id = ctx.rng.lock().unwrap().gen(); + let session_id = ctx.rng.lock().unwrap().r#gen(); let outside_mtu = MAX_OUTSIDE_MTU; let outside_plugins = ctx.outside_plugins.build()?; diff --git a/lightway-core/src/connection/dplpmtud.rs b/lightway-core/src/connection/dplpmtud.rs index 9cd838f..c1eaf8e 100644 --- a/lightway-core/src/connection/dplpmtud.rs +++ b/lightway-core/src/connection/dplpmtud.rs @@ -4,7 +4,7 @@ use std::{sync::Arc, time::Duration}; -use crate::{wire, IPV4_HEADER_SIZE, MAX_DTLS_HEADER_SIZE, UDP_HEADER_SIZE}; +use crate::{IPV4_HEADER_SIZE, MAX_DTLS_HEADER_SIZE, UDP_HEADER_SIZE, wire}; use more_asserts::*; @@ -83,11 +83,11 @@ impl ProbeId { } fn is_zero(&self) -> bool { - self.0 .0 == 0 + self.0.0 == 0 } fn as_u16(&self) -> u16 { - self.0 .0 + self.0.0 } } @@ -121,7 +121,7 @@ impl std::ops::Sub for ProbeId { impl std::cmp::PartialEq for ProbeId { fn eq(&self, other: &u16) -> bool { - &self.0 .0 == other + &self.0.0 == other } } @@ -513,7 +513,7 @@ impl Dplpmtud { #[cfg(test)] mod tests { - use crate::{max_dtls_mtu, MAX_OUTSIDE_MTU}; + use crate::{MAX_OUTSIDE_MTU, max_dtls_mtu}; use super::*; use std::sync::Mutex; diff --git a/lightway-core/src/connection/io_adapter.rs b/lightway-core/src/connection/io_adapter.rs index 234c2c6..4dbc702 100644 --- a/lightway-core/src/connection/io_adapter.rs +++ b/lightway-core/src/connection/io_adapter.rs @@ -7,7 +7,7 @@ use more_asserts::*; use wolfssl::IOCallbackResult; use crate::{ - plugin::PluginList, wire, ConnectionType, OutsideIOSendCallbackArg, PluginResult, Version, + ConnectionType, OutsideIOSendCallbackArg, PluginResult, Version, plugin::PluginList, wire, }; pub(crate) struct SendBuffer { @@ -299,7 +299,7 @@ impl wolfssl::IOCallbacks for WolfSSLIOAdapter { #[cfg(test)] mod tests { use super::*; - use crate::{OutsideIOSendCallback, Plugin, SessionId, MAX_OUTSIDE_MTU}; + use crate::{MAX_OUTSIDE_MTU, OutsideIOSendCallback, Plugin, SessionId}; use std::{ collections::VecDeque, io::{Error, ErrorKind}, diff --git a/lightway-core/src/context.rs b/lightway-core/src/context.rs index 24466ae..6dc2158 100644 --- a/lightway-core/src/context.rs +++ b/lightway-core/src/context.rs @@ -6,14 +6,15 @@ use std::sync::{Arc, Mutex}; use thiserror::Error; use crate::{ + BuilderPredicates, Cipher, ClientConnectionBuilder, ConnectionBuilderError, + InsideIOSendCallbackArg, MAX_INSIDE_MTU, MIN_INSIDE_MTU, OutsideIOSendCallbackArg, + OutsidePacket, PluginResult, RootCertificate, Secret, ServerConnectionBuilder, ServerIpPoolArg, + Version, context::ip_pool::ClientIpConfigArg, packet::OutsidePacketError, plugin::{PluginFactoryError, PluginFactoryList, PluginList}, version::VersionRangeInclusive, - wire, BuilderPredicates, Cipher, ClientConnectionBuilder, ConnectionBuilderError, - InsideIOSendCallbackArg, OutsideIOSendCallbackArg, OutsidePacket, PluginResult, - RootCertificate, Secret, ServerConnectionBuilder, ServerIpPoolArg, Version, MAX_INSIDE_MTU, - MIN_INSIDE_MTU, + wire, }; pub use server_auth::{ServerAuth, ServerAuthArg, ServerAuthHandle, ServerAuthResult}; @@ -347,7 +348,9 @@ impl ServerContextBuilder { let cipher_list = match connection_type { ConnectionType::Stream => "TLS13-AES256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256", - ConnectionType::Datagram => "TLS13-CHACHA20-POLY1305-SHA256:ECDHE-RSA-CHACHA20-POLY1305:TLS13-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384", + ConnectionType::Datagram => { + "TLS13-CHACHA20-POLY1305-SHA256:ECDHE-RSA-CHACHA20-POLY1305:TLS13-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384" + } }; let wolfssl = wolfssl::ContextBuilder::new(protocol)? diff --git a/lightway-core/src/context/server_auth.rs b/lightway-core/src/context/server_auth.rs index f51a583..c1e93fc 100644 --- a/lightway-core/src/context/server_auth.rs +++ b/lightway-core/src/context/server_auth.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use bytes::Bytes; use tracing::info; -use crate::{wire, Version}; +use crate::{Version, wire}; /// A handle onto a successful auth result. pub trait ServerAuthHandle: std::fmt::Debug { diff --git a/lightway-core/src/lib.rs b/lightway-core/src/lib.rs index 3930ef2..f8e1471 100644 --- a/lightway-core/src/lib.rs +++ b/lightway-core/src/lib.rs @@ -28,14 +28,14 @@ pub use wolfssl::Tls13SecretCallbacks; pub use builder_predicates::BuilderPredicates; pub use cipher::Cipher; pub use connection::{ - dplpmtud::Timer as DplpmtudTimer, ClientConnectionBuilder, Connection, ConnectionActivity, - ConnectionBuilderError, ConnectionError, ConnectionResult, Event, EventCallback, - EventCallbackArg, ServerConnectionBuilder, State, + ClientConnectionBuilder, Connection, ConnectionActivity, ConnectionBuilderError, + ConnectionError, ConnectionResult, Event, EventCallback, EventCallbackArg, + ServerConnectionBuilder, State, dplpmtud::Timer as DplpmtudTimer, }; pub use context::{ - ip_pool::{ClientIpConfig, ClientIpConfigArg, InsideIpConfig, ServerIpPool, ServerIpPoolArg}, ClientContext, ClientContextBuilder, ConnectionType, ContextError, ScheduleTickCb, ServerAuth, ServerAuthArg, ServerAuthHandle, ServerAuthResult, ServerContext, ServerContextBuilder, + ip_pool::{ClientIpConfig, ClientIpConfigArg, InsideIpConfig, ServerIpPool, ServerIpPoolArg}, }; pub use io::{ InsideIOSendCallback, InsideIOSendCallbackArg, OutsideIOSendCallback, OutsideIOSendCallbackArg, diff --git a/lightway-core/src/metrics.rs b/lightway-core/src/metrics.rs index 53f2013..60f8cfd 100644 --- a/lightway-core/src/metrics.rs +++ b/lightway-core/src/metrics.rs @@ -1,4 +1,4 @@ -use metrics::{counter, Counter}; +use metrics::{Counter, counter}; use std::sync::LazyLock; use tracing::debug; use wolfssl::ProtocolVersion; diff --git a/lightway-core/src/packet.rs b/lightway-core/src/packet.rs index 1495175..894fcf2 100644 --- a/lightway-core/src/packet.rs +++ b/lightway-core/src/packet.rs @@ -1,7 +1,7 @@ use bytes::BytesMut; use thiserror::Error; -use crate::{plugin::PluginList, ConnectionType, Header, PluginResult}; +use crate::{ConnectionType, Header, PluginResult, plugin::PluginList}; #[derive(Debug)] /// Packet structure used by application to inject outside packets into lightway-core diff --git a/lightway-core/src/utils.rs b/lightway-core/src/utils.rs index 2bb1b57..3215572 100644 --- a/lightway-core/src/utils.rs +++ b/lightway-core/src/utils.rs @@ -1,9 +1,9 @@ use pnet::packet::{ + MutablePacket, PacketSize, ip::IpNextHeaderProtocols, ipv4::MutableIpv4Packet, tcp::{MutableTcpOptionPacket, MutableTcpPacket, TcpFlags, TcpOptionNumbers}, udp::MutableUdpPacket, - MutablePacket, PacketSize, }; use std::net::Ipv4Addr; use std::ops; diff --git a/lightway-core/src/wire.rs b/lightway-core/src/wire.rs index 2bd3da0..b3fc2d9 100644 --- a/lightway-core/src/wire.rs +++ b/lightway-core/src/wire.rs @@ -129,7 +129,7 @@ impl SessionId { impl rand::distributions::Distribution for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> SessionId { loop { - let candidate = SessionId(rng.gen()); + let candidate = SessionId(rng.r#gen()); if !candidate.is_reserved() { break candidate; } @@ -345,7 +345,7 @@ impl Frame<'_> { }; buf.commit(); // We've successfully parsed a frame, move the - // underlying buffer forward. + // underlying buffer forward. Ok(frame) } @@ -357,15 +357,15 @@ impl Frame<'_> { match self { Self::NoOp => {} - Self::Ping(ref ping) => ping.append_to_wire(buf), - Self::Pong(ref ping) => ping.append_to_wire(buf), - Self::AuthRequest(ref auth) => auth.append_to_wire(buf), - Self::Data(ref data) => data.append_to_wire(buf), - Self::AuthSuccessWithConfigV4(ref cfg) => cfg.append_to_wire(buf), - Self::AuthFailure(ref auth) => auth.append_to_wire(buf), + Self::Ping(ping) => ping.append_to_wire(buf), + Self::Pong(ping) => ping.append_to_wire(buf), + Self::AuthRequest(auth) => auth.append_to_wire(buf), + Self::Data(data) => data.append_to_wire(buf), + Self::AuthSuccessWithConfigV4(cfg) => cfg.append_to_wire(buf), + Self::AuthFailure(auth) => auth.append_to_wire(buf), Self::Goodbye => {} - Self::ServerConfig(ref sc) => sc.append_to_wire(buf), - Self::DataFrag(ref df) => df.append_to_wire(buf), + Self::ServerConfig(sc) => sc.append_to_wire(buf), + Self::DataFrag(df) => df.append_to_wire(buf), } } } @@ -391,8 +391,8 @@ mod session_id { #[test] fn gen_random() { - let a: SessionId = rand::thread_rng().gen(); - let b: SessionId = rand::thread_rng().gen(); + let a: SessionId = rand::thread_rng().r#gen(); + let b: SessionId = rand::thread_rng().r#gen(); assert_ne!(a, b, "Two genuinely random sessions IDs should not match"); } } diff --git a/lightway-core/tests/connection.rs b/lightway-core/tests/connection.rs index 50ee400..d67845a 100644 --- a/lightway-core/tests/connection.rs +++ b/lightway-core/tests/connection.rs @@ -14,7 +14,7 @@ use tokio::{ }; use tokio_stream::StreamExt; -use lightway_app_utils::{connection_ticker_cb, ConnectionTicker, EventStreamCallback}; +use lightway_app_utils::{ConnectionTicker, EventStreamCallback, connection_ticker_cb}; use lightway_core::*; const CA_CERT: &[u8] = &include!("data/ca_cert_der_2048"); @@ -340,7 +340,9 @@ async fn client( let protocol = client.tls_protocol_version(); let cipher = client.current_cipher().unwrap(); let curve = client.current_curve().unwrap(); - eprintln!("{conn_type:?} connection is Online with {session_id:?}, negotiated protocol {protocol:?}, {cipher} & {curve}"); + eprintln!( + "{conn_type:?} connection is Online with {session_id:?}, negotiated protocol {protocol:?}, {cipher} & {curve}" + ); } Event::StateChanged(state) => eprintln!("Connection change to {state:?}"), Event::KeepaliveReply => eprintln!("Got keepalive reply"), diff --git a/lightway-server/src/auth.rs b/lightway-server/src/auth.rs index 85b10b2..288df33 100644 --- a/lightway-server/src/auth.rs +++ b/lightway-server/src/auth.rs @@ -5,7 +5,7 @@ use std::{ path::Path, }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use jsonwebtoken::{Algorithm, DecodingKey, Validation}; use pwhash::unix; diff --git a/lightway-server/src/connection_manager.rs b/lightway-server/src/connection_manager.rs index 2fc62c3..9682b77 100644 --- a/lightway-server/src/connection_manager.rs +++ b/lightway-server/src/connection_manager.rs @@ -5,8 +5,8 @@ use std::{ collections::HashMap, net::SocketAddr, sync::{ - atomic::{AtomicUsize, Ordering}, Arc, Mutex, Weak, + atomic::{AtomicUsize, Ordering}, }, }; use thiserror::Error; diff --git a/lightway-server/src/connection_manager/connection_map.rs b/lightway-server/src/connection_manager/connection_map.rs index cb29dda..6032f5a 100644 --- a/lightway-server/src/connection_manager/connection_map.rs +++ b/lightway-server/src/connection_manager/connection_map.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map, HashMap}, + collections::{HashMap, hash_map}, net::SocketAddr, sync::Arc, }; diff --git a/lightway-server/src/io/inside/tun.rs b/lightway-server/src/io/inside/tun.rs index 81647bd..5f23a22 100644 --- a/lightway-server/src/io/inside/tun.rs +++ b/lightway-server/src/io/inside/tun.rs @@ -9,7 +9,7 @@ use async_trait::async_trait; use bytes::BytesMut; use lightway_app_utils::{Tun as AppUtilsTun, TunConfig}; use lightway_core::{ - ipv4_update_source, IOCallbackResult, InsideIOSendCallback, InsideIOSendCallbackArg, + IOCallbackResult, InsideIOSendCallback, InsideIOSendCallbackArg, ipv4_update_source, }; use std::os::fd::{AsRawFd, RawFd}; use std::sync::Arc; diff --git a/lightway-server/src/io/outside/tcp.rs b/lightway-server/src/io/outside/tcp.rs index 427565d..47948b4 100644 --- a/lightway-server/src/io/outside/tcp.rs +++ b/lightway-server/src/io/outside/tcp.rs @@ -1,11 +1,11 @@ use std::{net::SocketAddr, num::NonZeroUsize, sync::Arc, time::Duration}; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use async_trait::async_trait; use bytes::BytesMut; use lightway_core::{ - ConnectionType, IOCallbackResult, OutsideIOSendCallback, OutsidePacket, Version, - MAX_OUTSIDE_MTU, + ConnectionType, IOCallbackResult, MAX_OUTSIDE_MTU, OutsideIOSendCallback, OutsidePacket, + Version, }; use socket2::SockRef; use tokio::io::AsyncReadExt as _; diff --git a/lightway-server/src/io/outside/udp.rs b/lightway-server/src/io/outside/udp.rs index 3329fec..c820968 100644 --- a/lightway-server/src/io/outside/udp.rs +++ b/lightway-server/src/io/outside/udp.rs @@ -13,8 +13,8 @@ use bytes::BytesMut; use bytesize::ByteSize; use lightway_app_utils::sockopt::socket_enable_pktinfo; use lightway_core::{ - ConnectionType, Header, IOCallbackResult, OutsideIOSendCallback, OutsidePacket, SessionId, - Version, MAX_OUTSIDE_MTU, + ConnectionType, Header, IOCallbackResult, MAX_OUTSIDE_MTU, OutsideIOSendCallback, + OutsidePacket, SessionId, Version, }; use socket2::{MaybeUninitSlice, MsgHdr, MsgHdrMut, SockAddr, SockRef}; use tokio::io::Interest; diff --git a/lightway-server/src/io/outside/udp/cmsg.rs b/lightway-server/src/io/outside/udp/cmsg.rs index 0aa94c8..76965d9 100644 --- a/lightway-server/src/io/outside/udp/cmsg.rs +++ b/lightway-server/src/io/outside/udp/cmsg.rs @@ -272,9 +272,10 @@ mod tests { let mut builder = cmsg.builder(); let err = builder.fill_next(0, 0, 0).unwrap_err(); assert!(matches!(err.kind(), std::io::ErrorKind::Other)); - assert!(err - .to_string() - .contains("cmsg buffer: insufficient space for next header")); + assert!( + err.to_string() + .contains("cmsg buffer: insufficient space for next header") + ); } #[test] @@ -285,9 +286,10 @@ mod tests { let mut builder = cmsg.builder(); let err = builder.fill_next(0, 0, 0).unwrap_err(); assert!(matches!(err.kind(), std::io::ErrorKind::Other)); - assert!(err - .to_string() - .contains("cmsg buffer: insufficient space for next header")); + assert!( + err.to_string() + .contains("cmsg buffer: insufficient space for next header") + ); } #[test] @@ -310,9 +312,10 @@ mod tests { .unwrap(); let err = builder.fill_next(0, 0, 0).unwrap_err(); assert!(matches!(err.kind(), std::io::ErrorKind::Other)); - assert!(err - .to_string() - .contains("cmsg buffer: insufficient space for next header")); + assert!( + err.to_string() + .contains("cmsg buffer: insufficient space for next header") + ); } #[test] @@ -337,8 +340,9 @@ mod tests { ) .unwrap_err(); assert!(matches!(err.kind(), std::io::ErrorKind::Other)); - assert!(err - .to_string() - .contains("cmsg buffer: insufficient space for data")); + assert!( + err.to_string() + .contains("cmsg buffer: insufficient space for data") + ); } } diff --git a/lightway-server/src/lib.rs b/lightway-server/src/lib.rs index b09fbdc..0516973 100644 --- a/lightway-server/src/lib.rs +++ b/lightway-server/src/lib.rs @@ -14,12 +14,12 @@ pub use lightway_core::{ ServerAuthResult, Version, }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use ipnet::Ipv4Net; -use lightway_app_utils::{connection_ticker_cb, TunConfig}; +use lightway_app_utils::{TunConfig, connection_ticker_cb}; use lightway_core::{ - ipv4_update_destination, AuthMethod, BuilderPredicates, ConnectionError, IOCallbackResult, - InsideIpConfig, Secret, ServerContextBuilder, + AuthMethod, BuilderPredicates, ConnectionError, IOCallbackResult, InsideIpConfig, Secret, + ServerContextBuilder, ipv4_update_destination, }; use pnet::packet::ipv4::Ipv4Packet; use std::{ diff --git a/lightway-server/src/main.rs b/lightway-server/src/main.rs index 0584295..61bb744 100644 --- a/lightway-server/src/main.rs +++ b/lightway-server/src/main.rs @@ -3,7 +3,7 @@ mod auth; use std::path::PathBuf; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::CommandFactory; use metrics_util::debugging::DebuggingRecorder; @@ -12,7 +12,7 @@ use tracing::{error, trace}; use twelf::Layer; use args::Config; -use lightway_app_utils::{validate_configuration_file_path, TunConfig, Validate}; +use lightway_app_utils::{TunConfig, Validate, validate_configuration_file_path}; use lightway_server::*; async fn metrics_debug() { @@ -50,7 +50,7 @@ async fn metrics_debug() { metrics_util::debugging::DebugValue::Histogram(values) => { // TODO: https://docs.rs/average/latest/average/macro.concatenate.html for min/max and avg? - use average::{concatenate, Estimate, Max, Mean, Min}; + use average::{Estimate, Max, Mean, Min, concatenate}; concatenate!(Stats, [Min, min], [Mean, mean], [Max, max]); let len = values.len(); diff --git a/lightway-server/src/metrics.rs b/lightway-server/src/metrics.rs index d3afd4b..29fefe4 100644 --- a/lightway-server/src/metrics.rs +++ b/lightway-server/src/metrics.rs @@ -1,5 +1,5 @@ use lightway_core::{SessionId, Version}; -use metrics::{counter, gauge, histogram, Counter, Gauge, Histogram}; +use metrics::{Counter, Gauge, Histogram, counter, gauge, histogram}; use std::sync::LazyLock; use tracing::trace;