@@ -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
0 commit comments