1
2
3
4
5 package quic
6
7 import (
8 "time"
9 )
10
11
12
13 const (
14 quicVersion1 = 1
15 quicVersion2 = 0x6b3343cf
16 )
17
18
19
20
21
22 const connIDLen = 8
23
24
25
26 const (
27 defaultMaxIdleTimeout = 30 * time.Second
28
29
30
31
32
33
34
35
36
37
38
39 maxUDPPayloadSize = 1472
40
41 ackDelayExponent = 3
42 maxAckDelay = 25 * time.Millisecond
43
44
45
46
47
48
49
50
51 activeConnIDLimit = 2
52 maxPeerActiveConnIDLimit = 4
53 )
54
55
56 const defaultHandshakeTimeout = 10 * time.Second
57
58
59 const defaultKeepAlivePeriod = 0
60
61
62
63 const timerGranularity = 1 * time.Millisecond
64
65
66
67 const smallestMaxDatagramSize = 1200
68
69
70
71
72 const paddedInitialDatagramSize = smallestMaxDatagramSize
73
74
75
76 const maxStreamsLimit = 1 << 60
77
78
79
80
81
82
83 const implicitStreamLimit = 100
84
85
86 type connSide int8
87
88 const (
89 clientSide = connSide(iota)
90 serverSide
91 )
92
93 func (s connSide) String() string {
94 switch s {
95 case clientSide:
96 return "client"
97 case serverSide:
98 return "server"
99 default:
100 return "BUG"
101 }
102 }
103
104 func (s connSide) peer() connSide {
105 if s == clientSide {
106 return serverSide
107 } else {
108 return clientSide
109 }
110 }
111
112
113
114 type numberSpace byte
115
116 const (
117 initialSpace = numberSpace(iota)
118 handshakeSpace
119 appDataSpace
120 numberSpaceCount
121 )
122
123 func (n numberSpace) String() string {
124 switch n {
125 case initialSpace:
126 return "Initial"
127 case handshakeSpace:
128 return "Handshake"
129 case appDataSpace:
130 return "AppData"
131 default:
132 return "BUG"
133 }
134 }
135
136
137 type streamType uint8
138
139 const (
140 bidiStream = streamType(iota)
141 uniStream
142 streamTypeCount
143 )
144
145 func (s streamType) qlogString() string {
146 switch s {
147 case bidiStream:
148 return "bidirectional"
149 case uniStream:
150 return "unidirectional"
151 default:
152 return "BUG"
153 }
154 }
155
156 func (s streamType) String() string {
157 switch s {
158 case bidiStream:
159 return "bidi"
160 case uniStream:
161 return "uni"
162 default:
163 return "BUG"
164 }
165 }
166
167
168
169 type streamID uint64
170
171
172
173
174
175 const (
176 clientInitiatedStreamBit = 0x0
177 serverInitiatedStreamBit = 0x1
178 initiatorStreamBitMask = 0x1
179
180 bidiStreamBit = 0x0
181 uniStreamBit = 0x2
182 dirStreamBitMask = 0x2
183 )
184
185 func newStreamID(initiator connSide, typ streamType, num int64) streamID {
186 id := streamID(num << 2)
187 if typ == uniStream {
188 id |= uniStreamBit
189 }
190 if initiator == serverSide {
191 id |= serverInitiatedStreamBit
192 }
193 return id
194 }
195
196 func (s streamID) initiator() connSide {
197 if s&initiatorStreamBitMask == serverInitiatedStreamBit {
198 return serverSide
199 }
200 return clientSide
201 }
202
203 func (s streamID) num() int64 {
204 return int64(s) >> 2
205 }
206
207 func (s streamID) streamType() streamType {
208 if s&dirStreamBitMask == uniStreamBit {
209 return uniStream
210 }
211 return bidiStream
212 }
213
214
215
216 type packetFate byte
217
218 const (
219 packetLost = packetFate(iota)
220 packetAcked
221 )
222
View as plain text