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