Skip to content
Merged
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
28 changes: 27 additions & 1 deletion quiche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ pub struct Config {
enable_relaxed_loss_threshold: bool,
enable_cubic_idle_restart_fix: bool,
enable_send_streams_blocked: bool,
enable_ack_latency_loss_floor: bool,

pmtud: bool,
pmtud_max_probes: u8,
Expand Down Expand Up @@ -658,6 +659,7 @@ impl Config {
enable_relaxed_loss_threshold: false,
enable_cubic_idle_restart_fix: true,
enable_send_streams_blocked: false,
enable_ack_latency_loss_floor: false,
pmtud: false,
pmtud_max_probes: pmtud::MAX_PROBES_DEFAULT,
hystart: true,
Expand Down Expand Up @@ -1150,6 +1152,23 @@ impl Config {
self.enable_send_streams_blocked = enable;
}

/// Configure whether the loss delay is floored at the ack latency the
/// connection has observed.
///
/// Acknowledgements are processed in batches, and the RTT estimate only
/// samples the freshest packet of each batch. On a path whose RTT is
/// close to or below the granularity of ack processing, the time and
/// packet thresholds declare packets lost whose acknowledgements have
/// not had a chance to be processed yet. With this enabled, the loss
/// delay is never lower than the slowest send-to-processed-ack loop
/// observed in the last half second, and the packet reordering
/// threshold only applies to packets older than that loop.
///
/// The default value is false.
pub fn set_enable_ack_latency_loss_floor(&mut self, enable: bool) {
self.enable_ack_latency_loss_floor = enable;
}

/// Configures whether to enable HyStart++.
///
/// The default value is `true`.
Expand Down Expand Up @@ -7618,11 +7637,18 @@ impl<F: BufFactory> Connection<F> {
///
/// The exporter is available after the TLS handshake completes. The label
/// identifies the protocol usage, while the optional context can separate
/// exporter instances within that usage.
/// exporter instances within that usage. Returns [`InvalidState`] until
/// the connection is established.
///
/// [`InvalidState`]: enum.Error.html#variant.InvalidState
#[inline]
pub fn export_keying_material(
&self, out: &mut [u8], label: &[u8], context: Option<&[u8]>,
) -> Result<()> {
if !self.is_established() {
return Err(Error::InvalidState);
}

self.handshake.export_keying_material(out, label, context)
}

Expand Down
90 changes: 84 additions & 6 deletions quiche/src/recovery/congestion/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use crate::recovery::LossDetectionTimer;
use crate::recovery::OnAckReceivedOutcome;
use crate::recovery::ReleaseDecision;
use crate::recovery::ReleaseTime;
use crate::recovery::ACK_LOOP_WINDOW;
use crate::recovery::GRANULARITY;
use crate::recovery::INITIAL_PACKET_THRESHOLD;
use crate::recovery::INITIAL_TIME_THRESHOLD;
Expand Down Expand Up @@ -221,8 +222,8 @@ impl RecoveryEpoch {
}

fn detect_lost_packets(
&mut self, loss_delay: Duration, pkt_thresh: u64, now: Instant,
trace_id: &str, epoch: Epoch,
&mut self, loss_delay: Duration, pkt_thresh: u64, pkt_age_gate: Duration,
now: Instant, trace_id: &str, epoch: Epoch,
) -> LossDetectionResult {
self.loss_time = None;

Expand All @@ -232,6 +233,9 @@ impl RecoveryEpoch {

// Packets sent before this time are deemed lost.
let lost_send_time = now.checked_sub(loss_delay).unwrap();
// The reordering threshold only convicts a packet old enough
// that its acknowledgement had a fair chance to be processed.
let pkt_gate_time = now.checked_sub(pkt_age_gate).unwrap();

let mut lost_packets = 0;
let mut lost_bytes = 0;
Expand All @@ -249,7 +253,8 @@ impl RecoveryEpoch {
for unacked in unacked_iter {
// Mark packet as lost, or set time when it should be marked.
if unacked.time_sent <= lost_send_time ||
largest_acked >= unacked.pkt_num + pkt_thresh
(largest_acked >= unacked.pkt_num + pkt_thresh &&
unacked.time_sent <= pkt_gate_time)
{
self.lost_frames_ack.extend(unacked.frames.drain(..));

Expand Down Expand Up @@ -357,6 +362,16 @@ pub struct LegacyRecovery {

loss_timer: LossDetectionTimer,

// The worst full-loop ack latency (send to processed acknowledgement)
// seen in the current window, and when it was recorded. A loss delay
// below this declares packets whose acknowledgements could not have
// been processed yet whatever the RTT estimate says, because RTT is
// sampled from the freshest packet of each ack batch and batched ack
// processing hides exactly the latency that matters here.
ack_loop_max: Duration,
ack_loop_at: Option<Instant>,
ack_latency_loss_floor: bool,

pto_count: u32,

rtt_stats: RttStats,
Expand Down Expand Up @@ -396,6 +411,9 @@ impl LegacyRecovery {
epochs: Default::default(),

loss_timer: Default::default(),
ack_loop_max: Duration::ZERO,
ack_loop_at: None,
ack_latency_loss_floor: recovery_config.enable_ack_latency_loss_floor,

pto_count: 0,

Expand Down Expand Up @@ -453,6 +471,23 @@ impl LegacyRecovery {
(time, epoch)
}

fn expire_ack_loop_floor(&mut self, now: Instant) -> bool {
let expired = self.ack_latency_loss_floor &&
self.ack_loop_at.is_some_and(|at| {
now.saturating_duration_since(at) >= ACK_LOOP_WINDOW
});
if expired {
self.ack_loop_max = Duration::ZERO;
self.ack_loop_at = None;
}
expired
}

fn cap_timer_at_ack_loop_expiry(&self, timeout: Instant) -> Instant {
self.ack_loop_at
.map_or(timeout, |at| cmp::min(timeout, at + ACK_LOOP_WINDOW))
}

fn pto_time_and_space(
&self, handshake_status: HandshakeStatus, now: Instant,
) -> (Option<Instant>, Epoch) {
Expand Down Expand Up @@ -508,7 +543,8 @@ impl LegacyRecovery {

if let Some(to) = earliest_loss_time {
// Time threshold loss detection.
self.loss_timer.update(to);
self.loss_timer
.update(self.cap_timer_at_ack_loop_expiry(to));
return;
}

Expand All @@ -522,7 +558,11 @@ impl LegacyRecovery {
// PTO timer.
if let (Some(timeout), _) = self.pto_time_and_space(handshake_status, now)
{
self.loss_timer.update(timeout);
self.loss_timer.update(if self.bytes_in_flight.is_zero() {
timeout
} else {
self.cap_timer_at_ack_loop_expiry(timeout)
});
} else {
self.loss_timer.clear();
}
Expand All @@ -531,12 +571,20 @@ impl LegacyRecovery {
fn detect_lost_packets(
&mut self, epoch: Epoch, now: Instant, trace_id: &str,
) -> (usize, usize) {
let loss_delay = cmp::max(self.rtt_stats.latest_rtt, self.rtt())
self.expire_ack_loop_floor(now);
let mut loss_delay = cmp::max(self.rtt_stats.latest_rtt, self.rtt())
.mul_f64(self.time_thresh);
if self.ack_latency_loss_floor {
loss_delay = cmp::max(
loss_delay,
self.ack_loop_max.saturating_add(GRANULARITY),
);
}

let loss = self.epochs[epoch].detect_lost_packets(
loss_delay,
self.pkt_thresh,
self.ack_loop_max,
now,
trace_id,
epoch,
Expand Down Expand Up @@ -705,6 +753,25 @@ impl RecoveryOps for LegacyRecovery {
return Ok(OnAckReceivedOutcome::default());
}

// The slowest acknowledgement in this batch proves how late an
// honest ack can currently be. Windowed so a transient stall
// stops inflating the loss delay shortly after it passes.
if self.ack_latency_loss_floor {
let batch_loop = self
.newly_acked
.iter()
.map(|acked| now.saturating_duration_since(acked.time_sent))
.max()
.unwrap_or(Duration::ZERO);
let expired = self.ack_loop_at.is_none_or(|at| {
now.saturating_duration_since(at) >= ACK_LOOP_WINDOW
});
if expired || batch_loop >= self.ack_loop_max {
self.ack_loop_max = batch_loop;
self.ack_loop_at = Some(now);
}
}

let largest_newly_acked = self.newly_acked.last().unwrap();

// Update `largest_acked_packet` based on the validated `newly_acked`
Expand Down Expand Up @@ -761,6 +828,7 @@ impl RecoveryOps for LegacyRecovery {
&mut self, handshake_status: HandshakeStatus, now: Instant,
trace_id: &str,
) -> OnLossDetectionTimeoutOutcome {
let ack_loop_expired = self.expire_ack_loop_floor(now);
let (earliest_loss_time, epoch) = self.loss_time_and_space();

if earliest_loss_time.is_some() {
Expand All @@ -777,6 +845,16 @@ impl RecoveryOps for LegacyRecovery {
};
}

if ack_loop_expired &&
!self.bytes_in_flight.is_zero() &&
self.pto_time_and_space(handshake_status, now)
.0
.is_none_or(|timeout| timeout > now)
{
self.set_loss_detection_timer(handshake_status, now);
return OnLossDetectionTimeoutOutcome::default();
}

let epoch = if self.bytes_in_flight.get() > 0 {
// Send new data if available, else retransmit old data. If neither
// is available, send a single PING frame.
Expand Down
Loading
Loading