From 40e8f0d3076426f6bb5780f0bf21bd2509f5c17a Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 26 Oct 2024 22:05:54 +0800 Subject: [PATCH] revert missing retry and opt keep session (#9755) * Revert "fix missing retry (#8750)" If `hasRetry` is true: there is a retry timeout; If `hasRetry` is false: there is no retry button; In https://github.com/rustdesk/rustdesk/discussions/8748#discussioncomment-10081038,when doesn't want inactive to retry, https://github.com/rustdesk/rustdesk/blob/cf0e3ec303990a48e0b3a6beedd3587079a6526c/flutter/lib/models/model.dart#L444, 1.2.3 always show retry no matter what `hasRetry` is. This reverts commit c3c99ba10725158eaf37fb7fbf7665526138bb88. * not keep session if there is no remote connection left. Signed-off-by: 21pages --------- Signed-off-by: 21pages --- flutter/lib/common.dart | 38 ++++++++++++----------------------- flutter/lib/models/model.dart | 2 +- src/server/connection.rs | 34 +++++++++++-------------------- 3 files changed, 26 insertions(+), 48 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 099a04a15..a2ad96775 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1174,33 +1174,21 @@ void msgBox(SessionID sessionId, String type, String title, String text, dialogManager.dismissAll(); })); } - if (reconnect != null && title == "Connection Error") { + if (reconnect != null && + title == "Connection Error" && + reconnectTimeout != null) { // `enabled` is used to disable the dialog button once the button is clicked. final enabled = true.obs; - final button = reconnectTimeout != null - ? Obx(() => _ReconnectCountDownButton( - second: reconnectTimeout, - onPressed: enabled.isTrue - ? () { - // Disable the button - enabled.value = false; - reconnect(dialogManager, sessionId, false); - } - : null, - )) - : Obx( - () => dialogButton( - 'Reconnect', - isOutline: true, - onPressed: enabled.isTrue - ? () { - // Disable the button - enabled.value = false; - reconnect(dialogManager, sessionId, false); - } - : null, - ), - ); + final button = Obx(() => _ReconnectCountDownButton( + second: reconnectTimeout, + onPressed: enabled.isTrue + ? () { + // Disable the button + enabled.value = false; + reconnect(dialogManager, sessionId, false); + } + : null, + )); buttons.insert(0, button); } if (link.isNotEmpty) { diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 8bd0530f1..bd9194984 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -638,7 +638,7 @@ class FfiModel with ChangeNotifier { {bool? hasCancel}) { msgBox(sessionId, type, title, text, link, dialogManager, hasCancel: hasCancel, - reconnect: reconnect, + reconnect: hasRetry ? reconnect : null, reconnectTimeout: hasRetry ? _reconnects : null); _timer?.cancel(); if (hasRetry) { diff --git a/src/server/connection.rs b/src/server/connection.rs index 12157ddbb..c0cf8c784 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -760,10 +760,7 @@ impl Connection { } if let Err(err) = conn.try_port_forward_loop(&mut rx_from_cm).await { conn.on_close(&err.to_string(), false).await; - raii::AuthedConnID::remove_session_if_last_duplication( - conn.inner.id(), - conn.session_key(), - ); + raii::AuthedConnID::check_remove_session(conn.inner.id(), conn.session_key()); } conn.post_conn_audit(json!({ @@ -2377,7 +2374,7 @@ impl Connection { } Some(misc::Union::CloseReason(_)) => { self.on_close("Peer close", true).await; - raii::AuthedConnID::remove_session_if_last_duplication( + raii::AuthedConnID::check_remove_session( self.inner.id(), self.session_key(), ); @@ -3140,7 +3137,7 @@ impl Connection { let mut msg_out = Message::new(); msg_out.set_misc(misc); self.send(msg_out).await; - raii::AuthedConnID::remove_session_if_last_duplication(self.inner.id(), self.session_key()); + raii::AuthedConnID::check_remove_session(self.inner.id(), self.session_key()); } fn read_dir(&mut self, dir: &str, include_hidden: bool) { @@ -3295,17 +3292,6 @@ impl Connection { } } - #[inline] - fn conn_type(&self) -> AuthConnType { - if self.file_transfer.is_some() { - AuthConnType::FileTransfer - } else if self.port_forward_socket.is_some() { - AuthConnType::PortForward - } else { - AuthConnType::Remote - } - } - #[inline] fn session_key(&self) -> SessionKey { SessionKey { @@ -3848,20 +3834,24 @@ mod raii { .count() } - pub fn remove_session_if_last_duplication(conn_id: i32, key: SessionKey) { + pub fn check_remove_session(conn_id: i32, key: SessionKey) { let mut lock = SESSIONS.lock().unwrap(); let contains = lock.contains_key(&key); if contains { - let another = AUTHED_CONNS + // If there are 2 connections with the same peer_id and session_id, a remote connection and a file transfer or port forward connection, + // If any of the connections is closed allowing retry, this will not be called; + // If the file transfer/port forward connection is closed with no retry, the session should be kept for remote control menu action; + // If the remote connection is closed with no retry, keep the session is not reasonable in case there is a retry button in the remote side, and ignore network fluctuations. + let another_remote = AUTHED_CONNS .lock() .unwrap() .iter() - .any(|c| c.0 != conn_id && c.2 == key); - if !another { - // Keep the session if there is another connection with same peer_id and session_id. + .any(|c| c.0 != conn_id && c.2 == key && c.1 == AuthConnType::Remote); + if !another_remote { lock.remove(&key); log::info!("remove session"); } else { + // Keep the session if there is another remote connection with same peer_id and session_id. log::info!("skip remove session"); } }