Skip to content

Commit 5eac310

Browse files
committed
Don't plumb current time through endpoint events
This was only needed to determine the base time for the next CID retirement timer, for which the marginal delay caused by fetching a new `Instant::now()` on demand is harmless.
1 parent 7723cbc commit 5eac310

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ impl Connection {
956956
/// Will execute protocol logic upon receipt of a connection event, in turn preparing signals
957957
/// (including application `Event`s, `EndpointEvent`s and outgoing datagrams) that should be
958958
/// extracted through the relevant methods.
959-
pub fn handle_event(&mut self, event: ConnectionEvent) {
959+
pub fn handle_event(&mut self, event: ConnectionEvent, now: Instant) {
960960
use self::ConnectionEventInner::*;
961961
match event.0 {
962962
Datagram {
@@ -1001,7 +1001,7 @@ impl Connection {
10011001
self.set_loss_detection_timer(now);
10021002
}
10031003
}
1004-
NewIdentifiers(ids, now) => {
1004+
NewIdentifiers(ids) => {
10051005
self.local_cid_state.new_cids(&ids, now);
10061006
ids.into_iter().rev().for_each(|frame| {
10071007
self.spaces[SpaceId::Data].pending.new_cids.push(frame);
@@ -1071,7 +1071,7 @@ impl Connection {
10711071
self.local_cid_state.retire_prior_to()
10721072
);
10731073
self.endpoint_events
1074-
.push_back(EndpointEventInner::NeedIdentifiers(now, num_new_cid));
1074+
.push_back(EndpointEventInner::NeedIdentifiers(num_new_cid));
10751075
}
10761076
}
10771077
Timer::MaxAckDelay => {
@@ -2354,7 +2354,7 @@ impl Connection {
23542354
.push_back(EndpointEventInner::ResetToken(self.path.remote, token));
23552355
}
23562356
self.handle_peer_params(params)?;
2357-
self.issue_first_cids(now);
2357+
self.issue_first_cids();
23582358
} else {
23592359
// Server-only
23602360
self.spaces[SpaceId::Data].pending.handshake_done = true;
@@ -2401,7 +2401,7 @@ impl Connection {
24012401
reason: "transport parameters missing".into(),
24022402
})?;
24032403
self.handle_peer_params(params)?;
2404-
self.issue_first_cids(now);
2404+
self.issue_first_cids();
24052405
self.init_0rtt();
24062406
}
24072407
Ok(())
@@ -2662,7 +2662,6 @@ impl Connection {
26622662
.on_cid_retirement(sequence, self.peer_params.issue_cids_limit())?;
26632663
self.endpoint_events
26642664
.push_back(EndpointEventInner::RetireConnectionId(
2665-
now,
26662665
sequence,
26672666
allow_more_cids,
26682667
));
@@ -2889,15 +2888,15 @@ impl Connection {
28892888
}
28902889

28912890
/// Issue an initial set of connection IDs to the peer upon connection
2892-
fn issue_first_cids(&mut self, now: Instant) {
2891+
fn issue_first_cids(&mut self) {
28932892
if self.local_cid_state.cid_len() == 0 {
28942893
return;
28952894
}
28962895

28972896
// Subtract 1 to account for the CID we supplied while handshaking
28982897
let n = self.peer_params.issue_cids_limit() - 1;
28992898
self.endpoint_events
2900-
.push_back(EndpointEventInner::NeedIdentifiers(now, n));
2899+
.push_back(EndpointEventInner::NeedIdentifiers(n));
29012900
}
29022901

29032902
fn populate_packet(
@@ -3372,10 +3371,10 @@ impl Connection {
33723371
/// Instruct the peer to replace previously issued CIDs by sending a NEW_CONNECTION_ID frame
33733372
/// with updated `retire_prior_to` field set to `v`
33743373
#[cfg(test)]
3375-
pub(crate) fn rotate_local_cid(&mut self, v: u64, now: Instant) {
3374+
pub(crate) fn rotate_local_cid(&mut self, v: u64) {
33763375
let n = self.local_cid_state.assign_retire_seq(v);
33773376
self.endpoint_events
3378-
.push_back(EndpointEventInner::NeedIdentifiers(now, n));
3377+
.push_back(EndpointEventInner::NeedIdentifiers(n));
33793378
}
33803379

33813380
/// Check the current active remote CID sequence

quinn-proto/src/endpoint.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl Endpoint {
8585
) -> Option<ConnectionEvent> {
8686
use EndpointEventInner::*;
8787
match event.0 {
88-
NeedIdentifiers(now, n) => {
89-
return Some(self.send_new_identifiers(now, ch, n));
88+
NeedIdentifiers(n) => {
89+
return Some(self.send_new_identifiers(ch, n));
9090
}
9191
ResetToken(remote, token) => {
9292
if let Some(old) = self.connections[ch].reset_token.replace((remote, token)) {
@@ -96,12 +96,12 @@ impl Endpoint {
9696
warn!("duplicate reset token");
9797
}
9898
}
99-
RetireConnectionId(now, seq, allow_more_cids) => {
99+
RetireConnectionId(seq, allow_more_cids) => {
100100
if let Some(cid) = self.connections[ch].loc_cids.remove(&seq) {
101101
trace!("peer retired CID {}: {}", seq, cid);
102102
self.index.retire(&cid);
103103
if allow_more_cids {
104-
return Some(self.send_new_identifiers(now, ch, 1));
104+
return Some(self.send_new_identifiers(ch, 1));
105105
}
106106
}
107107
}
@@ -362,12 +362,7 @@ impl Endpoint {
362362
Ok((ch, conn))
363363
}
364364

365-
fn send_new_identifiers(
366-
&mut self,
367-
now: Instant,
368-
ch: ConnectionHandle,
369-
num: u64,
370-
) -> ConnectionEvent {
365+
fn send_new_identifiers(&mut self, ch: ConnectionHandle, num: u64) -> ConnectionEvent {
371366
let mut ids = vec![];
372367
for _ in 0..num {
373368
let id = self.new_cid(ch);
@@ -381,7 +376,7 @@ impl Endpoint {
381376
reset_token: ResetToken::new(&*self.config.reset_key, &id),
382377
});
383378
}
384-
ConnectionEvent(ConnectionEventInner::NewIdentifiers(ids, now))
379+
ConnectionEvent(ConnectionEventInner::NewIdentifiers(ids))
385380
}
386381

387382
/// Generate a connection ID for `ch`

quinn-proto/src/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) enum ConnectionEventInner {
1919
remaining: Option<BytesMut>,
2020
},
2121
/// New connection identifiers have been issued for the Connection
22-
NewIdentifiers(Vec<IssuedCid>, Instant),
22+
NewIdentifiers(Vec<IssuedCid>),
2323
}
2424

2525
/// Events sent from a Connection to an Endpoint
@@ -50,10 +50,10 @@ pub(crate) enum EndpointEventInner {
5050
/// The reset token and/or address eligible for generating resets has been updated
5151
ResetToken(SocketAddr, ResetToken),
5252
/// The connection needs connection identifiers
53-
NeedIdentifiers(Instant, u64),
53+
NeedIdentifiers(u64),
5454
/// Stop routing connection ID for this sequence number to the connection
5555
/// When `bool == true`, a new connection ID will be issued to peer
56-
RetireConnectionId(Instant, u64, bool),
56+
RetireConnectionId(u64, bool),
5757
}
5858

5959
/// Protocol-level identifier for a connection.

quinn-proto/src/tests/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn version_negotiate_client() {
9191
&mut buf,
9292
);
9393
if let Some(DatagramEvent::ConnectionEvent(_, event)) = opt_event {
94-
client_ch.handle_event(event);
94+
client_ch.handle_event(event, now);
9595
}
9696
assert_matches!(
9797
client_ch.poll(),
@@ -1406,8 +1406,7 @@ fn cid_retirement() {
14061406
let (client_ch, server_ch) = pair.connect();
14071407

14081408
// Server retires current active remote CIDs
1409-
pair.server_conn_mut(server_ch)
1410-
.rotate_local_cid(1, Instant::now());
1409+
pair.server_conn_mut(server_ch).rotate_local_cid(1);
14111410
pair.drive();
14121411
// Any unexpected behavior may trigger TransportError::CONNECTION_ID_LIMIT_ERROR
14131412
assert!(!pair.client_conn_mut(client_ch).is_closed());
@@ -1423,7 +1422,7 @@ fn cid_retirement() {
14231422
pair.client_conn_mut(client_ch).ping();
14241423
// Server retires all valid remote CIDs
14251424
pair.server_conn_mut(server_ch)
1426-
.rotate_local_cid(next_retire_prior_to, Instant::now());
1425+
.rotate_local_cid(next_retire_prior_to);
14271426
pair.drive();
14281427
assert!(!pair.client_conn_mut(client_ch).is_closed());
14291428
assert!(!pair.server_conn_mut(server_ch).is_closed());

quinn-proto/src/tests/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl TestEndpoint {
371371

372372
for (_, mut events) in self.conn_events.drain() {
373373
for event in events.drain(..) {
374-
conn.handle_event(event);
374+
conn.handle_event(event, now);
375375
}
376376
}
377377

@@ -393,7 +393,7 @@ impl TestEndpoint {
393393
for (ch, event) in endpoint_events {
394394
if let Some(event) = self.handle_event(ch, event) {
395395
if let Some(conn) = self.connections.get_mut(&ch) {
396-
conn.handle_event(event);
396+
conn.handle_event(event, now);
397397
}
398398
}
399399
}

quinn/src/connection.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,14 @@ impl State {
913913
shared: &Shared,
914914
cx: &mut Context,
915915
) -> Result<(), ConnectionError> {
916+
let now = Instant::now();
916917
loop {
917918
match self.conn_events.poll_recv(cx) {
918919
Poll::Ready(Some(ConnectionEvent::Ping)) => {
919920
self.inner.ping();
920921
}
921922
Poll::Ready(Some(ConnectionEvent::Proto(event))) => {
922-
self.inner.handle_event(event);
923+
self.inner.handle_event(event, now);
923924
}
924925
Poll::Ready(Some(ConnectionEvent::Close { reason, error_code })) => {
925926
self.close(error_code, reason, shared);

0 commit comments

Comments
 (0)