规范依赖管理并适配 rand 0.10

- 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)
This commit is contained in:
lbl
2026-08-20 20:58:07 +08:00
parent e088d305b1
commit 7d481560e3
14 changed files with 258 additions and 162 deletions
+16 -17
View File
@@ -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"
+3 -1
View File
@@ -107,9 +107,11 @@ impl TrafficStats {
}
}
type PingStatsMap = HashMap<(Ipv4Addr, RouteKey), Arc<Mutex<PingStats>>>;
#[derive(Clone, Default)]
pub struct PacketLossStats {
inner: Arc<RwLock<HashMap<(Ipv4Addr, RouteKey), Arc<Mutex<PingStats>>>>>,
inner: Arc<RwLock<PingStatsMap>>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -47,10 +47,7 @@ pub(crate) async fn quic_tunnel_start(
config: QuicTunnelConfig,
components: QuicTunnelComponents,
) -> anyhow::Result<(EnhancedQuicInbound, Option<EnhancedQuicOutbound>)> {
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?;
+1 -4
View File
@@ -34,10 +34,7 @@ impl InternalNatInbound {
network: SharedNetworkAddr,
no_tun: bool,
) -> anyhow::Result<Self> {
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?;
+8 -8
View File
@@ -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);
}
}
@@ -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 = {
@@ -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()
@@ -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<ServerTurnManager>,
managers: &mut [ServerTurnManager],
) -> anyhow::Result<ResponseMessage> {
if managers.is_empty() {
bail!("No servers to register");