mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-24 20:25:00 +00:00
proto: Factor out IncomingToken
Factors out the retry_src_cid and orig_dst_cid fields of Incoming into a new token::IncomingToken struct.
This commit is contained in:
committed by
Dirkjan Ochtman
parent
6ee883a20c
commit
89f3f458de
+11
-11
@@ -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,
|
||||
@@ -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,
|
||||
}))
|
||||
@@ -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()
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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")))]
|
||||
|
||||
Reference in New Issue
Block a user