protocol.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package protocol
  2. import (
  3. "fmt"
  4. )
  5. // A PacketNumber in QUIC
  6. type PacketNumber uint64
  7. // The PacketType is the Long Header Type
  8. type PacketType uint8
  9. const (
  10. // PacketTypeInitial is the packet type of an Initial packet
  11. PacketTypeInitial PacketType = 1 + iota
  12. // PacketTypeRetry is the packet type of a Retry packet
  13. PacketTypeRetry
  14. // PacketTypeHandshake is the packet type of a Handshake packet
  15. PacketTypeHandshake
  16. // PacketType0RTT is the packet type of a 0-RTT packet
  17. PacketType0RTT
  18. )
  19. func (t PacketType) String() string {
  20. switch t {
  21. case PacketTypeInitial:
  22. return "Initial"
  23. case PacketTypeRetry:
  24. return "Retry"
  25. case PacketTypeHandshake:
  26. return "Handshake"
  27. case PacketType0RTT:
  28. return "0-RTT Protected"
  29. default:
  30. return fmt.Sprintf("unknown packet type: %d", t)
  31. }
  32. }
  33. // A ByteCount in QUIC
  34. type ByteCount uint64
  35. // MaxByteCount is the maximum value of a ByteCount
  36. const MaxByteCount = ByteCount(1<<62 - 1)
  37. // An ApplicationErrorCode is an application-defined error code.
  38. type ApplicationErrorCode uint16
  39. // MaxReceivePacketSize maximum packet size of any QUIC packet, based on
  40. // ethernet's max size, minus the IP and UDP headers. IPv6 has a 40 byte header,
  41. // UDP adds an additional 8 bytes. This is a total overhead of 48 bytes.
  42. // Ethernet's max packet size is 1500 bytes, 1500 - 48 = 1452.
  43. const MaxReceivePacketSize ByteCount = 1452 - 64
  44. // DefaultTCPMSS is the default maximum packet size used in the Linux TCP implementation.
  45. // Used in QUIC for congestion window computations in bytes.
  46. const DefaultTCPMSS ByteCount = 1460
  47. // MinInitialPacketSize is the minimum size an Initial packet is required to have.
  48. const MinInitialPacketSize = 1200
  49. // MinStatelessResetSize is the minimum size of a stateless reset packet
  50. const MinStatelessResetSize = 1 /* first byte */ + 22 /* random bytes */ + 16 /* token */
  51. // MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet.
  52. const MinConnectionIDLenInitial = 8