From 66de44e32f8b7dabec9539b2fbc3af8dc3abea45 Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Sat, 23 Aug 2025 00:20:07 +0800 Subject: [PATCH] chore(cargo): bump to Rust edition `2024` (#223) * chore(cargo): bump to Rust edition 2024 and move shared dependency into workspace `Cargo.toml` * style(phantun): use Rust 2024 `&&` combination for `if let` --- Cargo.toml | 7 +++++-- fake-tcp/Cargo.toml | 6 +++--- phantun/Cargo.toml | 6 +++--- phantun/src/bin/client.rs | 5 ++--- phantun/src/bin/server.rs | 5 ++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4ab4671..7579e67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [workspace] - -resolver = "2" +resolver = "3" members = [ "fake-tcp", "phantun", ] + +[workspace.dependencies] +tokio = { version = "1", features = ["full"] } +log = "0" diff --git a/fake-tcp/Cargo.toml b/fake-tcp/Cargo.toml index e4a195d..69dfa0b 100644 --- a/fake-tcp/Cargo.toml +++ b/fake-tcp/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "fake-tcp" version = "0.6.0" -edition = "2021" +edition = "2024" authors = ["Datong Sun "] license = "MIT OR Apache-2.0" repository = "https://github.com/dndx/phantun" @@ -17,9 +17,9 @@ benchmark = [] [dependencies] bytes = "1" pnet = "0" -tokio = { version = "1", features = ["full"] } rand = { version = "0", features = ["small_rng"] } -log = "0" internet-checksum = "0" tokio-tun = "0" flume = "0" +tokio = { workspace = true } +log = { workspace = true } diff --git a/phantun/Cargo.toml b/phantun/Cargo.toml index 07130fb..a134f69 100644 --- a/phantun/Cargo.toml +++ b/phantun/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "phantun" version = "0.7.0" -edition = "2021" +edition = "2024" authors = ["Datong Sun "] license = "MIT OR Apache-2.0" repository = "https://github.com/dndx/phantun" @@ -14,11 +14,11 @@ Layer 3 & Layer 4 (NAPT) firewalls/NATs. clap = { version = "4", features = ["cargo"] } socket2 = { version = "0", features = ["all"] } fake-tcp = { path = "../fake-tcp", version = "0" } -tokio = { version = "1", features = ["full"] } tokio-util = "0" -log = "0" pretty_env_logger = "0" tokio-tun = "0" num_cpus = "1" neli = "0" nix = { version = "0", features = ["net"] } +tokio = { workspace = true } +log = { workspace = true } diff --git a/phantun/src/bin/client.rs b/phantun/src/bin/client.rs index 2219953..e18d7a1 100644 --- a/phantun/src/bin/client.rs +++ b/phantun/src/bin/client.rs @@ -245,13 +245,12 @@ async fn main() -> io::Result<()> { res = sock.recv(&mut buf_tcp) => { match res { Some(size) => { - if size > 0 { - if let Err(e) = udp_sock.send(&buf_tcp[..size]).await { + if size > 0 + && let Err(e) = udp_sock.send(&buf_tcp[..size]).await { error!("Unable to send UDP packet to {}: {}, closing connection", e, addr); quit.cancel(); return; } - } }, None => { debug!("removed fake TCP socket from connections table"); diff --git a/phantun/src/bin/server.rs b/phantun/src/bin/server.rs index 5160d0e..960fb99 100644 --- a/phantun/src/bin/server.rs +++ b/phantun/src/bin/server.rs @@ -219,13 +219,12 @@ async fn main() -> io::Result<()> { res = sock.recv(&mut buf_tcp) => { match res { Some(size) => { - if size > 0 { - if let Err(e) = udp_sock.send(&buf_tcp[..size]).await { + if size > 0 + && let Err(e) = udp_sock.send(&buf_tcp[..size]).await { error!("Unable to send UDP packet to {}: {}, closing connection", e, remote_addr); quit.cancel(); return; } - } }, None => { quit.cancel();