Skip to content

Commit f5485c2

Browse files
some fixes for PathId as a transport param
1 parent 969ece9 commit f5485c2

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

quinn-proto/src/config/transport.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{fmt, sync::Arc};
22

33
use crate::{
4-
address_discovery, congestion, Duration, VarInt, VarIntBoundsExceeded, INITIAL_MTU,
5-
MAX_UDP_PAYLOAD,
4+
address_discovery, congestion, connection::PathId, Duration, VarInt, VarIntBoundsExceeded,
5+
INITIAL_MTU, MAX_UDP_PAYLOAD,
66
};
77

88
/// Parameters governing the core QUIC state machine
@@ -48,7 +48,7 @@ pub struct TransportConfig {
4848
pub(crate) enable_segmentation_offload: bool,
4949

5050
pub(crate) address_discovery_role: address_discovery::Role,
51-
pub(crate) initial_max_path_id: Option<VarInt>,
51+
pub(crate) initial_max_path_id: Option<PathId>,
5252
}
5353

5454
impl TransportConfig {
@@ -344,7 +344,7 @@ impl TransportConfig {
344344

345345
/// DOCS :D
346346
// TODO(@divma): decent docs, talk about multipath, reference draft.
347-
pub fn initial_max_path_id(&mut self, value: Option<VarInt>) -> &mut Self {
347+
pub fn initial_max_path_id(&mut self, value: Option<PathId>) -> &mut Self {
348348
self.initial_max_path_id = value;
349349
self
350350
}

quinn-proto/src/connection/paths.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ impl coding::Codec for PathId {
3131
}
3232
}
3333

34+
impl PathId {
35+
pub const MAX: Self = PathId(u32::MAX);
36+
37+
pub(crate) fn size(&self) -> usize {
38+
VarInt(self.0 as u64).size()
39+
}
40+
}
41+
42+
impl std::fmt::Display for PathId {
43+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44+
self.0.fmt(f)
45+
}
46+
}
47+
3448
/// Description of a particular network path
3549
pub(super) struct PathData {
3650
pub(super) remote: SocketAddr,

quinn-proto/src/transport_parameters.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
cid_queue::CidQueue,
2222
coding::{BufExt, BufMutExt, UnexpectedEnd},
2323
config::{EndpointConfig, ServerConfig, TransportConfig},
24+
connection::PathId,
2425
shared::ConnectionId,
2526
ResetToken, Side, TransportError, VarInt, LOC_CID_COUNT, MAX_CID_SIZE, MAX_STREAM_COUNT,
2627
RESET_TOKEN_SIZE, TIMER_GRANULARITY,
@@ -117,7 +118,7 @@ macro_rules! make_struct {
117118
pub(crate) address_discovery_role: address_discovery::Role,
118119

119120
// Multipath extension
120-
pub(crate) initial_max_path_id: Option<VarInt>,
121+
pub(crate) initial_max_path_id: Option<PathId>,
121122
}
122123

123124
// We deliberately don't implement the `Default` trait, since that would be public, and
@@ -528,7 +529,7 @@ impl TransportParameters {
528529
return Err(Error::Malformed);
529530
}
530531

531-
let value: VarInt = r.get()?;
532+
let value: PathId = r.get()?;
532533
if len != value.size() {
533534
return Err(Error::Malformed);
534535
}
@@ -708,7 +709,7 @@ pub(crate) enum TransportParameterId {
708709

709710
impl TransportParameterId {
710711
/// Array with all supported transport parameter IDs
711-
const SUPPORTED: [Self; 22] = [
712+
const SUPPORTED: [Self; 23] = [
712713
Self::MaxIdleTimeout,
713714
Self::MaxUdpPayloadSize,
714715
Self::InitialMaxData,
@@ -731,6 +732,7 @@ impl TransportParameterId {
731732
Self::GreaseQuicBit,
732733
Self::MinAckDelayDraft07,
733734
Self::ObservedAddr,
735+
Self::InitialMaxPathId,
734736
];
735737
}
736738

@@ -810,7 +812,7 @@ mod test {
810812
grease_quic_bit: true,
811813
min_ack_delay: Some(2_000u32.into()),
812814
address_discovery_role: address_discovery::Role::SendOnly,
813-
initial_max_path_id: Some(VarInt::MAX),
815+
initial_max_path_id: Some(PathId::MAX),
814816
..TransportParameters::default()
815817
};
816818
params.write(&mut buf);

0 commit comments

Comments
 (0)