Skip to content

Commit 3ebdf2f

Browse files
committed
fix: cid groups, padding size, cleanups
1 parent f3de07e commit 3ebdf2f

File tree

5 files changed

+117
-82
lines changed

5 files changed

+117
-82
lines changed

quinn-proto/src/config/transport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl QlogConfig {
766766
None,
767767
self.start_time,
768768
trace,
769-
qlog::events::EventImportance::Core,
769+
qlog::events::EventImportance::Extra,
770770
writer,
771771
);
772772

quinn-proto/src/connection/mod.rs

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
config::{ServerConfig, TransportConfig},
3131
congestion::Controller,
3232
connection::{
33-
qlog::{QlogPacket, QlogRecvPacket},
33+
qlog::{QlogRecvPacket, QlogSentPacket},
3434
timer::{ConnTimer, PathTimer},
3535
},
3636
crypto::{self, KeyPair, Keys, PacketKey},
@@ -457,9 +457,14 @@ impl Connection {
457457
this.write_crypto();
458458
this.init_0rtt();
459459
}
460-
this.config
461-
.qlog_sink
462-
.emit_connection_started(now, loc_cid, rem_cid, remote, local_ip);
460+
this.config.qlog_sink.emit_connection_started(
461+
now,
462+
loc_cid,
463+
rem_cid,
464+
remote,
465+
local_ip,
466+
this.initial_dst_cid,
467+
);
463468
this
464469
}
465470

@@ -1139,7 +1144,7 @@ impl Connection {
11391144
prev.update_unacked = false;
11401145
}
11411146

