github.com/pion/dtls/v2@v2.2.12/flight.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package dtls 5 6 /* 7 DTLS messages are grouped into a series of message flights, according 8 to the diagrams below. Although each flight of messages may consist 9 of a number of messages, they should be viewed as monolithic for the 10 purpose of timeout and retransmission. 11 https://tools.ietf.org/html/rfc4347#section-4.2.4 12 13 Message flights for full handshake: 14 15 Client Server 16 ------ ------ 17 Waiting Flight 0 18 19 ClientHello --------> Flight 1 20 21 <------- HelloVerifyRequest Flight 2 22 23 ClientHello --------> Flight 3 24 25 ServerHello \ 26 Certificate* \ 27 ServerKeyExchange* Flight 4 28 CertificateRequest* / 29 <-------- ServerHelloDone / 30 31 Certificate* \ 32 ClientKeyExchange \ 33 CertificateVerify* Flight 5 34 [ChangeCipherSpec] / 35 Finished --------> / 36 37 [ChangeCipherSpec] \ Flight 6 38 <-------- Finished / 39 40 Message flights for session-resuming handshake (no cookie exchange): 41 42 Client Server 43 ------ ------ 44 Waiting Flight 0 45 46 ClientHello --------> Flight 1 47 48 ServerHello \ 49 [ChangeCipherSpec] Flight 4b 50 <-------- Finished / 51 52 [ChangeCipherSpec] \ Flight 5b 53 Finished --------> / 54 55 [ChangeCipherSpec] \ Flight 6 56 <-------- Finished / 57 */ 58 59 type flightVal uint8 60 61 const ( 62 flight0 flightVal = iota + 1 63 flight1 64 flight2 65 flight3 66 flight4 67 flight4b 68 flight5 69 flight5b 70 flight6 71 ) 72 73 func (f flightVal) String() string { 74 switch f { 75 case flight0: 76 return "Flight 0" 77 case flight1: 78 return "Flight 1" 79 case flight2: 80 return "Flight 2" 81 case flight3: 82 return "Flight 3" 83 case flight4: 84 return "Flight 4" 85 case flight4b: 86 return "Flight 4b" 87 case flight5: 88 return "Flight 5" 89 case flight5b: 90 return "Flight 5b" 91 case flight6: 92 return "Flight 6" 93 default: 94 return "Invalid Flight" 95 } 96 } 97 98 func (f flightVal) isLastSendFlight() bool { 99 return f == flight6 || f == flight5b 100 } 101 102 func (f flightVal) isLastRecvFlight() bool { 103 return f == flight5 || f == flight4b 104 }