Skip to content

Commit 64e5711

Browse files
committed
Emit qlog PacketLost events
1 parent 7bdbea9 commit 64e5711

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,14 @@ impl Connection {
17381738

17391739
for &packet in &lost_packets {
17401740
let info = self.spaces[pn_space].take(packet).unwrap(); // safe: lost_packets is populated just above
1741+
self.config.qlog_sink.emit_packet_lost(
1742+
packet,
1743+
&info,
1744+
lost_send_time,
1745+
pn_space,
1746+
now,
1747+
self.orig_rem_cid,
1748+
);
17411749
self.remove_in_flight(packet, &info);
17421750
for frame in info.stream_frames {
17431751
self.streams.retransmit(frame);

quinn-proto/src/connection/qlog.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ use std::sync::{Arc, Mutex};
66

77
#[cfg(feature = "qlog")]
88
use qlog::{
9-
events::{Event, EventData},
9+
events::{
10+
Event, EventData,
11+
quic::{PacketHeader, PacketLost, PacketLostTrigger, PacketType},
12+
},
1013
streamer::QlogStreamer,
1114
};
1215
#[cfg(feature = "qlog")]
1316
use tracing::warn;
1417

15-
use crate::{ConnectionId, Instant, connection::PathData};
18+
use crate::{
19+
ConnectionId, Instant,
20+
connection::{PathData, SentPacket},
21+
packet::SpaceId,
22+
};
1623

1724
/// Shareable handle to a single qlog output stream
1825
#[cfg(feature = "qlog")]
@@ -72,6 +79,39 @@ impl QlogSink {
7279
stream.emit_event(orig_rem_cid, EventData::MetricsUpdated(metrics), now);
7380
}
7481
}
82+
83+
pub(super) fn emit_packet_lost(
84+
&self,
85+
pn: u64,
86+
info: &SentPacket,
87+
lost_send_time: Instant,
88+
space: SpaceId,
89+
now: Instant,
90+
orig_rem_cid: ConnectionId,
91+
) {
92+
#[cfg(feature = "qlog")]
93+
{
94+
let Some(stream) = self.stream.as_ref() else {
95+
return;
96+
};
97+
98+
let event = PacketLost {
99+
header: Some(PacketHeader {
100+
packet_number: Some(pn),
101+
packet_type: packet_type(space),
102+
length: Some(info.size),
103+
..Default::default()
104+
}),
105+
frames: None,
106+
trigger: Some(match info.time_sent <= lost_send_time {
107+
true => PacketLostTrigger::TimeThreshold,
108+
false => PacketLostTrigger::ReorderingThreshold,
109+
}),
110+
};
111+
112+
stream.emit_event(orig_rem_cid, EventData::PacketLost(event), now);
113+
}
114+
}
75115
}
76116

77117
#[cfg(feature = "qlog")]
@@ -80,3 +120,12 @@ impl From<Option<QlogStream>> for QlogSink {
80120
Self { stream }
81121
}
82122
}
123+
124+
#[cfg(feature = "qlog")]
125+
fn packet_type(space: SpaceId) -> PacketType {
126+
match space {
127+
SpaceId::Initial => PacketType::Initial,
128+
SpaceId::Handshake => PacketType::Handshake,
129+
SpaceId::Data => PacketType::OneRtt,
130+
}
131+
}

0 commit comments

Comments
 (0)