1142-
let mut qlog = QlogPacket::default();
1147+
let mut qlog = QlogSentPacket::default();
11431148
let mut builder = PacketBuilder::new(
11441149
now,
11451150
space_id,
@@ -1422,7 +1427,7 @@ impl Connection {
14221427
self.path_data(path_id).pto_count,
14231428
&mut self.paths.get_mut(&path_id).unwrap().data,
14241429
now,
1425-
self.orig_rem_cid,
1430+
self.initial_dst_cid,
14261431
);
14271432

14281433
self.app_limited = transmit.is_empty() && !congestion_blocked;
@@ -1443,7 +1448,7 @@ impl Connection {
14431448
transmit.start_new_datagram_with_size(probe_size as usize);
14441449

14451450
debug_assert_eq!(transmit.datagram_start_offset(), 0);
1446-
let mut qlog = QlogPacket::default();
1451+
let mut qlog = QlogSentPacket::default();
14471452
let mut builder = PacketBuilder::new(
14481453
now,
14491454
space_id,
@@ -1642,7 +1647,7 @@ impl Connection {
16421647
// if a post-migration packet caused the CID to be retired, it's fair to pretend
16431648
// this is sent first.
16441649
debug_assert_eq!(buf.datagram_start_offset(), 0);
1645-
let mut qlog = QlogPacket::default();
1650+
let mut qlog = QlogSentPacket::default();
16461651
let mut builder = PacketBuilder::new(
16471652
now,
16481653
SpaceId::Data,
@@ -1773,7 +1778,7 @@ impl Connection {
17731778
path.data.pto_count,
17741779
&mut path.data,
17751780
now,
1776-
self.orig_rem_cid,
1781+
self.initial_dst_cid,
17771782
);
17781783
}
17791784

@@ -1878,7 +1883,7 @@ impl Connection {
18781883
self.path_data(path_id).pto_count,
18791884
&mut self.paths.get_mut(&path_id).unwrap().data,
18801885
now,
1881-
self.orig_rem_cid,
1886+
self.initial_dst_cid,
18821887
);
18831888
}
18841889
PathTimer::PathValidation => {
@@ -2754,7 +2759,7 @@ impl Connection {
27542759
lost_send_time,
27552760
pn_space,
27562761
now,
2757-
self.orig_rem_cid,
2762+
self.initial_dst_cid,
27582763
);
27592764
self.paths
27602765
.get_mut(&path_id)
@@ -3139,7 +3144,7 @@ impl Connection {
31393144

31403145
let packet: Packet = packet.into();
31413146

3142-
let mut qlog = QlogRecvPacket::default();
3147+
let mut qlog = QlogRecvPacket::new(len);
31433148
#[cfg(feature = "qlog")]
31443149
qlog.header(&packet, Some(packet_number));
31453150

@@ -3151,9 +3156,7 @@ impl Connection {
31513156
packet,
31523157
&mut qlog,
31533158
)?;
3154-
self.config
3155-
.qlog_sink
3156-
.emit_packet_received(qlog, now, self.orig_rem_cid);
3159+
self.config.qlog_sink.emit_packet_received(self, qlog, now);
31573160
if let Some(data) = remaining {
31583161
self.handle_coalesced(now, remote, path_id, ecn, data);
31593162
}
@@ -3162,7 +3165,7 @@ impl Connection {
31623165
self.path_data(path_id).pto_count,
31633166
&mut self.paths.get_mut(&path_id).unwrap().data,
31643167
now,
3165-
self.orig_rem_cid,
3168+
self.initial_dst_cid,
31663169
);
31673170

31683171
Ok(())
@@ -3386,6 +3389,7 @@ impl Connection {
33863389
ecn: Option<EcnCodepoint>,
33873390
partial_decode: PartialDecode,
33883391
) {
3392+
let qlog = QlogRecvPacket::new(partial_decode.len());
33893393
if let Some(decoded) = packet_crypto::unprotect_header(
33903394
partial_decode,
33913395
&self.spaces,
@@ -3399,6 +3403,7 @@ impl Connection {
33993403
ecn,
34003404
decoded.packet,
34013405
decoded.stateless_reset,
3406+
qlog,
34023407
);
34033408
}
34043409
}
@@ -3411,6 +3416,7 @@ impl Connection {
34113416
ecn: Option<EcnCodepoint>,
34123417
packet: Option<Packet>,
34133418
stateless_reset: bool,
3419+
mut qlog: QlogRecvPacket,
34143420
) {
34153421
self.stats.udp_rx.ios += 1;
34163422
if let Some(ref packet) = packet {
@@ -3477,7 +3483,6 @@ impl Connection {
34773483
}
34783484
}
34793485
Ok((packet, number)) => {
3480-
let mut qlog = QlogRecvPacket::default();
34813486
#[cfg(feature = "qlog")]
34823487
qlog.header(&packet, number);
34833488
let span = match number {
@@ -3491,16 +3496,12 @@ impl Connection {
34913496
.map(|pns| &mut pns.dedup);
34923497
if number.zip(dedup).is_some_and(|(n, d)| d.insert(n)) {
34933498
debug!("discarding possible duplicate packet");
3494-
self.config
3495-
.qlog_sink
3496-
.emit_packet_received(qlog, now, self.orig_rem_cid);
3499+
self.config.qlog_sink.emit_packet_received(self, qlog, now);
34973500
return;
34983501
} else if self.state.is_handshake() && packet.header.is_short() {
34993502
// TODO: SHOULD buffer these to improve reordering tolerance.
35003503
trace!("dropping short packet during handshake");
3501-
self.config
3502-
.qlog_sink
3503-
.emit_packet_received(qlog, now, self.orig_rem_cid);
3504+
self.config.qlog_sink.emit_packet_received(self, qlog, now);
35043505
return;
35053506
} else {
35063507
if let Header::Initial(InitialHeader { ref token, .. }) = packet.header {
@@ -3510,11 +3511,7 @@ impl Connection {
35103511
// packets can be spoofed, so we discard rather than killing the
35113512
// connection.
35123513
warn!("discarding Initial with invalid retry token");
3513-
self.config.qlog_sink.emit_packet_received(
3514-
qlog,
3515-
now,
3516-
self.orig_rem_cid,
3517-
);
3514+
self.config.qlog_sink.emit_packet_received(self, qlog, now);
35183515
return;
35193516
}
35203517
}
@@ -3546,9 +3543,7 @@ impl Connection {
35463543
let res = self
35473544
.process_decrypted_packet(now, remote, path_id, number, packet, &mut qlog);
35483545

3549-
self.config
3550-
.qlog_sink
3551-
.emit_packet_received(qlog, now, self.orig_rem_cid);
3546+
self.config.qlog_sink.emit_packet_received(self, qlog, now);
35523547
res
35533548
}
35543549
}
@@ -4757,7 +4752,7 @@ impl Connection {
47574752
path_exclusive_only: bool,
47584753
buf: &mut impl BufMut,
47594754
pn: u64,
4760-
#[allow(unused)] qlog: &mut QlogPacket,
4755+
#[allow(unused)] qlog: &mut QlogSentPacket,
47614756
) -> SentFrames {
47624757
let mut sent = SentFrames::default();
47634758
let is_multipath_negotiated = self.is_multipath_negotiated();
@@ -5352,7 +5347,7 @@ impl Connection {
53525347
send_path_acks: bool,
53535348
buf: &mut impl BufMut,
53545349
stats: &mut ConnectionStats,
5355-
#[allow(unused)] qlog: &mut QlogPacket,
5350+
#[allow(unused)] qlog: &mut QlogSentPacket,
53565351
) {
53575352
// 0-RTT packets must never carry acks (which would have to be of handshake packets)
53585353
debug_assert!(space.crypto.is_some(), "tried to send ACK in 0-RTT");

quinn-proto/src/connection/packet_builder.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use bytes::{BufMut, Bytes};
2+
#[cfg(feature = "qlog")]
3+
use qlog::events::quic::QuicFrame;
24
use rand::Rng;
35
use tracing::{debug, trace, trace_span};
46

57
use super::{Connection, PathId, SentFrames, TransmitBuf, spaces::SentPacket};
68
use crate::{
79
ConnectionId, Instant, MIN_INITIAL_SIZE, TransportError, TransportErrorCode,
8-
connection::{ConnectionSide, qlog::QlogPacket},
10+
connection::{ConnectionSide, qlog::QlogSentPacket},
911
frame::{self, Close},
1012
packet::{FIXED_BIT, Header, InitialHeader, LongType, PacketNumber, PartialEncode, SpaceId},
1113
};
@@ -46,7 +48,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
4648
buffer: &'a mut TransmitBuf<'b>,
4749
ack_eliciting: bool,
4850
conn: &mut Connection,
49-
#[allow(unused)] qlog: &mut QlogPacket,
51+
#[allow(unused)] qlog: &mut QlogSentPacket,
5052
) -> Option<Self>
5153
where
5254
'b: 'a,
@@ -214,7 +216,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
214216
path_id: PathId,
215217
sent: SentFrames,
216218
pad_datagram: PadDatagram,
217-
qlog: QlogPacket,
219+
qlog: QlogSentPacket,
218220
) {
219221
match pad_datagram {
220222
PadDatagram::No => (),
@@ -269,16 +271,22 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
269271
self,
270272
conn: &mut Connection,
271273
now: Instant,
272-
#[allow(unused_mut)] mut qlog: QlogPacket,
274+
#[allow(unused_mut)] mut qlog: QlogSentPacket,
273275
) -> (usize, bool) {
274276
debug_assert!(
275277
self.buf.len() <= self.buf.datagram_max_offset() - self.tag_len,
276278
"packet exceeds maximum size"
277279
);
278280
let pad = self.buf.len() < self.min_size;
279281
if pad {
280-
trace!("PADDING * {}", self.min_size - self.buf.len());
281-
self.buf.put_bytes(0, self.min_size - self.buf.len());
282+
let padding = self.min_size - self.buf.len();
283+
trace!("PADDING * {}", padding);
284+
self.buf.put_bytes(0, padding);
285+
#[cfg(feature = "qlog")]
286+
qlog.frame(QuicFrame::Padding {
287+
length: Some(padding as u32),
288+
payload_length: padding as u32,
289+
});
282290
}
283291

284292
let space = &conn.spaces[self.space];
@@ -311,9 +319,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
311319
trace!(size = %packet_len, short_header = %self.short_header, "wrote packet");
312320
#[cfg(feature = "qlog")]
313321
qlog.finalize(packet_len);
314-
conn.config
315-
.qlog_sink
316-
.emit_packet_sent(conn.orig_rem_cid, qlog, now);
322+
conn.config.qlog_sink.emit_packet_sent(conn, qlog, now);
317323
(packet_len, pad)
318324
}
319325

0 commit comments

Comments
 (0)