mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-25 04:35:17 +00:00
proto: Factor out DatagramConnectionEvent
This commit is contained in:
committed by
Dirkjan Ochtman
parent
af30cbdc4b
commit
89f99bbdc0
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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,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);
|
||||
|
||||
Reference in New Issue
Block a user