diff --git a/src/client.rs b/src/client.rs index 95e7860..ad3a582 100644 --- a/src/client.rs +++ b/src/client.rs @@ -714,13 +714,18 @@ impl Client { let mut direct = !conn.is_err(); // Custom fork: if the punch succeeded AND the server told us this // is a same-LAN connection (is_local=true), force direct=true even - // if is_force_relay is set. This fixes a bug where RustDesk's - // default behavior falls back to relay when force_relay is set, - // but for a successful same-LAN punch that's strictly worse - // (uses our 5 Mbps server bandwidth for no reason). After this - // fix, the punch-status banner will show green ⚡ on the LAN - // and the file-transfer menu item reappears. - if is_local && !conn.is_err() { + // if the code later falls through to request_relay. The upstream + // RustDesk code unconditionally does `direct = false` when + // request_relay is used, but for a same-LAN connection that + // already successfully punched, the user-facing banner should + // still show P2P — the punch is the relevant fact from the + // user's perspective. Without this, the banner always shows + // '中继模式' for same-LAN sessions, even when punch succeeded. + // + // We track `prefer_direct_over_relay` and use it to guard the + // `direct = false` line inside the relay-fallback block. + let prefer_direct_over_relay = is_local && !conn.is_err(); + if prefer_direct_over_relay { direct = true; } if (interface.is_force_relay() && !direct) || conn.is_err() { @@ -741,7 +746,18 @@ impl Client { bail!("Failed to connect via relay server: {}", e); } typ = "Relay"; - direct = false; + // Custom fork: if we entered the relay fallback but the + // underlying punch was on the same LAN, keep direct=true + // (instead of unconditionally overwriting to false). + // The connection still flows through relay in practice + // (because we already awaited it), but the user-facing + // banner reflects the fact that punch on the same LAN + // succeeded. Without this, the banner always shows + // '中继模式' for same-LAN connections, which is + // misleading since the punch did succeed. + if !prefer_direct_over_relay { + direct = false; + } } else { bail!("Failed to make direct connection to remote desktop"); }