Skip to content

Commit 03aebdd

Browse files
authored
Add files via upload
1 parent 6a0da9c commit 03aebdd

File tree

1 file changed

+17
-62
lines changed

1 file changed

+17
-62
lines changed

src/client.rs

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl Client {
204204
debug_assert!(peer == interface.get_id());
205205
interface.update_direct(None);
206206
interface.update_received(false);
207-
match Self::_start(peer, key, token, conn_type, interface.clone()).await {
207+
match Self::_start(peer, key, token, conn_type, interface).await {
208208
Err(err) => {
209209
let err_str = err.to_string();
210210
if err_str.starts_with("Failed") {
@@ -213,19 +213,7 @@ impl Client {
213213
return Err(err);
214214
}
215215
}
216-
Ok(x) => {
217-
// Set x.2 to true only in the connect() function to indicate that direct_failures needs to be updated; everywhere else it should be set to false.
218-
if x.2 {
219-
let direct_failures = interface.get_lch().read().unwrap().direct_failures;
220-
let direct = x.0 .1;
221-
if !interface.is_force_relay() && (direct_failures == 0) != direct {
222-
let n = if direct { 0 } else { 1 };
223-
log::info!("direct_failures updated to {}", n);
224-
interface.get_lch().write().unwrap().set_direct_failure(n);
225-
}
226-
}
227-
Ok((x.0, x.1))
228-
}
216+
Ok(x) => Ok(x),
229217
}
230218
}
231219

@@ -245,7 +233,6 @@ impl Client {
245233
&'static str,
246234
),
247235
(i32, String),
248-
bool,
249236
)> {
250237
if config::is_incoming_only() {
251238
bail!("Incoming only mode");
@@ -262,7 +249,6 @@ impl Client {
262249
"TCP",
263250
),
264251
(0, "".to_owned()),
265-
false,
266252
));
267253
}
268254
// Allow connect to {domain}:{port}
@@ -276,7 +262,6 @@ impl Client {
276262
"TCP",
277263
),
278264
(0, "".to_owned()),
279-
false,
280265
));
281266
}
282267

@@ -358,7 +343,7 @@ impl Client {
358343
);
359344
connect_futures.push(fut.boxed());
360345
match select_ok(connect_futures).await {
361-
Ok(conn) => Ok((conn.0 .0, conn.0 .1, conn.0 .2)),
346+
Ok(conn) => Ok((conn.0 .0, conn.0 .1)),
362347
Err(e) => Err(e),
363348
}
364349
}
@@ -383,7 +368,6 @@ impl Client {
383368
&'static str,
384369
),
385370
(i32, String),
386-
bool,
387371
)> {
388372
let mut start = Instant::now();
389373
let mut socket = connect_tcp(&*rendezvous_server, CONNECT_TIMEOUT).await;
@@ -557,7 +541,7 @@ impl Client {
557541
connect_futures.push(
558542
async move {
559543
let conn = fut.await?;
560-
Ok((conn, None, if use_ws() { "WebSocket" } else { "Relay" }))
544+
Ok((conn, None, "Relay"))
561545
}
562546
.boxed(),
563547
);
@@ -572,11 +556,7 @@ impl Client {
572556
log::info!("{:?} used to establish {typ} connection", start.elapsed());
573557
let pk =
574558
Self::secure_connection(&peer, signed_id_pk, &key, &mut conn).await?;
575-
return Ok((
576-
(conn, typ == "IPv6", pk, kcp, typ),
577-
(feedback, rendezvous_server),
578-
false,
579-
));
559+
return Ok(((conn, false, pk, kcp, typ), (feedback, rendezvous_server)));
580560
}
581561
_ => {
582562
log::error!("Unexpected protobuf msg received: {:?}", msg_in);
@@ -622,7 +602,6 @@ impl Client {
622602
)
623603
.await?,
624604
(feedback, rendezvous_server),
625-
true,
626605
))
627606
}
628607

@@ -709,6 +688,7 @@ impl Client {
709688
};
710689

