diff --git a/src/common.rs b/src/common.rs index d74ecac8b..977c26832 100644 --- a/src/common.rs +++ b/src/common.rs @@ -507,6 +507,16 @@ audio_rechannel!(audio_rechannel_8_7, 8, 7); pub fn test_nat_type() { let mut i = 0; std::thread::spawn(move || loop { + if i == 0 { + #[cfg(not(any(target_os = "android", target_os = "ios")))] + let is_direct = crate::ipc::get_socks().is_none(); // sync socks BTW + #[cfg(any(target_os = "android", target_os = "ios"))] + let is_direct = Config::get_socks().is_none(); // sync socks BTW + if !is_direct { + Config::set_nat_type(NatType::SYMMETRIC as _); + break; + } + } match test_nat_type_() { Ok(true) => break, Err(err) => { @@ -528,14 +538,6 @@ pub fn test_nat_type() { #[tokio::main(flavor = "current_thread")] async fn test_nat_type_() -> ResultType { log::info!("Testing nat ..."); - #[cfg(not(any(target_os = "android", target_os = "ios")))] - let is_direct = crate::ipc::get_socks_async(1_000).await.is_none(); // sync socks BTW - #[cfg(any(target_os = "android", target_os = "ios"))] - let is_direct = Config::get_socks().is_none(); // sync socks BTW - if !is_direct { - Config::set_nat_type(NatType::SYMMETRIC as _); - return Ok(true); - } let start = std::time::Instant::now(); let (rendezvous_server, _, _) = get_rendezvous_server(1_000).await; let server1 = rendezvous_server; diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rs index 135352e68..d53fd0e05 100644 --- a/src/rendezvous_mediator.rs +++ b/src/rendezvous_mediator.rs @@ -65,13 +65,9 @@ impl RendezvousMediator { if crate::platform::is_installed() && !crate::is_custom_client() { crate::updater::start_auto_update(); } - let mut nat_tested = false; check_zombie(); let server = new_server(); - if Config::get_nat_type() == NatType::UNKNOWN_NAT as i32 { - crate::test_nat_type(); - nat_tested = true; - } + crate::test_nat_type(); if config::option2bool("stop-service", &Config::get_option("stop-service")) { crate::test_rendezvous_server(); } @@ -100,10 +96,6 @@ impl RendezvousMediator { if !config::option2bool("stop-service", &Config::get_option("stop-service")) && !crate::platform::installing_service() { - if !nat_tested { - crate::test_nat_type(); - nat_tested = true; - } let mut futs = Vec::new(); let servers = Config::get_rendezvous_servers(); SHOULD_EXIT.store(false, Ordering::SeqCst);