flight.go 3.1 KB

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