@@ -6,13 +6,20 @@ use std::sync::{Arc, Mutex};
66
77#[ cfg( feature = "qlog" ) ]
88use 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" ) ]
1316use 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