From 6841e3aeba5af3739dc4fc0023bd797619e63de5 Mon Sep 17 00:00:00 2001 From: threeninesixseven Date: Mon, 14 Apr 2025 14:56:59 -0700 Subject: [PATCH] feat: BBR congestion control for http3 --- src/async_impl/client.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 0615c68e0..5e9fd59e9 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -188,6 +188,8 @@ struct Config { #[cfg(feature = "http3")] quic_send_window: Option, #[cfg(feature = "http3")] + quic_congestion_bbr: bool, + #[cfg(feature = "http3")] h3_max_field_section_size: Option, #[cfg(feature = "http3")] h3_send_grease: Option, @@ -307,6 +309,8 @@ impl ClientBuilder { #[cfg(feature = "http3")] quic_send_window: None, #[cfg(feature = "http3")] + quic_congestion_bbr: false, + #[cfg(feature = "http3")] h3_max_field_section_size: None, #[cfg(feature = "http3")] h3_send_grease: None, @@ -373,6 +377,7 @@ impl ClientBuilder { quic_stream_receive_window, quic_receive_window, quic_send_window, + quic_congestion_bbr, h3_max_field_section_size, h3_send_grease, local_address, @@ -397,6 +402,11 @@ impl ClientBuilder { transport_config.send_window(send_window); } + if quic_congestion_bbr { + let factory = Arc::new(quinn::congestion::BbrConfig::default()); + transport_config.congestion_controller_factory(factory); + } + let mut h3_client_config = H3ClientConfig::default(); if let Some(max_field_section_size) = h3_max_field_section_size { @@ -542,6 +552,7 @@ impl ClientBuilder { config.quic_stream_receive_window, config.quic_receive_window, config.quic_send_window, + config.quic_congestion_bbr, config.h3_max_field_section_size, config.h3_send_grease, config.local_address, @@ -746,6 +757,7 @@ impl ClientBuilder { config.quic_stream_receive_window, config.quic_receive_window, config.quic_send_window, + config.quic_congestion_bbr, config.h3_max_field_section_size, config.h3_send_grease, config.local_address, @@ -2071,6 +2083,20 @@ impl ClientBuilder { self } + /// Override the default congestion control algorithm to use [BBR] + /// + /// The current default congestion control algorithm is [CUBIC]. This method overrides the + /// default. + /// + /// [BBR]: https://datatracker.ietf.org/doc/html/draft-ietf-ccwg-bbr + /// [CUBIC]: https://datatracker.ietf.org/doc/html/rfc8312 + #[cfg(feature = "http3")] + #[cfg_attr(docsrs, doc(cfg(all(reqwest_unstable, feature = "http3",))))] + pub fn http3_congestion_bbr(mut self) -> ClientBuilder { + self.config.quic_congestion_bbr = true; + self + } + /// Set the maximum HTTP/3 header size this client is willing to accept. /// /// See [header size constraints] section of the specification for details.