Skip to content

Commit

Permalink
WIP: Support variable-length connection IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed May 23, 2024
1 parent 1eb96dc commit 7479835
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 21 deletions.
11 changes: 0 additions & 11 deletions quinn-proto/src/cid_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pub trait ConnectionIdGenerator: Send + Sync + ConnectionIdParser {
Ok(())
}

/// Returns the length of a CID for connections created by this generator
fn cid_len(&self) -> usize;
/// Returns the lifetime of generated Connection IDs
///
/// Connection IDs will be retired after the returned `Duration`, if any. Assumed to be constant.
Expand Down Expand Up @@ -90,11 +88,6 @@ impl ConnectionIdGenerator for RandomConnectionIdGenerator {
ConnectionId::new(&bytes_arr[..self.cid_len])
}

/// Provide the length of dst_cid in short header packet
fn cid_len(&self) -> usize {
self.cid_len
}

fn cid_lifetime(&self) -> Option<Duration> {
self.lifetime
}
Expand Down Expand Up @@ -171,10 +164,6 @@ impl ConnectionIdGenerator for HashedConnectionIdGenerator {
}
}

fn cid_len(&self) -> usize {
HASHED_CID_LEN
}

fn cid_lifetime(&self) -> Option<Duration> {
self.lifetime
}
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pub struct EndpointConfig {
///
/// Create a cid generator for local cid in Endpoint struct
pub(crate) connection_id_generator_factory:
Arc<dyn Fn() -> Arc<dyn ConnectionIdGenerator> + Send + Sync>,
Option<Arc<dyn Fn() -> Arc<dyn ConnectionIdGenerator> + Send + Sync>>,
pub(crate) supported_versions: Vec<u32>,
pub(crate) grease_quic_bit: bool,
/// Minimum interval between outgoing stateless reset packets
Expand All @@ -635,7 +635,7 @@ impl EndpointConfig {
Self {
reset_key,
max_udp_payload_size: (1500u32 - 28).into(), // Ethernet MTU minus IP + UDP headers
connection_id_generator_factory: Arc::new(cid_factory),
connection_id_generator_factory: Some(Arc::new(cid_factory)),
supported_versions: DEFAULT_SUPPORTED_VERSIONS.to_vec(),
grease_quic_bit: true,
min_reset_interval: Duration::from_millis(20),
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Connection {
remote: SocketAddr,
local_ip: Option<IpAddr>,
crypto: Box<dyn crypto::Session>,
cid_gen: Arc<dyn ConnectionIdGenerator>,
cid_gen: Option<Arc<dyn ConnectionIdGenerator>>,
now: Instant,
version: u32,
allow_mtud: bool,
Expand Down
5 changes: 1 addition & 4 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,7 @@ impl Endpoint {
// bytes. If this is a Retry packet, then the length must instead match our usual CID
// length. If we ever issue non-Retry address validation tokens via `NEW_TOKEN`, then we'll
// also need to validate CID length for those after decoding the token.
if header.dst_cid.len() < 8
&& (!header.token_pos.is_empty()
&& header.dst_cid.len() != self.local_cid_generator.cid_len())
{
if header.dst_cid.len() < 8 && !header.token_pos.is_empty() {
debug!(
"rejecting connection due to invalid DCID length {}",
header.dst_cid.len()
Expand Down
5 changes: 2 additions & 3 deletions quinn-proto/src/transport_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use bytes::{Buf, BufMut};
use thiserror::Error;

use crate::{
cid_generator::ConnectionIdGenerator,
cid_queue::CidQueue,
coding::{BufExt, BufMutExt, UnexpectedEnd},
config::{EndpointConfig, ServerConfig, TransportConfig},
Expand Down Expand Up @@ -132,7 +131,7 @@ impl TransportParameters {
pub(crate) fn new(
config: &TransportConfig,
endpoint_config: &EndpointConfig,
cid_gen: &dyn ConnectionIdGenerator,
use_cids: bool,
initial_src_cid: ConnectionId,
server_config: Option<&ServerConfig>,
) -> Self {
Expand All @@ -147,7 +146,7 @@ impl TransportParameters {
max_udp_payload_size: endpoint_config.max_udp_payload_size,
max_idle_timeout: config.max_idle_timeout.unwrap_or(VarInt(0)),
disable_active_migration: server_config.map_or(false, |c| !c.migration),
active_connection_id_limit: if cid_gen.cid_len() == 0 {
active_connection_id_limit: if !use_cids {
2 // i.e. default, i.e. unsent
} else {
CidQueue::LEN as u32
Expand Down

0 comments on commit 7479835

Please sign in to comment.