From 20d5019a4268cd203491500a5ca2c72578076704 Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 16 Oct 2026 17:35:46 +0800 Subject: [PATCH 1/4] fix: reduce noisy smithay client toolkit logs --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8bc7f0978..503954535 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -437,7 +437,7 @@ pub fn init_log(_is_async: bool, _name: &str) -> Option Option Date: Thu, 22 Oct 2026 16:05:24 +0800 Subject: [PATCH 2/4] feat(websocket): add websocket-port for a proxy off the default port check_ws turns a domain endpoint into ws(s):///ws/id or /ws/relay with no port, so a reverse proxy that cannot take 443 (or 80) is unreachable, even when api-server already points at it, for example https://example.com:8443. websocket-port adds that port for the hosts this client is configured with: custom-rendezvous-server and relay-server. A relay that hbbs hands out on another host, or a peer's server, keeps the default port, since another machine has its own proxy. IP endpoints are unchanged, and an empty option gives the same URL as before. https://github.com/rustdesk/rustdesk-server-pro/discussions/1029 Co-Authored-By: Claude Opus 5.5 --- src/config.rs | 1 + src/websocket.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 6fe100455..31a539b07 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2869,6 +2869,7 @@ pub mod keys { pub const OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD: &str = "allow-numeric-one-time-password"; pub const OPTION_DIRECT_SERVER: &str = "direct-server"; pub const OPTION_ALLOW_WEBSOCKET: &str = "allow-websocket"; + pub const OPTION_WEBSOCKET_PORT: &str = "websocket-port"; pub const OPTION_TRACKPAD_SPEED: &str = "trackpad-speed"; pub const OPTION_REGISTER_DEVICE: &str = "register-device"; pub const OPTION_RELAY_SERVER: &str = "relay-server"; diff --git a/src/websocket.rs b/src/websocket.rs index af797acc1..bc4eef271 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -513,7 +513,10 @@ pub fn check_ws(endpoint: &str) -> String { (format!("{}:{}", endpoint_host, dst_port), false) } else { let domain_path = if relay { "/ws/relay" } else { "/ws/id" }; - (format!("{}{}", endpoint_host, domain_path), true) + let port = websocket_port(&endpoint_host, &[&custom_rendezvous_server, &relay_server]) + .map(|port| format!(":{}", port)) + .unwrap_or_default(); + (format!("{}{}{}", endpoint_host, port, domain_path), true) }; let protocol = if is_domain { let api_server = Config::get_option("api-server"); @@ -528,6 +531,33 @@ pub fn check_ws(endpoint: &str) -> String { format!("{}://{}", protocol, address) } +/// Port of the reverse proxy serving `/ws/id` and `/ws/relay` on this client's own servers, for +/// when it cannot listen on the scheme's default port. Any other host, such as a peer's server or +/// a relay on another machine, keeps the default port. IP endpoints never get here. +fn websocket_port(host: &str, own_servers: &[&str]) -> Option { + use crate::config::keys::OPTION_WEBSOCKET_PORT; + let port = Config::get_option(OPTION_WEBSOCKET_PORT); + if port.is_empty() { + return None; + } + let is_own = own_servers.iter().any(|server| { + split_host_port(server) + .map(|(h, _)| h) + .unwrap_or_else(|| server.to_string()) + .eq_ignore_ascii_case(host) + }); + if !is_own { + return None; + } + match port.parse::() { + Ok(port) if port > 0 => Some(port), + _ => { + log::warn!("Ignoring invalid {}: {}", OPTION_WEBSOCKET_PORT, port); + None + } + } +} + #[cfg(test)] mod proxy_tests; @@ -709,6 +739,34 @@ mod tests { assert_eq!(check_ws("127.0.0.1:23455"), "ws://127.0.0.1:23458"); assert_eq!(check_ws("127.0.0.1:23456"), "ws://127.0.0.1:23458"); assert_eq!(check_ws("127.0.0.1:34567"), "ws://127.0.0.1:34569"); + + // set websocket-port, a reverse proxy off the default port on our own servers + Config::set_option( + "custom-rendezvous-server".to_string(), + "rustdesk.com".to_string(), + ); + Config::set_option("relay-server".to_string(), "relay.rustdesk.com".to_string()); + Config::set_option( + "api-server".to_string(), + "https://rustdesk.com:8443".to_string(), + ); + Config::set_option(keys::OPTION_WEBSOCKET_PORT.to_string(), "8443".to_string()); + assert_eq!( + check_ws("rustdesk.com:21116"), + "wss://rustdesk.com:8443/ws/id" + ); + assert_eq!( + check_ws("rustdesk.com:21117"), + "wss://rustdesk.com:8443/ws/relay" + ); + assert_eq!( + check_ws("relay.rustdesk.com:21117"), + "wss://relay.rustdesk.com:8443/ws/relay" + ); + // a peer's server or a relay on another host keeps the default port + assert_eq!(check_ws("example.com:21116"), "wss://example.com/ws/id"); + assert_eq!(check_ws("example.com:21117"), "wss://example.com/ws/relay"); + assert_eq!(check_ws("127.0.0.1:21116"), "ws://127.0.0.1:21118"); Config::set_options(options); } // A server-to-client frame is unmasked, so it can be put on the wire by hand: the header alone, From b3bf7b76e2d3a44b70c7b90a2a302c1982a6a33e Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 22 Oct 2026 17:04:26 +0800 Subject: [PATCH 3/4] fix(websocket): throttle the invalid websocket-port warning check_ws runs on every rendezvous reconnect, online query and relay connect, so an invalid websocket-port logged a warning each time. Keep one line a minute with a count of the rest. Also import the key with the other config keys instead of in the function body. Co-Authored-By: Claude Opus 5.5 --- src/websocket.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/websocket.rs b/src/websocket.rs index bc4eef271..57a58c5e3 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -1,6 +1,7 @@ use crate::{ config::{ - keys::OPTION_RELAY_SERVER, use_ws, Config, Socks5Server, RELAY_PORT, RENDEZVOUS_PORT, + keys::{OPTION_RELAY_SERVER, OPTION_WEBSOCKET_PORT}, + use_ws, Config, Socks5Server, RELAY_PORT, RENDEZVOUS_PORT, }, protobuf::Message, socket_client::split_host_port, @@ -535,7 +536,6 @@ pub fn check_ws(endpoint: &str) -> String { /// when it cannot listen on the scheme's default port. Any other host, such as a peer's server or /// a relay on another machine, keeps the default port. IP endpoints never get here. fn websocket_port(host: &str, own_servers: &[&str]) -> Option { - use crate::config::keys::OPTION_WEBSOCKET_PORT; let port = Config::get_option(OPTION_WEBSOCKET_PORT); if port.is_empty() { return None; @@ -552,7 +552,13 @@ fn websocket_port(host: &str, own_servers: &[&str]) -> Option { match port.parse::() { Ok(port) if port > 0 => Some(port), _ => { - log::warn!("Ignoring invalid {}: {}", OPTION_WEBSOCKET_PORT, port); + crate::throttled_log!( + Duration::from_secs(60), + warn, + "Ignoring invalid {}: {}", + OPTION_WEBSOCKET_PORT, + port + ); None } } From dfb9d0d1c6cb2048b84a8e61290b1ea0b14cae21 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 22 Oct 2026 17:28:28 +0800 Subject: [PATCH 4/4] fix(websocket): match websocket-port only against configured servers websocket_port() took the rendezvous host from get_rendezvous_server(), which falls back to a cached or public server when none is set. With only relay-server and websocket-port set, the public rendezvous server also got the port, and registration failed. Match the servers this client is set up with instead: the exe-name host, custom-rendezvous-server, the build-time server, and relay-server. Co-Authored-By: Claude Opus 5.5 --- src/websocket.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/websocket.rs b/src/websocket.rs index 57a58c5e3..3a98a842c 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -1,7 +1,8 @@ use crate::{ config::{ keys::{OPTION_RELAY_SERVER, OPTION_WEBSOCKET_PORT}, - use_ws, Config, Socks5Server, RELAY_PORT, RENDEZVOUS_PORT, + use_ws, Config, Socks5Server, EXE_RENDEZVOUS_SERVER, PROD_RENDEZVOUS_SERVER, RELAY_PORT, + RENDEZVOUS_PORT, }, protobuf::Message, socket_client::split_host_port, @@ -514,7 +515,7 @@ pub fn check_ws(endpoint: &str) -> String { (format!("{}:{}", endpoint_host, dst_port), false) } else { let domain_path = if relay { "/ws/relay" } else { "/ws/id" }; - let port = websocket_port(&endpoint_host, &[&custom_rendezvous_server, &relay_server]) + let port = websocket_port(&endpoint_host, &relay_server) .map(|port| format!(":{}", port)) .unwrap_or_default(); (format!("{}{}{}", endpoint_host, port, domain_path), true) @@ -535,11 +536,18 @@ pub fn check_ws(endpoint: &str) -> String { /// Port of the reverse proxy serving `/ws/id` and `/ws/relay` on this client's own servers, for /// when it cannot listen on the scheme's default port. Any other host, such as a peer's server or /// a relay on another machine, keeps the default port. IP endpoints never get here. -fn websocket_port(host: &str, own_servers: &[&str]) -> Option { +fn websocket_port(host: &str, relay_server: &str) -> Option { let port = Config::get_option(OPTION_WEBSOCKET_PORT); if port.is_empty() { return None; } + // Only servers this client is set up with, not the public fallback of get_rendezvous_server(). + let own_servers = [ + EXE_RENDEZVOUS_SERVER.read().unwrap().clone(), + Config::get_option("custom-rendezvous-server"), + PROD_RENDEZVOUS_SERVER.read().unwrap().clone(), + relay_server.to_owned(), + ]; let is_own = own_servers.iter().any(|server| { split_host_port(server) .map(|(h, _)| h) @@ -773,6 +781,14 @@ mod tests { assert_eq!(check_ws("example.com:21116"), "wss://example.com/ws/id"); assert_eq!(check_ws("example.com:21117"), "wss://example.com/ws/relay"); assert_eq!(check_ws("127.0.0.1:21116"), "ws://127.0.0.1:21118"); + // with no rendezvous server set, the public fallback is not one of ours + Config::set_option("custom-rendezvous-server".to_string(), "".to_string()); + let fallback = Config::get_rendezvous_server(); + let (fallback_host, _) = split_host_port(&fallback).unwrap(); + assert_eq!( + check_ws(&fallback), + format!("wss://{}/ws/id", fallback_host) + ); Config::set_options(options); } // A server-to-client frame is unmasked, so it can be put on the wire by hand: the header alone,