Skip to content

Commit b062df3

Browse files
committed
Improve comments
1 parent ff356c7 commit b062df3

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,25 @@ impl Connection {
547547
&& self.peer_supports_ack_frequency();
548548
}
549549

550+
// Whether this packet can be coalesced with another one in the same datagram.
550551
let mut coalesce = true;
552+
553+
// Whether the last packet in the datagram must be padded to at least
554+
// MIN_INITIAL_SIZE.
551555
let mut pad_datagram = false;
556+
557+
// Whether congestion control stopped the next packet from being sent. Further
558+
// packets could still be built, as e.g. tail-loss probes are not congestion
559+
// limited.
552560
let mut congestion_blocked = false;
561+
562+
// The packet number of the last built packet.
553563
let mut last_packet_number = None;
554564

555565
// Iterate over all spaces and find data to send
556566
//
557-
// Each loop builds one packet. When packets are coalesced a datagram is filled
558-
// over multiple loops.
567+
// Each loop builds one packet, which is finished before the next iteration of the
568+
// loop. When packets are coalesced a datagram is filled over multiple loops.
559569
let mut next_space_id = self.next_send_space(SpaceId::Initial, path_id, &buf, close);
560570
while let Some(space_id) = next_space_id {
561571
// Whether the next packet will contain ack-eliciting frames.
@@ -867,9 +877,7 @@ impl Connection {
867877
// are the only packets for which we might grow `buf_capacity`
868878
// by less than `segment_size`.
869879
const MAX_PADDING: usize = 16;
870-
let packet_len_unpadded = cmp::max(builder.min_size, builder.buf.len())
871-
- builder.buf.datagram_start_offset()
872-
+ builder.tag_len;
880+
let packet_len_unpadded = builder.predict_packet_size();
873881
if packet_len_unpadded + MAX_PADDING < builder.buf.segment_size()
874882
|| builder.buf.datagram_start_offset() + builder.buf.segment_size()
875883
> builder.buf.datagram_max_offset()

quinn-proto/src/connection/packet_builder.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ pub(super) struct PacketBuilder<'a, 'b> {
2929
/// Smallest absolute position in the associated buffer that must be occupied by this packet's
3030
/// frames
3131
pub(super) min_size: usize,
32-
/// Largest absolute position in the buffer that may be occupied by this packet's frames
33-
///
34-
/// This takes the size of the cryptographic tag into account.
35-
pub(super) max_size: usize,
3632
pub(super) tag_len: usize,
3733
pub(super) _span: tracing::span::EnteredSpan,
3834
}
@@ -173,7 +169,6 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
173169
exact_number,
174170
short_header: header.is_short(),
175171
min_size,
176-
max_size,
177172
tag_len,
178173
ack_eliciting,
179174
_span: span,
@@ -253,7 +248,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
253248
/// Encrypt packet, returning the length of the packet and whether padding was added
254249
pub(super) fn finish(self, conn: &mut Connection) -> (usize, bool) {
255250
debug_assert!(
256-
self.buf.len() <= self.max_size,
251+
self.buf.len() <= self.buf.datagram_max_offset() - self.tag_len,
257252
"packet exceeds maximum size"
258253
);
259254
let pad = self.buf.len() < self.min_size;
@@ -304,7 +299,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
304299
/// This leaves space in the datagram for the cryptographic tag that needs to be written
305300
/// when the packet is finished.
306301
pub(super) fn frame_space_remaining(&self) -> usize {
307-
debug_assert!(self.max_size >= self.buf.len(), "packet exceeds bounds");
308-
self.max_size.saturating_sub(self.buf.len())
302+
let max_offset = self.buf.datagram_max_offset() - self.tag_len;
303+
max_offset.saturating_sub(self.buf.len())
309304
}
310305
}

0 commit comments

Comments
 (0)