From f8ae3555753ffa86eff006773a19c04c8a263e7f Mon Sep 17 00:00:00 2001 From: BiagioFesta <15035284+BiagioFesta@users.noreply.github.com> Date: Thu, 18 Nov 2021 23:11:16 +0100 Subject: [PATCH] Make pub visibility for RttEstimator used by pub trait Congestion --- quinn-proto/src/congestion.rs | 2 +- quinn-proto/src/congestion/bbr/mod.rs | 2 +- quinn-proto/src/congestion/cubic.rs | 2 +- quinn-proto/src/congestion/new_reno.rs | 2 +- quinn-proto/src/connection/mod.rs | 3 +- quinn-proto/src/connection/paths.rs | 46 ++++++++++++++------------ quinn-proto/src/lib.rs | 4 +-- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/quinn-proto/src/congestion.rs b/quinn-proto/src/congestion.rs index aff276ebe..39a004975 100644 --- a/quinn-proto/src/congestion.rs +++ b/quinn-proto/src/congestion.rs @@ -1,6 +1,6 @@ //! Logic for controlling the rate at which data is sent -use crate::connection::paths::RttEstimator; +use crate::connection::RttEstimator; use std::any::Any; use std::time::Instant; diff --git a/quinn-proto/src/congestion/bbr/mod.rs b/quinn-proto/src/congestion/bbr/mod.rs index 3b2385e2b..5f093f767 100644 --- a/quinn-proto/src/congestion/bbr/mod.rs +++ b/quinn-proto/src/congestion/bbr/mod.rs @@ -7,7 +7,7 @@ use rand::{Rng, SeedableRng}; use crate::congestion::bbr::bw_estimation::BandwidthEstimation; use crate::congestion::bbr::min_max::MinMax; -use crate::connection::paths::RttEstimator; +use crate::connection::RttEstimator; use super::{Controller, ControllerFactory}; diff --git a/quinn-proto/src/congestion/cubic.rs b/quinn-proto/src/congestion/cubic.rs index c3ce198ac..9d878f0ac 100644 --- a/quinn-proto/src/congestion/cubic.rs +++ b/quinn-proto/src/congestion/cubic.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use super::{Controller, ControllerFactory}; -use crate::connection::paths::RttEstimator; +use crate::connection::RttEstimator; use std::cmp; /// CUBIC Constants. diff --git a/quinn-proto/src/congestion/new_reno.rs b/quinn-proto/src/congestion/new_reno.rs index 332a06553..89b470acc 100644 --- a/quinn-proto/src/congestion/new_reno.rs +++ b/quinn-proto/src/congestion/new_reno.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use std::time::Instant; use super::{Controller, ControllerFactory}; -use crate::connection::paths::RttEstimator; +use crate::connection::RttEstimator; /// A simple, standard congestion controller #[derive(Debug, Clone)] diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index b9a367382..fa639b2c9 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -48,8 +48,9 @@ mod pacing; mod packet_builder; use packet_builder::PacketBuilder; -pub(crate) mod paths; +mod paths; use paths::PathData; +pub use paths::RttEstimator; mod send_buffer; diff --git a/quinn-proto/src/connection/paths.rs b/quinn-proto/src/connection/paths.rs index bb32ff418..86d2253f2 100644 --- a/quinn-proto/src/connection/paths.rs +++ b/quinn-proto/src/connection/paths.rs @@ -91,6 +91,7 @@ impl PathData { } } +/// RTT estimation for a particular network path #[derive(Copy, Clone)] pub struct RttEstimator { /// The most recent RTT measurement made when receiving an ack for a previously unacked packet @@ -113,7 +114,30 @@ impl RttEstimator { } } - pub fn update(&mut self, ack_delay: Duration, rtt: Duration) { + /// The current best RTT estimation. + pub fn get(&self) -> Duration { + self.smoothed.unwrap_or(self.latest) + } + + /// Conservative estimate of RTT + /// + /// Takes the maximum of smoothed and latest RTT, as recommended + /// in 6.1.2 of the recovery spec (draft 29). + pub fn conservative(&self) -> Duration { + self.get().max(self.latest) + } + + /// Minimum RTT registered so far for this estimator. + pub fn min(&self) -> Duration { + self.min + } + + // PTO computed as described in RFC9002#6.2.1 + pub(crate) fn pto_base(&self) -> Duration { + self.get() + cmp::max(4 * self.var, TIMER_GRANULARITY) + } + + pub(crate) fn update(&mut self, ack_delay: Duration, rtt: Duration) { self.latest = rtt; // min_rtt ignores ack delay. self.min = cmp::min(self.min, self.latest); @@ -137,24 +161,4 @@ impl RttEstimator { self.min = self.latest; } } - - pub fn get(&self) -> Duration { - self.smoothed.unwrap_or(self.latest) - } - - /// Conservative estimate of RTT - /// - /// Takes the maximum of smoothed and latest RTT, as recommended - /// in 6.1.2 of the recovery spec (draft 29). - pub fn conservative(&self) -> Duration { - self.get().max(self.latest) - } - - pub fn pto_base(&self) -> Duration { - self.get() + cmp::max(4 * self.var, TIMER_GRANULARITY) - } - - pub fn min(&self) -> Duration { - self.min - } } diff --git a/quinn-proto/src/lib.rs b/quinn-proto/src/lib.rs index 5785cfac1..374618ebb 100644 --- a/quinn-proto/src/lib.rs +++ b/quinn-proto/src/lib.rs @@ -41,8 +41,8 @@ pub use varint::{VarInt, VarIntBoundsExceeded}; mod connection; pub use crate::connection::{ BytesSource, Chunk, Chunks, Connection, ConnectionError, ConnectionStats, Datagrams, Event, - FinishError, ReadError, ReadableError, RecvStream, SendDatagramError, SendStream, StreamEvent, - Streams, UnknownStream, WriteError, Written, + FinishError, ReadError, ReadableError, RecvStream, RttEstimator, SendDatagramError, SendStream, + StreamEvent, Streams, UnknownStream, WriteError, Written, }; mod config;