Skip to content

Commit 06f7f7d

Browse files
Ralithdjc
authored andcommitted
Take boxed connection ID generator factories
When we store a type-erased, boxed value internally, accepting that value directly allows users to avoid double-boxing. Probably not hugely important in this case, but we've been adopting this pattern everywhere else and we should be consistent.
1 parent 37625fe commit 06f7f7d

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

quinn-proto/src/config/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ impl EndpointConfig {
7474
/// information in local connection IDs, e.g. to support stateless packet-level load balancers.
7575
///
7676
/// Defaults to [`HashedConnectionIdGenerator`].
77-
pub fn cid_generator<F: Fn() -> Box<dyn ConnectionIdGenerator> + Send + Sync + 'static>(
77+
pub fn cid_generator(
7878
&mut self,
79-
factory: F,
79+
factory: Arc<dyn Fn() -> Box<dyn ConnectionIdGenerator> + Send + Sync>,
8080
) -> &mut Self {
81-
self.connection_id_generator_factory = Arc::new(factory);
81+
self.connection_id_generator_factory = factory;
8282
self
8383
}
8484

quinn-proto/src/tests/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ fn server_stateless_reset() {
188188
rng.fill_bytes(&mut key_material);
189189

190190
let mut endpoint_config = EndpointConfig::new(Arc::new(reset_key));
191-
endpoint_config.cid_generator(move || Box::new(HashedConnectionIdGenerator::from_key(0)));
191+
endpoint_config.cid_generator(Arc::new(move || {
192+
Box::new(HashedConnectionIdGenerator::from_key(0))
193+
}));
192194
let endpoint_config = Arc::new(endpoint_config);
193195

194196
let mut pair = Pair::new(endpoint_config.clone(), server_config());
@@ -217,7 +219,9 @@ fn client_stateless_reset() {
217219
rng.fill_bytes(&mut key_material);
218220

219221
let mut endpoint_config = EndpointConfig::new(Arc::new(reset_key));
220-
endpoint_config.cid_generator(move || Box::new(HashedConnectionIdGenerator::from_key(0)));
222+
endpoint_config.cid_generator(Arc::new(move || {
223+
Box::new(HashedConnectionIdGenerator::from_key(0))
224+
}));
221225
let endpoint_config = Arc::new(endpoint_config);
222226

223227
let mut pair = Pair::new(endpoint_config.clone(), server_config());
@@ -245,7 +249,9 @@ fn stateless_reset_limit() {
245249
let _guard = subscribe();
246250
let remote = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 42);
247251
let mut endpoint_config = EndpointConfig::default();
248-
endpoint_config.cid_generator(move || Box::new(RandomConnectionIdGenerator::new(8)));
252+
endpoint_config.cid_generator(Arc::new(move || {
253+
Box::new(RandomConnectionIdGenerator::new(8))
254+
}));
249255
let endpoint_config = Arc::new(endpoint_config);
250256
let mut endpoint = Endpoint::new(
251257
endpoint_config.clone(),

quinn/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ async fn multiple_conns_with_zero_length_cids() {
826826
let mut factory = EndpointFactory::new();
827827
factory
828828
.endpoint_config
829-
.cid_generator(|| Box::new(RandomConnectionIdGenerator::new(0)));
829+
.cid_generator(Arc::new(|| Box::new(RandomConnectionIdGenerator::new(0))));
830830
let server = {
831831
let _guard = error_span!("server").entered();
832832
factory.endpoint()

0 commit comments

Comments
 (0)