From 49d396538c6afcb75d6eb4efc82061d29f447217 Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 28 Feb 2024 12:18:13 +0800 Subject: [PATCH] port forward, wait until TestDelay is replied (#7282) * Revert "fix rdp not work, caused by test_delay_timer (#7274)" This reverts commit 7fca0ba588cc038ba4141a912a67399fe68bfabd. * port forward, wait until TestDelay is replied Signed-off-by: 21pages --------- Signed-off-by: 21pages --- src/server/connection.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/server/connection.rs b/src/server/connection.rs index 87cafed21..d88ab0c3e 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -423,14 +423,8 @@ impl Connection { if !conn.block_input { conn.send_permission(Permission::BlockInput, false).await; } - // Note: The start parameter of interval_at needs to add TEST_DELAY_TIMEOUT, otherwise windows rdp will be affected. - // This is because controlling's TestDelay messsage comes late and injects to rdp data flow. - // Todo: Controlling side sends a notification message to controlled side before entering port forward loop, https://github.com/rustdesk/rustdesk/blob/50d080d098b22f53e46744fbdd286f2d81d64a4d/src/port_forward.rs#L187 - //, and controller side waits for this notification before entering port forward loop. - let mut test_delay_timer = crate::rustdesk_interval(time::interval_at( - Instant::now() + TEST_DELAY_TIMEOUT, - TEST_DELAY_TIMEOUT, - )); + let mut test_delay_timer = + crate::rustdesk_interval(time::interval_at(Instant::now(), TEST_DELAY_TIMEOUT)); let mut last_recv_time = Instant::now(); conn.stream.set_send_timeout( @@ -594,7 +588,11 @@ impl Connection { break; } if conn.port_forward_socket.is_some() && conn.authorized { - break; + log::info!("Port forward, last_test_delay is none: {}", conn.last_test_delay.is_none()); + // Avoid TestDelay reply injection into rdp data stream + if conn.last_test_delay.is_none() { + break; + } } } } @@ -701,18 +699,18 @@ impl Connection { conn.on_close("Timeout", true).await; break; } - let mut qos = video_service::VIDEO_QOS.lock().unwrap(); - if conn.last_test_delay.is_none() { + // The control end will jump out of the loop after receiving LoginResponse and will not reply to the TestDelay + if conn.last_test_delay.is_none() && !(conn.port_forward_socket.is_some() && conn.authorized) { conn.last_test_delay = Some(Instant::now()); let mut msg_out = Message::new(); msg_out.set_test_delay(TestDelay{ last_delay: conn.network_delay, - target_bitrate: qos.bitrate(), + target_bitrate: video_service::VIDEO_QOS.lock().unwrap().bitrate(), ..Default::default() }); - conn.inner.send(msg_out.into()); + conn.send(msg_out.into()).await; } - qos.user_delay_response_elapsed(conn.inner.id(), conn.delay_response_instant.elapsed().as_millis()); + video_service::VIDEO_QOS.lock().unwrap().user_delay_response_elapsed(conn.inner.id(), conn.delay_response_instant.elapsed().as_millis()); } } } @@ -1835,6 +1833,9 @@ impl Connection { } } } else if self.authorized { + if self.port_forward_socket.is_some() { + return true; + } match msg.union { #[allow(unused_mut)] Some(message::Union::MouseEvent(mut me)) => {