Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

receiver timestamps #1984

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ use paths::{PathData, PathResponses};

mod send_buffer;

mod spaces;
#[cfg(fuzzing)]
pub use spaces::Retransmits;
mod receiver_timestamps;
use receiver_timestamps::ReceiverTimestampConfig;

pub mod spaces;
#[cfg(not(fuzzing))]
use spaces::Retransmits;
use spaces::{PacketNumberFilter, PacketSpace, SendableFrames, SentPacket, ThinRetransmits};
#[cfg(fuzzing)]
pub use spaces::{ReceivedTimestamps, Retransmits};

mod stats;
pub use stats::{ConnectionStats, FrameStats, PathStats, UdpStats};
Expand Down Expand Up @@ -227,6 +230,11 @@ pub struct Connection {
/// no outgoing application data.
app_limited: bool,

//
// Ack Receive Timestamps
//
receiver_timestamp_cfg: Option<ReceiverTimestampConfig>,

streams: StreamsState,
/// Surplus remote CIDs for future use on new paths
rem_cids: CidQueue,
Expand Down Expand Up @@ -275,6 +283,7 @@ impl Connection {
});
let mut rng = StdRng::from_seed(rng_seed);
let mut this = Self {
receiver_timestamp_cfg: None,
endpoint_config,
server_config,
crypto,
Expand Down Expand Up @@ -817,6 +826,7 @@ impl Connection {
&mut self.spaces[space_id],
buf,
&mut self.stats,
None,
);
}

Expand Down Expand Up @@ -3047,6 +3057,7 @@ impl Connection {
space,
buf,
&mut self.stats,
self.receiver_timestamp_cfg.as_ref(),
);
}

Expand Down Expand Up @@ -3231,6 +3242,7 @@ impl Connection {
space: &mut PacketSpace,
buf: &mut Vec<u8>,
stats: &mut ConnectionStats,
timestamp_config: Option<&ReceiverTimestampConfig>,
) {
debug_assert!(!space.pending_acks.ranges().is_empty());

Expand All @@ -3255,7 +3267,16 @@ impl Connection {
delay_micros
);

frame::Ack::encode(delay as _, space.pending_acks.ranges(), ecn, buf);
frame::Ack::encode(
delay as _,
space.pending_acks.ranges(),
ecn,
Some(space.pending_acks.received_timestamps()),
timestamp_config.as_ref().map(|cfg| cfg.basis),
timestamp_config.as_ref().map(|cfg| cfg.exponent),
timestamp_config.as_ref().map(|cfg| cfg.instant_basis),
buf,
);
stats.frame_tx.acks += 1;
}

Expand Down
17 changes: 17 additions & 0 deletions quinn-proto/src/connection/receiver_timestamps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::time::Instant;

pub(crate) struct ReceiverTimestampConfig {
pub exponent: u64,
pub basis: u64,
pub instant_basis: Instant,
}

impl ReceiverTimestampConfig {
fn new(basis: u64, exponent: u64, instant_basis: Instant) -> Self {
ReceiverTimestampConfig {
exponent,
basis,
instant_basis,
}
}
}
58 changes: 56 additions & 2 deletions quinn-proto/src/connection/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{
cmp,
collections::{BTreeMap, VecDeque},
mem,
ops::{Bound, Index, IndexMut},
time::{Duration, Instant},
ops::{Bound, Index, IndexMut, Range},
time::{Duration, Instant, SystemTime},
};

use rand::Rng;
Expand Down Expand Up @@ -553,6 +553,53 @@ impl SendableFrames {
}
}

pub struct ReceiverTimestamps(VecDeque<(u64, Instant)>);

impl std::fmt::Debug for ReceiverTimestamps {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut l = f.debug_list();
self.iter().for_each(|v| {
l.entry(&v);
});
l.finish()
}
}

impl ReceiverTimestamps {
pub fn new() -> Self {
ReceiverTimestamps(VecDeque::new())
}

pub fn add(&mut self, packet_number: u64, t: Instant) -> Result<(), &str> {
if let Some(v) = self.0.back() {
if packet_number <= v.0 {
return Err("out of order packets are unsupported");
}
}
self.0.push_back((packet_number, t));
Ok(())
}

fn clear(&mut self) {
self.0.clear()
}

pub fn encode_iter(&mut self) {}

// why do we need '_
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (u64, Instant)> + '_ {
self.0.iter().cloned()
}

pub fn len(&self) -> usize {
self.0.len()
}

pub fn inner(&self) -> &VecDeque<(u64, Instant)> {
&self.0
}
}

#[derive(Debug)]
pub(super) struct PendingAcks {
/// Whether we should send an ACK immediately, even if that means sending an ACK-only packet
Expand Down Expand Up @@ -587,6 +634,8 @@ pub(super) struct PendingAcks {
largest_ack_eliciting_packet: Option<u64>,
/// The largest acknowledged packet number sent in an ACK frame
largest_acked: Option<u64>,

received_timestamps: ReceiverTimestamps,
}

impl PendingAcks {
Expand All @@ -602,6 +651,7 @@ impl PendingAcks {
largest_packet: None,
largest_ack_eliciting_packet: None,
largest_acked: None,
received_timestamps: ReceiverTimestamps::new(),
}
}

Expand Down Expand Up @@ -755,6 +805,10 @@ impl PendingAcks {
&self.ranges
}

pub(super) fn received_timestamps(&self) -> &ReceiverTimestamps {
&self.received_timestamps
}

/// Queue an ACK if a significant number of non-ACK-eliciting packets have not yet been
/// acknowledged
///
Expand Down
Loading
Loading