@@ -55,7 +55,15 @@ use crate::{
55
55
stats:: { Stats , StatsCell } ,
56
56
stream_id:: StreamType ,
57
57
streams:: { SendOrder , Streams } ,
58
- tparams:: { self , TransportParameters , TransportParametersHandler } ,
58
+ tparams:: {
59
+ self ,
60
+ TransportParameterId :: {
61
+ self , AckDelayExponent , ActiveConnectionIdLimit , DisableMigration , GreaseQuicBit ,
62
+ InitialSourceConnectionId , MaxAckDelay , MaxDatagramFrameSize , MinAckDelay ,
63
+ OriginalDestinationConnectionId , RetrySourceConnectionId , StatelessResetToken ,
64
+ } ,
65
+ TransportParameters , TransportParametersHandler ,
66
+ } ,
59
67
tracking:: { AckTracker , PacketNumberSpace , RecvdPackets } ,
60
68
version:: { Version , WireVersion } ,
61
69
AppError , CloseReason , Error , Res , StreamId ,
@@ -373,10 +381,8 @@ impl Connection {
373
381
let mut cid_manager =
374
382
ConnectionIdManager :: new ( cid_generator, local_initial_source_cid. clone ( ) ) ;
375
383
let mut tps = conn_params. create_transport_parameter ( role, & mut cid_manager) ?;
376
- tps. local . set_bytes (
377
- tparams:: INITIAL_SOURCE_CONNECTION_ID ,
378
- local_initial_source_cid. to_vec ( ) ,
379
- ) ;
384
+ tps. local
385
+ . set_bytes ( InitialSourceConnectionId , local_initial_source_cid. to_vec ( ) ) ;
380
386
381
387
let tphandler = Rc :: new ( RefCell :: new ( tps) ) ;
382
388
let crypto = Crypto :: new (
@@ -498,7 +504,7 @@ impl Connection {
498
504
#[ cfg( test) ]
499
505
pub fn set_local_tparam (
500
506
& self ,
501
- tp : tparams :: TransportParameterId ,
507
+ tp : TransportParameterId ,
502
508
value : tparams:: TransportParameter ,
503
509
) -> Res < ( ) > {
504
510
if * self . state ( ) == State :: Init {
@@ -525,8 +531,8 @@ impl Connection {
525
531
qtrace ! ( "[{self}] Retry CIDs: odcid={odcid} remote={remote_cid} retry={retry_cid}" ) ;
526
532
// We advertise "our" choices in transport parameters.
527
533
let local_tps = & mut self . tps . borrow_mut ( ) . local ;
528
- local_tps. set_bytes ( tparams :: ORIGINAL_DESTINATION_CONNECTION_ID , odcid. to_vec ( ) ) ;
529
- local_tps. set_bytes ( tparams :: RETRY_SOURCE_CONNECTION_ID , retry_cid. to_vec ( ) ) ;
534
+ local_tps. set_bytes ( OriginalDestinationConnectionId , odcid. to_vec ( ) ) ;
535
+ local_tps. set_bytes ( RetrySourceConnectionId , retry_cid. to_vec ( ) ) ;
530
536
531
537
// ...and save their choices for later validation.
532
538
self . remote_initial_source_cid = Some ( remote_cid) ;
@@ -536,7 +542,7 @@ impl Connection {
536
542
self . tps
537
543
. borrow ( )
538
544
. local
539
- . get_bytes ( tparams :: RETRY_SOURCE_CONNECTION_ID )
545
+ . get_bytes ( RetrySourceConnectionId )
540
546
. is_some ( )
541
547
}
542
548
@@ -1407,10 +1413,10 @@ impl Connection {
1407
1413
// This has to happen prior to processing the packet so that
1408
1414
// the TLS handshake has all it needs.
1409
1415
if !self . retry_sent ( ) {
1410
- self . tps . borrow_mut ( ) . local . set_bytes (
1411
- tparams :: ORIGINAL_DESTINATION_CONNECTION_ID ,
1412
- packet . dcid ( ) . to_vec ( ) ,
1413
- ) ;
1416
+ self . tps
1417
+ . borrow_mut ( )
1418
+ . local
1419
+ . set_bytes ( OriginalDestinationConnectionId , packet . dcid ( ) . to_vec ( ) ) ;
1414
1420
}
1415
1421
}
1416
1422
( PacketType :: VersionNegotiation , State :: WaitInitial , Role :: Client ) => {
@@ -1890,12 +1896,7 @@ impl Connection {
1890
1896
if !matches ! ( self . state( ) , State :: Confirmed ) {
1891
1897
return Err ( Error :: InvalidMigration ) ;
1892
1898
}
1893
- if self
1894
- . tps
1895
- . borrow ( )
1896
- . remote ( )
1897
- . get_empty ( tparams:: DISABLE_MIGRATION )
1898
- {
1899
+ if self . tps . borrow ( ) . remote ( ) . get_empty ( DisableMigration ) {
1899
1900
return Err ( Error :: InvalidMigration ) ;
1900
1901
}
1901
1902
@@ -2113,9 +2114,9 @@ impl Connection {
2113
2114
fn can_grease_quic_bit ( & self ) -> bool {
2114
2115
let tph = self . tps . borrow ( ) ;
2115
2116
if let Some ( r) = & tph. remote {
2116
- r. get_empty ( tparams :: GREASE_QUIC_BIT )
2117
+ r. get_empty ( GreaseQuicBit )
2117
2118
} else if let Some ( r) = & tph. remote_0rtt {
2118
- r. get_empty ( tparams :: GREASE_QUIC_BIT )
2119
+ r. get_empty ( GreaseQuicBit )
2119
2120
} else {
2120
2121
false
2121
2122
}
@@ -2621,18 +2622,14 @@ impl Connection {
2621
2622
. tps
2622
2623
. borrow ( )
2623
2624
. remote ( )
2624
- . get_integer ( tparams :: IDLE_TIMEOUT ) ;
2625
+ . get_integer ( TransportParameterId :: IdleTimeout ) ;
2625
2626
if peer_timeout > 0 {
2626
2627
self . idle_timeout
2627
2628
. set_peer_timeout ( Duration :: from_millis ( peer_timeout) ) ;
2628
2629
}
2629
2630
2630
- self . quic_datagrams . set_remote_datagram_size (
2631
- self . tps
2632
- . borrow ( )
2633
- . remote ( )
2634
- . get_integer ( tparams:: MAX_DATAGRAM_FRAME_SIZE ) ,
2635
- ) ;
2631
+ self . quic_datagrams
2632
+ . set_remote_datagram_size ( self . tps . borrow ( ) . remote ( ) . get_integer ( MaxDatagramFrameSize ) ) ;
2636
2633
}
2637
2634
2638
2635
#[ must_use]
@@ -2661,18 +2658,16 @@ impl Connection {
2661
2658
return Err ( Error :: TransportParameterError ) ;
2662
2659
}
2663
2660
2664
- let reset_token = remote
2665
- . get_bytes ( tparams:: STATELESS_RESET_TOKEN )
2666
- . map_or_else (
2667
- || Ok ( ConnectionIdEntry :: random_srt ( ) ) ,
2668
- |token| <[ u8 ; 16 ] >:: try_from ( token) . map_err ( |_| Error :: TransportParameterError ) ,
2669
- ) ?;
2661
+ let reset_token = remote. get_bytes ( StatelessResetToken ) . map_or_else (
2662
+ || Ok ( ConnectionIdEntry :: random_srt ( ) ) ,
2663
+ |token| <[ u8 ; 16 ] >:: try_from ( token) . map_err ( |_| Error :: TransportParameterError ) ,
2664
+ ) ?;
2670
2665
let path = self . paths . primary ( ) . ok_or ( Error :: NoAvailablePath ) ?;
2671
2666
path. borrow_mut ( ) . set_reset_token ( reset_token) ;
2672
2667
2673
- let max_ad = Duration :: from_millis ( remote. get_integer ( tparams :: MAX_ACK_DELAY ) ) ;
2674
- let min_ad = if remote. has_value ( tparams :: MIN_ACK_DELAY ) {
2675
- let min_ad = Duration :: from_micros ( remote. get_integer ( tparams :: MIN_ACK_DELAY ) ) ;
2668
+ let max_ad = Duration :: from_millis ( remote. get_integer ( MaxAckDelay ) ) ;
2669
+ let min_ad = if remote. has_value ( MinAckDelay ) {
2670
+ let min_ad = Duration :: from_micros ( remote. get_integer ( MinAckDelay ) ) ;
2676
2671
if min_ad > max_ad {
2677
2672
return Err ( Error :: TransportParameterError ) ;
2678
2673
}
@@ -2683,7 +2678,7 @@ impl Connection {
2683
2678
path. borrow_mut ( )
2684
2679
. set_ack_delay ( max_ad, min_ad, self . conn_params . get_ack_ratio ( ) ) ;
2685
2680
2686
- let max_active_cids = remote. get_integer ( tparams :: ACTIVE_CONNECTION_ID_LIMIT ) ;
2681
+ let max_active_cids = remote. get_integer ( ActiveConnectionIdLimit ) ;
2687
2682
self . cid_manager . set_limit ( max_active_cids) ;
2688
2683
}
2689
2684
self . set_initial_limits ( ) ;
@@ -2695,7 +2690,7 @@ impl Connection {
2695
2690
let tph = self . tps . borrow ( ) ;
2696
2691
let remote_tps = tph. remote . as_ref ( ) . ok_or ( Error :: TransportParameterError ) ?;
2697
2692
2698
- let tp = remote_tps. get_bytes ( tparams :: INITIAL_SOURCE_CONNECTION_ID ) ;
2693
+ let tp = remote_tps. get_bytes ( InitialSourceConnectionId ) ;
2699
2694
if self
2700
2695
. remote_initial_source_cid
2701
2696
. as_ref ( )
@@ -2711,7 +2706,7 @@ impl Connection {
2711
2706
}
2712
2707
2713
2708
if self . role == Role :: Client {
2714
- let tp = remote_tps. get_bytes ( tparams :: ORIGINAL_DESTINATION_CONNECTION_ID ) ;
2709
+ let tp = remote_tps. get_bytes ( OriginalDestinationConnectionId ) ;
2715
2710
if self
2716
2711
. original_destination_cid
2717
2712
. as_ref ( )
@@ -2726,7 +2721,7 @@ impl Connection {
2726
2721
return Err ( Error :: ProtocolViolation ) ;
2727
2722
}
2728
2723
2729
- let tp = remote_tps. get_bytes ( tparams :: RETRY_SOURCE_CONNECTION_ID ) ;
2724
+ let tp = remote_tps. get_bytes ( RetrySourceConnectionId ) ;
2730
2725
let expected = if let AddressValidationInfo :: Retry {
2731
2726
retry_source_cid, ..
2732
2727
} = & self . address_validation
@@ -3120,7 +3115,7 @@ impl Connection {
3120
3115
self . tps . borrow ( ) . remote . as_ref ( ) . map_or_else (
3121
3116
|| Ok ( Duration :: default ( ) ) ,
3122
3117
|r| {
3123
- let exponent = u32:: try_from ( r. get_integer ( tparams :: ACK_DELAY_EXPONENT ) ) ?;
3118
+ let exponent = u32:: try_from ( r. get_integer ( AckDelayExponent ) ) ?;
3124
3119
// ACK_DELAY_EXPONENT > 20 is invalid per RFC9000. We already checked that in
3125
3120
// TransportParameter::decode.
3126
3121
let corrected = if v. leading_zeros ( ) >= exponent {
0 commit comments