diff --git a/Cargo.lock b/Cargo.lock index 66c13e91f..4349b1767 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -299,6 +299,19 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-compression" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc2d0cfb2a7388d34f590e76686704c494ed7aaceed62ee1ba35cbf363abc2a5" +dependencies = [ + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-executor" version = "1.6.0" @@ -5064,6 +5077,7 @@ name = "reqwest" version = "0.11.18" source = "git+https://github.com/rustdesk-org/reqwest#4cc834539d9c44f7b6bbc5d2f8805842dc5aa328" dependencies = [ + "async-compression", "base64", "bytes", "encoding_rs", @@ -5088,6 +5102,7 @@ dependencies = [ "serde_urlencoded", "tokio", "tokio-rustls", + "tokio-util", "tower-service", "url", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index b844f1cfb..4fa88fcfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ rdev = { git = "https://github.com/fufesou/rdev" } url = { version = "2.3", features = ["serde"] } crossbeam-queue = "0.3" hex = "0.4" -reqwest = { git = "https://github.com/rustdesk-org/reqwest", features = ["blocking", "json", "rustls-tls"], default-features=false } +reqwest = { git = "https://github.com/rustdesk-org/reqwest", features = ["blocking", "json", "rustls-tls", "gzip"], default-features=false } chrono = "0.4" cidr-utils = "0.5" libloading = "0.8" diff --git a/src/server/connection.rs b/src/server/connection.rs index ca0ac112c..27c51b5c9 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -188,8 +188,8 @@ pub struct Connection { restart: bool, recording: bool, block_input: bool, - last_test_delay: i64, - network_delay: Option, + last_test_delay: Option, + network_delay: u32, lock_after_session_end: bool, show_remote_cursor: bool, // by peer @@ -269,7 +269,7 @@ impl Subscriber for ConnInner { } } -const TEST_DELAY_TIMEOUT: Duration = Duration::from_secs(3); +const TEST_DELAY_TIMEOUT: Duration = Duration::from_secs(1); const SEC30: Duration = Duration::from_secs(30); const H1: Duration = Duration::from_secs(3600); const MILLI1: Duration = Duration::from_millis(1); @@ -335,8 +335,8 @@ impl Connection { restart: Connection::permission("enable-remote-restart"), recording: Connection::permission("enable-record-session"), block_input: Connection::permission("enable-block-input"), - last_test_delay: 0, - network_delay: None, + last_test_delay: None, + network_delay: 0, lock_after_session_end: false, show_remote_cursor: false, ip: "".to_owned(), @@ -408,8 +408,7 @@ impl Connection { if !conn.block_input { conn.send_permission(Permission::BlockInput, false).await; } - let mut test_delay_timer = - time::interval_at(Instant::now() + TEST_DELAY_TIMEOUT, TEST_DELAY_TIMEOUT); + let mut test_delay_timer = time::interval(TEST_DELAY_TIMEOUT); let mut last_recv_time = Instant::now(); conn.stream.set_send_timeout( @@ -664,14 +663,12 @@ impl Connection { conn.on_close("Timeout", true).await; break; } - let time = get_time(); let mut qos = video_service::VIDEO_QOS.lock().unwrap(); - if time > 0 && conn.last_test_delay == 0 { - conn.last_test_delay = time; + if conn.last_test_delay.is_none() { + conn.last_test_delay = Some(Instant::now()); let mut msg_out = Message::new(); msg_out.set_test_delay(TestDelay{ - time, - last_delay: conn.network_delay.unwrap_or_default(), + last_delay: conn.network_delay, target_bitrate: qos.bitrate(), ..Default::default() }); @@ -1715,13 +1712,15 @@ impl Connection { msg_out.set_test_delay(t); self.inner.send(msg_out.into()); } else { - self.last_test_delay = 0; - let new_delay = (get_time() - t.time) as u32; - video_service::VIDEO_QOS - .lock() - .unwrap() - .user_network_delay(self.inner.id(), new_delay); - self.network_delay = Some(new_delay); + if let Some(tm) = self.last_test_delay { + self.last_test_delay = None; + let new_delay = tm.elapsed().as_millis() as u32; + video_service::VIDEO_QOS + .lock() + .unwrap() + .user_network_delay(self.inner.id(), new_delay); + self.network_delay = new_delay; + } self.delay_response_instant = Instant::now(); } } else if let Some(message::Union::SwitchSidesResponse(_s)) = msg.union {