规范依赖管理并适配 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
+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");