Skip to content

Commit cdd378e

Browse files
committed
refactor: Some much needed renaming of variables mostly
And collecting some functions together. Split off from #338.
1 parent 7706e5a commit cdd378e

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(),
@@ -970,7 +970,7 @@ impl Connection {
970970
StateType::Draining | StateType::Closed => {
971971
// self.close is only reset once the associated packet had been
972972
// encoded successfully
973-
if !self.close {
973+
if !self.connection_close_pending {
974974
self.app_limited = true;
975975
return None;
976976
}
@@ -979,7 +979,7 @@ impl Connection {
979979
_ => false,
980980
};
981981

982-
// Check whether we need to send an ACK_FREQUENCY frame
982+
// Schedule an ACK_FREQUENCY frame if a new one needs to be sent.
983983
if let Some(config) = &self.config.ack_frequency_config {
984984
let rtt = self
985985
.paths
@@ -1019,15 +1019,8 @@ impl Connection {
10191019
&& self.remote_cids.contains_key(id)
10201020
});
10211021

1022-
if let Some(challenge) = self.send_prev_path_challenge(now, buf, path_id) {
1023-
return Some(challenge);
1024-
}
1025-
1026-
// Send an off-path PATH_RESPONSE. Prioritized over on-path data to ensure that
1027-
// path validation can occur while the link is saturated.
1028-
// TODO(@divma): I have no idea what this comment is supposed to mean
1029-
if let Some(response) = self.send_off_path_path_response(now, buf, path_id) {
1030-
return Some(response);
1022+
if let Some(transmit) = self.poll_transmit_off_path(now, buf, path_id) {
1023+
return Some(transmit);
10311024
}
10321025

10331026
let mut space_id = match path_id {
@@ -1249,7 +1242,7 @@ impl Connection {
12491242
can_send.other,
12501243
self,
12511244
)?;
1252-
last_packet_number = Some(builder.exact_number);
1245+
last_packet_number = Some(builder.packet_number);
12531246
coalesce = coalesce && builder.can_coalesce;
12541247

12551248
if space_id == SpaceId::Initial && (self.side.is_client() || can_send.other) {
@@ -1317,7 +1310,7 @@ impl Connection {
13171310
if space_id == self.highest_space {
13181311
// Don't send another close packet. Even with multipath we only send
13191312
// CONNECTION_CLOSE on a single path since we expect our paths to work.
1320-
self.close = false;
1313+
self.connection_close_pending = false;
13211314
// `CONNECTION_CLOSE` is the final packet
13221315
break;
13231316
} else {
@@ -1412,8 +1405,11 @@ impl Connection {
14121405
} else {
14131406
builder.finish_and_track(now, self, path_id, pad_datagram);
14141407
}
1408+
1409+
// If this is the first datagram we set the segment size to the size of the
1410+
// first datagram.
14151411
if transmit.num_datagrams() == 1 {
1416-
transmit.clip_datagram_size();
1412+
transmit.clip_segment_size();
14171413
}
14181414
}
14191415
}
@@ -1511,6 +1507,15 @@ impl Connection {
15111507
return None;
15121508
}
15131509

1510+
Some(self.build_transmit(path_id, transmit))
1511+
}
1512+
1513+
fn build_transmit(&mut self, path_id: PathId, transmit: TransmitBuf<'_>) -> Transmit {
1514+
debug_assert!(
1515+
!transmit.is_empty(),
1516+
"must not be called with an empty transmit buffer"
1517+
);
1518+
15141519
let network_path = self.path_data(path_id).network_path;
15151520
trace!(
15161521
segment_size = transmit.segment_size(),
@@ -1532,7 +1537,7 @@ impl Connection {
15321537
.udp_tx
15331538
.on_sent(transmit.num_datagrams() as u64, transmit.len());
15341539

1535-
Some(Transmit {
1540+
Transmit {
15361541
destination: network_path.remote,
15371542
size: transmit.len(),
15381543
ecn: if self.path_data(path_id).sending_ecn {
@@ -1545,7 +1550,23 @@ impl Connection {
15451550
_ => Some(transmit.segment_size()),
15461551
},
15471552
src_ip: network_path.local_ip,
1548-
})
1553+
}
1554+
}
1555+
1556+
/// poll_transmit logic for off-path data.
1557+
fn poll_transmit_off_path(
1558+
&mut self,
1559+
now: Instant,
1560+
buf: &mut Vec<u8>,
1561+
path_id: PathId,
1562+
) -> Option<Transmit> {
1563+
if let Some(challenge) = self.send_prev_path_challenge(now, buf, path_id) {
1564+
return Some(challenge);
1565+
}
1566+
if let Some(response) = self.send_off_path_path_response(now, buf, path_id) {
1567+
return Some(response);
1568+
}
1569+
None
15491570
}
15501571

15511572
/// Returns the [`SpaceId`] of the next packet space which has data to send
@@ -1744,13 +1765,14 @@ impl Connection {
17441765
/// Indicate what types of frames are ready to send for the given space
17451766
///
17461767
/// *packet_size* is the number of bytes available to build the next packet.
1747-
/// *close* indicates whether a CONNECTION_CLOSE frame needs to be sent.
1768+
/// *connection_close_pending* indicates whether a CONNECTION_CLOSE frame needs to be
1769+
/// sent.
17481770
fn space_can_send(
17491771
&mut self,
17501772
space_id: SpaceId,
17511773
path_id: PathId,
17521774
packet_size: usize,
1753-
close: bool,
1775+
connection_close_pending: bool,
17541776
) -> SendableFrames {
17551777
let space = &mut self.spaces[space_id];
17561778
let space_has_crypto = space.crypto.is_some();
@@ -1774,7 +1796,7 @@ impl Connection {
17741796
can_send |= self.can_send_1rtt(path_id, frame_space_1rtt);
17751797
}
17761798

1777-
can_send.close = close && space_has_crypto;
1799+
can_send.close = connection_close_pending && space_has_crypto;
17781800

17791801
can_send
17801802
}
@@ -2109,7 +2131,7 @@ impl Connection {
21092131
if !was_closed {
21102132
self.close_common();
21112133
self.set_close_timer(now);
2112-
self.close = true;
2134+
self.connection_close_pending = true;
21132135
self.state.move_to_closed_local(reason);
21142136
}
21152137
}
@@ -3170,7 +3192,7 @@ impl Connection {
31703192
));
31713193
self.close_common();
31723194
self.set_close_timer(now);
3173-
self.close = true;
3195+
self.connection_close_pending = true;
31743196
}
31753197
return;
31763198
}
@@ -3817,7 +3839,7 @@ impl Connection {
38173839
.get(&path_id)
38183840
.map(|p| p.data.network_path)
38193841
.unwrap_or(network_path);
3820-
self.close = network_path == path_remote;
3842+
self.connection_close_pending = network_path == path_remote;
38213843
}
38223844
}
38233845

@@ -4891,7 +4913,7 @@ impl Connection {
48914913

48924914
if let Some(reason) = close {
48934915
self.state.move_to_draining(Some(reason.into()));
4894-
self.close = true;
4916+
self.connection_close_pending = true;
48954917
}
48964918

48974919
if Some(number) == self.spaces[SpaceId::Data].for_path(path_id).rx_packet
@@ -5087,7 +5109,7 @@ impl Connection {
50875109
path_exclusive_only: bool,
50885110
builder: &mut PacketBuilder<'a, 'b>,
50895111
) {
5090-
let pn = builder.exact_number;
5112+
let pn = builder.packet_number;
50915113
let is_multipath_negotiated = self.is_multipath_negotiated();
50925114
let stats = &mut self.stats.frame_tx;
50935115
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)