This commit is contained in:
rustdesk
2025-05-09 00:49:18 +08:00
parent d46862e47d
commit 4f6818477f

View File

@@ -505,19 +505,28 @@ audio_rechannel!(audio_rechannel_8_6, 8, 6);
audio_rechannel!(audio_rechannel_8_7, 8, 7); audio_rechannel!(audio_rechannel_8_7, 8, 7);
pub fn test_nat_type() { pub fn test_nat_type() {
let mut i = 0; use std::sync::atomic::{AtomicBool, Ordering};
std::thread::spawn(move || loop { std::thread::spawn(move || {
if i == 0 { static IS_RUNNING: AtomicBool = AtomicBool::new(false);
if IS_RUNNING.load(Ordering::SeqCst) {
return;
}
IS_RUNNING.store(true, Ordering::SeqCst);
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
let is_direct = crate::ipc::get_socks().is_none(); // sync socks BTW let is_direct = crate::ipc::get_socks().is_none(); // sync socks BTW
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
let is_direct = Config::get_socks().is_none(); // sync socks BTW let is_direct = Config::get_socks().is_none(); // sync socks BTW
if !is_direct { if !is_direct {
Config::set_nat_type(NatType::SYMMETRIC as _); Config::set_nat_type(NatType::SYMMETRIC as _);
break; IS_RUNNING.store(false, Ordering::SeqCst);
return;
} }
}
match test_nat_type_() { let mut i = 0;
let (rendezvous_server, _, _) = get_rendezvous_server_sync(1_000);
loop {
match test_nat_type_(&rendezvous_server) {
Ok(true) => break, Ok(true) => break,
Err(err) => { Err(err) => {
log::error!("test nat: {}", err); log::error!("test nat: {}", err);
@@ -532,14 +541,16 @@ pub fn test_nat_type() {
i = 300; i = 300;
} }
std::thread::sleep(std::time::Duration::from_secs(i)); std::thread::sleep(std::time::Duration::from_secs(i));
}
IS_RUNNING.store(false, Ordering::SeqCst);
}); });
} }
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
async fn test_nat_type_() -> ResultType<bool> { async fn test_nat_type_(rendezvous_server: &str) -> ResultType<bool> {
log::info!("Testing nat ..."); log::info!("Testing nat ...");
let start = std::time::Instant::now(); let start = std::time::Instant::now();
let (rendezvous_server, _, _) = get_rendezvous_server(1_000).await;
let server1 = rendezvous_server; let server1 = rendezvous_server;
let server2 = crate::increase_port(&server1, -1); let server2 = crate::increase_port(&server1, -1);
let mut msg_out = RendezvousMessage::new(); let mut msg_out = RendezvousMessage::new();
@@ -597,6 +608,11 @@ async fn test_nat_type_() -> ResultType<bool> {
Ok(ok) Ok(ok)
} }
#[tokio::main(flavor = "current_thread")]
async fn get_rendezvous_server_sync(ms_timeout: u64) -> (String, Vec<String>, bool) {
get_rendezvous_server(ms_timeout).await
}
pub async fn get_rendezvous_server(ms_timeout: u64) -> (String, Vec<String>, bool) { pub async fn get_rendezvous_server(ms_timeout: u64) -> (String, Vec<String>, bool) {
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
let (mut a, mut b) = get_rendezvous_server_(ms_timeout); let (mut a, mut b) = get_rendezvous_server_(ms_timeout);