Skip to content

Commit

Permalink
Use new initial_rtt field in Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Nov 11, 2024
1 parent 1bc2aa6 commit 7b6fe8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
quic_datagrams::{DatagramTracking, QuicDatagrams},
recovery::{LossRecovery, RecoveryToken, SendProfile, SentPacket},
recv_stream::RecvStreamStats,
rtt::{RttEstimate, GRANULARITY, INITIAL_RTT},
rtt::{RttEstimate, GRANULARITY},
send_stream::SendStream,
stats::{Stats, StatsCell},
stream_id::StreamType,
Expand Down Expand Up @@ -604,7 +604,7 @@ impl Connection {
// When we have no actual RTT sample, do not encode a guestimated RTT larger
// than the default initial RTT. (The guess can be very large under lossy
// conditions.)
if rtt < INITIAL_RTT {
if rtt < self.conn_params.get_initial_rtt() {
rtt
} else {
Duration::from_millis(0)
Expand Down Expand Up @@ -638,7 +638,7 @@ impl Connection {
/// only use it where a more precise value is not important.
fn pto(&self) -> Duration {
self.paths.primary().map_or_else(
|| RttEstimate::default().pto(self.confirmed()),
|| RttEstimate::new(self.conn_params.get_initial_rtt()).pto(self.confirmed()),
|p| p.borrow().rtt().pto(self.confirmed()),
)
}
Expand Down
7 changes: 4 additions & 3 deletions neqo-transport/src/connection/tests/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
stream_id::{StreamId, StreamType},
tparams::{self, TransportParameter},
tracking::PacketNumberSpace,
INITIAL_RTT,
};

fn default_timeout() -> Duration {
Expand Down Expand Up @@ -55,9 +56,9 @@ fn test_idle_timeout(client: &mut Connection, server: &mut Connection, timeout:

#[test]
fn init_rtt_configuration() {
const CUSTOM_INIT_RTT: Duration = Duration::from_millis(200);
let client = new_client(ConnectionParameters::default().initial_rtt(CUSTOM_INIT_RTT));
assert_eq!(client.conn_params.get_initial_rtt(), CUSTOM_INIT_RTT);
let custom_init_rtt = INITIAL_RTT * 2;
let client = new_client(ConnectionParameters::default().initial_rtt(custom_init_rtt));
assert_eq!(client.conn_params.get_initial_rtt(), custom_init_rtt);
}

#[test]
Expand Down
23 changes: 14 additions & 9 deletions neqo-transport/src/rtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ pub struct RttEstimate {
}

impl RttEstimate {
pub fn new(rtt: Duration) -> Self {
// Only allow this when there are no samples.
Self {
first_sample_time: None,
latest_rtt: rtt,
smoothed_rtt: rtt,
rttvar: rtt / 2,
min_rtt: rtt,
ack_delay: PeerAckDelay::default(),
best_source: RttSource::Guesstimate,
}
}

fn init(&mut self, rtt: Duration) {
// Only allow this when there are no samples.
debug_assert!(self.first_sample_time.is_none());
Expand Down Expand Up @@ -217,14 +230,6 @@ impl RttEstimate {

impl Default for RttEstimate {
fn default() -> Self {
Self {
first_sample_time: None,
latest_rtt: INITIAL_RTT,
smoothed_rtt: INITIAL_RTT,
rttvar: INITIAL_RTT / 2,
min_rtt: INITIAL_RTT,
ack_delay: PeerAckDelay::default(),
best_source: RttSource::Guesstimate,
}
Self::new(INITIAL_RTT)
}
}

0 comments on commit 7b6fe8c

Please sign in to comment.