From 7d481560e3d65dec956177b266cf2f35044f364d Mon Sep 17 00:00:00 2001 From: lbl <1791778603@qq.com> Date: Thu, 20 Aug 2026 20:58:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BE=9D=E8=B5=96=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=B9=B6=E9=80=82=E9=85=8D=20rand=200.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tcp_ip 从 git 依赖切换为 crates.io 0.2(IpStackConfig 改用 builder) - 公共依赖收拢到 workspace.dependencies 统一版本 - 移除 release profile 的 panic=abort(避免 vnt-jni 中止宿主 JVM) - vnt-jni 升级 edition 2024(no_mangle 改为 unsafe(no_mangle)) - vnt-ipc 显式声明 tokio features - 适配 rand 0.10:random_range 移至 RngExt,choose_multiple 改名 sample - 修复 clippy 警告(type_complexity/collapsible_if/ptr_arg) --- Cargo.lock | 205 ++++++++++++------ Cargo.toml | 36 ++- vnt-core/Cargo.toml | 33 ++- vnt-core/src/context/mod.rs | 4 +- .../src/enhanced_tunnel/quic_over/boot.rs | 5 +- vnt-core/src/nat/internal_nat/mod.rs | 5 +- vnt-core/src/tunnel_core/p2p/route_table.rs | 16 +- .../src/tunnel_core/p2p/transport/nat_test.rs | 2 +- .../src/tunnel_core/p2p/transport/task.rs | 12 +- .../tunnel_core/server/connection_manager.rs | 2 +- vnt-ipc/Cargo.toml | 18 +- vnt-jni/Cargo.toml | 20 +- vnt-jni/src/lib.rs | 36 +-- vnt-web/Cargo.toml | 26 +-- 14 files changed, 258 insertions(+), 162 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34fcb98..0871c22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -299,6 +299,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + [[package]] name = "blocking" version = "1.6.2" @@ -378,6 +387,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + [[package]] name = "chrono" version = "0.4.43" @@ -490,6 +510,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "core-foundation" version = "0.9.4" @@ -525,6 +551,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-queue" version = "0.3.12" @@ -550,6 +585,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + [[package]] name = "csv" version = "1.4.0" @@ -658,8 +702,19 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid", + "crypto-common 0.2.2", ] [[package]] @@ -768,18 +823,6 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" -[[package]] -name = "flume" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" -dependencies = [ - "futures-core", - "futures-sink", - "nanorand", - "spin", -] - [[package]] name = "flume" version = "0.12.0" @@ -968,11 +1011,23 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "r-efi", + "r-efi 5.3.0", "wasip2", "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.1", +] + [[package]] name = "glob" version = "0.3.3" @@ -1089,6 +1144,15 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" +[[package]] +name = "hybrid-array" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707114b52a152fa7bdb290cd7cd5912d9467273b6d74e21b8d81aca1f8533f6b" +dependencies = [ + "typenum", +] + [[package]] name = "hyper" version = "1.8.1" @@ -1305,7 +1369,7 @@ dependencies = [ "log-mdc", "mock_instant", "parking_lot 0.12.5", - "rand", + "rand 0.9.2", "serde", "serde-value", "serde_json", @@ -1347,9 +1411,9 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" [[package]] name = "lz4_flex" -version = "0.12.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab6473172471198271ff72e9379150e9dfd70d8e533e0752a27e515b48dd375e" +checksum = "ecbdfe44b1bd960b68170b417450a628c43f7cf56bb3c5317e61cb230ee7f226" dependencies = [ "twox-hash", ] @@ -1440,15 +1504,6 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" -[[package]] -name = "nanorand" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" -dependencies = [ - "getrandom 0.2.17", -] - [[package]] name = "netconfig-rs" version = "0.1.5" @@ -1993,7 +2048,7 @@ dependencies = [ "bytes", "getrandom 0.3.4", "lru-slab", - "rand", + "rand 0.9.2", "ring", "rustc-hash", "rustls", @@ -2034,6 +2089,12 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "r-ex" version = "1.0.1" @@ -2047,7 +2108,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core 0.10.1", ] [[package]] @@ -2057,7 +2129,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.5", ] [[package]] @@ -2069,6 +2141,12 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "rcgen" version = "0.14.7" @@ -2163,7 +2241,7 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "319bb478ff9aae1dc7a544fa599e9eb47e2521621dc3921fba6abcaaa312092c" dependencies = [ - "flume 0.12.0", + "flume", "libc", "netlink-packet-core 0.8.1", "netlink-packet-route 0.28.0", @@ -2201,7 +2279,7 @@ version = "8.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bcdef0be6fe7f6fa333b1073c949729274b05f123a0ad7efcb8efd878e5c3b1" dependencies = [ - "sha2", + "sha2 0.10.9", "walkdir", ] @@ -2224,7 +2302,7 @@ dependencies = [ "libc", "log", "parking_lot 0.12.5", - "rand", + "rand 0.9.2", "serde", "socket2 0.5.10", "stun-format", @@ -2488,13 +2566,13 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.3.0", + "digest 0.11.3", ] [[package]] @@ -2504,8 +2582,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.3", ] [[package]] @@ -2658,17 +2747,18 @@ dependencies = [ [[package]] name = "tcp_ip" -version = "0.1.10" -source = "git+https://github.com/rustp2p/tcp_ip#09c64c81da70a35248dfef4ef42bb9f5e8b6e05e" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a3b3309aae4733df008397c448ddeff5d54dfbcc6c19950b43272cef668f0fe" dependencies = [ "bytes", "dashmap", - "flume 0.11.1", + "flume", "log", "num_enum", "parking_lot 0.12.5", "pnet_packet", - "rand", + "rand 0.10.2", "tokio", "tokio-util", ] @@ -2842,9 +2932,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.28.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25a406cddcc431a75d3d9afc6a7c0f7428d4891dd973e4d54c56b46127bf857" +checksum = "17a073bfed563fa236697a068031408a93cd9522e08abf9933ead3e73411bd71" dependencies = [ "futures-util", "log", @@ -2934,9 +3024,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.8" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +checksum = "b11f75e912b0c2be01b63d8cf8057b8c3f97cf34abb3d431a3a4c8675498e233" dependencies = [ "bitflags 2.10.0", "bytes", @@ -3062,19 +3152,18 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.28.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8628dcc84e5a09eb3d8423d6cb682965dea9133204e8fb3efee74c2a0c259442" +checksum = "e48ac77174b19c110a50ab2128b24215ac9cb40e0e12e093fb602d175c569d22" dependencies = [ "bytes", "data-encoding", "http", "httparse", "log", - "rand", + "rand 0.10.2", "sha1", "thiserror 2.0.18", - "utf-8", ] [[package]] @@ -3094,9 +3183,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicase" @@ -3149,12 +3238,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "utf8parse" version = "0.2.2" @@ -3203,7 +3286,7 @@ dependencies = [ "prost", "prost-build", "quinn", - "rand", + "rand 0.10.2", "rcgen", "reed-solomon-erasure", "ring", @@ -3211,7 +3294,7 @@ dependencies = [ "rustls", "rustls-native-certs", "serde", - "sha2", + "sha2 0.11.0", "socket2 0.6.2", "tcp_ip", "time", diff --git a/Cargo.toml b/Cargo.toml index 79dfde1..8e2a75d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,19 +8,19 @@ vnt-ipc = { path = "vnt-ipc", optional = true } vnt-web = { path = "vnt-web", optional = true } clap = { version = "4.5", features = ["derive"] } -tokio = { version = "1", features = ["full"] } +tokio = { workspace = true, features = ["full"] } -log = "0.4" +log.workspace = true log4rs = "1.4" -serde = { version = "1.0.228", features = ["derive"] } -anyhow = "1.0.100" -toml = "0.9.8" -hostname = "0.4.2" -ipnet = { version = "2.11", features = ["serde"] } +serde.workspace = true +anyhow.workspace = true +toml.workspace = true +hostname.workspace = true +ipnet.workspace = true -route_manager = "0.2.11" +route_manager.workspace = true [features] default = [] @@ -45,13 +45,31 @@ required-features = ["vnt-web"] [workspace] members = ["vnt-web", "vnt-ipc", "vnt-core", "vnt-jni"] +[workspace.dependencies] +vnt-core = { path = "vnt-core" } + +tokio = "1" +tokio-util = "0.7" +futures = "0.3" + +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +anyhow = "1" +log = "0.4" +toml = "0.9" +time = "0.3" +hostname = "0.4" +ipnet = { version = "2.11", features = ["serde"] } +route_manager = "0.2" +parking_lot = "0.12" +prost = "0.14" + [profile.release] opt-level = 'z' debug = 0 debug-assertions = false strip = true lto = true -panic = 'abort' incremental = false codegen-units = 1 rpath = false diff --git a/vnt-core/Cargo.toml b/vnt-core/Cargo.toml index 69db3bf..f11e199 100644 --- a/vnt-core/Cargo.toml +++ b/vnt-core/Cargo.toml @@ -5,45 +5,44 @@ edition = "2024" [dependencies] - -tokio = { version = "1", features = ["full"] } -tokio-util = { version = "0.7", features = ["codec"] } -futures = "0.3" +tokio = { workspace = true, features = ["full"] } +tokio-util = { workspace = true, features = ["codec"] } +futures.workspace = true tun-rs = { version = "2", features = ["async", "async_framed"] } rust-p2p-core = { version="0.4" } -tcp_ip = { git = "https://github.com/rustp2p/tcp_ip" } +tcp_ip = "0.2" -anyhow = "1" -parking_lot = "0.12" +anyhow.workspace = true +parking_lot.workspace = true quinn = { version = "0.11", default-features = false, features = ["rustls", "runtime-tokio"] } tokio-rustls = { version = "0.26", default-features = false, features = ["ring"] } rustls = { version = "0.23", default-features = false, features = ["ring"] } hex = "0.4" -sha2 = "0.10" +sha2 = "0.11" rustls-native-certs = "0.8.2" -log = "0.4" +log.workspace = true bytes = "1.11.0" -rand = "0.9" -time = { version = "0.3", features = ["macros", "formatting", "local-offset"] } +rand = "0.10" +time = { workspace = true, features = ["macros", "formatting", "local-offset"] } pnet_packet = "0.35" ring = "0.17.14" -prost = "0.14" -tokio-tungstenite = "0.28.0" -tungstenite = "0.28.0" +prost.workspace = true +tokio-tungstenite = "0.30" +tungstenite = "0.30" uuid = { version = "1.18.1", features = ["v4"] } -ipnet = { version = "2.11", features = ["serde"] } +ipnet.workspace = true getifaddrs = "0.6.0" dns-parser = "0.8" -lz4_flex = "0.12.0" +lz4_flex = "0.14" reed-solomon-erasure = "6.0" -serde = { version = "1.0.228", features = ["derive"] } +serde.workspace = true rcgen = "0.14.6" machine-uid = "0.5.4" diff --git a/vnt-core/src/context/mod.rs b/vnt-core/src/context/mod.rs index 8c2dc8b..13c6861 100644 --- a/vnt-core/src/context/mod.rs +++ b/vnt-core/src/context/mod.rs @@ -107,9 +107,11 @@ impl TrafficStats { } } +type PingStatsMap = HashMap<(Ipv4Addr, RouteKey), Arc>>; + #[derive(Clone, Default)] pub struct PacketLossStats { - inner: Arc>>>>, + inner: Arc>, } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/vnt-core/src/enhanced_tunnel/quic_over/boot.rs b/vnt-core/src/enhanced_tunnel/quic_over/boot.rs index ad2a297..06b5c25 100644 --- a/vnt-core/src/enhanced_tunnel/quic_over/boot.rs +++ b/vnt-core/src/enhanced_tunnel/quic_over/boot.rs @@ -47,10 +47,7 @@ pub(crate) async fn quic_tunnel_start( config: QuicTunnelConfig, components: QuicTunnelComponents, ) -> anyhow::Result<(EnhancedQuicInbound, Option)> { - let ip_stack_config = IpStackConfig { - mtu: config.mtu, - ..Default::default() - }; + let ip_stack_config = IpStackConfig::builder().mtu(config.mtu).build(); let (ip_stack, ip_socket, quic_outbound) = if let Some(tun_data_sender) = tun_data_sender { let (ip_stack, ip_stack_send, ip_stack_recv) = tcp_ip::ip_stack(ip_stack_config)?; let ip_socket = tcp_ip::ip::IpSocket::bind_all(None, ip_stack.clone()).await?; diff --git a/vnt-core/src/nat/internal_nat/mod.rs b/vnt-core/src/nat/internal_nat/mod.rs index ffcfa3d..55c73cc 100644 --- a/vnt-core/src/nat/internal_nat/mod.rs +++ b/vnt-core/src/nat/internal_nat/mod.rs @@ -34,10 +34,7 @@ impl InternalNatInbound { network: SharedNetworkAddr, no_tun: bool, ) -> anyhow::Result { - let ip_stack_config = IpStackConfig { - mtu, - ..Default::default() - }; + let ip_stack_config = IpStackConfig::builder().mtu(mtu).build(); let (ip_stack, ip_stack_send, ip_stack_recv) = tcp_ip::ip_stack(ip_stack_config)?; #[cfg(not(target_os = "android"))] icmp_nat::start_icmp_nat(task_group, &ip_stack, no_tun, network.clone()).await?; diff --git a/vnt-core/src/tunnel_core/p2p/route_table.rs b/vnt-core/src/tunnel_core/p2p/route_table.rs index ece99cc..5182333 100644 --- a/vnt-core/src/tunnel_core/p2p/route_table.rs +++ b/vnt-core/src/tunnel_core/p2p/route_table.rs @@ -197,10 +197,10 @@ impl RouteTable { } } - if let Some(owner_id) = owner_map.get(route_key) { - if owner_id == id { - owner_map.remove(route_key); - } + if let Some(owner_id) = owner_map.get(route_key) + && owner_id == id + { + owner_map.remove(route_key); } time_map.remove(&(*id, *route_key)); @@ -309,10 +309,10 @@ impl RouteTableInner { } } - if let Some(owner_id) = owner_map.get(route_key) { - if *owner_id == *id { - owner_map.remove(route_key); - } + if let Some(owner_id) = owner_map.get(route_key) + && *owner_id == *id + { + owner_map.remove(route_key); } } diff --git a/vnt-core/src/tunnel_core/p2p/transport/nat_test.rs b/vnt-core/src/tunnel_core/p2p/transport/nat_test.rs index 604472c..ed88bc2 100644 --- a/vnt-core/src/tunnel_core/p2p/transport/nat_test.rs +++ b/vnt-core/src/tunnel_core/p2p/transport/nat_test.rs @@ -187,7 +187,7 @@ pub(crate) async fn query_tcp_public_addr_loop( app_context: AppState, socket_manager: SocketManager, ) { - use rand::Rng; + use rand::RngExt; use rand::seq::SliceRandom; let tcp_stun_servers = { diff --git a/vnt-core/src/tunnel_core/p2p/transport/task.rs b/vnt-core/src/tunnel_core/p2p/transport/task.rs index d487567..9ef04bb 100644 --- a/vnt-core/src/tunnel_core/p2p/transport/task.rs +++ b/vnt-core/src/tunnel_core/p2p/transport/task.rs @@ -213,7 +213,7 @@ pub async fn relay_probe_task( non_direct_targets } else { non_direct_targets - .choose_multiple(&mut rng, 10) + .sample(&mut rng, 10) .copied() .collect() } @@ -222,10 +222,10 @@ pub async fn relay_probe_task( let all_routes = route_table.route_table(); let mut direct_peers = Vec::new(); for (ip, routes) in &all_routes { - if let Some(best_route) = routes.first() { - if best_route.is_direct() { - direct_peers.push((*ip, best_route.route_key())); - } + if let Some(best_route) = routes.first() + && best_route.is_direct() + { + direct_peers.push((*ip, best_route.route_key())); } } @@ -242,7 +242,7 @@ pub async fn relay_probe_task( direct_peers .iter() .filter(|(ip, _)| ip != target_ip) - .choose_multiple(&mut rng, max_probes_per_target) + .sample(&mut rng, max_probes_per_target) .into_iter() .cloned() .collect() diff --git a/vnt-core/src/tunnel_core/server/connection_manager.rs b/vnt-core/src/tunnel_core/server/connection_manager.rs index 35c9c51..2ad4176 100644 --- a/vnt-core/src/tunnel_core/server/connection_manager.rs +++ b/vnt-core/src/tunnel_core/server/connection_manager.rs @@ -264,7 +264,7 @@ impl ServerTurnManager { /// 3. Send confirmation to all servers /// 4. Return the registration response pub async fn coordinated_registration( - managers: &mut Vec, + managers: &mut [ServerTurnManager], ) -> anyhow::Result { if managers.is_empty() { bail!("No servers to register"); diff --git a/vnt-ipc/Cargo.toml b/vnt-ipc/Cargo.toml index 96a1abf..bcec018 100644 --- a/vnt-ipc/Cargo.toml +++ b/vnt-ipc/Cargo.toml @@ -5,16 +5,16 @@ edition = "2024" [dependencies] -vnt-core = { path = "../vnt-core" } -anyhow = "1.0.100" -futures = "0.3.31" -prost = "0.14.1" -tokio = "1.48.0" -tokio-util = "0.7.17" -log = "0.4.29" +vnt-core.workspace = true +anyhow.workspace = true +futures.workspace = true +prost.workspace = true +tokio = { workspace = true, features = ["rt", "net", "io-util", "time"] } +tokio-util.workspace = true +log.workspace = true +time.workspace = true console = "0.16.2" -time = "0.3.44" cli-table = "0.5.0" [build-dependencies] -prost-build = "0.14" \ No newline at end of file +prost-build = "0.14" diff --git a/vnt-jni/Cargo.toml b/vnt-jni/Cargo.toml index 9cc8aae..0ff40df 100644 --- a/vnt-jni/Cargo.toml +++ b/vnt-jni/Cargo.toml @@ -1,21 +1,21 @@ [package] name = "vnt-jni" version = "2.0.0" -edition = "2021" +edition = "2024" [lib] crate-type = ["cdylib"] [dependencies] -vnt-core = { path = "../vnt-core" } +vnt-core.workspace = true jni = "0.21" -tokio = { version = "1", features = ["full"] } -parking_lot = "0.12" -log = "0.4" -anyhow = "1" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -ipnet = { version = "2.11", features = ["serde"] } +tokio = { workspace = true, features = ["full"] } +parking_lot.workspace = true +log.workspace = true +anyhow.workspace = true +serde.workspace = true +serde_json.workspace = true +ipnet.workspace = true lazy_static = "1.5" -hostname = "0.4.2" +hostname.workspace = true diff --git a/vnt-jni/src/lib.rs b/vnt-jni/src/lib.rs index dad6b0b..29ea896 100644 --- a/vnt-jni/src/lib.rs +++ b/vnt-jni/src/lib.rs @@ -47,7 +47,7 @@ lazy_static::lazy_static! { } /// 初始化JNI模块 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntManager_nativeInit( mut env: JNIEnv, _class: JClass, @@ -70,14 +70,14 @@ pub extern "system" fn Java_com_vnt_VntManager_nativeInit( } /// 销毁JNI模块 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntManager_nativeDestroy(_env: JNIEnv, _class: JClass) { let mut state = GLOBAL_STATE.lock(); *state = None; } /// 创建网络实例 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntManager_nativeCreateNetwork<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -128,7 +128,7 @@ pub extern "system" fn Java_com_vnt_VntManager_nativeCreateNetwork<'local>( } /// 注册网络 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntNetwork_nativeRegister<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -192,7 +192,7 @@ pub extern "system" fn Java_com_vnt_VntNetwork_nativeRegister<'local>( } /// 启动TUN设备(Android使用,需要传入fd) -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntNetwork_nativeStartTun( mut env: JNIEnv, _class: JClass, @@ -244,7 +244,7 @@ pub extern "system" fn Java_com_vnt_VntNetwork_nativeStartTun( } /// 设置网络IP(非Android系统) -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntNetwork_nativeSetNetworkIp<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -300,7 +300,7 @@ pub extern "system" fn Java_com_vnt_VntNetwork_nativeSetNetworkIp<'local>( } /// 获取VntApi实例 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntNetwork_nativeGetApi( mut env: JNIEnv, _class: JClass, @@ -338,7 +338,7 @@ pub extern "system" fn Java_com_vnt_VntNetwork_nativeGetApi( } /// 检查是否为无TUN模式 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntNetwork_nativeIsNoTun( mut env: JNIEnv, _class: JClass, @@ -378,7 +378,7 @@ pub extern "system" fn Java_com_vnt_VntNetwork_nativeIsNoTun( } /// 关闭网络 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntNetwork_nativeStop( mut env: JNIEnv, _class: JClass, @@ -413,7 +413,7 @@ pub extern "system" fn Java_com_vnt_VntNetwork_nativeStop( // ==================== VntApi 接口 ==================== /// 获取客户端列表 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetClientList<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -454,7 +454,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetClientList<'local>( } /// 获取网络配置信息 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetNetwork<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -495,7 +495,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetNetwork<'local>( } /// 获取NAT信息 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetNatInfo<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -535,7 +535,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetNatInfo<'local>( } /// 获取服务器节点列表 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetServerList<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -580,7 +580,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetServerList<'local>( } /// 获取路由表 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetRouteTable<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -633,7 +633,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetRouteTable<'local>( } /// 检查目标IP是否直连 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeIsDirect<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -671,7 +671,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeIsDirect<'local>( } /// 获取对端NAT信息 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetPeerNatInfo<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -715,7 +715,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetPeerNatInfo<'local>( } /// 获取丢包信息 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetPacketLoss<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, @@ -760,7 +760,7 @@ pub extern "system" fn Java_com_vnt_VntApi_nativeGetPacketLoss<'local>( } /// 获取流量信息 -#[no_mangle] +#[unsafe(no_mangle)] pub extern "system" fn Java_com_vnt_VntApi_nativeGetTrafficInfo<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, diff --git a/vnt-web/Cargo.toml b/vnt-web/Cargo.toml index d9535ed..0f43490 100644 --- a/vnt-web/Cargo.toml +++ b/vnt-web/Cargo.toml @@ -4,20 +4,20 @@ version = "2.0.0" edition = "2024" [dependencies] -vnt-core = { path = "../vnt-core" } -tokio = { version = "1", features = ["full"] } +vnt-core.workspace = true +tokio = { workspace = true, features = ["full"] } axum = "0.8.8" -tower-http = { version = "0.6", features = ["fs", "cors", "trace"] } +tower-http = { version = "0.7", features = ["fs", "cors", "trace"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -anyhow = "1.0.100" -log = "0.4.29" -ipnet = "2.11.0" -hostname = "0.4.2" -route_manager = "0.2.11" -toml = "0.9.8" +serde.workspace = true +serde_json.workspace = true +anyhow.workspace = true +log.workspace = true +ipnet.workspace = true +hostname.workspace = true +route_manager.workspace = true +toml.workspace = true rust-embed = "8.0" mime_guess = "2.0" -parking_lot = "0.12" -time = { version = "0.3.45", features = ["local-offset", "formatting", "macros"] } \ No newline at end of file +parking_lot.workspace = true +time = { workspace = true, features = ["local-offset", "formatting", "macros"] }