@@ -12,6 +12,7 @@ import (
1212 dtlsflight "github.com/pion/dtls/v3/internal/flight"
1313 dtlsflight13 "github.com/pion/dtls/v3/internal/flight/flight13"
1414 dtlsstate "github.com/pion/dtls/v3/internal/state"
15+ "github.com/pion/dtls/v3/pkg/protocol"
1516 "github.com/pion/dtls/v3/pkg/protocol/alert"
1617 "github.com/pion/dtls/v3/pkg/protocol/handshake"
1718)
@@ -347,7 +348,7 @@ func (s *fsm13) finish(ctx context.Context, conn Conn) (State, error) {
347348 return StateFinished , nil
348349}
349350
350- func (s * fsm13 ) handleReceivedFlight (
351+ func (s * fsm13 ) handleReceivedFlight ( //nolint:cyclop
351352 ctx context.Context ,
352353 conn Conn ,
353354 received RecvHandshakeState ,
@@ -362,6 +363,9 @@ func (s *fsm13) handleReceivedFlight(
362363 if ! received .HasHandshake && len (received .ACKs ) != 0 {
363364 return s .transitionAfterACK (ackResult , false ), nil
364365 }
366+ if received .HasHandshake && received .IsRetransmit && s .currentFlight .IsLastSendFlight () {
367+ return s .handlePreviousFlightRetransmit (ctx , conn , received .RecordsToACK , ackResult )
368+ }
365369
366370 nextFlight , err := s .parseReceivedFlight (ctx , conn , s .currentFlight )
367371 if err != nil {
@@ -386,6 +390,23 @@ func (s *fsm13) handleReceivedFlight(
386390 return transition , nil
387391}
388392
393+ func (s * fsm13 ) handlePreviousFlightRetransmit (
394+ ctx context.Context ,
395+ conn Conn ,
396+ recordsToACK []protocol.RecordNumber ,
397+ ackResult ACKResult ,
398+ ) (receivedFlightTransition , error ) {
399+ // A duplicate peer flight means it didn't receive our response.
400+ // ACK the duplicate and retransmit the pending final flight.
401+ // check WAIT exit 3:
402+ // https://datatracker.ietf.org/doc/html/rfc9147#section-5.8.1
403+ if err := sendACK (ctx , conn , s .state .LocalEpoch (), recordsToACK ); err != nil {
404+ return receivedFlightTransition {}, err
405+ }
406+
407+ return s .transitionAfterACK (ackResult , true ), nil
408+ }
409+
389410func (s * fsm13 ) prepareFlightACKTracking (flights []* dtlsflight.Packet , retransmit bool ) {
390411 s .flightACK .reset ()
391412 if retransmit {
0 commit comments