Skip to content

Commit

Permalink
Account for active CIDs when initially issuing new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith authored and djc committed Mar 12, 2020
1 parent 47f58b4 commit e443c6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
19 changes: 11 additions & 8 deletions quinn-proto/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
timer::{Timer, TimerTable},
transport_parameters::{self, TransportParameters},
Dir, Frame, Side, StreamId, Transmit, TransportError, TransportErrorCode, VarInt,
MAX_STREAM_COUNT, MIN_INITIAL_SIZE, MIN_MTU, REM_CID_COUNT, RESET_TOKEN_SIZE,
LOC_CID_COUNT, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, MIN_MTU, REM_CID_COUNT, RESET_TOKEN_SIZE,
TIMER_GRANULARITY,
};

Expand Down Expand Up @@ -1484,9 +1484,7 @@ where
}
self.validate_params(&params)?;
self.set_params(params);
if self.endpoint_config.local_cid_len != 0 {
self.issue_cids(params.active_connection_id_limit);
}
self.issue_cids();
} else {
// Server-only
self.space_mut(SpaceId::Data).pending.handshake_done = true;
Expand Down Expand Up @@ -1533,9 +1531,7 @@ where
})?;
self.validate_params(&params)?;
self.set_params(params);
if self.endpoint_config.local_cid_len != 0 {
self.issue_cids(params.active_connection_id_limit);
}
self.issue_cids();
self.init_0rtt();
}
Ok(())
Expand Down Expand Up @@ -2138,7 +2134,14 @@ where
Ok(())
}

fn issue_cids(&mut self, n: u64) {
/// Issue an initial set of connection IDs to the peer
fn issue_cids(&mut self) {
if self.endpoint_config.local_cid_len == 0 {
return;
}

let initially_active = 1 + self.params.preferred_address.is_some() as u64;
let n = (self.params.active_connection_id_limit - initially_active).max(LOC_CID_COUNT - 1);
self.endpoint_events
.push_back(EndpointEventInner::NeedIdentifiers(n));
self.cids_issued += n;
Expand Down
14 changes: 4 additions & 10 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use crate::{
ServerConfig,
},
transport_parameters::TransportParameters,
Side, Transmit, TransportError, LOC_CID_COUNT, MAX_CID_SIZE, MIN_INITIAL_SIZE,
RESET_TOKEN_SIZE, VERSION,
Side, Transmit, TransportError, MAX_CID_SIZE, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE, VERSION,
};

/// The main entry point to the library
Expand Down Expand Up @@ -104,13 +103,8 @@ where
) -> Option<ConnectionEvent> {
use EndpointEventInner::*;
match event.0 {
NeedIdentifiers(max) => {
if self.config.local_cid_len != 0 {
// We've already issued one CID as part of the normal handshake process.
return Some(
self.send_new_identifiers(ch, max.min(LOC_CID_COUNT - 1) as usize),
);
}
NeedIdentifiers(n) => {
return Some(self.send_new_identifiers(ch, n));
}
ResetToken(remote, token) => {
if let Some(old) = self.connections[ch].reset_token.replace((remote, token)) {
Expand Down Expand Up @@ -360,7 +354,7 @@ where
Ok((ch, conn))
}

fn send_new_identifiers(&mut self, ch: ConnectionHandle, num: usize) -> ConnectionEvent {
fn send_new_identifiers(&mut self, ch: ConnectionHandle, num: u64) -> ConnectionEvent {
let mut ids = vec![];
for _ in 0..num {
let id = self.new_cid();
Expand Down

0 comments on commit e443c6d

Please sign in to comment.