From 1ce3e9ff2e4ead3deb5848f96f107c6ec8ce3069 Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Thu, 23 May 2024 22:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9C=E6=AD=A2=E6=97=B6=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=80=9A=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/core/conn.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/vnt/src/core/conn.rs b/vnt/src/core/conn.rs index 411e9f6..a380c50 100644 --- a/vnt/src/core/conn.rs +++ b/vnt/src/core/conn.rs @@ -38,7 +38,7 @@ pub struct Vnt { current_device: Arc>, nat_test: NatTest, device_list: Arc)>>, - context: ChannelContext, + context: Arc>>, peer_nat_info_map: Arc>>, down_count_watcher: WatchU64Adder, up_count_watcher: WatchSingleU64Adder, @@ -132,8 +132,11 @@ impl Vnt { // pc上先创建虚拟网卡 #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let device = { + log::info!("开始创建tun"); let device = tun_tap_device::create_device(&config)?; + log::info!("创建tun成功"); let tun_info = DeviceInfo::new(device.name()?, device.version()?); + log::info!("tun信息{:?}",tun_info); callback.create_tun(tun_info); device }; @@ -273,7 +276,7 @@ impl Vnt { current_device, nat_test, device_list, - context, + context: Arc::new(Mutex::new(Some(context))), peer_nat_info_map, down_count_watcher, up_count_watcher, @@ -390,16 +393,24 @@ impl Vnt { device_list } pub fn route(&self, ip: &Ipv4Addr) -> Option { - self.context.route_table.route_one(ip) + self.context.lock().as_ref()?.route_table.route_one(ip) } pub fn is_gateway(&self, ip: &Ipv4Addr) -> bool { self.current_device.load().is_gateway(ip) } pub fn route_key(&self, route_key: &RouteKey) -> Option { - self.context.route_table.route_to_id(route_key) + self.context + .lock() + .as_ref()? + .route_table + .route_to_id(route_key) } pub fn route_table(&self) -> Vec<(Ipv4Addr, Vec)> { - self.context.route_table.route_table() + if let Some(context) = self.context.lock().as_ref() { + context.route_table.route_table() + } else { + vec![] + } } pub fn up_stream(&self) -> u64 { self.up_count_watcher.get() @@ -408,6 +419,8 @@ impl Vnt { self.down_count_watcher.get() } pub fn stop(&self) { + //退出协助回收资源 + let _ = self.context.lock().take(); self.stop_manager.stop() } pub fn wait(&self) {