From 880ce4b18f3b9439a64b5e772a65a055cf6a4fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diva=20Mart=C3=ADnez?= Date: Tue, 14 Oct 2025 16:40:53 -0500 Subject: [PATCH 1/4] use PathId::ZERO whenever possible --- quinn-proto/src/connection/mod.rs | 78 ++++++++++---------- quinn-proto/src/connection/packet_builder.rs | 2 +- quinn-proto/src/connection/spaces.rs | 8 +- quinn-proto/src/endpoint.rs | 24 +++--- quinn-proto/src/packet.rs | 4 +- quinn-proto/src/tests/mod.rs | 2 +- quinn-proto/src/tests/multipath.rs | 6 +- 7 files changed, 62 insertions(+), 62 deletions(-) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index c7a5fcde21..3979e9277f 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -343,7 +343,7 @@ impl Connection { allow_server_migration: side.is_client(), }); let local_cid_state = FxHashMap::from_iter([( - PathId(0), + PathId::ZERO, CidState::new( cid_gen.cid_len(), cid_gen.cid_lifetime(), @@ -362,7 +362,7 @@ impl Connection { rem_handshake_cid: rem_cid, local_cid_state, paths: BTreeMap::from_iter([( - PathId(0), + PathId::ZERO, PathState { data: path, prev: None, @@ -426,7 +426,7 @@ impl Connection { ), datagrams: DatagramState::default(), config, - rem_cids: FxHashMap::from_iter([(PathId(0), CidQueue::new(rem_cid))]), + rem_cids: FxHashMap::from_iter([(PathId::ZERO, CidQueue::new(rem_cid))]), rng, stats: ConnectionStats::default(), version, @@ -439,7 +439,7 @@ impl Connection { abandoned_paths: Default::default(), }; if path_validated { - this.on_path_validated(PathId(0)); + this.on_path_validated(PathId::ZERO); } if side.is_client() { // Kick off the connection @@ -920,7 +920,7 @@ impl Connection { return Some(challenge); } let mut space_id = match path_id { - PathId(0) => SpaceId::Initial, + PathId::ZERO => SpaceId::Initial, _ => SpaceId::Data, }; @@ -1159,7 +1159,7 @@ impl Connection { { debug_assert!( is_multipath_enabled || path_id == PathId::ZERO, - "Only PathId(0) allowed without multipath (have {path_id:?})" + "Only PathId::ZERO allowed without multipath (have {path_id:?})" ); Self::populate_acks( now, @@ -2039,13 +2039,13 @@ impl Connection { pub fn rtt(&self) -> Duration { // this should return at worst the same that the poll_transmit logic would use // TODO(@divma): wrong - self.path_data(PathId(0)).rtt.get() + self.path_data(PathId::ZERO).rtt.get() } /// Current state of this connection's congestion controller, for debugging purposes pub fn congestion_state(&self) -> &dyn Controller { // TODO(@divma): same as everything, wrong - self.path_data(PathId(0)).congestion.as_ref() + self.path_data(PathId::ZERO).congestion.as_ref() } /// Resets path-specific settings. @@ -2062,7 +2062,7 @@ impl Connection { // TODO(@divma): evaluate how this is used // wrong call in the multipath case anyhow self.paths - .get_mut(&PathId(0)) + .get_mut(&PathId::ZERO) .expect("this might fail") .data .reset(now, &self.config); @@ -3018,7 +3018,7 @@ impl Connection { let _guard = span.enter(); debug_assert!(self.side.is_server()); let len = packet.header_data.len() + packet.payload.len(); - let path_id = PathId(0); + let path_id = PathId::ZERO; self.path_data_mut(path_id).total_recvd = len as u64; match self.state { @@ -3028,7 +3028,7 @@ impl Connection { _ => unreachable!("first packet must be delivered in Handshake state"), } - // The first packet is always on PathId(0) + // The first packet is always on PathId::ZERO self.on_packet_authenticated( now, SpaceId::Initial, @@ -3529,7 +3529,7 @@ impl Connection { Header::Retry { src_cid: rem_cid, .. } => { - debug_assert_eq!(path_id, PathId(0)); + debug_assert_eq!(path_id, PathId::ZERO); if self.side.is_server() { return Err(TransportError::PROTOCOL_VIOLATION("client sent Retry").into()); } @@ -3566,13 +3566,13 @@ impl Connection { self.retry_src_cid = Some(rem_cid); self.rem_cids .get_mut(&path_id) - .expect("PathId(0) not yet abandoned, is_valid_retry would have been false") + .expect("PathId::ZERO not yet abandoned, is_valid_retry would have been false") .update_initial_cid(rem_cid); self.rem_handshake_cid = rem_cid; let space = &mut self.spaces[SpaceId::Initial]; - if let Some(info) = space.for_path(PathId(0)).take(0) { - self.on_packet_acked(now, PathId(0), info); + if let Some(info) = space.for_path(PathId::ZERO).take(0) { + self.on_packet_acked(now, PathId::ZERO, info); }; self.discard_space(now, SpaceId::Initial); // Make sure we clean up after @@ -3593,7 +3593,7 @@ impl Connection { // Retransmit all 0-RTT data let zero_rtt = - mem::take(&mut self.spaces[SpaceId::Data].for_path(PathId(0)).sent_packets); + mem::take(&mut self.spaces[SpaceId::Data].for_path(PathId::ZERO).sent_packets); for info in zero_rtt.into_values() { self.paths .get_mut(&PathId::ZERO) @@ -3623,7 +3623,7 @@ impl Connection { dst_cid: loc_cid, .. } => { - debug_assert_eq!(path_id, PathId(0)); + debug_assert_eq!(path_id, PathId::ZERO); if rem_cid != self.rem_handshake_cid { debug!( "discarding packet with mismatched remote CID: {} != {}", @@ -3706,13 +3706,13 @@ impl Connection { dst_cid: loc_cid, .. }) => { - debug_assert_eq!(path_id, PathId(0)); + debug_assert_eq!(path_id, PathId::ZERO); if !state.rem_cid_set { trace!("switching remote CID to {}", rem_cid); let mut state = state.clone(); self.rem_cids .get_mut(&path_id) - .expect("PathId(0) not yet abandoned") + .expect("PathId::ZERO not yet abandoned") .update_initial_cid(rem_cid); self.rem_handshake_cid = rem_cid; self.orig_rem_cid = rem_cid; @@ -3785,7 +3785,7 @@ impl Connection { packet: Packet, ) -> Result<(), TransportError> { debug_assert_ne!(packet.header.space(), SpaceId::Data); - debug_assert_eq!(path_id, PathId(0)); + debug_assert_eq!(path_id, PathId::ZERO); let payload_len = packet.payload.len(); let mut ack_eliciting = false; for result in frame::Iter::new(packet.payload.freeze())? { @@ -4461,7 +4461,7 @@ impl Connection { /// Handle a change in the local address, i.e. an active migration pub fn local_address_changed(&mut self) { // TODO(flub): if multipath is enabled this needs to create a new path entirely. - self.update_rem_cid(PathId(0)); + self.update_rem_cid(PathId::ZERO); self.ping(); } @@ -4508,8 +4508,8 @@ impl Connection { fn issue_first_cids(&mut self, now: Instant) { if self .local_cid_state - .get(&PathId(0)) - .expect("PathId(0) exists when the connection is created") + .get(&PathId::ZERO) + .expect("PathId::ZERO exists when the connection is created") .cid_len() == 0 { @@ -4525,7 +4525,7 @@ impl Connection { } } self.endpoint_events - .push_back(EndpointEventInner::NeedIdentifiers(PathId(0), now, n)); + .push_back(EndpointEventInner::NeedIdentifiers(PathId::ZERO, now, n)); } /// Issues an initial set of CIDs for paths that have not yet had any CIDs issued @@ -4633,7 +4633,7 @@ impl Connection { { debug_assert!( is_multipath_negotiated || path_id == PathId::ZERO, - "Only PathId(0) allowed without multipath (have {path_id:?})" + "Only PathId::ZERO allowed without multipath (have {path_id:?})" ); Self::populate_acks( now, @@ -4955,7 +4955,7 @@ impl Connection { id = %issued.id, "NEW_CONNECTION_ID" ); - debug_assert_eq!(issued.path_id, PathId(0)); + debug_assert_eq!(issued.path_id, PathId::ZERO); self.stats.frame_tx.new_connection_id += 1; None } @@ -4975,7 +4975,7 @@ impl Connection { let retire_cid_bound = frame::RetireConnectionId::size_bound(is_multipath_negotiated); while !path_exclusive_only && buf.remaining_mut() > retire_cid_bound { let (path_id, sequence) = match space.pending.retire_cids.pop() { - Some((PathId(0), seq)) if !is_multipath_negotiated => { + Some((PathId::ZERO, seq)) if !is_multipath_negotiated => { trace!(sequence = seq, "RETIRE_CONNECTION_ID"); self.stats.frame_tx.retire_connection_id += 1; (None, seq) @@ -5165,7 +5165,7 @@ impl Connection { trace!("negotiated max idle timeout {:?}", self.idle_timeout); if let Some(ref info) = params.preferred_address { - // During the handshake PathId(0) exists. + // During the handshake PathId::ZERO exists. self.rem_cids.get_mut(&PathId::ZERO).expect("not yet abandoned").insert(frame::NewConnectionId { path_id: None, sequence: 1, @@ -5327,13 +5327,13 @@ impl Connection { #[cfg(test)] pub(crate) fn bytes_in_flight(&self) -> u64 { // TODO(@divma): consider including for multipath? - self.path_data(PathId(0)).in_flight.bytes + self.path_data(PathId::ZERO).in_flight.bytes } /// Number of bytes worth of non-ack-only packets that may be sent #[cfg(test)] pub(crate) fn congestion_window(&self) -> u64 { - let path = self.path_data(PathId(0)); + let path = self.path_data(PathId::ZERO); path.congestion .window() .saturating_sub(path.in_flight.bytes) @@ -5361,18 +5361,18 @@ impl Connection { /// Whether explicit congestion notification is in use on outgoing packets. #[cfg(test)] pub(crate) fn using_ecn(&self) -> bool { - self.path_data(PathId(0)).sending_ecn + self.path_data(PathId::ZERO).sending_ecn } /// The number of received bytes in the current path #[cfg(test)] pub(crate) fn total_recvd(&self) -> u64 { - self.path_data(PathId(0)).total_recvd + self.path_data(PathId::ZERO).total_recvd } #[cfg(test)] pub(crate) fn active_local_cid_seq(&self) -> (u64, u64) { - self.local_cid_state.get(&PathId(0)).unwrap().active_seq() + self.local_cid_state.get(&PathId::ZERO).unwrap().active_seq() } #[cfg(test)] @@ -5390,23 +5390,23 @@ impl Connection { pub(crate) fn rotate_local_cid(&mut self, v: u64, now: Instant) { let n = self .local_cid_state - .get_mut(&PathId(0)) + .get_mut(&PathId::ZERO) .unwrap() .assign_retire_seq(v); self.endpoint_events - .push_back(EndpointEventInner::NeedIdentifiers(PathId(0), now, n)); + .push_back(EndpointEventInner::NeedIdentifiers(PathId::ZERO, now, n)); } - /// Check the current active remote CID sequence for `PathId(0)` + /// Check the current active remote CID sequence for `PathId::ZERO` #[cfg(test)] pub(crate) fn active_rem_cid_seq(&self) -> u64 { - self.rem_cids.get(&PathId(0)).unwrap().active_seq() + self.rem_cids.get(&PathId::ZERO).unwrap().active_seq() } /// Returns the detected maximum udp payload size for the current path #[cfg(test)] pub(crate) fn path_mtu(&self) -> u16 { - self.path_data(PathId(0)).current_mtu() + self.path_data(PathId::ZERO).current_mtu() } /// Whether we have 1-RTT data to send @@ -5455,7 +5455,7 @@ impl Connection { /// Buffers passed to [`Connection::poll_transmit`] should be at least this large. pub fn current_mtu(&self) -> u16 { // TODO(@divma): fix - self.path_data(PathId(0)).current_mtu() + self.path_data(PathId::ZERO).current_mtu() } /// Size of non-frame data for a 1-RTT packet diff --git a/quinn-proto/src/connection/packet_builder.rs b/quinn-proto/src/connection/packet_builder.rs index 186cea9c15..ca91925630 100644 --- a/quinn-proto/src/connection/packet_builder.rs +++ b/quinn-proto/src/connection/packet_builder.rs @@ -284,7 +284,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> { self.buf.put_bytes(0, packet_crypto.tag_len()); let encode_start = self.partial_encode.start; let packet_buf = &mut self.buf.as_mut_slice()[encode_start..]; - // for packet protection, PathId(0) and no path are equivalent. + // for packet protection, PathId::ZERO and no path are equivalent. self.partial_encode.finish( packet_buf, header_crypto, diff --git a/quinn-proto/src/connection/spaces.rs b/quinn-proto/src/connection/spaces.rs index b5ec9f882b..96b91118ed 100644 --- a/quinn-proto/src/connection/spaces.rs +++ b/quinn-proto/src/connection/spaces.rs @@ -33,7 +33,7 @@ pub(super) struct PacketSpace { /// /// Each [`PathId`] has it's own [`PacketNumberSpace`]. Only the [`SpaceId::Data`] can /// have multiple packet number spaces, the other spaces only have a number space for - /// `PathId(0)`, which is populated at creation. + /// `PathId::ZERO`, which is populated at creation. pub(super) number_spaces: BTreeMap, } @@ -46,7 +46,7 @@ impl PacketSpace { pending: Retransmits::default(), crypto_stream: Assembler::new(), crypto_offset: 0, - number_spaces: BTreeMap::from([(PathId(0), number_space_0)]), + number_spaces: BTreeMap::from([(PathId::ZERO, number_space_0)]), } } @@ -59,7 +59,7 @@ impl PacketSpace { pending: Retransmits::default(), crypto_stream: Assembler::new(), crypto_offset: 0, - number_spaces: BTreeMap::from([(PathId(0), number_space_0)]), + number_spaces: BTreeMap::from([(PathId::ZERO, number_space_0)]), } } @@ -79,7 +79,7 @@ impl PacketSpace { /// Returns the [`PacketNumberSpace`] for a path /// - /// When multipath is disabled use `PathId(0)`. + /// When multipath is disabled use `PathId::ZERO`. // TODO(flub): Note that this only exists as `&mut self` because it creates a new // [`PacketNumberSpace`] if one is not yet available for a path. This forces a few // more `&mut` references to users than strictly needed. An alternative would be to diff --git a/quinn-proto/src/endpoint.rs b/quinn-proto/src/endpoint.rs index 543962396a..4518a37794 100644 --- a/quinn-proto/src/endpoint.rs +++ b/quinn-proto/src/endpoint.rs @@ -169,7 +169,7 @@ impl Endpoint { Ok((first_decode, remaining)) => DatagramConnectionEvent { now, remote, - path_id: PathId(0), // Corrected later for existing paths + path_id: PathId::ZERO, // Corrected later for existing paths ecn, first_decode, remaining, @@ -218,7 +218,7 @@ impl Endpoint { if let Some(route_to) = self.index.get(&addresses, &event.first_decode) { event.path_id = match route_to { - RouteDatagramTo::Incoming(_) => PathId(0), + RouteDatagramTo::Incoming(_) => PathId::ZERO, RouteDatagramTo::Connection(_, path_id) => path_id, }; match route_to { @@ -358,7 +358,7 @@ impl Endpoint { trace!(initial_dcid = %remote_id); let ch = ConnectionHandle(self.connections.vacant_key()); - let loc_cid = self.new_cid(ch, PathId(0)); + let loc_cid = self.new_cid(ch, PathId::ZERO); let params = TransportParameters::new( &config.transport, &self.config, @@ -600,7 +600,7 @@ impl Endpoint { .packet .remote .decrypt( - PathId(0), + PathId::ZERO, packet_number, &incoming.packet.header_data, &mut incoming.packet.payload, @@ -616,7 +616,7 @@ impl Endpoint { }; let ch = ConnectionHandle(self.connections.vacant_key()); - let loc_cid = self.new_cid(ch, PathId(0)); + let loc_cid = self.new_cid(ch, PathId::ZERO); let mut params = TransportParameters::new( &server_config.transport, &self.config, @@ -855,7 +855,7 @@ impl Endpoint { let id = self.connections.insert(ConnectionMeta { init_cid, - loc_cids: FxHashMap::from_iter([(PathId(0), path_cids)]), + loc_cids: FxHashMap::from_iter([(PathId::ZERO, path_cids)]), addresses, side, reset_token: Default::default(), @@ -1044,7 +1044,7 @@ impl ConnectionIndex { return; } self.connection_ids_initial - .insert(dst_cid, RouteDatagramTo::Connection(connection, PathId(0))); + .insert(dst_cid, RouteDatagramTo::Connection(connection, PathId::ZERO)); } /// Associate a connection with its first locally-chosen destination CID if used, or otherwise @@ -1068,7 +1068,7 @@ impl ConnectionIndex { } }, _ => { - self.connection_ids.insert(dst_cid, (connection, PathId(0))); + self.connection_ids.insert(dst_cid, (connection, PathId::ZERO)); } } } @@ -1109,12 +1109,12 @@ impl ConnectionIndex { if datagram.dst_cid().is_empty() { if let Some(&ch) = self.incoming_connection_remotes.get(addresses) { // Never multipath because QUIC-MULTIPATH 1.1 mandates the use of non-zero - // length CIDs. So this is always PathId(0). - return Some(RouteDatagramTo::Connection(ch, PathId(0))); + // length CIDs. So this is always PathId::ZERO. + return Some(RouteDatagramTo::Connection(ch, PathId::ZERO)); } if let Some(&ch) = self.outgoing_connection_remotes.get(&addresses.remote) { // Like above, QUIC-MULTIPATH 1.1 mandates the use of non-zero length CIDs. - return Some(RouteDatagramTo::Connection(ch, PathId(0))); + return Some(RouteDatagramTo::Connection(ch, PathId::ZERO)); } } let data = datagram.data(); @@ -1122,7 +1122,7 @@ impl ConnectionIndex { return None; } // For stateless resets the PathId is meaningless since it closes the entire - // connection regarldess of path. So use PathId(0). + // connection regarldess of path. So use PathId::ZERO. self.connection_reset_tokens .get(addresses.remote, &data[data.len() - RESET_TOKEN_SIZE..]) .cloned() diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index 1d6dba25b5..28b925742d 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -993,7 +993,7 @@ mod tests { encode.finish( &mut buf, &*client.header.local, - Some((0, PathId(0), &*client.packet.local)), + Some((0, PathId::ZERO, &*client.packet.local)), ); for byte in &buf { @@ -1026,7 +1026,7 @@ mod tests { server .packet .remote - .decrypt(PathId(0), 0, &packet.header_data, &mut packet.payload) + .decrypt(PathId::ZERO, 0, &packet.header_data, &mut packet.payload) .unwrap(); assert_eq!(packet.payload[..], [0; 16]); match packet.header { diff --git a/quinn-proto/src/tests/mod.rs b/quinn-proto/src/tests/mod.rs index 68296afb18..73d4220947 100644 --- a/quinn-proto/src/tests/mod.rs +++ b/quinn-proto/src/tests/mod.rs @@ -2682,7 +2682,7 @@ fn immediate_ack_triggers_ack() { let acks_after_connect = pair.client_conn_mut(client_ch).stats().frame_rx.acks; - pair.client_conn_mut(client_ch).immediate_ack(PathId(0)); + pair.client_conn_mut(client_ch).immediate_ack(PathId::ZERO); pair.drive_client(); // Send immediate ack pair.drive_server(); // Process immediate ack pair.drive_client(); // Give the client a chance to process the ack diff --git a/quinn-proto/src/tests/multipath.rs b/quinn-proto/src/tests/multipath.rs index 0d770ca8c4..e269e9e3a2 100644 --- a/quinn-proto/src/tests/multipath.rs +++ b/quinn-proto/src/tests/multipath.rs @@ -263,10 +263,10 @@ fn multipath_cid_rotation() { let stats = pair.server_conn_mut(server_ch).stats(); - // Server sends CIDs for PathId(0) before multipath is negotiated. + // Server sends CIDs for PathId::ZERO before multipath is negotiated. assert_eq!(stats.frame_tx.new_connection_id, (CidQueue::LEN - 1) as u64); - // For the first batch the PathId(0) CIDs have already been sent. + // For the first batch the PathId::ZERO CIDs have already been sent. let initial_batch: u64 = (MAX_PATHS - 1) as u64 * CidQueue::LEN as u64; // Each round expires all CIDs, so they all get re-issued. let each_round: u64 = MAX_PATHS as u64 * CidQueue::LEN as u64; @@ -338,7 +338,7 @@ fn issue_max_path_id() { assert_eq!(stats.frame_tx.new_connection_id, server_new_cids); assert_eq!(stats.frame_tx.path_new_connection_id, server_path_new_cids); - // Client should have sent PATH_NEW_CONNECTION_ID frames for PathId(0). + // Client should have sent PATH_NEW_CONNECTION_ID frames for PathId::ZERO. let client_new_cids = 0; let mut client_path_new_cids = CidQueue::LEN as u64; assert_eq!(stats.frame_rx.new_connection_id, client_new_cids); From c4334ad20339db90ff2011273a65f773bdeda1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diva=20Mart=C3=ADnez?= Date: Wed, 15 Oct 2025 11:05:34 -0500 Subject: [PATCH 2/4] avoid accesing PathId's inner in general --- quinn-proto/src/connection/mod.rs | 18 +++++++++++------- quinn-proto/src/connection/paths.rs | 11 ++++++++++- quinn-proto/src/crypto/rustls.rs | 8 ++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 3979e9277f..6b325a8107 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -2099,8 +2099,11 @@ impl Connection { } self.max_concurrent_paths = count; - let in_use_count = - (self.local_max_path_id.0 + 1).saturating_sub(self.abandoned_paths.len() as u32); + let in_use_count = self + .local_max_path_id + .next() + .saturating_sub(self.abandoned_paths.len() as u32) + .as_u32(); let extra_needed = count.get().saturating_sub(in_use_count); let new_max_path_id = self.local_max_path_id.saturating_add(extra_needed); @@ -4532,17 +4535,18 @@ impl Connection { /// /// Later CIDs are issued when CIDs expire or are retired by the peer. fn issue_first_path_cids(&mut self, now: Instant) { - if let Some(PathId(max_path_id)) = self.max_path_id() { - let start_path_id = self.max_path_id_with_cids.0 + 1; - for n in start_path_id..=max_path_id { + if let Some(max_path_id) = self.max_path_id() { + let mut path_id = self.max_path_id_with_cids.next(); + while path_id <= max_path_id { self.endpoint_events .push_back(EndpointEventInner::NeedIdentifiers( - PathId(n), + path_id, now, self.peer_params.issue_cids_limit(), )); + path_id = path_id.next(); } - self.max_path_id_with_cids = PathId(max_path_id); + self.max_path_id_with_cids = max_path_id; } } diff --git a/quinn-proto/src/connection/paths.rs b/quinn-proto/src/connection/paths.rs index 530f89b3d7..4afd9fd62a 100644 --- a/quinn-proto/src/connection/paths.rs +++ b/quinn-proto/src/connection/paths.rs @@ -18,7 +18,6 @@ use crate::{ use qlog::events::quic::MetricsUpdated; /// Id representing different paths when using multipath extension -// TODO(@divma): improve docs, reconsider access to inner #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] pub struct PathId(pub(crate) u32); @@ -61,6 +60,16 @@ impl PathId { let inner = self.0.saturating_sub(rhs.0); Self(inner) } + + /// Get the next [`PathId`] + pub(crate) fn next(&self) -> Self { + self.saturating_add(Self(1)) + } + + /// Get the underlying u32 + pub(crate) fn as_u32(&self) -> u32 { + self.0 + } } impl std::fmt::Display for PathId { diff --git a/quinn-proto/src/crypto/rustls.rs b/quinn-proto/src/crypto/rustls.rs index 5ffa3be5e2..4fd9d7ad85 100644 --- a/quinn-proto/src/crypto/rustls.rs +++ b/quinn-proto/src/crypto/rustls.rs @@ -602,24 +602,24 @@ pub(crate) fn initial_keys( } impl crypto::PacketKey for Box { - fn encrypt(&self, PathId(path_id): PathId, packet: u64, buf: &mut [u8], header_len: usize) { + fn encrypt(&self, path_id: PathId, packet: u64, buf: &mut [u8], header_len: usize) { let (header, payload_tag) = buf.split_at_mut(header_len); let (payload, tag_storage) = payload_tag.split_at_mut(payload_tag.len() - self.tag_len()); let tag = self - .encrypt_in_place_for_path(path_id, packet, &*header, payload) + .encrypt_in_place_for_path(path_id.as_u32(), packet, &*header, payload) .unwrap(); tag_storage.copy_from_slice(tag.as_ref()); } fn decrypt( &self, - PathId(path_id): PathId, + path_id: PathId, packet: u64, header: &[u8], payload: &mut BytesMut, ) -> Result<(), CryptoError> { let plain = self - .decrypt_in_place_for_path(path_id, packet, header, payload.as_mut()) + .decrypt_in_place_for_path(path_id.as_u32(), packet, header, payload.as_mut()) .map_err(|_| CryptoError)?; let plain_len = plain.len(); payload.truncate(plain_len); From 21fc3fb09c20aeccfc84a40558d71b98e95d49cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diva=20Mart=C3=ADnez?= Date: Wed, 15 Oct 2025 11:05:47 -0500 Subject: [PATCH 3/4] fmt --- quinn-proto/src/connection/mod.rs | 12 +++++++++--- quinn-proto/src/endpoint.rs | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 6b325a8107..ecaa336bb4 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -3595,8 +3595,11 @@ impl Connection { }; // Retransmit all 0-RTT data - let zero_rtt = - mem::take(&mut self.spaces[SpaceId::Data].for_path(PathId::ZERO).sent_packets); + let zero_rtt = mem::take( + &mut self.spaces[SpaceId::Data] + .for_path(PathId::ZERO) + .sent_packets, + ); for info in zero_rtt.into_values() { self.paths .get_mut(&PathId::ZERO) @@ -5376,7 +5379,10 @@ impl Connection { #[cfg(test)] pub(crate) fn active_local_cid_seq(&self) -> (u64, u64) { - self.local_cid_state.get(&PathId::ZERO).unwrap().active_seq() + self.local_cid_state + .get(&PathId::ZERO) + .unwrap() + .active_seq() } #[cfg(test)] diff --git a/quinn-proto/src/endpoint.rs b/quinn-proto/src/endpoint.rs index 4518a37794..0a42622022 100644 --- a/quinn-proto/src/endpoint.rs +++ b/quinn-proto/src/endpoint.rs @@ -1043,8 +1043,10 @@ impl ConnectionIndex { if dst_cid.is_empty() { return; } - self.connection_ids_initial - .insert(dst_cid, RouteDatagramTo::Connection(connection, PathId::ZERO)); + self.connection_ids_initial.insert( + dst_cid, + RouteDatagramTo::Connection(connection, PathId::ZERO), + ); } /// Associate a connection with its first locally-chosen destination CID if used, or otherwise @@ -1068,7 +1070,8 @@ impl ConnectionIndex { } }, _ => { - self.connection_ids.insert(dst_cid, (connection, PathId::ZERO)); + self.connection_ids + .insert(dst_cid, (connection, PathId::ZERO)); } } } From 632e55f23d59103b16ea5f24bbcbe9f9824d5632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diva=20Mart=C3=ADnez?= Date: Wed, 15 Oct 2025 11:13:05 -0500 Subject: [PATCH 4/4] prefer PathId::MAX over max construction --- quinn-proto/src/frame.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quinn-proto/src/frame.rs b/quinn-proto/src/frame.rs index 604058d5bd..485870ce78 100644 --- a/quinn-proto/src/frame.rs +++ b/quinn-proto/src/frame.rs @@ -1504,7 +1504,7 @@ mod test { ect1: 24, ce: 12, }; - const PATH_ID: PathId = PathId(u32::MAX); + const PATH_ID: PathId = PathId::MAX; PathAck::encode(PATH_ID, 42, &ranges, Some(&ECN), &mut buf); let frames = frames(buf); assert_eq!(frames.len(), 1);