From f78f8de15e386462a26513144d9e8d9e7725ff9c Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Tue, 30 Apr 2024 23:25:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/channel/context.rs | 6 +++--- vnt/src/channel/handler.rs | 4 ++-- vnt/src/channel/idle.rs | 6 +++--- vnt/src/channel/mod.rs | 8 ++++---- vnt/src/channel/punch.rs | 6 +++--- vnt/src/channel/sender.rs | 8 ++++---- vnt/src/channel/tcp_channel.rs | 14 +++++++------- vnt/src/channel/udp_channel.rs | 16 ++++++++++------ vnt/src/core/conn.rs | 6 +++--- vnt/src/handle/handshaker.rs | 4 ++-- vnt/src/handle/maintain/addr_request.rs | 8 ++++---- vnt/src/handle/maintain/heartbeat.rs | 12 ++++++------ vnt/src/handle/maintain/idle.rs | 12 ++++++------ vnt/src/handle/maintain/punch.rs | 8 ++++---- vnt/src/handle/maintain/re_nat_type.rs | 6 +++--- vnt/src/handle/maintain/up_status.rs | 8 ++++---- vnt/src/handle/recv_data/client.rs | 10 +++++----- vnt/src/handle/recv_data/mod.rs | 8 ++++---- vnt/src/handle/recv_data/server.rs | 16 ++++++++++------ vnt/src/handle/recv_data/turn.rs | 4 ++-- vnt/src/handle/tun_tap/mod.rs | 6 +++--- vnt/src/handle/tun_tap/tun_handler.rs | 8 ++++---- vnt/src/ip_proxy/icmp_proxy.rs | 10 +++++----- vnt/src/ip_proxy/mod.rs | 4 ++-- vnt/src/tun_tap_device/tun_create_helper.rs | 6 +++--- 25 files changed, 106 insertions(+), 98 deletions(-) diff --git a/vnt/src/channel/context.rs b/vnt/src/channel/context.rs index a18a49e3..d130c9bc 100644 --- a/vnt/src/channel/context.rs +++ b/vnt/src/channel/context.rs @@ -16,11 +16,11 @@ use crate::channel::{Route, RouteKey, UseChannelType, DEFAULT_RT}; /// 传输通道上下文,持有udp socket、tcp socket和路由信息 #[derive(Clone)] -pub struct Context { +pub struct ChannelContext { inner: Arc, } -impl Context { +impl ChannelContext { pub fn new( main_udp_socket: Vec, use_channel_type: UseChannelType, @@ -63,7 +63,7 @@ impl Context { } } -impl Deref for Context { +impl Deref for ChannelContext { type Target = ContextInner; fn deref(&self) -> &Self::Target { diff --git a/vnt/src/channel/handler.rs b/vnt/src/channel/handler.rs index 16c10172..d9e8c0ed 100644 --- a/vnt/src/channel/handler.rs +++ b/vnt/src/channel/handler.rs @@ -1,6 +1,6 @@ -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::RouteKey; pub trait RecvChannelHandler: Clone + Send + 'static { - fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &Context); + fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &ChannelContext); } diff --git a/vnt/src/channel/idle.rs b/vnt/src/channel/idle.rs index 42377df6..ecb877f3 100644 --- a/vnt/src/channel/idle.rs +++ b/vnt/src/channel/idle.rs @@ -1,16 +1,16 @@ use std::net::Ipv4Addr; use std::time::Duration; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::Route; pub struct Idle { read_idle: Duration, - context: Context, + context: ChannelContext, } impl Idle { - pub fn new(read_idle: Duration, context: Context) -> Self { + pub fn new(read_idle: Duration, context: ChannelContext) -> Self { Self { read_idle, context } } } diff --git a/vnt/src/channel/mod.rs b/vnt/src/channel/mod.rs index 863c1dce..c54d4aee 100644 --- a/vnt/src/channel/mod.rs +++ b/vnt/src/channel/mod.rs @@ -2,7 +2,7 @@ use std::io; use std::net::{SocketAddr, UdpSocket}; use std::str::FromStr; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::handler::RecvChannelHandler; use crate::channel::sender::AcceptSocketSender; use crate::channel::tcp_channel::tcp_listen; @@ -151,7 +151,7 @@ pub fn init_context( is_tcp: bool, packet_loss_rate: Option, packet_delay: u32, -) -> io::Result<(Context, mio::net::TcpListener)> { +) -> io::Result<(ChannelContext, mio::net::TcpListener)> { assert!(!ports.is_empty(), "not channel"); let mut udps = Vec::with_capacity(ports.len()); //检查系统是否支持ipv6 @@ -191,7 +191,7 @@ pub fn init_context( let main_channel: UdpSocket = socket.into(); udps.push(main_channel); } - let context = Context::new( + let context = ChannelContext::new( udps, use_channel_type, first_latency, @@ -242,7 +242,7 @@ pub fn init_context( pub fn init_channel( tcp_listener: mio::net::TcpListener, - context: Context, + context: ChannelContext, stop_manager: StopManager, recv_handler: H, ) -> io::Result<( diff --git a/vnt/src/channel/punch.rs b/vnt/src/channel/punch.rs index 9c29088c..004b80a1 100644 --- a/vnt/src/channel/punch.rs +++ b/vnt/src/channel/punch.rs @@ -8,7 +8,7 @@ use mio::net::TcpStream; use rand::prelude::SliceRandom; use rand::Rng; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::sender::AcceptSocketSender; use crate::external_route::ExternalRoute; use crate::nat::NatTest; @@ -181,7 +181,7 @@ impl NatInfo { #[derive(Clone)] pub struct Punch { - context: Context, + context: ChannelContext, port_vec: Vec, port_index: HashMap, punch_model: PunchModel, @@ -193,7 +193,7 @@ pub struct Punch { impl Punch { pub fn new( - context: Context, + context: ChannelContext, punch_model: PunchModel, is_tcp: bool, tcp_socket_sender: AcceptSocketSender<(TcpStream, SocketAddr, Option>)>, diff --git a/vnt/src/channel/sender.rs b/vnt/src/channel/sender.rs index 0ec1c793..bfc6d923 100644 --- a/vnt/src/channel/sender.rs +++ b/vnt/src/channel/sender.rs @@ -5,22 +5,22 @@ use std::sync::Arc; use mio::Token; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::notify::{AcceptNotify, WritableNotify}; #[derive(Clone)] pub struct ChannelSender { - context: Context, + context: ChannelContext, } impl ChannelSender { - pub fn new(context: Context) -> Self { + pub fn new(context: ChannelContext) -> Self { Self { context } } } impl Deref for ChannelSender { - type Target = Context; + type Target = ChannelContext; fn deref(&self) -> &Self::Target { &self.context diff --git a/vnt/src/channel/tcp_channel.rs b/vnt/src/channel/tcp_channel.rs index 34c1d6b0..5628937f 100644 --- a/vnt/src/channel/tcp_channel.rs +++ b/vnt/src/channel/tcp_channel.rs @@ -15,7 +15,7 @@ use std::{io, thread}; use mio::net::{TcpListener, TcpStream}; use mio::{Events, Interest, Poll, Registry, Token, Waker}; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::handler::RecvChannelHandler; use crate::channel::notify::{AcceptNotify, WritableNotify}; use crate::channel::sender::{AcceptSocketSender, PacketSender}; @@ -30,7 +30,7 @@ pub fn tcp_listen( tcp_server: TcpListener, stop_manager: StopManager, recv_handler: H, - context: Context, + context: ChannelContext, ) -> io::Result>)>> where H: RecvChannelHandler, @@ -74,7 +74,7 @@ fn tcp_listen0( accept_notify: AcceptNotify, accept_tcp_receiver: Receiver<(TcpStream, SocketAddr, Option>)>, mut recv_handler: H, - context: Context, + context: ChannelContext, ) -> io::Result<()> where H: RecvChannelHandler, @@ -158,7 +158,7 @@ where fn init_writable_handler( receiver: Receiver<(TcpStream, Token, SocketAddr, Option>)>, stop_manager: StopManager, - context: Context, + context: ChannelContext, ) -> io::Result { let poll = Poll::new()?; let writable_notify = WritableNotify::new(Waker::new(poll.registry(), NOTIFY)?); @@ -190,7 +190,7 @@ fn tcp_writable_listen( receiver: Receiver<(TcpStream, Token, SocketAddr, Option>)>, mut poll: Poll, writable_notify: WritableNotify, - context: &Context, + context: &ChannelContext, ) -> io::Result<()> { let mut events = Events::with_capacity(1024); let mut write_map: HashMap< @@ -338,7 +338,7 @@ fn readable_handle( token: &Token, map: &mut HashMap, usize)>, recv_handler: &mut H, - context: &Context, + context: &ChannelContext, ) -> io::Result<()> where H: RecvChannelHandler, @@ -447,7 +447,7 @@ fn closed_handle_w( Option<(Vec, usize)>, ), >, - context: &Context, + context: &ChannelContext, ) { if let Some((tcp, addr, _, _)) = map.remove(token) { context.tcp_map.write().remove(&addr); diff --git a/vnt/src/channel/udp_channel.rs b/vnt/src/channel/udp_channel.rs index 1a29cecf..3f3b1ec2 100644 --- a/vnt/src/channel/udp_channel.rs +++ b/vnt/src/channel/udp_channel.rs @@ -6,7 +6,7 @@ use mio::event::Source; use mio::net::UdpSocket; use mio::{Events, Interest, Poll, Token, Waker}; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::handler::RecvChannelHandler; use crate::channel::notify::AcceptNotify; use crate::channel::sender::AcceptSocketSender; @@ -16,7 +16,7 @@ use crate::util::StopManager; pub fn udp_listen( stop_manager: StopManager, recv_handler: H, - context: Context, + context: ChannelContext, ) -> io::Result>>> where H: RecvChannelHandler, @@ -30,7 +30,7 @@ const NOTIFY: Token = Token(0); fn sub_udp_listen( stop_manager: StopManager, recv_handler: H, - context: Context, + context: ChannelContext, ) -> io::Result>>> where H: RecvChannelHandler, @@ -61,7 +61,7 @@ where fn sub_udp_listen0( mut poll: Poll, mut recv_handler: H, - context: Context, + context: ChannelContext, accept_notify: AcceptNotify, accept_receiver: Receiver>>, ) -> io::Result<()> @@ -205,7 +205,7 @@ where fn main_udp_listen( stop_manager: StopManager, recv_handler: H, - context: Context, + context: ChannelContext, ) -> io::Result<()> where H: RecvChannelHandler, @@ -231,7 +231,11 @@ where Ok(()) } -pub fn main_udp_listen0(mut poll: Poll, mut recv_handler: H, context: Context) -> io::Result<()> +pub fn main_udp_listen0( + mut poll: Poll, + mut recv_handler: H, + context: ChannelContext, +) -> io::Result<()> where H: RecvChannelHandler, { diff --git a/vnt/src/core/conn.rs b/vnt/src/core/conn.rs index 852391b3..ef666ed1 100644 --- a/vnt/src/core/conn.rs +++ b/vnt/src/core/conn.rs @@ -11,7 +11,7 @@ use rsa::signature::digest::Digest; #[cfg(not(target_os = "android"))] use tun::device::IFace; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::idle::Idle; use crate::channel::punch::{NatInfo, Punch}; use crate::channel::{init_channel, init_context, Route, RouteKey}; @@ -40,7 +40,7 @@ pub struct Vnt { current_device: Arc>, nat_test: NatTest, device_list: Arc)>>, - context: Context, + context: ChannelContext, peer_nat_info_map: Arc>>, down_count_watcher: WatchU64Adder, up_count_watcher: WatchSingleU64Adder, @@ -282,7 +282,7 @@ impl Vnt { pub fn start( scheduler: &Scheduler, - context: Context, + context: ChannelContext, nat_test: NatTest, device_list: Arc)>>, current_device: Arc>, diff --git a/vnt/src/handle/handshaker.rs b/vnt/src/handle/handshaker.rs index ca907529..4d5b269b 100644 --- a/vnt/src/handle/handshaker.rs +++ b/vnt/src/handle/handshaker.rs @@ -7,7 +7,7 @@ use crossbeam_utils::atomic::AtomicCell; use parking_lot::Mutex; use protobuf::Message; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; #[cfg(feature = "server_encrypt")] use crate::cipher::RsaCipher; use crate::handle::{GATEWAY_IP, SELF_IP}; @@ -37,7 +37,7 @@ impl Handshake { rsa_cipher, } } - pub fn send(&self, context: &Context, secret: bool, addr: SocketAddr) -> io::Result<()> { + pub fn send(&self, context: &ChannelContext, secret: bool, addr: SocketAddr) -> io::Result<()> { let last = self.time.load(); //短时间不重复发送 if last.elapsed() < Duration::from_secs(3) { diff --git a/vnt/src/handle/maintain/addr_request.rs b/vnt/src/handle/maintain/addr_request.rs index 51bef9a6..05412f5d 100644 --- a/vnt/src/handle/maintain/addr_request.rs +++ b/vnt/src/handle/maintain/addr_request.rs @@ -3,7 +3,7 @@ use std::time::Duration; use crossbeam_utils::atomic::AtomicCell; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::handle::{BaseConfigInfo, CurrentDeviceInfo}; use crate::protocol::body::ENCRYPTION_RESERVED; @@ -12,7 +12,7 @@ use crate::util::Scheduler; pub fn addr_request( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device_info: Arc>, server_cipher: Cipher, _config: BaseConfigInfo, @@ -26,7 +26,7 @@ pub fn addr_request( } pub fn pub_address_request( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device_info: Arc>, server_cipher: Cipher, ) { @@ -41,7 +41,7 @@ pub fn pub_address_request( } pub fn addr_request0( - context: &Context, + context: &ChannelContext, current_device: &AtomicCell, server_cipher: &Cipher, ) { diff --git a/vnt/src/handle/maintain/heartbeat.rs b/vnt/src/handle/maintain/heartbeat.rs index d857a704..d9ce1dc3 100644 --- a/vnt/src/handle/maintain/heartbeat.rs +++ b/vnt/src/handle/maintain/heartbeat.rs @@ -7,7 +7,7 @@ use crossbeam_utils::atomic::AtomicCell; use parking_lot::Mutex; use rand::prelude::SliceRandom; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo}; use crate::protocol::body::ENCRYPTION_RESERVED; @@ -18,7 +18,7 @@ use crate::util::Scheduler; /// 定时发送心跳包 pub fn heartbeat( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device_info: Arc>, device_list: Arc)>>, client_cipher: Cipher, @@ -48,7 +48,7 @@ pub fn heartbeat( } fn heartbeat0( - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, device_list: &Mutex<(u16, Vec)>, client_cipher: &Cipher, @@ -125,7 +125,7 @@ fn heartbeat0( /// 客户端中继路径探测,延迟启动 pub fn client_relay( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device: Arc>, device_list: Arc)>>, client_cipher: Cipher, @@ -141,7 +141,7 @@ pub fn client_relay( /// 客户端中继路径探测,每30秒探测一次 fn client_relay_( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device: Arc>, device_list: Arc)>>, client_cipher: Cipher, @@ -163,7 +163,7 @@ fn client_relay_( } fn client_relay0( - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, device_list: &Mutex<(u16, Vec)>, client_cipher: &Cipher, diff --git a/vnt/src/handle/maintain/idle.rs b/vnt/src/handle/maintain/idle.rs index 403c0179..2589f78e 100644 --- a/vnt/src/handle/maintain/idle.rs +++ b/vnt/src/handle/maintain/idle.rs @@ -6,7 +6,7 @@ use std::time::Duration; use crossbeam_utils::atomic::AtomicCell; use mio::net::TcpStream; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::idle::{Idle, IdleType}; use crate::channel::sender::AcceptSocketSender; use crate::handle::callback::{ConnectInfo, ErrorType}; @@ -18,7 +18,7 @@ use crate::{ErrorInfo, VntCallback}; pub fn idle_route( scheduler: &Scheduler, idle: Idle, - context: Context, + context: ChannelContext, current_device_info: Arc>, call: Call, ) { @@ -33,7 +33,7 @@ pub fn idle_route( pub fn idle_gateway( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device_info: Arc>, config: BaseConfigInfo, tcp_socket_sender: AcceptSocketSender<(TcpStream, SocketAddr, Option>)>, @@ -68,7 +68,7 @@ pub fn idle_gateway( } fn idle_gateway0( - context: &Context, + context: &ChannelContext, current_device: &AtomicCell, config: &BaseConfigInfo, tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option>)>, @@ -95,7 +95,7 @@ fn idle_gateway0( fn idle_route0( idle: &Idle, - context: &Context, + context: &ChannelContext, current_device: &AtomicCell, call: &Call, ) -> Duration { @@ -117,7 +117,7 @@ fn idle_route0( } fn check_gateway_channel( - context: &Context, + context: &ChannelContext, current_device_info: &AtomicCell, config: &BaseConfigInfo, tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option>)>, diff --git a/vnt/src/handle/maintain/punch.rs b/vnt/src/handle/maintain/punch.rs index b1172b3a..8c7c226c 100644 --- a/vnt/src/handle/maintain/punch.rs +++ b/vnt/src/handle/maintain/punch.rs @@ -10,7 +10,7 @@ use parking_lot::Mutex; use protobuf::Message; use rand::prelude::SliceRandom; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::punch::{NatInfo, NatType, Punch}; use crate::cipher::Cipher; use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo}; @@ -86,7 +86,7 @@ pub fn punch_channel() -> (PunchSender, PunchReceiver) { pub fn punch( scheduler: &Scheduler, - context: Context, + context: ChannelContext, nat_test: NatTest, device_list: Arc)>>, current_device: Arc>, @@ -166,7 +166,7 @@ fn punch_start( /// 定时发起打洞请求 fn punch_request( scheduler: &Scheduler, - context: Context, + context: ChannelContext, nat_test: NatTest, device_list: Arc)>>, current_device: Arc>, @@ -214,7 +214,7 @@ fn punch_request( /// 随机对需要打洞的客户端发起打洞请求 fn punch0( - context: &Context, + context: &ChannelContext, nat_test: &NatTest, device_list: &Arc)>>, current_device: CurrentDeviceInfo, diff --git a/vnt/src/handle/maintain/re_nat_type.rs b/vnt/src/handle/maintain/re_nat_type.rs index 37c84050..975f4b20 100644 --- a/vnt/src/handle/maintain/re_nat_type.rs +++ b/vnt/src/handle/maintain/re_nat_type.rs @@ -1,7 +1,7 @@ use std::thread; use std::time::Duration; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::sender::AcceptSocketSender; use crate::nat; use crate::nat::NatTest; @@ -10,7 +10,7 @@ use crate::util::Scheduler; /// 10分钟探测一次nat pub fn retrieve_nat_type( scheduler: &Scheduler, - context: Context, + context: ChannelContext, nat_test: NatTest, udp_socket_sender: AcceptSocketSender>>, ) { @@ -21,7 +21,7 @@ pub fn retrieve_nat_type( } fn retrieve_nat_type0( - context: Context, + context: ChannelContext, nat_test: NatTest, udp_socket_sender: AcceptSocketSender>>, ) { diff --git a/vnt/src/handle/maintain/up_status.rs b/vnt/src/handle/maintain/up_status.rs index 5d2fae2d..74d554b7 100644 --- a/vnt/src/handle/maintain/up_status.rs +++ b/vnt/src/handle/maintain/up_status.rs @@ -1,4 +1,4 @@ -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::handle::CurrentDeviceInfo; use crate::proto::message::{ClientStatusInfo, PunchNatType, RouteItem}; use crate::protocol::body::ENCRYPTION_RESERVED; @@ -13,7 +13,7 @@ use std::time::Duration; /// 上报状态给服务器 pub fn up_status( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device_info: Arc>, down_count_watcher: WatchU64Adder, up_count_watcher: WatchSingleU64Adder, @@ -31,7 +31,7 @@ pub fn up_status( fn up_status0( scheduler: &Scheduler, - context: Context, + context: ChannelContext, current_device_info: Arc>, down_count_watcher: WatchU64Adder, up_count_watcher: WatchSingleU64Adder, @@ -59,7 +59,7 @@ fn up_status0( } fn send_up_status_packet( - context: &Context, + context: &ChannelContext, current_device_info: &AtomicCell, down_count_watcher: &WatchU64Adder, up_count_watcher: &WatchSingleU64Adder, diff --git a/vnt/src/handle/recv_data/client.rs b/vnt/src/handle/recv_data/client.rs index f53f9a2b..df6f68bd 100644 --- a/vnt/src/handle/recv_data/client.rs +++ b/vnt/src/handle/recv_data/client.rs @@ -9,7 +9,7 @@ use packet::icmp::{icmp, Kind}; use packet::ip::ipv4; use packet::ip::ipv4::packet::IpV4Packet; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::punch::NatInfo; use crate::channel::{Route, RouteKey}; use crate::cipher::Cipher; @@ -71,7 +71,7 @@ impl PacketHandler for ClientPacketHandler { &self, mut net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, ) -> io::Result<()> { self.client_cipher.decrypt_ipv4(&mut net_packet)?; @@ -100,7 +100,7 @@ impl ClientPacketHandler { fn ip_turn( &self, mut net_packet: NetPacket<&mut [u8]>, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, route_key: RouteKey, ) -> io::Result<()> { @@ -186,7 +186,7 @@ impl ClientPacketHandler { } fn control( &self, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, mut net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, @@ -274,7 +274,7 @@ impl ClientPacketHandler { } fn other_turn( &self, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, diff --git a/vnt/src/handle/recv_data/mod.rs b/vnt/src/handle/recv_data/mod.rs index 01ff982c..32420f64 100644 --- a/vnt/src/handle/recv_data/mod.rs +++ b/vnt/src/handle/recv_data/mod.rs @@ -6,7 +6,7 @@ use std::{io, thread}; use crossbeam_utils::atomic::AtomicCell; use parking_lot::{Mutex, RwLock}; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::handler::RecvChannelHandler; use crate::channel::punch::NatInfo; use crate::channel::RouteKey; @@ -42,7 +42,7 @@ pub struct RecvDataHandler { } impl RecvChannelHandler for RecvDataHandler { - fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &Context) { + fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &ChannelContext) { if let Err(e) = self.handle0(buf, route_key, context) { log::error!("[{}]-{:?}", thread::current().name().unwrap_or(""), e); } @@ -104,7 +104,7 @@ impl RecvDataHandler { &mut self, buf: &mut [u8], route_key: RouteKey, - context: &Context, + context: &ChannelContext, ) -> io::Result<()> { // 统计流量 self.counter.add(buf.len() as _); @@ -145,7 +145,7 @@ pub trait PacketHandler { &self, net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, ) -> io::Result<()>; } diff --git a/vnt/src/handle/recv_data/server.rs b/vnt/src/handle/recv_data/server.rs index 4dcb085b..72eb14c2 100644 --- a/vnt/src/handle/recv_data/server.rs +++ b/vnt/src/handle/recv_data/server.rs @@ -12,7 +12,7 @@ use packet::icmp::{icmp, Kind}; use packet::ip::ipv4; use packet::ip::ipv4::packet::IpV4Packet; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::{Route, RouteKey}; use crate::cipher::Cipher; #[cfg(feature = "server_encrypt")] @@ -95,7 +95,7 @@ impl PacketHandler for ServerPacketHandler { &self, mut net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, ) -> io::Result<()> { context @@ -248,7 +248,7 @@ impl PacketHandler for ServerPacketHandler { impl ServerPacketHandler { fn service( &self, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, @@ -435,7 +435,11 @@ impl ServerPacketHandler { .collect(), ); } - fn register(&self, current_device: &CurrentDeviceInfo, context: &Context) -> io::Result<()> { + fn register( + &self, + current_device: &CurrentDeviceInfo, + context: &ChannelContext, + ) -> io::Result<()> { if current_device.status.online() { log::info!("已连接的不需要注册,{:?}", self.config_info); return Ok(()); @@ -468,7 +472,7 @@ impl ServerPacketHandler { } fn error( &self, - context: &Context, + context: &ChannelContext, _current_device: &CurrentDeviceInfo, net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, @@ -518,7 +522,7 @@ impl ServerPacketHandler { } fn control( &self, - context: &Context, + context: &ChannelContext, current_device: &CurrentDeviceInfo, net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, diff --git a/vnt/src/handle/recv_data/turn.rs b/vnt/src/handle/recv_data/turn.rs index 106ea2d3..fa7e8141 100644 --- a/vnt/src/handle/recv_data/turn.rs +++ b/vnt/src/handle/recv_data/turn.rs @@ -1,4 +1,4 @@ -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::channel::RouteKey; use crate::handle::recv_data::PacketHandler; use crate::handle::CurrentDeviceInfo; @@ -19,7 +19,7 @@ impl PacketHandler for TurnPacketHandler { &self, mut net_packet: NetPacket<&mut [u8]>, route_key: RouteKey, - context: &Context, + context: &ChannelContext, _current_device: &CurrentDeviceInfo, ) -> std::io::Result<()> { // ttl减一 diff --git a/vnt/src/handle/tun_tap/mod.rs b/vnt/src/handle/tun_tap/mod.rs index 92243d67..3697320f 100644 --- a/vnt/src/handle/tun_tap/mod.rs +++ b/vnt/src/handle/tun_tap/mod.rs @@ -6,7 +6,7 @@ use parking_lot::Mutex; use packet::ip::ipv4::packet::IpV4Packet; use packet::ip::ipv4::protocol::Protocol; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::external_route::ExternalRoute; use crate::handle::{check_dest, CurrentDeviceInfo, PeerDeviceInfo}; @@ -22,7 +22,7 @@ pub mod tun_handler; fn broadcast( server_cipher: &Cipher, - sender: &Context, + sender: &ChannelContext, net_packet: &mut NetPacket<&mut [u8]>, current_device: &CurrentDeviceInfo, device_list: &Mutex<(u16, Vec)>, @@ -108,7 +108,7 @@ fn broadcast( /// #[inline] pub fn base_handle( - context: &Context, + context: &ChannelContext, buf: &mut [u8], data_len: usize, //数据总长度=12+ip包长度 current_device: CurrentDeviceInfo, diff --git a/vnt/src/handle/tun_tap/tun_handler.rs b/vnt/src/handle/tun_tap/tun_handler.rs index 83da150a..c918b011 100644 --- a/vnt/src/handle/tun_tap/tun_handler.rs +++ b/vnt/src/handle/tun_tap/tun_handler.rs @@ -11,7 +11,7 @@ use packet::ip::ipv4::packet::IpV4Packet; use tun::device::IFace; use tun::Device; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::external_route::ExternalRoute; use crate::handle::tun_tap::channel_group::{channel_group, GroupSyncSender}; @@ -38,7 +38,7 @@ fn icmp(device_writer: &Device, mut ipv4_packet: IpV4Packet<&mut [u8]>) -> io::R /// 接收tun数据,并且转发到udp上 fn handle( - context: &Context, + context: &ChannelContext, data: &mut [u8], len: usize, device_writer: &Device, @@ -75,7 +75,7 @@ fn handle( pub fn start( stop_manager: StopManager, - context: Context, + context: ChannelContext, device: Arc, current_device: Arc>, ip_route: ExternalRoute, @@ -179,7 +179,7 @@ pub fn start( fn start_simple( stop_manager: StopManager, - context: &Context, + context: &ChannelContext, device: Arc, current_device: Arc>, ip_route: ExternalRoute, diff --git a/vnt/src/ip_proxy/icmp_proxy.rs b/vnt/src/ip_proxy/icmp_proxy.rs index d59980a6..d24dbd49 100644 --- a/vnt/src/ip_proxy/icmp_proxy.rs +++ b/vnt/src/ip_proxy/icmp_proxy.rs @@ -12,7 +12,7 @@ use packet::icmp::icmp; use packet::icmp::icmp::HeaderOther; use packet::ip::ipv4::packet::IpV4Packet; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::handle::CurrentDeviceInfo; use crate::ip_proxy::ProxyHandler; @@ -28,7 +28,7 @@ pub struct IcmpProxy { impl IcmpProxy { pub fn new( - context: Context, + context: ChannelContext, stop_manager: StopManager, current_device: Arc>, client_cipher: Cipher, @@ -86,7 +86,7 @@ fn icmp_proxy( mut icmp_socket: UdpSocket, // 对端-> 真实来源 nat_map: Arc>>, - context: Context, + context: ChannelContext, stop_manager: StopManager, current_device: Arc>, client_cipher: Cipher, @@ -130,7 +130,7 @@ fn readable_handle( icmp_socket: &UdpSocket, buf: &mut [u8], nat_map: &Mutex>, - context: &Context, + context: &ChannelContext, current_device: &AtomicCell, client_cipher: &Cipher, ) { @@ -181,7 +181,7 @@ fn recv_handle( data_len: usize, peer_ip: Ipv4Addr, nat_map: &Mutex>, - context: &Context, + context: &ChannelContext, current_device: &AtomicCell, client_cipher: &Cipher, ) { diff --git a/vnt/src/ip_proxy/mod.rs b/vnt/src/ip_proxy/mod.rs index 38cba05f..54a97c59 100644 --- a/vnt/src/ip_proxy/mod.rs +++ b/vnt/src/ip_proxy/mod.rs @@ -7,7 +7,7 @@ use crossbeam_utils::atomic::AtomicCell; use packet::ip::ipv4; use packet::ip::ipv4::packet::IpV4Packet; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::handle::CurrentDeviceInfo; use crate::ip_proxy::icmp_proxy::IcmpProxy; @@ -37,7 +37,7 @@ pub struct IpProxyMap { } pub fn init_proxy( - context: Context, + context: ChannelContext, scheduler: Scheduler, stop_manager: StopManager, current_device: Arc>, diff --git a/vnt/src/tun_tap_device/tun_create_helper.rs b/vnt/src/tun_tap_device/tun_create_helper.rs index c5ecc45c..576f9b1b 100644 --- a/vnt/src/tun_tap_device/tun_create_helper.rs +++ b/vnt/src/tun_tap_device/tun_create_helper.rs @@ -6,7 +6,7 @@ use parking_lot::Mutex; use tun::Device; -use crate::channel::context::Context; +use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::external_route::ExternalRoute; use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo}; @@ -70,7 +70,7 @@ pub struct TunDeviceHelper { struct TunDeviceHelperInner { stop_manager: StopManager, - context: Context, + context: ChannelContext, current_device: Arc>, ip_route: ExternalRoute, #[cfg(feature = "ip_proxy")] @@ -85,7 +85,7 @@ struct TunDeviceHelperInner { impl TunDeviceHelper { pub fn new( stop_manager: StopManager, - context: Context, + context: ChannelContext, current_device: Arc>, ip_route: ExternalRoute, #[cfg(feature = "ip_proxy")] ip_proxy_map: Option,