From 1fbab5c5683520a3ac127441500cbf19767bbd31 Mon Sep 17 00:00:00 2001 From: Benno Zeeman Date: Tue, 7 Jan 2025 08:45:21 +0100 Subject: [PATCH] feat(networking): override QUIC receive window env Allow to pass ANT_MAX_STREAM_DATA=x to override the stream receive window setting in libp2p/quinn. --- ant-networking/src/transport.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ant-networking/src/transport.rs b/ant-networking/src/transport.rs index d452560301..63e0f83fc0 100644 --- a/ant-networking/src/transport.rs +++ b/ant-networking/src/transport.rs @@ -14,6 +14,8 @@ use libp2p::{ PeerId, Transport as _, }; +const MAX_STREAM_DATA_ENV_STR: &str = "ANT_MAX_STREAM_DATA"; + pub(crate) fn build_transport( keypair: &Keypair, #[cfg(feature = "open-metrics")] registries: &mut MetricsRegistries, @@ -30,5 +32,18 @@ pub(crate) fn build_transport( fn generate_quic_transport( keypair: &Keypair, ) -> libp2p::quic::GenTransport { - libp2p::quic::tokio::Transport::new(libp2p::quic::Config::new(keypair)) + let mut quic_config = libp2p::quic::Config::new(keypair); + if let Ok(val) = std::env::var(MAX_STREAM_DATA_ENV_STR) { + match val.parse::() { + Ok(val) => { + quic_config.max_stream_data = val; + tracing::info!("Overriding QUIC connection receive window value to {val}"); + } + Err(e) => { + tracing::warn!("QUIC connection receive window value override failed. Could not parse `{MAX_STREAM_DATA_ENV_STR}={val}` as integer: {e}") + } + } + } + + libp2p::quic::tokio::Transport::new(quic_config) }