Skip to content

Commit

Permalink
revert missing retry and opt keep session (rustdesk#9755)
Browse files Browse the repository at this point in the history
* Revert "fix missing retry (rustdesk#8750)"

If `hasRetry` is true: there is a retry timeout;
If `hasRetry` is false: there is no retry button;

In
rustdesk#8748 (reply in thread)
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 c3c99ba.

* not keep session if there is no remote connection left.

Signed-off-by: 21pages <[email protected]>

---------

Signed-off-by: 21pages <[email protected]>
  • Loading branch information
21pages authored Oct 26, 2024
1 parent 129f6c8 commit 40e8f0d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
38 changes: 13 additions & 25 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/models/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
34 changes: 12 additions & 22 deletions src/server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
}
Expand Down

0 comments on commit 40e8f0d

Please sign in to comment.