Skip to content

Commit e6c004e

Browse files
refactor: Some much needed renaming of variables mostly (#354)
And collecting some functions together. Split off from #338. Co-authored-by: Diva Martínez <26765164+divagant-martian@users.noreply.github.com>
1 parent 3752420 commit e6c004e

File tree

3 files changed

+60
-38
lines changed

3 files changed

+60
-38
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub struct Connection {
229229
// Queued non-retransmittable 1-RTT data
230230
//
231231
/// If the CONNECTION_CLOSE frame needs to be sent
232-
close: bool,
232+
connection_close_pending: bool,
233233

234234
//
235235
// ACK frequency
@@ -426,7 +426,7 @@ impl Connection {
426426
},
427427
timers: TimerTable::default(),
428428
authentication_failures: 0,
429-
close: false,
429+
connection_close_pending: false,
430430

431431
ack_frequency: AckFrequencyState::new(get_max_ack_delay(
432432
&TransportParameters::default(),
@@ -987,7 +987,7 @@ impl Connection {
987987
StateType::Draining | StateType::Closed => {
988988
// self.close is only reset once the associated packet had been
989989
// encoded successfully
990-
if !self.close {
990+
if !self.connection_close_pending {
991991
self.app_limited = true;
992992
return None;
993993
}
@@ -996,7 +996,7 @@ impl Connection {
996996
_ => false,
997997
};
998998

999-
// Check whether we need to send an ACK_FREQUENCY frame
999+
// Schedule an ACK_FREQUENCY frame if a new one needs to be sent.
10001000
if let Some(config) = &self.config.ack_frequency_config {
10011001
let rtt = self
10021002
.paths
@@ -1036,15 +1036,8 @@ impl Connection {
10361036
&& self.remote_cids.contains_key(id)
10371037
});
10381038

1039-
if let Some(challenge) = self.send_prev_path_challenge(now, buf, path_id) {
1040-
return Some(challenge);
1041-
}
1042-
1043-
// Send an off-path PATH_RESPONSE. Prioritized over on-path data to ensure that
1044-
// path validation can occur while the link is saturated.
1045-
// TODO(@divma): I have no idea what this comment is supposed to mean
1046-
if let Some(response) = self.send_off_path_path_response(now, buf, path_id) {
1047-
return Some(response);
1039+
if let Some(transmit) = self.poll_transmit_off_path(now, buf, path_id) {
1040+
return Some(transmit);
10481041
}
10491042

10501043
let mut space_id = match path_id {
@@ -1246,7 +1239,7 @@ impl Connection {
12461239
can_send.other,
12471240
self,
12481241
)?;
1249-
last_packet_number = Some(builder.exact_number);
1242+
last_packet_number = Some(builder.packet_number);
12501243
coalesce = coalesce && builder.can_coalesce;
12511244

12521245
if space_id == SpaceId::Initial && (self.side.is_client() || can_send.other) {
@@ -1314,7 +1307,7 @@ impl Connection {
13141307
if space_id == self.highest_space {
13151308
// Don't send another close packet. Even with multipath we only send
13161309
// CONNECTION_CLOSE on a single path since we expect our paths to work.
1317-
self.close = false;
1310+
self.connection_close_pending = false;
13181311
// `CONNECTION_CLOSE` is the final packet
13191312
break;
13201313
} else {
@@ -1409,8 +1402,11 @@ impl Connection {
14091402
} else {
14101403
builder.finish_and_track(now, self, path_id, pad_datagram);
14111404
}
1405+
1406+
// If this is the first datagram we set the segment size to the size of the
1407+
// first datagram.
14121408
if transmit.num_datagrams() == 1 {
1413-
transmit.clip_datagram_size();
1409+
transmit.clip_segment_size();
14141410
}
14151411
}
14161412
}
@@ -1508,6 +1504,15 @@ impl Connection {
15081504
return None;
15091505
}
15101506

1507+
Some(self.build_transmit(path_id, transmit))
1508+
}
1509+
1510+
fn build_transmit(&mut self, path_id: PathId, transmit: TransmitBuf<'_>) -> Transmit {
1511+
debug_assert!(
1512+
!transmit.is_empty(),
1513+
"must not be called with an empty transmit buffer"
1514+
);
1515+
15111516
let network_path = self.path_data(path_id).network_path;
15121517
trace!(
15131518
segment_size = transmit.segment_size(),
@@ -1529,7 +1534,7 @@ impl Connection {
15291534
.udp_tx
15301535
.on_sent(transmit.num_datagrams() as u64, transmit.len());
15311536

1532-
Some(Transmit {
1537+
Transmit {
15331538
destination: network_path.remote,
15341539
size: transmit.len(),
15351540
ecn: if self.path_data(path_id).sending_ecn {
@@ -1542,7 +1547,23 @@ impl Connection {
15421547
_ => Some(transmit.segment_size()),
15431548
},
15441549
src_ip: network_path.local_ip,
1545-
})
1550+
}
1551+
}
1552+
1553+
/// poll_transmit logic for off-path data.
1554+
fn poll_transmit_off_path(
1555+
&mut self,
1556+
now: Instant,
1557+
buf: &mut Vec<u8>,
1558+
path_id: PathId,
1559+
) -> Option<Transmit> {
1560+
if let Some(challenge) = self.send_prev_path_challenge(now, buf, path_id) {
1561+
return Some(challenge);
1562+
}
1563+
if let Some(response) = self.send_off_path_path_response(now, buf, path_id) {
1564+
return Some(response);
1565+
}
1566+
None
15461567
}
15471568

15481569
/// Returns the [`SpaceId`] of the next packet space which has data to send
@@ -1741,13 +1762,14 @@ impl Connection {
17411762
/// Indicate what types of frames are ready to send for the given space
17421763
///
17431764
/// *packet_size* is the number of bytes available to build the next packet.
1744-
/// *close* indicates whether a CONNECTION_CLOSE frame needs to be sent.
1765+
/// *connection_close_pending* indicates whether a CONNECTION_CLOSE frame needs to be
1766+
/// sent.
17451767
fn space_can_send(
17461768
&mut self,
17471769
space_id: SpaceId,
17481770
path_id: PathId,
17491771
packet_size: usize,
1750-
close: bool,
1772+
connection_close_pending: bool,
17511773
) -> SendableFrames {
17521774
let space = &mut self.spaces[space_id];
17531775
let space_has_crypto = space.crypto.is_some();
@@ -1771,7 +1793,7 @@ impl Connection {
17711793
can_send |= self.can_send_1rtt(path_id, frame_space_1rtt);
17721794
}
17731795

1774-
can_send.close = close && space_has_crypto;
1796+
can_send.close = connection_close_pending && space_has_crypto;
17751797

17761798
can_send
17771799
}
@@ -2107,7 +2129,7 @@ impl Connection {
21072129
if !was_closed {
21082130
self.close_common();
21092131
self.set_close_timer(now);
2110-
self.close = true;
2132+
self.connection_close_pending = true;
21112133
self.state.move_to_closed_local(reason);
21122134
}
21132135
}
@@ -3168,7 +3190,7 @@ impl Connection {
31683190
));
31693191
self.close_common();
31703192
self.set_close_timer(now);
3171-
self.close = true;
3193+
self.connection_close_pending = true;
31723194
}
31733195
return;
31743196
}
@@ -3815,7 +3837,7 @@ impl Connection {
38153837
.get(&path_id)
38163838
.map(|p| p.data.network_path)
38173839
.unwrap_or(network_path);
3818-
self.close = network_path == path_remote;
3840+
self.connection_close_pending = network_path == path_remote;
38193841
}
38203842
}
38213843

@@ -4889,7 +4911,7 @@ impl Connection {
48894911

48904912
if let Some(reason) = close {
48914913
self.state.move_to_draining(Some(reason.into()));
4892-
self.close = true;
4914+
self.connection_close_pending = true;
48934915
}
48944916

48954917
if Some(number) == self.spaces[SpaceId::Data].for_path(path_id).rx_packet
@@ -5085,7 +5107,7 @@ impl Connection {
50855107
path_exclusive_only: bool,
50865108
builder: &mut PacketBuilder<'a, 'b>,
50875109
) {
5088-
let pn = builder.exact_number;
5110+
let pn = builder.packet_number;
50895111
let is_multipath_negotiated = self.is_multipath_negotiated();
50905112
let stats = &mut self.stats.frame_tx;
50915113
let space = &mut self.spaces[space_id];

quinn-proto/src/connection/packet_builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(super) struct PacketBuilder<'a, 'b> {
2525
path: PathId,
2626
pub(super) partial_encode: PartialEncode,
2727
pub(super) ack_eliciting: bool,
28-
pub(super) exact_number: u64,
28+
pub(super) packet_number: u64,
2929
/// Is this packet allowed to be coalesced?
3030
pub(super) can_coalesce: bool,
3131
/// Smallest absolute position in the associated buffer that must be occupied by this packet's
@@ -93,11 +93,11 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
9393
}
9494

9595
let space = &mut conn.spaces[space_id];
96-
let exact_number = space.for_path(path_id).get_tx_number(&mut conn.rng);
97-
let span = trace_span!("send", space = ?space_id, pn = exact_number, %path_id).entered();
96+
let packet_number = space.for_path(path_id).get_tx_number(&mut conn.rng);
97+
let span = trace_span!("send", space = ?space_id, pn = packet_number, %path_id).entered();
9898

9999
let number = PacketNumber::new(
100-
exact_number,
100+
packet_number,
101101
space.for_path(path_id).largest_acked_packet.unwrap_or(0),
102102
);
103103
let header = match space_id {
@@ -171,7 +171,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
171171

172172
qlog.header(
173173
&header,
174-
Some(exact_number),
174+
Some(packet_number),
175175
space_id,
176176
space_id == SpaceId::Data && conn.spaces[SpaceId::Data].crypto.is_none(),
177177
path_id,
@@ -182,7 +182,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
182182
space: space_id,
183183
path: path_id,
184184
partial_encode,
185-
exact_number,
185+
packet_number,
186186
can_coalesce: header.can_coalesce(),
187187
min_size,
188188
tag_len,
@@ -201,7 +201,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
201201
path: PathId::ZERO,
202202
partial_encode: PartialEncode::no_header(),
203203
ack_eliciting: true,
204-
exact_number: 0,
204+
packet_number: 0,
205205
can_coalesce: true,
206206
min_size: 0,
207207
tag_len: 0,
@@ -291,7 +291,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
291291
PadDatagram::ToMinMtu => self.pad_to(MIN_INITIAL_SIZE),
292292
}
293293
let ack_eliciting = self.ack_eliciting;
294-
let exact_number = self.exact_number;
294+
let packet_number = self.packet_number;
295295
let space_id = self.space;
296296
let (size, padded, sent) = self.finish(conn, now);
297297

@@ -311,7 +311,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
311311
};
312312

313313
conn.paths.get_mut(&path_id).unwrap().data.sent(
314-
exact_number,
314+
packet_number,
315315
packet,
316316
conn.spaces[space_id].for_path(path_id),
317317
);
@@ -372,7 +372,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
372372
self.partial_encode.finish(
373373
packet_buf,
374374
header_crypto,
375-
Some((self.exact_number, self.path, packet_crypto)),
375+
Some((self.packet_number, self.path, packet_crypto)),
376376
);
377377

378378
let packet_len = self.buf.len() - encode_start;

quinn-proto/src/connection/transmit_buf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ impl<'a> TransmitBuf<'a> {
132132
self.num_datagrams += 1;
133133
}
134134

135-
/// Clips the datagram size to the current size
135+
/// Clips the segment size to the current size
136136
///
137137
/// Only valid for the first datagram, when the datagram might be smaller than the
138138
/// segment size. Needed before estimating the available space in the next datagram
139139
/// based on [`TransmitBuf::segment_size`].
140140
///
141141
/// Use [`TransmitBuf::start_new_datagram_with_size`] if you need to reduce the size of
142142
/// the last datagram in a batch.
143-
pub(super) fn clip_datagram_size(&mut self) {
143+
pub(super) fn clip_segment_size(&mut self) {
144144
debug_assert_eq!(self.num_datagrams, 1);
145145
if self.buf.len() < self.segment_size {
146146
trace!(

0 commit comments

Comments
 (0)