@@ -11,7 +11,11 @@ use crate::{
11
11
transport:: parameters:: { DcSupportedVersions , InitialFlowControlLimits } ,
12
12
varint:: VarInt ,
13
13
} ;
14
- use core:: { num:: NonZeroU32 , time:: Duration } ;
14
+ use core:: {
15
+ num:: NonZeroU32 ,
16
+ sync:: atomic:: { AtomicU16 , Ordering } ,
17
+ time:: Duration ,
18
+ } ;
15
19
16
20
mod disabled;
17
21
mod traits;
@@ -91,25 +95,37 @@ impl<'a> DatagramInfo<'a> {
91
95
}
92
96
93
97
/// Various settings relevant to the dc path
94
- #[ derive( Clone , Copy , Debug ) ]
98
+ #[ derive( Debug ) ]
95
99
#[ non_exhaustive]
96
100
pub struct ApplicationParams {
97
- pub max_datagram_size : u16 ,
101
+ pub max_datagram_size : AtomicU16 ,
98
102
pub remote_max_data : VarInt ,
99
103
pub local_send_max_data : VarInt ,
100
104
pub local_recv_max_data : VarInt ,
101
105
// Actually a Duration, stored as milliseconds to shrink this struct
102
106
pub max_idle_timeout : Option < NonZeroU32 > ,
103
107
}
104
108
109
+ impl Clone for ApplicationParams {
110
+ fn clone ( & self ) -> Self {
111
+ Self {
112
+ max_datagram_size : AtomicU16 :: new ( self . max_datagram_size . load ( Ordering :: Relaxed ) ) ,
113
+ remote_max_data : self . remote_max_data ,
114
+ local_send_max_data : self . local_send_max_data ,
115
+ local_recv_max_data : self . local_recv_max_data ,
116
+ max_idle_timeout : self . max_idle_timeout ,
117
+ }
118
+ }
119
+ }
120
+
105
121
impl ApplicationParams {
106
122
pub fn new (
107
123
max_datagram_size : u16 ,
108
124
peer_flow_control_limits : & InitialFlowControlLimits ,
109
125
limits : & Limits ,
110
126
) -> Self {
111
127
Self {
112
- max_datagram_size,
128
+ max_datagram_size : AtomicU16 :: new ( max_datagram_size ) ,
113
129
remote_max_data : peer_flow_control_limits. max_data ,
114
130
local_send_max_data : limits. initial_stream_limits ( ) . max_data_bidi_local ,
115
131
local_recv_max_data : limits. initial_stream_limits ( ) . max_data_bidi_remote ,
@@ -125,3 +141,52 @@ impl ApplicationParams {
125
141
Some ( Duration :: from_millis ( self . max_idle_timeout ?. get ( ) as u64 ) )
126
142
}
127
143
}
144
+
145
+ #[ cfg( test) ]
146
+ mod tests {
147
+ use crate :: {
148
+ connection:: Limits , dc:: ApplicationParams , transport:: parameters:: InitialFlowControlLimits ,
149
+ varint:: VarInt ,
150
+ } ;
151
+ use std:: { sync:: atomic:: Ordering , time:: Duration } ;
152
+
153
+ #[ test]
154
+ fn clone ( ) {
155
+ let initial_flow_control_limits = InitialFlowControlLimits {
156
+ max_data : VarInt :: from_u32 ( 2222 ) ,
157
+ ..Default :: default ( )
158
+ } ;
159
+
160
+ let limits = Limits {
161
+ bidirectional_local_data_window : 1234 . try_into ( ) . unwrap ( ) ,
162
+ bidirectional_remote_data_window : 6789 . try_into ( ) . unwrap ( ) ,
163
+ max_idle_timeout : Duration :: from_millis ( 999 ) . try_into ( ) . unwrap ( ) ,
164
+ ..Default :: default ( )
165
+ } ;
166
+
167
+ let params = ApplicationParams :: new ( 9000 , & initial_flow_control_limits, & limits) ;
168
+
169
+ assert_eq ! ( 9000 , params. max_datagram_size. load( Ordering :: Relaxed ) ) ;
170
+ assert_eq ! ( limits. max_idle_timeout( ) , params. max_idle_timeout( ) ) ;
171
+ assert_eq ! ( 1234 , params. local_send_max_data. as_u64( ) ) ;
172
+ assert_eq ! ( 6789 , params. local_recv_max_data. as_u64( ) ) ;
173
+ assert_eq ! ( 2222 , params. remote_max_data. as_u64( ) ) ;
174
+
175
+ let cloned_params = params. clone ( ) ;
176
+
177
+ assert_eq ! (
178
+ params. max_datagram_size. load( Ordering :: Relaxed ) ,
179
+ cloned_params. max_datagram_size. load( Ordering :: Relaxed )
180
+ ) ;
181
+ assert_eq ! ( params. max_idle_timeout, cloned_params. max_idle_timeout) ;
182
+ assert_eq ! (
183
+ params. local_send_max_data,
184
+ cloned_params. local_send_max_data
185
+ ) ;
186
+ assert_eq ! (
187
+ params. local_recv_max_data,
188
+ cloned_params. local_recv_max_data
189
+ ) ;
190
+ assert_eq ! ( params. remote_max_data, cloned_params. remote_max_data) ;
191
+ }
192
+ }
0 commit comments