mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-13 23:21:27 +03:00
fix: Fix the proxy address test function.
This commit is contained in:
@@ -251,6 +251,26 @@ impl ProxyScheme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_host_and_port(&self) -> Result<String, ProxyError> {
|
||||||
|
match self {
|
||||||
|
ProxyScheme::Http { host, .. } => {
|
||||||
|
Ok(self.append_default_port(host, 80))
|
||||||
|
},
|
||||||
|
ProxyScheme::Https { host, .. } => {
|
||||||
|
Ok(self.append_default_port(host, 443))
|
||||||
|
},
|
||||||
|
ProxyScheme::Socks5 { addr, .. } => {
|
||||||
|
Ok(format!("{}", addr))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn append_default_port(&self, host: &str, default_port: u16) -> String {
|
||||||
|
if host.contains(':') {
|
||||||
|
host.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{}:{}", host, default_port)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use log::info;
|
||||||
use tokio::net::ToSocketAddrs;
|
use tokio::net::ToSocketAddrs;
|
||||||
use tokio_socks::{IntoTargetAddr, TargetAddr};
|
use tokio_socks::{IntoTargetAddr, TargetAddr};
|
||||||
|
use crate::proxy::IntoProxyScheme;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn check_port<T: std::string::ToString>(host: T, port: i32) -> String {
|
pub fn check_port<T: std::string::ToString>(host: T, port: i32) -> String {
|
||||||
@@ -50,19 +52,15 @@ pub fn increase_port<T: std::string::ToString>(host: T, offset: i32) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_if_valid_server(host: &str) -> String {
|
pub fn test_if_valid_server(host: &str) -> String {
|
||||||
let host = check_port(host, 0);
|
info!("Testing server validity for host: {}", host);
|
||||||
|
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
match Config::get_network_type() {
|
// Even if the current network type is a proxy type,
|
||||||
NetworkType::Direct => match host.to_socket_addrs() {
|
// the system DNS should be used to resolve the proxy server address.
|
||||||
Err(err) => err.to_string(),
|
host.into_proxy_scheme()
|
||||||
Ok(_) => "".to_owned(),
|
.and_then(|scheme| scheme.get_host_and_port())
|
||||||
},
|
.and_then(|domain| domain.to_socket_addrs().map_err(Into::into))
|
||||||
NetworkType::ProxySocks => match &host.into_target_addr() {
|
.map(|_| "".to_owned()) // on success, return an empty string
|
||||||
Err(err) => err.to_string(),
|
.unwrap_or_else(|e| e.to_string()) // on error, convert the error into a string
|
||||||
Ok(_) => "".to_owned(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IsResolvedSocketAddr {
|
pub trait IsResolvedSocketAddr {
|
||||||
|
|||||||
Reference in New Issue
Block a user