github.com/ooni/psiphon/tunnel-core@v0.0.0-20230105123940-fe12a24c96ee/oovendor/quic-go/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 ByteCount = 1452 63 64 // MinInitialPacketSize is the minimum size an Initial packet is required to have. 65 const MinInitialPacketSize = 1200 66 67 // MinUnknownVersionPacketSize is the minimum size a packet with an unknown version 68 // needs to have in order to trigger a Version Negotiation packet. 69 const MinUnknownVersionPacketSize = MinInitialPacketSize 70 71 // MinStatelessResetSize is the minimum size of a stateless reset packet that we send 72 const MinStatelessResetSize = 1 /* first byte */ + 20 /* max. conn ID length */ + 4 /* max. packet number length */ + 1 /* min. payload length */ + 16 /* token */ 73 74 // MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet. 75 const MinConnectionIDLenInitial = 8 76 77 // DefaultAckDelayExponent is the default ack delay exponent 78 const DefaultAckDelayExponent = 3 79 80 // MaxAckDelayExponent is the maximum ack delay exponent 81 const MaxAckDelayExponent = 20 82 83 // DefaultMaxAckDelay is the default max_ack_delay 84 const DefaultMaxAckDelay = 25 * time.Millisecond 85 86 // MaxMaxAckDelay is the maximum max_ack_delay 87 const MaxMaxAckDelay = (1<<14 - 1) * time.Millisecond 88 89 // MaxConnIDLen is the maximum length of the connection ID 90 const MaxConnIDLen = 20 91 92 // InvalidPacketLimitAES is the maximum number of packets that we can fail to decrypt when using 93 // AEAD_AES_128_GCM or AEAD_AES_265_GCM. 94 const InvalidPacketLimitAES = 1 << 52 95 96 // InvalidPacketLimitChaCha is the maximum number of packets that we can fail to decrypt when using AEAD_CHACHA20_POLY1305. 97 const InvalidPacketLimitChaCha = 1 << 36