mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-05-11 10:26:19 +02:00
refactor test_nat
This commit is contained in:
parent
61cdb60362
commit
d46862e47d
2 changed files with 11 additions and 17 deletions
|
@ -507,6 +507,16 @@ audio_rechannel!(audio_rechannel_8_7, 8, 7);
|
||||||
pub fn test_nat_type() {
|
pub fn test_nat_type() {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
std::thread::spawn(move || loop {
|
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_() {
|
match test_nat_type_() {
|
||||||
Ok(true) => break,
|
Ok(true) => break,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -528,14 +538,6 @@ pub fn test_nat_type() {
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn test_nat_type_() -> ResultType<bool> {
|
async fn test_nat_type_() -> ResultType<bool> {
|
||||||
log::info!("Testing nat ...");
|
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 start = std::time::Instant::now();
|
||||||
let (rendezvous_server, _, _) = get_rendezvous_server(1_000).await;
|
let (rendezvous_server, _, _) = get_rendezvous_server(1_000).await;
|
||||||
let server1 = rendezvous_server;
|
let server1 = rendezvous_server;
|
||||||
|
|
|
@ -65,13 +65,9 @@ impl RendezvousMediator {
|
||||||
if crate::platform::is_installed() && !crate::is_custom_client() {
|
if crate::platform::is_installed() && !crate::is_custom_client() {
|
||||||
crate::updater::start_auto_update();
|
crate::updater::start_auto_update();
|
||||||
}
|
}
|
||||||
let mut nat_tested = false;
|
|
||||||
check_zombie();
|
check_zombie();
|
||||||
let server = new_server();
|
let server = new_server();
|
||||||
if Config::get_nat_type() == NatType::UNKNOWN_NAT as i32 {
|
crate::test_nat_type();
|
||||||
crate::test_nat_type();
|
|
||||||
nat_tested = true;
|
|
||||||
}
|
|
||||||
if config::option2bool("stop-service", &Config::get_option("stop-service")) {
|
if config::option2bool("stop-service", &Config::get_option("stop-service")) {
|
||||||
crate::test_rendezvous_server();
|
crate::test_rendezvous_server();
|
||||||
}
|
}
|
||||||
|
@ -100,10 +96,6 @@ impl RendezvousMediator {
|
||||||
if !config::option2bool("stop-service", &Config::get_option("stop-service"))
|
if !config::option2bool("stop-service", &Config::get_option("stop-service"))
|
||||||
&& !crate::platform::installing_service()
|
&& !crate::platform::installing_service()
|
||||||
{
|
{
|
||||||
if !nat_tested {
|
|
||||||
crate::test_nat_type();
|
|
||||||
nat_tested = true;
|
|
||||||
}
|
|
||||||
let mut futs = Vec::new();
|
let mut futs = Vec::new();
|
||||||
let servers = Config::get_rendezvous_servers();
|
let servers = Config::get_rendezvous_servers();
|
||||||
SHOULD_EXIT.store(false, Ordering::SeqCst);
|
SHOULD_EXIT.store(false, Ordering::SeqCst);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue