Skip to content

Commit

Permalink
proto: Factor out IncomingToken
Browse files Browse the repository at this point in the history
Factors out the retry_src_cid and orig_dst_cid fields of Incoming into
a new token::IncomingToken struct.
  • Loading branch information
gretchenfrage committed Dec 17, 2024
1 parent 6ee883a commit 602363d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
22 changes: 11 additions & 11 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
ConnectionEvent, ConnectionEventInner, ConnectionId, DatagramConnectionEvent, EcnCodepoint,
EndpointEvent, EndpointEventInner, IssuedCid,
},
token,
token::{self, IncomingToken},
transport_parameters::{PreferredAddress, TransportParameters},
Duration, Instant, ResetToken, RetryToken, Side, Transmit, TransportConfig, TransportError,
INITIAL_MTU, MAX_CID_SIZE, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE,
Expand Down Expand Up @@ -539,8 +539,10 @@ impl Endpoint {
},
rest,
crypto,
retry_src_cid,
orig_dst_cid,
token: IncomingToken {
retry_src_cid,
orig_dst_cid,
},
incoming_idx,
improper_drop_warner: IncomingImproperDropWarner,
}))
Expand Down Expand Up @@ -630,8 +632,8 @@ impl Endpoint {
&mut self.rng,
);
params.stateless_reset_token = Some(ResetToken::new(&*self.config.reset_key, &loc_cid));
params.original_dst_cid = Some(incoming.orig_dst_cid);
params.retry_src_cid = incoming.retry_src_cid;
params.original_dst_cid = Some(incoming.token.orig_dst_cid);
params.retry_src_cid = incoming.token.retry_src_cid;
let mut pref_addr_cid = None;
if server_config.preferred_address_v4.is_some()
|| server_config.preferred_address_v6.is_some()
Expand Down Expand Up @@ -1192,8 +1194,7 @@ pub struct Incoming {
packet: InitialPacket,
rest: Option<BytesMut>,
crypto: Keys,
retry_src_cid: Option<ConnectionId>,
orig_dst_cid: ConnectionId,
token: IncomingToken,
incoming_idx: usize,
improper_drop_warner: IncomingImproperDropWarner,
}
Expand All @@ -1216,12 +1217,12 @@ impl Incoming {
/// This means that the sender of the initial packet has proved that they can receive traffic
/// sent to `self.remote_address()`.
pub fn remote_address_validated(&self) -> bool {
self.retry_src_cid.is_some()
self.token.retry_src_cid.is_some()
}

/// The original destination connection ID sent by the client
pub fn orig_dst_cid(&self) -> &ConnectionId {
&self.orig_dst_cid
&self.token.orig_dst_cid
}
}

Expand All @@ -1232,8 +1233,7 @@ impl fmt::Debug for Incoming {
.field("ecn", &self.ecn)
// packet doesn't implement debug
// rest is too big and not meaningful enough
.field("retry_src_cid", &self.retry_src_cid)
.field("orig_dst_cid", &self.orig_dst_cid)
.field("token", &self.token)
.field("incoming_idx", &self.incoming_idx)
// improper drop warner contains no information
.finish_non_exhaustive()
Expand Down
7 changes: 7 additions & 0 deletions quinn-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ impl fmt::Display for ResetToken {
}
}

/// State in an `Incoming` determined by a token or lack thereof
#[derive(Debug)]
pub(crate) struct IncomingToken {
pub(crate) retry_src_cid: Option<ConnectionId>,
pub(crate) orig_dst_cid: ConnectionId,
}

#[cfg(all(test, any(feature = "aws-lc-rs", feature = "ring")))]
mod test {
#[cfg(all(feature = "aws-lc-rs", not(feature = "ring")))]
Expand Down

0 comments on commit 602363d

Please sign in to comment.