proto: Factor out DatagramConnectionEvent

This commit is contained in:
Phoenix Kahlo
2024-04-25 23:30:33 -05:00
committed by Dirkjan Ochtman
parent af30cbdc4b
commit 89f99bbdc0
3 changed files with 21 additions and 17 deletions
+6 -6
View File
@@ -25,8 +25,8 @@ use crate::{
packet::{Header, InitialHeader, InitialPacket, LongType, Packet, PartialDecode, SpaceId},
range_set::ArrayRangeSet,
shared::{
ConnectionEvent, ConnectionEventInner, ConnectionId, EcnCodepoint, EndpointEvent,
EndpointEventInner,
ConnectionEvent, ConnectionEventInner, ConnectionId, DatagramConnectionEvent, EcnCodepoint,
EndpointEvent, EndpointEventInner,
},
token::ResetToken,
transport_parameters::TransportParameters,
@@ -989,13 +989,13 @@ impl Connection {
pub fn handle_event(&mut self, event: ConnectionEvent) {
use self::ConnectionEventInner::*;
match event.0 {
Datagram {
Datagram(DatagramConnectionEvent {
now,
remote,
ecn,
first_decode,
remaining,
} => {
}) => {
// If this packet could initiate a migration and we're a client or a server that
// forbids migration, drop the datagram. This could be relaxed to heuristically
// permit NAT-rebinding-like migration.
@@ -3346,11 +3346,11 @@ impl Connection {
#[cfg(test)]
pub(crate) fn decode_packet(&self, event: &ConnectionEvent) -> Option<Vec<u8>> {
let (first_decode, remaining) = match &event.0 {
ConnectionEventInner::Datagram {
ConnectionEventInner::Datagram(DatagramConnectionEvent {
first_decode,
remaining,
..
} => (first_decode, remaining),
}) => (first_decode, remaining),
_ => return None,
};
+4 -4
View File
@@ -27,8 +27,8 @@ use crate::{
PartialDecode, PlainInitialHeader,
},
shared::{
ConnectionEvent, ConnectionEventInner, ConnectionId, EcnCodepoint, EndpointEvent,
EndpointEventInner, IssuedCid,
ConnectionEvent, ConnectionEventInner, ConnectionId, DatagramConnectionEvent, EcnCodepoint,
EndpointEvent, EndpointEventInner, IssuedCid,
},
token::TokenDecodeError,
transport_parameters::{PreferredAddress, TransportParameters},
@@ -192,13 +192,13 @@ impl Endpoint {
if let Some(ch) = self.index.get(&addresses, &first_decode) {
return Some(DatagramEvent::ConnectionEvent(
ch,
ConnectionEvent(ConnectionEventInner::Datagram {
ConnectionEvent(ConnectionEventInner::Datagram(DatagramConnectionEvent {
now,
remote: addresses.remote,
ecn,
first_decode,
remaining,
}),
})),
));
}
+11 -7
View File
@@ -11,17 +11,21 @@ pub struct ConnectionEvent(pub(crate) ConnectionEventInner);
#[derive(Debug)]
pub(crate) enum ConnectionEventInner {
/// A datagram has been received for the Connection
Datagram {
now: Instant,
remote: SocketAddr,
ecn: Option<EcnCodepoint>,
first_decode: PartialDecode,
remaining: Option<BytesMut>,
},
Datagram(DatagramConnectionEvent),
/// New connection identifiers have been issued for the Connection
NewIdentifiers(Vec<IssuedCid>, Instant),
}
/// Variant of [`ConnectionEventInner`].
#[derive(Debug)]
pub(crate) struct DatagramConnectionEvent {
pub(crate) now: Instant,
pub(crate) remote: SocketAddr,
pub(crate) ecn: Option<EcnCodepoint>,
pub(crate) first_decode: PartialDecode,
pub(crate) remaining: Option<BytesMut>,
}
/// Events sent from a Connection to an Endpoint
#[derive(Debug)]
pub struct EndpointEvent(pub(crate) EndpointEventInner);