github.com/pion/dtls/v2@v2.2.12/flighthandler.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package dtls
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/pion/dtls/v2/pkg/protocol/alert"
    10  )
    11  
    12  // Parse received handshakes and return next flightVal
    13  type flightParser func(context.Context, flightConn, *State, *handshakeCache, *handshakeConfig) (flightVal, *alert.Alert, error)
    14  
    15  // Generate flights
    16  type flightGenerator func(flightConn, *State, *handshakeCache, *handshakeConfig) ([]*packet, *alert.Alert, error)
    17  
    18  func (f flightVal) getFlightParser() (flightParser, error) {
    19  	switch f {
    20  	case flight0:
    21  		return flight0Parse, nil
    22  	case flight1:
    23  		return flight1Parse, nil
    24  	case flight2:
    25  		return flight2Parse, nil
    26  	case flight3:
    27  		return flight3Parse, nil
    28  	case flight4:
    29  		return flight4Parse, nil
    30  	case flight4b:
    31  		return flight4bParse, nil
    32  	case flight5:
    33  		return flight5Parse, nil
    34  	case flight5b:
    35  		return flight5bParse, nil
    36  	case flight6:
    37  		return flight6Parse, nil
    38  	default:
    39  		return nil, errInvalidFlight
    40  	}
    41  }
    42  
    43  func (f flightVal) getFlightGenerator() (gen flightGenerator, retransmit bool, err error) {
    44  	switch f {
    45  	case flight0:
    46  		return flight0Generate, true, nil
    47  	case flight1:
    48  		return flight1Generate, true, nil
    49  	case flight2:
    50  		// https://tools.ietf.org/html/rfc6347#section-3.2.1
    51  		// HelloVerifyRequests must not be retransmitted.
    52  		return flight2Generate, false, nil
    53  	case flight3:
    54  		return flight3Generate, true, nil
    55  	case flight4:
    56  		return flight4Generate, true, nil
    57  	case flight4b:
    58  		return flight4bGenerate, true, nil
    59  	case flight5:
    60  		return flight5Generate, true, nil
    61  	case flight5b:
    62  		return flight5bGenerate, true, nil
    63  	case flight6:
    64  		return flight6Generate, true, nil
    65  	default:
    66  		return nil, false, errInvalidFlight
    67  	}
    68  }