711690
let mut direct = !conn.is_err();
691+
interface.update_direct(Some(direct));
712692
if interface.is_force_relay() || conn.is_err() {
713693
if !relay_server.is_empty() {
714694
conn = Self::request_relay(
@@ -721,9 +701,8 @@ impl Client {
721701
conn_type,
722702
)
723703
.await;
704+
interface.update_direct(Some(false));
724705
if let Err(e) = conn {
725-
// this direct is mainly used by on_establish_connection_error, so we update it here before bail
726-
interface.update_direct(Some(false));
727706
bail!("Failed to connect via relay server: {}", e);
728707
}
729708
typ = "Relay";
@@ -732,22 +711,19 @@ impl Client {
732711
bail!("Failed to make direct connection to remote desktop");
733712
}
734713
}
714+
if !relay_server.is_empty() && (direct_failures == 0) != direct {
715+
let n = if direct { 0 } else { 1 };
716+
log::info!("direct_failures updated to {}", n);
717+
interface.get_lch().write().unwrap().set_direct_failure(n);
718+
}
735719
let mut conn = conn?;
736720
log::info!(
737721
"{:?} used to establish {typ} connection with {} punch",
738722
start.elapsed(),
739723
punch_type
740724
);
741-
let res = Self::secure_connection(peer_id, signed_id_pk, key, &mut conn).await;
742-
let pk: Option<Vec<u8>> = match res {
743-
Ok(pk) => pk,
744-
Err(e) => {
745-
// this direct is mainly used by on_establish_connection_error, so we update it here before bail
746-
interface.update_direct(Some(direct));
747-
bail!(e);
748-
}
749-
};
750-
log::debug!("{} punch secure_connection ok", punch_type);
725+
let pk = Self::secure_connection(peer_id, signed_id_pk, key, &mut conn).await?;
726+
log::info!("{} punch secure_connection ok", punch_type);
751727
Ok((conn, direct, pk, kcp, typ))
752728
}
753729

@@ -2027,7 +2003,7 @@ impl LoginConfigHandler {
20272003
///
20282004
// It's Ok to check the option empty in this function.
20292005
// `toggle_option()` is only called in a session.
2030-
// Custom client advanced settings will not effect this function.
2006+
// Custom client advanced settings will not affact this function.
20312007
pub fn toggle_option(&mut self, name: String) -> Option<Message> {
20322008
let mut option = OptionMessage::default();
20332009
let mut config = self.load_config();
@@ -2132,19 +2108,7 @@ impl LoginConfigHandler {
21322108
option.show_remote_cursor = f(self.get_toggle_option("show-remote-cursor"));
21332109
option.enable_file_transfer = f(self.config.enable_file_copy_paste.v);
21342110
option.lock_after_session_end = f(self.config.lock_after_session_end.v);
2135-
if config.show_my_cursor.v {
2136-
config.show_my_cursor.v = false;
2137-
option.show_my_cursor = BoolOption::No.into();
2138-
}
2139-
}
2140-
} else if name == "show-my-cursor" {
2141-
config.show_my_cursor.v = !config.show_my_cursor.v;
2142-
option.show_my_cursor = if config.show_my_cursor.v {
2143-
BoolOption::Yes
2144-
} else {
2145-
BoolOption::No
21462111
}
2147-
.into();
21482112
} else {
21492113
let is_set = self
21502114
.options
@@ -2237,9 +2201,6 @@ impl LoginConfigHandler {
22372201
if view_only || self.get_toggle_option("show-remote-cursor") {
22382202
msg.show_remote_cursor = BoolOption::Yes.into();
22392203
}
2240-
if view_only && self.get_toggle_option("show-my-cursor") {
2241-
msg.show_my_cursor = BoolOption::Yes.into();
2242-
}
22432204
if self.get_toggle_option("follow-remote-cursor") {
22442205
msg.follow_remote_cursor = BoolOption::Yes.into();
22452206
}
@@ -2302,7 +2263,7 @@ impl LoginConfigHandler {
23022263
///
23032264
// It's Ok to check the option empty in this function.
23042265
// `get_toggle_option()` is only called in a session.
2305-
// Custom client advanced settings will not effect this function.
2266+
// Custom client advanced settings will not affact this function.
23062267
pub fn get_toggle_option(&self, name: &str) -> bool {
23072268
if name == "show-remote-cursor" {
23082269
self.config.show_remote_cursor.v
@@ -2324,8 +2285,6 @@ impl LoginConfigHandler {
23242285
self.config.allow_swap_key.v
23252286
} else if name == "view-only" {
23262287
self.config.view_only.v
2327-
} else if name == "show-my-cursor" {
2328-
self.config.show_my_cursor.v
23292288
} else if name == "follow-remote-cursor" {
23302289
self.config.follow_remote_cursor.v
23312290
} else if name == "follow-remote-window" {
@@ -3829,11 +3788,7 @@ pub fn check_if_retry(msgtype: &str, title: &str, text: &str, retry_for_relay: b
38293788
&& ((text.contains("10054") || text.contains("104")) && retry_for_relay
38303789
|| (!text.to_lowercase().contains("offline")
38313790
&& !text.to_lowercase().contains("not exist")
3832-
&& (!text.to_lowercase().contains("handshake")
3833-
// https://github.com/snapview/tungstenite-rs/blob/e7e060a89a72cb08e31c25a6c7284dc1bd982e23/src/error.rs#L248
3834-
|| text
3835-
.to_lowercase()
3836-
.contains("connection reset without closing handshake") && use_ws())
3791+
&& !text.to_lowercase().contains("handshake")
38373792
&& !text.to_lowercase().contains("failed")
38383793
&& !text.to_lowercase().contains("resolve")
38393794
&& !text.to_lowercase().contains("mismatch")

0 commit comments

Comments
 (0)