From 01f6890fd3cd2f4a887428e99a48e21b563ed649 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Thu, 21 Mar 2024 21:25:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E7=A6=BB=E7=BA=BF=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/channel/context.rs | 3 ++- vnt/src/handle/handshaker.rs | 2 +- vnt/src/handle/maintain/addr_request.rs | 2 +- vnt/src/handle/tun_tap/mod.rs | 10 ++++++++-- vnt/src/ip_proxy/icmp_proxy.rs | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/vnt/src/channel/context.rs b/vnt/src/channel/context.rs index a221ced..acb6049 100644 --- a/vnt/src/channel/context.rs +++ b/vnt/src/channel/context.rs @@ -225,6 +225,7 @@ impl ContextInner { buf: &[u8], id: &Ipv4Addr, server_addr: SocketAddr, + send_default: bool, ) -> io::Result<()> { if self.packet_loss_rate > 0 { if rand::thread_rng().gen_ratio(self.packet_loss_rate, PACKET_LOSS_RATE_DENOMINATOR) { @@ -239,7 +240,7 @@ impl ContextInner { if e.kind() != io::ErrorKind::NotFound { log::warn!("{}:{:?}", id, e); } - if !self.route_table.use_channel_type.is_only_p2p() { + if !self.route_table.use_channel_type.is_only_p2p() && send_default { //符合条件再发到服务器转发 self.send_default(buf, server_addr)?; } diff --git a/vnt/src/handle/handshaker.rs b/vnt/src/handle/handshaker.rs index ea3972b..8d7f22d 100644 --- a/vnt/src/handle/handshaker.rs +++ b/vnt/src/handle/handshaker.rs @@ -37,7 +37,7 @@ impl Handshake { pub fn send(&self, context: &Context, secret: bool, addr: SocketAddr) -> io::Result<()> { let last = self.time.load(); //短时间不重复发送 - if last.elapsed() < Duration::from_secs(5) { + if last.elapsed() < Duration::from_secs(3) { return Ok(()); } let request_packet = handshake_request_packet(secret)?; diff --git a/vnt/src/handle/maintain/addr_request.rs b/vnt/src/handle/maintain/addr_request.rs index 32ff1a1..f38044a 100644 --- a/vnt/src/handle/maintain/addr_request.rs +++ b/vnt/src/handle/maintain/addr_request.rs @@ -52,7 +52,7 @@ pub fn addr_request0( } } } - if current_dev.connect_server.is_ipv4() { + if current_dev.connect_server.is_ipv4() && current_dev.status.online() { // 如果连接的是ipv4服务,则探测公网端口 let gateway_ip = current_dev.virtual_gateway; let src_ip = current_dev.virtual_ip; diff --git a/vnt/src/handle/tun_tap/mod.rs b/vnt/src/handle/tun_tap/mod.rs index 002203a..4c4e190 100644 --- a/vnt/src/handle/tun_tap/mod.rs +++ b/vnt/src/handle/tun_tap/mod.rs @@ -33,6 +33,7 @@ fn broadcast( continue; } if peer_ips.len() == MAX_COUNT { + relay_count += 1; break; } if route.is_p2p() @@ -45,7 +46,7 @@ fn broadcast( relay_count += 1; } } - if relay_count == 0 && !peer_ips.is_empty() && peer_ips.len() != MAX_COUNT { + if (relay_count == 0 && !peer_ips.is_empty()) || current_device.status.offline() { //不需要转发 return Ok(()); } @@ -143,5 +144,10 @@ pub fn base_handle( proxy_map.send_handle(&mut ipv4_packet)?; } client_cipher.encrypt_ipv4(&mut net_packet)?; - context.send_ipv4_by_id(net_packet.buffer(), &dest_ip, current_device.connect_server) + context.send_ipv4_by_id( + net_packet.buffer(), + &dest_ip, + current_device.connect_server, + current_device.status.online(), + ) } diff --git a/vnt/src/ip_proxy/icmp_proxy.rs b/vnt/src/ip_proxy/icmp_proxy.rs index 3eb8b3b..9f1c8fc 100644 --- a/vnt/src/ip_proxy/icmp_proxy.rs +++ b/vnt/src/ip_proxy/icmp_proxy.rs @@ -188,6 +188,7 @@ fn recv_handle( net_packet.buffer(), &dest_ip, current_device.connect_server, + current_device.status.online(), ) { log::warn!("发送到目标失败:{}", e); }