protocol.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package protocol
  2. import (
  3. "fmt"
  4. )
  5. // A PacketNumber in QUIC
  6. type PacketNumber uint64
  7. // PacketNumberLen is the length of the packet number in bytes
  8. type PacketNumberLen uint8
  9. const (
  10. // PacketNumberLenInvalid is the default value and not a valid length for a packet number
  11. PacketNumberLenInvalid PacketNumberLen = 0
  12. // PacketNumberLen1 is a packet number length of 1 byte
  13. PacketNumberLen1 PacketNumberLen = 1
  14. // PacketNumberLen2 is a packet number length of 2 bytes
  15. PacketNumberLen2 PacketNumberLen = 2
  16. // PacketNumberLen4 is a packet number length of 4 bytes
  17. PacketNumberLen4 PacketNumberLen = 4
  18. // PacketNumberLen6 is a packet number length of 6 bytes
  19. PacketNumberLen6 PacketNumberLen = 6
  20. )
  21. // The PacketType is the Long Header Type (only used for the IETF draft header format)
  22. type PacketType uint8
  23. const (
  24. // PacketTypeInitial is the packet type of an Initial packet
  25. PacketTypeInitial PacketType = 0x7f
  26. // PacketTypeRetry is the packet type of a Retry packet
  27. PacketTypeRetry PacketType = 0x7e
  28. // PacketTypeHandshake is the packet type of a Handshake packet
  29. PacketTypeHandshake PacketType = 0x7d
  30. // PacketType0RTT is the packet type of a 0-RTT packet
  31. PacketType0RTT PacketType = 0x7c
  32. )
  33. func (t PacketType) String() string {
  34. switch t {
  35. case PacketTypeInitial:
  36. return "Initial"
  37. case PacketTypeRetry:
  38. return "Retry"
  39. case PacketTypeHandshake:
  40. return "Handshake"
  41. case PacketType0RTT:
  42. return "0-RTT Protected"
  43. default:
  44. return fmt.Sprintf("unknown packet type: %d", t)
  45. }
  46. }
  47. // A ByteCount in QUIC
  48. type ByteCount uint64
  49. // MaxByteCount is the maximum value of a ByteCount
  50. const MaxByteCount = ByteCount(1<<62 - 1)
  51. // An ApplicationErrorCode is an application-defined error code.
  52. type ApplicationErrorCode uint16
  53. // MaxReceivePacketSize maximum packet size of any QUIC packet, based on
  54. // ethernet's max size, minus the IP and UDP headers. IPv6 has a 40 byte header,
  55. // UDP adds an additional 8 bytes. This is a total overhead of 48 bytes.
  56. // Ethernet's max packet size is 1500 bytes, 1500 - 48 = 1452.
  57. const MaxReceivePacketSize ByteCount = 1452
  58. // DefaultTCPMSS is the default maximum packet size used in the Linux TCP implementation.
  59. // Used in QUIC for congestion window computations in bytes.
  60. const DefaultTCPMSS ByteCount = 1460
  61. // MinClientHelloSize is the minimum size the server expects an inchoate CHLO to have (in gQUIC)
  62. const MinClientHelloSize = 1024
  63. // MinInitialPacketSize is the minimum size an Initial packet (in IETF QUIC) is required to have.
  64. const MinInitialPacketSize = 1200
  65. // MaxClientHellos is the maximum number of times we'll send a client hello
  66. // The value 3 accounts for:
  67. // * one failure due to an incorrect or missing source-address token
  68. // * one failure due the server's certificate chain being unavailable and the server being unwilling to send it without a valid source-address token
  69. const MaxClientHellos = 3
  70. // ConnectionIDLenGQUIC is the length of the source Connection ID used on gQUIC QUIC packets.
  71. const ConnectionIDLenGQUIC = 8
  72. // MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet.
  73. const MinConnectionIDLenInitial = 8