Skip to content

Commit 2262a6f

Browse files
committed
Strip down ConnectionEvent to reflect its sole remaining purpose
1 parent 282b5c7 commit 2262a6f

File tree

9 files changed

+58
-68
lines changed

9 files changed

+58
-68
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
frame::{Close, Datagram, FrameStruct},
2525
packet::{Header, LongType, Packet, PartialDecode, SpaceId},
2626
range_set::ArrayRangeSet,
27-
shared::{ConnectionEvent, ConnectionEventInner, ConnectionId, EcnCodepoint},
27+
shared::{ConnectionDatagram, ConnectionId, EcnCodepoint},
2828
token::ResetToken,
2929
transport_parameters::TransportParameters,
3030
ConnectionHandle, Dir, Endpoint, EndpointConfig, Frame, Side, StreamId, Transmit,
@@ -873,56 +873,51 @@ impl Connection {
873873
SendableFrames::empty()
874874
}
875875

876-
/// Process `ConnectionEvent`s generated by the associated `Endpoint`
876+
/// Process an incoming [`ConnectionDatagram`] forwarded from the associated `Endpoint`
877877
///
878878
/// Will execute protocol logic upon receipt of a connection event, in turn preparing signals
879879
/// (including application `Event`s and outgoing datagrams) that should be extracted through the
880880
/// relevant methods.
881-
pub fn handle_event(&mut self, event: ConnectionEvent, endpoint: &Endpoint) {
882-
use self::ConnectionEventInner::*;
883-
match event.0 {
884-
Datagram {
885-
now,
886-
remote,
887-
ecn,
888-
first_decode,
889-
remaining,
890-
} => {
891-
// If this packet could initiate a migration and we're a client or a server that
892-
// forbids migration, drop the datagram. This could be relaxed to heuristically
893-
// permit NAT-rebinding-like migration.
894-
if remote != self.path.remote
895-
&& self.server_config.as_ref().map_or(true, |x| !x.migration)
896-
{
897-
trace!("discarding packet from unrecognized peer {}", remote);
898-
return;
899-
}
881+
pub fn handle(&mut self, datagram: ConnectionDatagram, endpoint: &Endpoint) {
882+
let ConnectionDatagram {
883+
now,
884+
remote,
885+
ecn,
886+
first_decode,
887+
remaining,
888+
} = datagram;
889+
// If this packet could initiate a migration and we're a client or a server that
890+
// forbids migration, drop the datagram. This could be relaxed to heuristically
891+
// permit NAT-rebinding-like migration.
892+
if remote != self.path.remote && self.server_config.as_ref().map_or(true, |x| !x.migration)
893+
{
894+
trace!("discarding packet from unrecognized peer {}", remote);
895+
return;
896+
}
900897

901-
let was_anti_amplification_blocked = self.path.anti_amplification_blocked(1);
898+
let was_anti_amplification_blocked = self.path.anti_amplification_blocked(1);
902899

903-
self.stats.udp_rx.datagrams += 1;
904-
self.stats.udp_rx.bytes += first_decode.len() as u64;
905-
let data_len = first_decode.len();
900+
self.stats.udp_rx.datagrams += 1;
901+
self.stats.udp_rx.bytes += first_decode.len() as u64;
902+
let data_len = first_decode.len();
906903

907-
self.handle_decode(now, remote, ecn, first_decode, endpoint);
908-
// The current `path` might have changed inside `handle_decode`,
909-
// since the packet could have triggered a migration. Make sure
910-
// the data received is accounted for the most recent path by accessing
911-
// `path` after `handle_decode`.
912-
self.path.total_recvd = self.path.total_recvd.saturating_add(data_len as u64);
904+
self.handle_decode(now, remote, ecn, first_decode, endpoint);
905+
// The current `path` might have changed inside `handle_decode`,
906+
// since the packet could have triggered a migration. Make sure
907+
// the data received is accounted for the most recent path by accessing
908+
// `path` after `handle_decode`.
909+
self.path.total_recvd = self.path.total_recvd.saturating_add(data_len as u64);
913910

914-
if let Some(data) = remaining {
915-
self.stats.udp_rx.bytes += data.len() as u64;
916-
self.handle_coalesced(now, remote, ecn, data, endpoint);
917-
}
911+
if let Some(data) = remaining {
912+
self.stats.udp_rx.bytes += data.len() as u64;
913+
self.handle_coalesced(now, remote, ecn, data, endpoint);
914+
}
918915

919-
if was_anti_amplification_blocked {
920-
// A prior attempt to set the loss detection timer may have failed due to
921-
// anti-amplification, so ensure it's set now. Prevents a handshake deadlock if
922-
// the server's first flight is lost.
923-
self.set_loss_detection_timer(now);
924-
}
925-
}
916+
if was_anti_amplification_blocked {
917+
// A prior attempt to set the loss detection timer may have failed due to
918+
// anti-amplification, so ensure it's set now. Prevents a handshake deadlock if
919+
// the server's first flight is lost.
920+
self.set_loss_detection_timer(now);
926921
}
927922
}
928923

quinn-proto/src/endpoint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
crypto::{self, Keys, UnsupportedVersion},
2424
frame,
2525
packet::{Header, Packet, PacketDecodeError, PacketNumber, PartialDecode},
26-
shared::{ConnectionEvent, ConnectionEventInner, ConnectionId, EcnCodepoint, IssuedCid},
26+
shared::{ConnectionDatagram, ConnectionId, EcnCodepoint, IssuedCid},
2727
transport_parameters::TransportParameters,
2828
ResetToken, RetryToken, Side, Transmit, TransportConfig, TransportError, INITIAL_MTU,
2929
MAX_CID_SIZE, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE,
@@ -169,13 +169,13 @@ impl Endpoint {
169169
if let Some(ch) = self.index.read().unwrap().get(&addresses, &first_decode) {
170170
return Some(DatagramEvent::ConnectionEvent(
171171
ch,
172-
ConnectionEvent(ConnectionEventInner::Datagram {
172+
ConnectionDatagram {
173173
now,
174174
remote: addresses.remote,
175175
ecn,
176176
first_decode,
177177
remaining,
178-
}),
178+
},
179179
));
180180
}
181181

@@ -852,7 +852,7 @@ impl IndexMut<ConnectionHandle> for Slab<ConnectionMeta> {
852852
#[allow(clippy::large_enum_variant)] // Not passed around extensively
853853
pub enum DatagramEvent {
854854
/// The datagram is redirected to its `Connection`
855-
ConnectionEvent(ConnectionHandle, ConnectionEvent),
855+
ConnectionEvent(ConnectionHandle, ConnectionDatagram),
856856
/// The datagram has resulted in starting a new `Connection`
857857
NewConnection(ConnectionHandle, Connection),
858858
/// Response generated directly by the endpoint

quinn-proto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mod endpoint;
6565
pub use crate::endpoint::{ConnectError, ConnectionHandle, DatagramEvent, Endpoint};
6666

6767
mod shared;
68-
pub use crate::shared::{ConnectionEvent, ConnectionId, EcnCodepoint};
68+
pub use crate::shared::{ConnectionDatagram, ConnectionId, EcnCodepoint};
6969

7070
mod transport_error;
7171
pub use crate::transport_error::{Code as TransportErrorCode, Error as TransportError};

quinn-proto/src/shared.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ use bytes::{Buf, BufMut, BytesMut};
44

55
use crate::{coding::BufExt, packet::PartialDecode, ResetToken, MAX_CID_SIZE};
66

7-
/// Events sent from an Endpoint to a Connection
7+
/// UDP datagram addressed to a specific
8+
/// [`Connection`](crate::Connection)
89
#[derive(Debug)]
9-
pub struct ConnectionEvent(pub(crate) ConnectionEventInner);
10-
11-
#[derive(Debug)]
12-
pub(crate) enum ConnectionEventInner {
13-
/// A datagram has been received for the Connection
14-
Datagram {
15-
now: Instant,
16-
remote: SocketAddr,
17-
ecn: Option<EcnCodepoint>,
18-
first_decode: PartialDecode,
19-
remaining: Option<BytesMut>,
20-
},
10+
pub struct ConnectionDatagram {
11+
pub(crate) now: Instant,
12+
pub(crate) remote: SocketAddr,
13+
pub(crate) ecn: Option<EcnCodepoint>,
14+
pub(crate) first_decode: PartialDecode,
15+
pub(crate) remaining: Option<BytesMut>,
2116
}
2217

2318
/// Protocol-level identifier for a connection.

quinn-proto/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn version_negotiate_client() {
7777
.into(),
7878
);
7979
if let Some(DatagramEvent::ConnectionEvent(_, event)) = opt_event {
80-
client_ch.handle_event(event, &client);
80+
client_ch.handle(event, &client);
8181
}
8282
assert_matches!(
8383
client_ch.poll(),

quinn-proto/src/tests/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub(super) struct TestEndpoint {
270270
pub(super) inbound: VecDeque<(Instant, Option<EcnCodepoint>, BytesMut)>,
271271
accepted: Option<ConnectionHandle>,
272272
pub(super) connections: HashMap<ConnectionHandle, Connection>,
273-
conn_events: HashMap<ConnectionHandle, VecDeque<ConnectionEvent>>,
273+
conn_events: HashMap<ConnectionHandle, VecDeque<ConnectionDatagram>>,
274274
}
275275

276276
impl TestEndpoint {
@@ -337,7 +337,7 @@ impl TestEndpoint {
337337

338338
for (_, mut events) in self.conn_events.drain() {
339339
for event in events.drain(..) {
340-
conn.handle_event(event, &self.endpoint);
340+
conn.handle(event, &self.endpoint);
341341
}
342342
}
343343

quinn/src/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ impl State {
906906
Poll::Ready(Some(ConnectionEvent::Ping)) => {
907907
self.inner.ping();
908908
}
909-
Poll::Ready(Some(ConnectionEvent::Proto(event))) => {
910-
self.inner.handle_event(event, &shared.endpoint);
909+
Poll::Ready(Some(ConnectionEvent::Datagram(datagram))) => {
910+
self.inner.handle(datagram, &shared.endpoint);
911911
}
912912
Poll::Ready(Some(ConnectionEvent::Close { reason, error_code })) => {
913913
self.close(error_code, reason, shared);

quinn/src/endpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,14 @@ impl State {
419419
);
420420
self.incoming.push_back(conn);
421421
}
422-
Some(DatagramEvent::ConnectionEvent(handle, event)) => {
422+
Some(DatagramEvent::ConnectionEvent(handle, datagram)) => {
423423
// Ignoring errors from dropped connections that haven't yet been cleaned up
424424
let _ = self
425425
.connections
426426
.senders
427427
.get_mut(&handle)
428428
.unwrap()
429-
.send(ConnectionEvent::Proto(event));
429+
.send(ConnectionEvent::Datagram(datagram));
430430
}
431431
Some(DatagramEvent::Response(t)) => {
432432
self.outgoing.push_back(udp_transmit(t));

quinn/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum ConnectionEvent {
8989
error_code: VarInt,
9090
reason: bytes::Bytes,
9191
},
92-
Proto(proto::ConnectionEvent),
92+
Datagram(proto::ConnectionDatagram),
9393
Ping,
9494
}
9595

0 commit comments

Comments
 (0)