@@ -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 ,
@@ -81,7 +81,7 @@ use timer::{Timer, TimerTable};
8181
8282/// Protocol state and logic for a single QUIC connection
8383///
84- /// Objects of this type receive [`ConnectionEvent `]s and emit application [`Event`]s to make
84+ /// Objects of this type receive [`ConnectionDatagram `]s and emit application [`Event`]s to make
8585/// progress. To handle timeouts, a `Connection` returns timer updates and expects timeouts through
8686/// various methods. A number of simple getter methods are exposed to allow callers to inspect some
8787/// of the connection state.
@@ -112,11 +112,10 @@ use timer::{Timer, TimerTable};
112112///
113113/// (A) may be called whenever desired.
114114///
115- /// Care should be made to ensure that the input events represent monotonically
116- /// increasing time. Specifically, calling [`handle_timeout`](Self::handle_timeout)
117- /// with events of the same [`Instant`] may be interleaved in any order with a
118- /// call to [`handle_event`](Self::handle_event) at that same instant; however
119- /// events or timeouts with different instants must not be interleaved.
115+ /// Care should be made to ensure that the input events represent monotonically increasing
116+ /// time. Specifically, calling [`handle_timeout`](Self::handle_timeout) with events of the same
117+ /// [`Instant`] may be interleaved in any order with a call to [`handle`](Self::handle) at that same
118+ /// instant; however events or timeouts with different instants must not be interleaved.
120119pub struct Connection {
121120 handle : ConnectionHandle ,
122121 endpoint_config : Arc < EndpointConfig > ,
@@ -873,56 +872,51 @@ impl Connection {
873872 SendableFrames :: empty ( )
874873 }
875874
876- /// Process `ConnectionEvent`s generated by the associated `Endpoint`
875+ /// Process an incoming [`ConnectionDatagram`] forwarded from the associated `Endpoint`
877876 ///
878877 /// Will execute protocol logic upon receipt of a connection event, in turn preparing signals
879878 /// (including application `Event`s and outgoing datagrams) that should be extracted through the
880879 /// 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- }
880+ pub fn handle ( & mut self , datagram : ConnectionDatagram , endpoint : & Endpoint ) {
881+ let ConnectionDatagram {
882+ now,
883+ remote,
884+ ecn,
885+ first_decode,
886+ remaining,
887+ } = datagram;
888+ // If this packet could initiate a migration and we're a client or a server that
889+ // forbids migration, drop the datagram. This could be relaxed to heuristically
890+ // permit NAT-rebinding-like migration.
891+ if remote != self . path . remote && self . server_config . as_ref ( ) . map_or ( true , |x| !x. migration )
892+ {
893+ trace ! ( "discarding packet from unrecognized peer {}" , remote) ;
894+ return ;
895+ }
900896
901- let was_anti_amplification_blocked = self . path . anti_amplification_blocked ( 1 ) ;
897+ let was_anti_amplification_blocked = self . path . anti_amplification_blocked ( 1 ) ;
902898
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 ( ) ;
899+ self . stats . udp_rx . datagrams += 1 ;
900+ self . stats . udp_rx . bytes += first_decode. len ( ) as u64 ;
901+ let data_len = first_decode. len ( ) ;
906902
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 ) ;
903+ self . handle_decode ( now, remote, ecn, first_decode, endpoint) ;
904+ // The current `path` might have changed inside `handle_decode`,
905+ // since the packet could have triggered a migration. Make sure
906+ // the data received is accounted for the most recent path by accessing
907+ // `path` after `handle_decode`.
908+ self . path . total_recvd = self . path . total_recvd . saturating_add ( data_len as u64 ) ;
913909
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- }
910+ if let Some ( data) = remaining {
911+ self . stats . udp_rx . bytes += data. len ( ) as u64 ;
912+ self . handle_coalesced ( now, remote, ecn, data, endpoint) ;
913+ }
918914
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- }
915+ if was_anti_amplification_blocked {
916+ // A prior attempt to set the loss detection timer may have failed due to
917+ // anti-amplification, so ensure it's set now. Prevents a handshake deadlock if
918+ // the server's first flight is lost.
919+ self . set_loss_detection_timer ( now) ;
926920 }
927921 }
928922
0 commit comments