From 6de35d16782d5aed34d6828b59f2809cf761045c Mon Sep 17 00:00:00 2001 From: iHsin Date: Thu, 25 Jun 2026 00:40:50 +0800 Subject: [PATCH] feat(wind-tuic): add effective_name() and Display to CongestionControl enums Add , and impls to both and . On the quiche side Bbr maps to "bbr2_gcongestion" (the quiche internal variant name). On the quinn side, unparseable strings fall back to Bbr like the inbound does. Assisted-by: OpenClaw:deepseek-v4-flash Signed-off-by: iHsin --- crates/wind-tuic/src/quiche/utils.rs | 34 +++++++++++++++++++++++++++- crates/wind-tuic/src/quinn/utils.rs | 24 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/crates/wind-tuic/src/quiche/utils.rs b/crates/wind-tuic/src/quiche/utils.rs index d9c6d0c..09fb627 100644 --- a/crates/wind-tuic/src/quiche/utils.rs +++ b/crates/wind-tuic/src/quiche/utils.rs @@ -1,7 +1,10 @@ //! Configuration types for the quiche backend (mirrors the former //! `wind-tuiche` surface). -use std::time::Duration; +use std::{ + fmt::{Display, Formatter, Result as FmtResult}, + time::Duration, +}; use wind_quic::QuicCongestionControl; @@ -14,6 +17,35 @@ pub enum CongestionControl { Reno, } +impl CongestionControl { + /// Return the effective algorithm name that quiche actually uses. + /// \`Bbr\` resolves to `Bbr2Gcongestion` internally. + pub fn effective_name(&self) -> &'static str { + match self { + Self::Cubic => "cubic", + Self::Bbr => "bbr2_gcongestion", + Self::Reno => "reno", + } + } + + /// Parse a config string into the effective quiche algorithm name, + /// matching the same mapping as the inbound's \`quiche_cc()\`. + pub fn effective_from_str(s: &str) -> &'static str { + match s.to_ascii_lowercase().as_str() { + "bbr" | "bbr3" => Self::Bbr, + "reno" | "newreno" | "new_reno" => Self::Reno, + _ => Self::Cubic, + } + .effective_name() + } +} + +impl Display for CongestionControl { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + f.write_str(self.effective_name()) + } +} + impl From for QuicCongestionControl { fn from(cc: CongestionControl) -> Self { match cc { diff --git a/crates/wind-tuic/src/quinn/utils.rs b/crates/wind-tuic/src/quinn/utils.rs index 4d63371..19192dd 100644 --- a/crates/wind-tuic/src/quinn/utils.rs +++ b/crates/wind-tuic/src/quinn/utils.rs @@ -47,6 +47,30 @@ pub enum CongestionControl { NewReno, } +impl CongestionControl { + /// Return the effective algorithm name, as quinn will use it. + pub fn effective_name(&self) -> &'static str { + match self { + Self::Bbr => "bbr", + Self::Bbr3 => "bbr3", + Self::Cubic => "cubic", + Self::NewReno => "new_reno", + } + } + + /// Parse a config string and return the effective algorithm name, + /// applying the same fallback (`Bbr`) that the inbound uses. + pub fn effective_from_str(s: &str) -> &'static str { + s.parse().unwrap_or(Self::Bbr).effective_name() + } +} + +impl Display for CongestionControl { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + f.write_str(self.effective_name()) + } +} + impl FromStr for CongestionControl { type Err = &'static str;