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
17 changes: 7 additions & 10 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ impl Connection {
Duration::from_micros(ack.delay << self.peer_params.ack_delay_exponent.0),
)
};
let rtt = instant_saturating_sub(now, self.spaces[space].largest_acked_packet_sent);
let rtt = now.saturating_duration_since(self.spaces[space].largest_acked_packet_sent);
self.path.rtt.update(ack_delay, rtt);
if self.path.first_packet_after_rtt_sample.is_none() {
self.path.first_packet_after_rtt_sample =
Expand Down Expand Up @@ -1712,8 +1712,6 @@ impl Connection {
let rtt = self.path.rtt.conservative();
let loss_delay = cmp::max(rtt.mul_f32(self.config.time_threshold), TIMER_GRANULARITY);

// Packets sent before this time are deemed lost.
let lost_send_time = now.checked_sub(loss_delay).unwrap();
let largest_acked_packet = self.spaces[pn_space].largest_acked_packet.unwrap();
let packet_threshold = self.config.packet_threshold as u64;
let mut size_of_lost_packets = 0u64;
Expand All @@ -1737,8 +1735,11 @@ impl Connection {
persistent_congestion_start = None;
}

if info.time_sent <= lost_send_time || largest_acked_packet >= packet + packet_threshold
{
// Packets sent before now - loss_delay are deemed lost.
// However, we avoid this subtraction as it can panic and there's no
// saturating equivalent of this substraction operation with a Duration.
let packet_too_old = now.saturating_duration_since(info.time_sent) >= loss_delay;
if packet_too_old || largest_acked_packet >= packet + packet_threshold {
if Some(packet) == in_flight_mtu_probe {
// Lost MTU probes are not included in `lost_packets`, because they should not
// trigger a congestion control response
Expand Down Expand Up @@ -1796,7 +1797,7 @@ impl Connection {
self.config.qlog_sink.emit_packet_lost(
packet,
&info,
lost_send_time,
loss_delay,
pn_space,
now,
self.orig_rem_cid,
Expand Down Expand Up @@ -4056,10 +4057,6 @@ pub enum Event {
DatagramsUnblocked,
}

fn instant_saturating_sub(x: Instant, y: Instant) -> Duration {
if x > y { x - y } else { Duration::ZERO }
}

fn get_max_ack_delay(params: &TransportParameters) -> Duration {
Duration::from_micros(params.max_ack_delay.0 * 1000)
}
Expand Down
13 changes: 8 additions & 5 deletions quinn-proto/src/connection/qlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#[cfg(feature = "qlog")]
use std::sync::{Arc, Mutex};
use std::time::Duration;

#[cfg(feature = "qlog")]
use qlog::{
Expand Down Expand Up @@ -86,7 +87,7 @@ impl QlogSink {
&self,
pn: u64,
info: &SentPacket,
lost_send_time: Instant,
loss_delay: Duration,
space: SpaceId,
now: Instant,
orig_rem_cid: ConnectionId,
Expand All @@ -105,10 +106,12 @@ impl QlogSink {
..Default::default()
}),
frames: None,
trigger: Some(match info.time_sent <= lost_send_time {
true => PacketLostTrigger::TimeThreshold,
false => PacketLostTrigger::ReorderingThreshold,
}),
trigger: Some(
match info.time_sent.saturating_duration_since(now) >= loss_delay {
true => PacketLostTrigger::TimeThreshold,
false => PacketLostTrigger::ReorderingThreshold,
},
),
};

stream.emit_event(orig_rem_cid, EventData::PacketLost(event), now);
Expand Down