github.com/mikelsr/quic-go@v0.36.1-0.20230701132136-1d9415b66898/internal/protocol/protocol.go (about) 1 package protocol 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 // The PacketType is the Long Header Type 9 type PacketType uint8 10 11 const ( 12 // PacketTypeInitial is the packet type of an Initial packet 13 PacketTypeInitial PacketType = 1 + iota 14 // PacketTypeRetry is the packet type of a Retry packet 15 PacketTypeRetry 16 // PacketTypeHandshake is the packet type of a Handshake packet 17 PacketTypeHandshake 18 // PacketType0RTT is the packet type of a 0-RTT packet 19 PacketType0RTT 20 ) 21 22 func (t PacketType) String() string { 23 switch t { 24 case PacketTypeInitial: 25 return "Initial" 26 case PacketTypeRetry: 27 return "Retry" 28 case PacketTypeHandshake: 29 return "Handshake" 30 case PacketType0RTT: 31 return "0-RTT Protected" 32 default: 33 return fmt.Sprintf("unknown packet type: %d", t) 34 } 35 } 36 37 type ECN uint8 38 39 const ( 40 ECNNon ECN = iota // 00 41 ECT1 // 01 42 ECT0 // 10 43 ECNCE // 11 44 ) 45 46 // A ByteCount in QUIC 47 type ByteCount int64 48 49 // MaxByteCount is the maximum value of a ByteCount 50 const MaxByteCount = ByteCount(1<<62 - 1) 51 52 // InvalidByteCount is an invalid byte count 53 const InvalidByteCount ByteCount = -1 54 55 // A StatelessResetToken is a stateless reset token. 56 type StatelessResetToken [16]byte 57 58 // MaxPacketBufferSize maximum packet size of any QUIC packet, based on 59 // ethernet's max size, minus the IP and UDP headers. IPv6 has a 40 byte header, 60 // UDP adds an additional 8 bytes. This is a total overhead of 48 bytes. 61 // Ethernet's max packet size is 1500 bytes, 1500 - 48 = 1452. 62 const MaxPacketBufferSize = 1452 63 64 // MaxLargePacketBufferSize is used when using GSO 65 const MaxLargePacketBufferSize = 20 * 1024 66 67 // MinInitialPacketSize is the minimum size an Initial packet is required to have. 68 const MinInitialPacketSize = 1200 69 70 // MinUnknownVersionPacketSize is the minimum size a packet with an unknown version 71 // needs to have in order to trigger a Version Negotiation packet. 72 const MinUnknownVersionPacketSize = MinInitialPacketSize 73 74 // MinStatelessResetSize is the minimum size of a stateless reset packet that we send 75 const MinStatelessResetSize = 1 /* first byte */ + 20 /* max. conn ID length */ + 4 /* max. packet number length */ + 1 /* min. payload length */ + 16 /* token */ 76 77 // MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet. 78 const MinConnectionIDLenInitial = 8 79 80 // DefaultAckDelayExponent is the default ack delay exponent 81 const DefaultAckDelayExponent = 3 82 83 // DefaultActiveConnectionIDLimit is the default active connection ID limit 84 const DefaultActiveConnectionIDLimit = 2 85 86 // MaxAckDelayExponent is the maximum ack delay exponent 87 const MaxAckDelayExponent = 20 88 89 // DefaultMaxAckDelay is the default max_ack_delay 90 const DefaultMaxAckDelay = 25 * time.Millisecond 91 92 // MaxMaxAckDelay is the maximum max_ack_delay 93 const MaxMaxAckDelay = (1<<14 - 1) * time.Millisecond 94 95 // MaxConnIDLen is the maximum length of the connection ID 96 const MaxConnIDLen = 20 97 98 // InvalidPacketLimitAES is the maximum number of packets that we can fail to decrypt when using 99 // AEAD_AES_128_GCM or AEAD_AES_265_GCM. 100 const InvalidPacketLimitAES = 1 << 52 101 102 // InvalidPacketLimitChaCha is the maximum number of packets that we can fail to decrypt when using AEAD_CHACHA20_POLY1305. 103 const InvalidPacketLimitChaCha = 1 << 36