From 364012f9ddfeae147fbf411f2b81f104f593c548 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Tue, 26 Dec 2023 21:47:01 +0800 Subject: [PATCH] fmt --- vnt/src/channel/channel.rs | 11 ++++++-- vnt/src/core/mod.rs | 39 +++++++++++++++----------- vnt/src/handle/handshake_handler.rs | 4 +-- vnt/src/handle/heartbeat_handler.rs | 11 ++++++-- vnt/src/handle/registration_handler.rs | 2 +- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/vnt/src/channel/channel.rs b/vnt/src/channel/channel.rs index d7d14de..39091ec 100644 --- a/vnt/src/channel/channel.rs +++ b/vnt/src/channel/channel.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use std::io::{Read, Write}; -use std::net::{SocketAddrV6, TcpStream}; use std::net::UdpSocket as StdUdpSocket; use std::net::{Ipv4Addr, Shutdown, SocketAddr}; +use std::net::{SocketAddrV6, TcpStream}; use std::sync::Arc; use std::time::{Duration, Instant}; use std::{io, thread}; @@ -113,8 +113,13 @@ impl Context { } #[inline] pub fn send_main_udp(&self, buf: &[u8], mut addr: SocketAddr) -> io::Result { - if let SocketAddr::V4(ipv4) = addr{ - addr = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(),0,0)); + if let SocketAddr::V4(ipv4) = addr { + addr = SocketAddr::V6(SocketAddrV6::new( + ipv4.ip().to_ipv6_mapped(), + ipv4.port(), + 0, + 0, + )); } self.inner.main_channel.send_to(buf, addr) } diff --git a/vnt/src/core/mod.rs b/vnt/src/core/mod.rs index c05e630..c3cb8e6 100644 --- a/vnt/src/core/mod.rs +++ b/vnt/src/core/mod.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use std::io; -use std::net::{SocketAddrV6, TcpStream}; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::net::UdpSocket; +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; +use std::net::{SocketAddrV6, TcpStream}; use std::sync::Arc; use std::time::Duration; @@ -11,25 +11,25 @@ use parking_lot::{Mutex, RwLock}; use rand::Rng; use tokio::sync::mpsc::channel; -use crate::channel::{Route, RouteKey}; use crate::channel::channel::{Channel, Context}; use crate::channel::idle::Idle; use crate::channel::punch::{NatInfo, Punch, PunchModel}; use crate::channel::sender::ChannelSender; +use crate::channel::{Route, RouteKey}; use crate::cipher::{Cipher, CipherModel, RsaCipher}; use crate::core::status::VntStatusManger; use crate::error::Error; use crate::external_route::{AllowExternalRoute, ExternalRoute}; -use crate::handle::{ - ConnectStatus, CurrentDeviceInfo, handshake_handler, heartbeat_handler, PeerDeviceInfo, - punch_handler, registration_handler, -}; use crate::handle::handshake_handler::HandshakeEnum; use crate::handle::recv_handler::ChannelDataHandler; use crate::handle::registration_handler::{RegResponse, ReqEnum}; #[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))] use crate::handle::tun_tap::tap_handler; use crate::handle::tun_tap::tun_handler; +use crate::handle::{ + handshake_handler, heartbeat_handler, punch_handler, registration_handler, ConnectStatus, + CurrentDeviceInfo, PeerDeviceInfo, +}; use crate::igmp_server::IgmpServer; use crate::nat::NatTest; use crate::tun_tap_device; @@ -287,18 +287,18 @@ impl VntUtil { Some(ExternalRoute::new(config.in_ips)) }; #[cfg(feature = "ip_proxy")] - let (tcp_proxy, udp_proxy, ip_proxy_map) = if config.out_ips.is_empty() || config.no_proxy { + let (tcp_proxy, udp_proxy, ip_proxy_map) = if config.out_ips.is_empty() || config.no_proxy { (None, None, None) } else { let (tcp_proxy, udp_proxy, ip_proxy_map) = crate::ip_proxy::init_proxy( #[cfg(not(target_os = "android"))] - channel_sender.clone(), + channel_sender.clone(), #[cfg(not(target_os = "android"))] - current_device.clone(), + current_device.clone(), #[cfg(not(target_os = "android"))] - client_cipher.clone(), + client_cipher.clone(), ) - .await?; + .await?; (Some(tcp_proxy), Some(udp_proxy), Some(ip_proxy_map)) }; let out_external_route = AllowExternalRoute::new(config.out_ips); @@ -319,7 +319,7 @@ impl VntUtil { current_device.clone(), in_external_route, #[cfg(feature = "ip_proxy")] - ip_proxy_map.clone(), + ip_proxy_map.clone(), client_cipher.clone(), self.server_cipher.clone(), config.parallel, @@ -334,7 +334,7 @@ impl VntUtil { current_device.clone(), in_external_route, #[cfg(feature = "ip_proxy")] - ip_proxy_map.clone(), + ip_proxy_map.clone(), client_cipher.clone(), self.server_cipher.clone(), config.parallel, @@ -350,7 +350,7 @@ impl VntUtil { current_device.clone(), in_external_route, #[cfg(feature = "ip_proxy")] - ip_proxy_map.clone(), + ip_proxy_map.clone(), client_cipher.clone(), self.server_cipher.clone(), config.parallel, @@ -367,7 +367,7 @@ impl VntUtil { connect_status.clone(), peer_nat_info_map.clone(), #[cfg(feature = "ip_proxy")] - ip_proxy_map, + ip_proxy_map, out_external_route, cone_sender, symmetric_sender, @@ -608,7 +608,12 @@ impl Config { } match server_address { SocketAddr::V4(ipv4) => { - server_address = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(), 0, 0)) + server_address = SocketAddr::V6(SocketAddrV6::new( + ipv4.ip().to_ipv6_mapped(), + ipv4.port(), + 0, + 0, + )) } SocketAddr::V6(_) => {} } diff --git a/vnt/src/handle/handshake_handler.rs b/vnt/src/handle/handshake_handler.rs index f22f7de..420a0da 100644 --- a/vnt/src/handle/handshake_handler.rs +++ b/vnt/src/handle/handshake_handler.rs @@ -174,7 +174,7 @@ fn send_recv( match main_channel.recv_from(recv_buf) { Ok((len, addr)) => { if server_address != addr { - log::warn!("请求{:?}和响应{:?}地址不一致",server_address,addr); + log::warn!("请求{:?}和响应{:?}地址不一致", server_address, addr); } Ok(len) } @@ -222,7 +222,7 @@ pub fn secret_handshake( if net_packet.is_gateway() && net_packet.protocol() == Protocol::Service && service_packet::Protocol::from(net_packet.transport_protocol()) - == service_packet::Protocol::SecretHandshakeResponse + == service_packet::Protocol::SecretHandshakeResponse { Ok(()) } else { diff --git a/vnt/src/handle/heartbeat_handler.rs b/vnt/src/handle/heartbeat_handler.rs index 9e5db7f..97ebf69 100644 --- a/vnt/src/handle/heartbeat_handler.rs +++ b/vnt/src/handle/heartbeat_handler.rs @@ -8,14 +8,14 @@ use parking_lot::Mutex; use rand::prelude::SliceRandom; use crate::channel::idle::Idle; -use crate::channel::Route; use crate::channel::sender::ChannelSender; +use crate::channel::Route; use crate::cipher::Cipher; use crate::core::status::VntWorker; use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo}; -use crate::protocol::{control_packet, MAX_TTL, NetPacket, Protocol, Version}; use crate::protocol::body::ENCRYPTION_RESERVED; use crate::protocol::control_packet::PingPacket; +use crate::protocol::{control_packet, NetPacket, Protocol, Version, MAX_TTL}; pub fn start_idle(mut worker: VntWorker, idle: Idle, sender: ChannelSender) { tokio::spawn(async move { @@ -142,7 +142,12 @@ async fn start_heartbeat_main_( if addr != current_dev.connect_server { let mut tmp = current_dev.clone(); if let SocketAddr::V4(ipv4) = addr { - addr = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(), 0, 0)) + addr = SocketAddr::V6(SocketAddrV6::new( + ipv4.ip().to_ipv6_mapped(), + ipv4.port(), + 0, + 0, + )) } tmp.connect_server = addr; log::info!( diff --git a/vnt/src/handle/registration_handler.rs b/vnt/src/handle/registration_handler.rs index 4755267..2970d95 100644 --- a/vnt/src/handle/registration_handler.rs +++ b/vnt/src/handle/registration_handler.rs @@ -88,7 +88,7 @@ pub fn registration( match main_channel.recv_from(&mut recv_buf) { Ok((len, addr)) => { if server_address != addr { - log::warn!("请求{:?}和响应{:?}地址不一致",server_address,addr); + log::warn!("请求{:?}和响应{:?}地址不一致", server_address, addr); } &mut recv_buf[..len] }