From 389e8e99da06d575675e537d5c9012beaefec5f3 Mon Sep 17 00:00:00 2001 From: Damien Deville Date: Fri, 3 Nov 2023 16:46:06 +0100 Subject: [PATCH] proto: add a way to configure the minimum MTU change needed to stop the binary search used during the MTU discovery phase. --- quinn-proto/src/config.rs | 9 +++++++++ quinn-proto/src/connection/mtud.rs | 11 +++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/quinn-proto/src/config.rs b/quinn-proto/src/config.rs index 499610571..d5483ed50 100644 --- a/quinn-proto/src/config.rs +++ b/quinn-proto/src/config.rs @@ -552,6 +552,7 @@ impl Default for AckFrequencyConfig { pub struct MtuDiscoveryConfig { pub(crate) interval: Duration, pub(crate) upper_bound: u16, + pub(crate) minimum_change: u16, pub(crate) black_hole_cooldown: Duration, } @@ -587,6 +588,13 @@ impl MtuDiscoveryConfig { self.black_hole_cooldown = value; self } + + /// Specifies the minimum MTU change to stop the MTU discovery phase. + /// Defaults to 20. + pub fn minimum_change(&mut self, value: u16) -> &mut Self { + self.minimum_change = value; + self + } } impl Default for MtuDiscoveryConfig { @@ -595,6 +603,7 @@ impl Default for MtuDiscoveryConfig { interval: Duration::from_secs(600), upper_bound: 1452, black_hole_cooldown: Duration::from_secs(60), + minimum_change: 20, } } } diff --git a/quinn-proto/src/connection/mtud.rs b/quinn-proto/src/connection/mtud.rs index 438d9b4f6..bf97716fd 100644 --- a/quinn-proto/src/connection/mtud.rs +++ b/quinn-proto/src/connection/mtud.rs @@ -288,6 +288,8 @@ struct SearchState { lower_bound: u16, /// The upper bound for the current binary search upper_bound: u16, + /// The minimum change to stop the current binary search + minimum_change: u16, /// The UDP payload size we last sent a probe for last_probed_mtu: u16, /// Packet number of an in-flight probe (if any) @@ -314,6 +316,7 @@ impl SearchState { lost_probe_count: 0, lower_bound, upper_bound, + minimum_change: config.minimum_change, // During initialization, we consider the lower bound to have already been // successfully probed last_probed_mtu: lower_bound, @@ -333,13 +336,10 @@ impl SearchState { let next_mtu = (self.lower_bound as i32 + self.upper_bound as i32) / 2; // Binary search stopping condition - if ((next_mtu - self.last_probed_mtu as i32).unsigned_abs() as u16) - < BINARY_SEARCH_MINIMUM_CHANGE - { + if ((next_mtu - self.last_probed_mtu as i32).unsigned_abs() as u16) < self.minimum_change { // Special case: if the upper bound is far enough, we want to probe it as a last // step (otherwise we will never achieve the upper bound) - if self.upper_bound.saturating_sub(self.last_probed_mtu) >= BINARY_SEARCH_MINIMUM_CHANGE - { + if self.upper_bound.saturating_sub(self.last_probed_mtu) >= self.minimum_change { return Some(self.upper_bound); } @@ -478,7 +478,6 @@ impl BlackHoleDetector { // https://www.rfc-editor.org/rfc/rfc8899#section-5.1.2) const MAX_PROBE_RETRANSMITS: usize = 3; const BLACK_HOLE_THRESHOLD: u8 = 3; -const BINARY_SEARCH_MINIMUM_CHANGE: u16 = 20; #[cfg(test)] mod tests {