Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion crates/wind-tuic/src/quiche/utils.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<CongestionControl> for QuicCongestionControl {
fn from(cc: CongestionControl) -> Self {
match cc {
Expand Down
24 changes: 24 additions & 0 deletions crates/wind-tuic/src/quinn/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading