mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-10-21 07:56:50 +00:00
fix: always use configured proxy for WebSocket
This commit is contained in:
1 parent
9ee2f3ef9a
commit
19b8b2242d
3 files changed
+8
-37
No files matched your search
@@ -2842,11 +2842,6 @@ pub fn use_ws() -> bool {
|
||||
option2bool(option, &Config::get_option(option))
|
||||
}
|
||||
|
||||
pub fn ws_use_proxy() -> bool {
|
||||
let option = keys::OPTION_ALLOW_WEBSOCKET_PROXY;
|
||||
option2bool(option, &Config::get_option(option))
|
||||
}
|
||||
|
||||
pub fn allow_insecure_tls_fallback() -> bool {
|
||||
let option = keys::OPTION_ALLOW_INSECURE_TLS_FALLBACK;
|
||||
option2bool(option, &Config::get_option(option))
|
||||
@@ -2874,7 +2869,6 @@ 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_ALLOW_WEBSOCKET_PROXY: &str = "allow-websocket-proxy";
|
||||
pub const OPTION_TRACKPAD_SPEED: &str = "trackpad-speed";
|
||||
pub const OPTION_REGISTER_DEVICE: &str = "register-device";
|
||||
pub const OPTION_RELAY_SERVER: &str = "relay-server";
|
||||
|
||||
+2
-7
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
config::{
|
||||
keys::OPTION_RELAY_SERVER, use_ws, ws_use_proxy, Config, Socks5Server, RELAY_PORT,
|
||||
RENDEZVOUS_PORT,
|
||||
keys::OPTION_RELAY_SERVER, use_ws, Config, Socks5Server, RELAY_PORT, RENDEZVOUS_PORT,
|
||||
},
|
||||
protobuf::Message,
|
||||
socket_client::split_host_port,
|
||||
@@ -299,11 +298,7 @@ impl WsFramedStream {
|
||||
local_addr: Option<SocketAddr>,
|
||||
ms_timeout: u64,
|
||||
) -> ResultType<Self> {
|
||||
let proxy_conf = if ws_use_proxy() {
|
||||
Config::get_socks()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let proxy_conf = Config::get_socks();
|
||||
let (stream, addr) =
|
||||
Self::connect(url.as_ref(), local_addr, proxy_conf.as_ref(), ms_timeout).await?;
|
||||
|
||||
|
||||
@@ -87,7 +87,6 @@ async fn proxy_round_trip(
|
||||
auth: bool,
|
||||
configured: bool,
|
||||
) {
|
||||
option(keys::OPTION_ALLOW_WEBSOCKET_PROXY, "Y");
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let proxy = Socks5Server {
|
||||
proxy: format!("{scheme}://{}", listener.local_addr().unwrap()),
|
||||
@@ -191,7 +190,6 @@ async fn rejected_or_stalled_proxy(stalled: bool, configured: bool) {
|
||||
proxy: format!("http://{}", listener.local_addr().unwrap()),
|
||||
..Default::default()
|
||||
};
|
||||
option(keys::OPTION_ALLOW_WEBSOCKET_PROXY, "Y");
|
||||
option(keys::OPTION_PROXY_URL, &proxy.proxy);
|
||||
let server = tokio::spawn(async move {
|
||||
let (stream, _) = listener.accept().await.unwrap();
|
||||
@@ -235,20 +233,11 @@ async fn rejected_or_stalled_proxy(stalled: bool, configured: bool) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
async fn direct_round_trip(setting: &str, configured: bool, wss: bool) {
|
||||
option(keys::OPTION_ALLOW_WEBSOCKET_PROXY, setting);
|
||||
let unused_proxy = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
if configured {
|
||||
option(
|
||||
keys::OPTION_PROXY_URL,
|
||||
&format!("http://{}", unused_proxy.local_addr().unwrap()),
|
||||
);
|
||||
} else {
|
||||
OVERWRITE_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.remove(keys::OPTION_PROXY_URL);
|
||||
}
|
||||
async fn direct_round_trip(wss: bool) {
|
||||
OVERWRITE_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.remove(keys::OPTION_PROXY_URL);
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
let url = format!("{}://{addr}/ws/id", if wss { "wss" } else { "ws" });
|
||||
@@ -267,9 +256,6 @@ async fn direct_round_trip(setting: &str, configured: bool, wss: bool) {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(timeout(Duration::from_millis(50), unused_proxy.accept())
|
||||
.await
|
||||
.is_err());
|
||||
}
|
||||
|
||||
async fn tcp_proxy_round_trip() {
|
||||
@@ -278,7 +264,6 @@ async fn tcp_proxy_round_trip() {
|
||||
proxy: format!("http://{}", listener.local_addr().unwrap()),
|
||||
..Default::default()
|
||||
};
|
||||
option(keys::OPTION_ALLOW_WEBSOCKET_PROXY, "N");
|
||||
option(keys::OPTION_PROXY_URL, &proxy.proxy);
|
||||
option(keys::OPTION_PROXY_USERNAME, "");
|
||||
option(keys::OPTION_PROXY_PASSWORD, "");
|
||||
@@ -408,12 +393,9 @@ async fn websocket_proxy_connections() {
|
||||
tcp_proxy_round_trip().await;
|
||||
|
||||
for wss in [false, true] {
|
||||
direct_round_trip("", true, wss).await;
|
||||
direct_round_trip("N", true, wss).await;
|
||||
direct_round_trip("Y", false, wss).await;
|
||||
direct_round_trip(wss).await;
|
||||
}
|
||||
|
||||
option(keys::OPTION_ALLOW_WEBSOCKET_PROXY, "N");
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
drop(listener);
|
||||
|
||||
Reference in new issue
Block a user