mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-14 21:57:24 +08:00
Update default_port and sni logic to improve reverse proxy reachability (#947)
This commit is contained in:
@@ -77,6 +77,15 @@ pub async fn socket_addrs(
|
|||||||
.port()
|
.port()
|
||||||
.or_else(default_port_number)
|
.or_else(default_port_number)
|
||||||
.ok_or(Error::InvalidUrl(url.to_string()))?;
|
.ok_or(Error::InvalidUrl(url.to_string()))?;
|
||||||
|
// See https://github.com/EasyTier/EasyTier/pull/947
|
||||||
|
let port = match port {
|
||||||
|
0 => match url.scheme() {
|
||||||
|
"ws" => 80,
|
||||||
|
"wss" => 443,
|
||||||
|
_ => port,
|
||||||
|
},
|
||||||
|
_ => port,
|
||||||
|
};
|
||||||
|
|
||||||
// if host is an ip address, return it directly
|
// if host is an ip address, return it directly
|
||||||
if let Ok(ip) = host.parse::<std::net::IpAddr>() {
|
if let Ok(ip) = host.parse::<std::net::IpAddr>() {
|
||||||
|
|||||||
@@ -202,8 +202,11 @@ impl WSTunnelConnector {
|
|||||||
init_crypto_provider();
|
init_crypto_provider();
|
||||||
let tls_conn =
|
let tls_conn =
|
||||||
tokio_rustls::TlsConnector::from(Arc::new(get_insecure_tls_client_config()));
|
tokio_rustls::TlsConnector::from(Arc::new(get_insecure_tls_client_config()));
|
||||||
// Modify SNI logic: always use "localhost" as SNI to avoid IP blocking.
|
// Modify SNI logic: use "localhost" as SNI for url without domain to avoid IP blocking.
|
||||||
let sni = "localhost";
|
let sni = match addr.domain() {
|
||||||
|
None => "localhost".to_string(),
|
||||||
|
Some(domain) => domain.to_string(),
|
||||||
|
};
|
||||||
let server_name = rustls::pki_types::ServerName::try_from(sni)
|
let server_name = rustls::pki_types::ServerName::try_from(sni)
|
||||||
.map_err(|_| TunnelError::InvalidProtocol("Invalid SNI".to_string()))?;
|
.map_err(|_| TunnelError::InvalidProtocol("Invalid SNI".to_string()))?;
|
||||||
let stream = tls_conn.connect(server_name, stream).await?;
|
let stream = tls_conn.connect(server_name, stream).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user