flight.go 3.0 KB

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