Skip to content

Commit

Permalink
proto: add a way to configure the minimum MTU change needed to stop
Browse files Browse the repository at this point in the history
the binary search used during the MTU discovery phase.
  • Loading branch information
stormshield-damiend committed Nov 3, 2023
1 parent 49aa4b6 commit 389e8e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 9 additions & 0 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions quinn-proto/src/connection/mtud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 389e8e9

Please sign in to comment.