mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-16 16:25:08 +00:00
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.
This commit is contained in:
committed by
Dirkjan Ochtman
parent
37625fe2d8
commit
06f7f7df1b
@@ -74,11 +74,11 @@ impl EndpointConfig {
|
||||
/// information in local connection IDs, e.g. to support stateless packet-level load balancers.
|
||||
///
|
||||
/// Defaults to [`HashedConnectionIdGenerator`].
|
||||
pub fn cid_generator<F: Fn() -> Box<dyn ConnectionIdGenerator> + Send + Sync + 'static>(
|
||||
pub fn cid_generator(
|
||||
&mut self,
|
||||
factory: F,
|
||||
factory: Arc<dyn Fn() -> Box<dyn ConnectionIdGenerator> + Send + Sync>,
|
||||
) -> &mut Self {
|
||||
self.connection_id_generator_factory = Arc::new(factory);
|
||||
self.connection_id_generator_factory = factory;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,9 @@ fn server_stateless_reset() {
|
||||
rng.fill_bytes(&mut key_material);
|
||||
|
||||
let mut endpoint_config = EndpointConfig::new(Arc::new(reset_key));
|
||||
endpoint_config.cid_generator(move || Box::new(HashedConnectionIdGenerator::from_key(0)));
|
||||
endpoint_config.cid_generator(Arc::new(move || {
|
||||
Box::new(HashedConnectionIdGenerator::from_key(0))
|
||||
}));
|
||||
let endpoint_config = Arc::new(endpoint_config);
|
||||
|
||||
let mut pair = Pair::new(endpoint_config.clone(), server_config());
|
||||
@@ -217,7 +219,9 @@ fn client_stateless_reset() {
|
||||
rng.fill_bytes(&mut key_material);
|
||||
|
||||
let mut endpoint_config = EndpointConfig::new(Arc::new(reset_key));
|
||||
endpoint_config.cid_generator(move || Box::new(HashedConnectionIdGenerator::from_key(0)));
|
||||
endpoint_config.cid_generator(Arc::new(move || {
|
||||
Box::new(HashedConnectionIdGenerator::from_key(0))
|
||||
}));
|
||||
let endpoint_config = Arc::new(endpoint_config);
|
||||
|
||||
let mut pair = Pair::new(endpoint_config.clone(), server_config());
|
||||
@@ -245,7 +249,9 @@ fn stateless_reset_limit() {
|
||||
let _guard = subscribe();
|
||||
let remote = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 42);
|
||||
let mut endpoint_config = EndpointConfig::default();
|
||||
endpoint_config.cid_generator(move || Box::new(RandomConnectionIdGenerator::new(8)));
|
||||
endpoint_config.cid_generator(Arc::new(move || {
|
||||
Box::new(RandomConnectionIdGenerator::new(8))
|
||||
}));
|
||||
let endpoint_config = Arc::new(endpoint_config);
|
||||
let mut endpoint = Endpoint::new(
|
||||
endpoint_config.clone(),
|
||||
|
||||
+1
-1
@@ -826,7 +826,7 @@ async fn multiple_conns_with_zero_length_cids() {
|
||||
let mut factory = EndpointFactory::new();
|
||||
factory
|
||||
.endpoint_config
|
||||
.cid_generator(|| Box::new(RandomConnectionIdGenerator::new(0)));
|
||||
.cid_generator(Arc::new(|| Box::new(RandomConnectionIdGenerator::new(0))));
|
||||
let server = {
|
||||
let _guard = error_span!("server").entered();
|
||||
factory.endpoint()
|
||||
|
||||
Reference in New Issue
Block a user