From 846daf86f0e77bc8a0cc323b5bab2267431f8d04 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 2 Sep 2026 11:18:28 +0800 Subject: [PATCH] webrtc: send over SCTP without a congestion window, as KCP does The data channel's SCTP association runs RFC 4960's AIMD: a fast retransmit halves cwnd, a T3 drops it to one MTU, and on a path whose loss is random rather than congestion that pins the rate to MSS/(RTT*sqrt(p)) - about 1.3 Mbps at 70ms RTT and 1% loss - however idle the link is. KCP has always shipped its turbo profile (nc=1) with no congestion window, which is why the same link streams over KCP and crawls over WebRTC. The sctp fork now carries a process-wide switch that bypasses the two places gating sends on cwnd. Turn it on unless `allow-webrtc-congestion-control` is set: the same opt-in `allow-kcp-congestion-control` gives KCP, for the reason at `get_kcp_cc_enabled`. It is re-read on every new peer connection, so a changed option reaches the next session without a restart. Sender-side only: nothing is negotiated, and a browser or an older build on the other end interoperates. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_019aokqJuhjvB3kijXtAg5Ns --- src/config.rs | 2 ++ src/webrtc.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/config.rs b/src/config.rs index 7da8c3592..0d995ea67 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3000,6 +3000,7 @@ pub mod keys { pub const OPTION_ENABLE_PORT_FORWARD_MUX: &str = "enable-port-forward-mux"; pub const OPTION_ENABLE_WEBRTC: &str = "enable-webrtc"; pub const OPTION_ALLOW_KCP_CC: &str = "allow-kcp-congestion-control"; + pub const OPTION_ALLOW_WEBRTC_CC: &str = "allow-webrtc-congestion-control"; pub const OPTION_HIDE_USERNAME_ON_CARD: &str = "hide-username-on-card"; pub const OPTION_HIDE_HELP_CARDS: &str = "hide-help-cards"; pub const OPTION_DEFAULT_CONNECT_PASSWORD: &str = "default-connect-password"; @@ -3208,6 +3209,7 @@ pub mod keys { OPTION_KEEP_AWAKE_DURING_INCOMING_SESSIONS, OPTION_ALLOW_AUTO_UPDATE, OPTION_ALLOW_KCP_CC, + OPTION_ALLOW_WEBRTC_CC, ]; // BUILDIN_SETTINGS diff --git a/src/webrtc.rs b/src/webrtc.rs index b0c9cb69f..57c609e8d 100644 --- a/src/webrtc.rs +++ b/src/webrtc.rs @@ -473,6 +473,12 @@ impl WebRTCStream { }) } + #[inline] + fn get_cc_enabled() -> bool { + let k = config::keys::OPTION_ALLOW_WEBRTC_CC; + config::option2bool(k, &config::Config::get_option(k)) + } + #[inline] fn get_ice_servers() -> Vec { Self::parse_ice_servers(&config::Config::get_option( @@ -599,6 +605,11 @@ impl WebRTCStream { IpAddr::V4(_) => true, })); + // KCP's nc=1 profile by default, with the same opt-in to a congestion window as + // `allow-kcp-congestion-control`, for the reason given at `get_kcp_cc_enabled`. Set per + // connection so the option takes effect on the next session, not the next start. + webrtc::sctp::association::set_no_congestion_control(!Self::get_cc_enabled()); + // Create the API object let api = APIBuilder::new().with_setting_engine(s).build();