Skip to content

Commit bee2b1a

Browse files
committed
Pass the TransmitBuilder 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 TransmitBuilder directly.
1 parent e7ce990 commit bee2b1a

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,7 @@ impl Connection {
761761
now,
762762
space_id,
763763
self.rem_cids.active(),
764-
transmit.buf,
765-
transmit.buf_capacity,
766-
transmit.datagram_start,
764+
&mut transmit,
767765
ack_eliciting,
768766
self,
769767
)?);
@@ -931,13 +929,12 @@ impl Connection {
931929
transmit.buf_capacity = probe_size as usize;
932930
transmit.buf.reserve(transmit.buf_capacity);
933931

932+
debug_assert_eq!(transmit.datagram_start, 0);
934933
let mut builder = PacketBuilder::new(
935934
now,
936935
space_id,
937936
self.rem_cids.active(),
938-
transmit.buf,
939-
transmit.buf_capacity,
940-
0,
937+
&mut transmit,
941938
true,
942939
self,
943940
)?;
@@ -1018,23 +1015,15 @@ impl Connection {
10181015
);
10191016
buf.buf.reserve(MIN_INITIAL_SIZE as usize);
10201017

1021-
let buf_capacity = buf.buf.capacity();
1018+
buf.buf_capacity = buf.buf.capacity();
10221019

10231020
// Use the previous CID to avoid linking the new path with the previous path. We
10241021
// don't bother accounting for possible retirement of that prev_cid because this is
10251022
// sent once, immediately after migration, when the CID is known to be valid. Even
10261023
// if a post-migration packet caused the CID to be retired, it's fair to pretend
10271024
// this is sent first.
1028-
let mut builder = PacketBuilder::new(
1029-
now,
1030-
SpaceId::Data,
1031-
*prev_cid,
1032-
buf.buf,
1033-
buf_capacity,
1034-
0,
1035-
false,
1036-
self,
1037-
)?;
1025+
debug_assert_eq!(buf.datagram_start, 0);
1026+
let mut builder = PacketBuilder::new(now, SpaceId::Data, *prev_cid, buf, false, self)?;
10381027
trace!("validating previous path with PATH_CHALLENGE {:08x}", token);
10391028
buf.write(frame::FrameType::PATH_CHALLENGE);
10401029
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, TransmitBuilder, 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 TransmitBuilder<'_>,
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)