From 7901407d69b9e7af8342bb5d21694044770a7add Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=B7=B2=E7=9F=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/channel/socket/unix.rs | 13 +++++++++++-- vnt/src/handle/maintain/heartbeat.rs | 12 ++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/vnt/src/channel/socket/unix.rs b/vnt/src/channel/socket/unix.rs index cea3262..4a7b50a 100644 --- a/vnt/src/channel/socket/unix.rs +++ b/vnt/src/channel/socket/unix.rs @@ -1,4 +1,7 @@ -use crate::channel::socket::{get_interface, LocalInterface, VntSocketTrait}; +#[cfg(any(target_os = "linux", target_os = "macos"))] +use crate::channel::socket::get_interface; +use crate::channel::socket::{LocalInterface, VntSocketTrait}; +#[cfg(any(target_os = "linux", target_os = "macos"))] use anyhow::Context; use std::net::Ipv4Addr; @@ -22,6 +25,12 @@ impl VntSocketTrait for socket2::Socket { Ok(()) } } +#[cfg(target_os = "android")] +impl VntSocketTrait for socket2::Socket { + fn set_ip_unicast_if(&self, _interface: &LocalInterface) -> anyhow::Result<()> { + Ok(()) + } +} #[cfg(any(target_os = "linux", target_os = "macos"))] pub fn get_best_interface(dest_ip: Ipv4Addr) -> anyhow::Result { @@ -35,6 +44,6 @@ pub fn get_best_interface(dest_ip: Ipv4Addr) -> anyhow::Result { Ok(LocalInterface::default()) } #[cfg(target_os = "android")] -pub fn get_best_interface(dest_ip: Ipv4Addr) -> anyhow::Result { +pub fn get_best_interface(_dest_ip: Ipv4Addr) -> anyhow::Result { Ok(LocalInterface::default()) } diff --git a/vnt/src/handle/maintain/heartbeat.rs b/vnt/src/handle/maintain/heartbeat.rs index d58fe88..5327a11 100644 --- a/vnt/src/handle/maintain/heartbeat.rs +++ b/vnt/src/handle/maintain/heartbeat.rs @@ -79,10 +79,6 @@ fn heartbeat0( } heartbeat_packet_server(device_map, server_cipher, src_ip, gateway_ip) } else { - if dest_ip < src_ip { - // 只向比自己大的发 - continue; - } heartbeat_packet_client(client_cipher, src_ip, dest_ip) }; let net_packet = match net_packet { @@ -93,9 +89,13 @@ fn heartbeat0( } }; for (index, route) in routes.iter().enumerate() { - if index >= channel_num + 1 { + let limit = if context.first_latency() { + channel_num + 1 + } else { + channel_num + }; + if index >= limit { // 多余的通道不再发送心跳包,让它自动过期 - // 这里多留一个增加稳定性 break; } if let Err(e) = context.send_by_key(&net_packet, route.route_key()) {