Skip to content

Commit d64058b

Browse files
committed
Pass the TransmitBuf directly to the PacketBuilder
This removes the extra arguments from Packetbuilder::new that tell the builder about datagram boundaries in favour of using the state of TransmitBuf directly.
1 parent 915f808 commit d64058b

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,7 @@ impl Connection {
759759
now,
760760
space_id,
761761
self.rem_cids.active(),
762-
buf.buf,
763-
buf.buf_capacity,
764-
buf.datagram_start,
762+
&mut buf,
765763
ack_eliciting,
766764
self,
767765
)?);
@@ -929,16 +927,9 @@ impl Connection {
929927
buf.buf_capacity = probe_size as usize;
930928
buf.buf.reserve(buf.buf_capacity);
931929

932-
let mut builder = PacketBuilder::new(
933-
now,
934-
space_id,
935-
self.rem_cids.active(),
936-
buf.buf,
937-
buf.buf_capacity,
938-
0,
939-
true,
940-
self,
941-
)?;
930+
debug_assert_eq!(buf.datagram_start, 0);
931+
let mut builder =
932+
PacketBuilder::new(now, space_id, self.rem_cids.active(), &mut buf, true, self)?;
942933

943934
// We implement MTU probes as ping packets padded up to the probe size
944935
buf.write(frame::FrameType::PING);
@@ -1012,23 +1003,15 @@ impl Connection {
10121003
);
10131004
buf.buf.reserve(MIN_INITIAL_SIZE as usize);
10141005

1015-
let buf_capacity = buf.buf.capacity();
1006+
buf.buf_capacity = buf.buf.capacity();
10161007

10171008
// Use the previous CID to avoid linking the new path with the previous path. We
10181009
// don't bother accounting for possible retirement of that prev_cid because this is
10191010
// sent once, immediately after migration, when the CID is known to be valid. Even
10201011
// if a post-migration packet caused the CID to be retired, it's fair to pretend
10211012
// this is sent first.
1022-
let mut builder = PacketBuilder::new(
1023-
now,
1024-
SpaceId::Data,
1025-
*prev_cid,
1026-
buf.buf,
1027-
buf_capacity,
1028-
0,
1029-
false,
1030-
self,
1031-
)?;
1013+
debug_assert_eq!(buf.datagram_start, 0);
1014+
let mut builder = PacketBuilder::new(now, SpaceId::Data, *prev_cid, buf, false, self)?;
10321015
trace!("validating previous path with PATH_CHALLENGE {:08x}", token);
10331016
buf.write(frame::FrameType::PATH_CHALLENGE);
10341017
buf.write(token);

quinn-proto/src/connection/packet_builder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bytes::Bytes;
22
use rand::Rng;
33
use tracing::{trace, trace_span};
44

5-
use super::{Connection, SentFrames, spaces::SentPacket};
5+
use super::{Connection, SentFrames, TransmitBuf, spaces::SentPacket};
66
use crate::{
77
ConnectionId, Instant, TransportError, TransportErrorCode,
88
connection::ConnectionSide,
@@ -36,9 +36,7 @@ impl PacketBuilder {
3636
now: Instant,
3737
space_id: SpaceId,
3838
dst_cid: ConnectionId,
39-
buffer: &mut Vec<u8>,
40-
buffer_capacity: usize,
41-
datagram_start: usize,
39+
buffer: &mut TransmitBuf<'_>,
4240
ack_eliciting: bool,
4341
conn: &mut Connection,
4442
) -> Option<Self> {
@@ -122,9 +120,9 @@ impl PacketBuilder {
122120
version,
123121
}),
124122
};
125-
let partial_encode = header.encode(buffer);
123+
let partial_encode = header.encode(buffer.buf);
126124
if conn.peer_params.grease_quic_bit && conn.rng.random() {
127-
buffer[partial_encode.start] ^= FIXED_BIT;
125+
buffer.buf[partial_encode.start] ^= FIXED_BIT;
128126
}
129127

130128
let (sample_size, tag_len) = if let Some(ref crypto) = space.crypto {
@@ -151,11 +149,11 @@ impl PacketBuilder {
151149
buffer.len() + (sample_size + 4).saturating_sub(number.len() + tag_len),
152150
partial_encode.start + dst_cid.len() + 6,
153151
);
154-
let max_size = buffer_capacity - tag_len;
152+
let max_size = buffer.buf_capacity - tag_len;
155153
debug_assert!(max_size >= min_size);
156154

157155
Some(Self {
158-
datagram_start,
156+
datagram_start: buffer.datagram_start,
159157
space: space_id,
160158
partial_encode,
161159
exact_number,

0 commit comments

Comments
 (0)