diff --git a/vnt/src/core/mod.rs b/vnt/src/core/mod.rs index 8184ed0..66f7421 100644 --- a/vnt/src/core/mod.rs +++ b/vnt/src/core/mod.rs @@ -280,34 +280,36 @@ impl VntUtil { let channel = Channel::new(context.clone(), channel_recv_handler); let channel_worker = vnt_status_manager.worker("channel_worker"); let relay = config.relay; - if let Some(tcp_proxy) = tcp_proxy { - tokio::spawn(tcp_proxy.start()); - } - if let Some(udp_proxy) = udp_proxy { - tokio::spawn(udp_proxy.start()); - } tokio::spawn(async move { channel.start(channel_worker, tcp, 14, 65, relay, config.parallel).await }); } { - let other_worker = vnt_status_manager.worker("punch_handler"); let nat_test = nat_test.clone(); let device_list = device_list.clone(); let current_device = current_device.clone(); // 定时心跳 - heartbeat_handler::start_heartbeat(other_worker.worker("heartbeat"), channel_sender.clone(), device_list.clone(), + heartbeat_handler::start_heartbeat(vnt_status_manager.worker("heartbeat"), channel_sender.clone(), device_list.clone(), current_device.clone(), config.server_address_str, client_cipher.clone(), self.server_cipher.clone()); // 空闲检查 - heartbeat_handler::start_idle(other_worker.worker("idle"), idle, channel_sender.clone()); + heartbeat_handler::start_idle(vnt_status_manager.worker("idle"), idle, channel_sender.clone()); if !config.relay { // 打洞处理 - punch_handler::start(other_worker.worker("cone_receiver"), cone_receiver, punch.clone(), current_device.clone(), client_cipher.clone()); - punch_handler::start(other_worker.worker("symmetric_receiver"), symmetric_receiver, punch, current_device.clone(), client_cipher.clone()); - tokio::spawn(punch_handler::start_punch(other_worker, nat_test, + punch_handler::start(vnt_status_manager.worker("cone_receiver"), cone_receiver, punch.clone(), current_device.clone(), client_cipher.clone()); + punch_handler::start(vnt_status_manager.worker("symmetric_receiver"), symmetric_receiver, punch, current_device.clone(), client_cipher.clone()); + tokio::spawn(punch_handler::start_punch(vnt_status_manager.worker("punch_handler"), nat_test, device_list, channel_sender, current_device, client_cipher.clone())); } } + { + //代理 + if let Some(tcp_proxy) = tcp_proxy { + tokio::spawn(tcp_proxy.start()); + } + if let Some(udp_proxy) = udp_proxy { + tokio::spawn(udp_proxy.start()); + } + } context.switch(nat_test.nat_info().nat_type); Ok(Vnt { config: self.config, diff --git a/vnt/src/nat/mod.rs b/vnt/src/nat/mod.rs index e4c6c6f..2fe16a5 100644 --- a/vnt/src/nat/mod.rs +++ b/vnt/src/nat/mod.rs @@ -96,17 +96,31 @@ impl NatTest { ) -> NatTest { let server = stun_server[0].clone(); stun_server.resize(3, server); - let info = NatTest::re_test_( - &stun_server, - public_ip, + let nat_info = NatInfo::new( + vec![public_ip], public_port, + 0, local_ipv4_addr, ipv6_addr, - ).await; - NatTest { + NatType::Cone, + ); + let info = Arc::new(Mutex::new(nat_info)); + let nat_test = NatTest { stun_server, - info: Arc::new(Mutex::new(info)), + info, + }; + { + let nat_test = nat_test.clone(); + tokio::spawn(async move { + let _ = nat_test.re_test( + public_ip, + public_port, + local_ipv4_addr, + ipv6_addr, + ).await; + }); } + nat_test } pub fn nat_info(&self) -> NatInfo { self.info.lock().clone()