Skip to content

Commit

Permalink
Make pub visibility for RttEstimator used by pub trait Congestion
Browse files Browse the repository at this point in the history
  • Loading branch information
BiagioFesta authored and Ralith committed Nov 19, 2021
1 parent b4c0405 commit f8ae355
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion 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;

Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/bbr/mod.rs
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/cubic.rs
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/new_reno.rs
Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion quinn-proto/src/connection/mod.rs
Expand Up @@ -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;

Expand Down
46 changes: 25 additions & 21 deletions quinn-proto/src/connection/paths.rs
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
}
}
4 changes: 2 additions & 2 deletions quinn-proto/src/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit f8ae355

Please sign in to comment.