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