forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.go
372 lines (333 loc) · 8.47 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
package qlog
import (
"fmt"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/qerr"
"github.com/quic-go/quic-go/logging"
)
type owner uint8
const (
ownerLocal owner = iota
ownerRemote
)
func (o owner) String() string {
switch o {
case ownerLocal:
return "local"
case ownerRemote:
return "remote"
default:
return "unknown owner"
}
}
type streamType protocol.StreamType
func (s streamType) String() string {
switch protocol.StreamType(s) {
case protocol.StreamTypeUni:
return "unidirectional"
case protocol.StreamTypeBidi:
return "bidirectional"
default:
return "unknown stream type"
}
}
// category is the qlog event category.
type category uint8
const (
categoryConnectivity category = iota
categoryTransport
categorySecurity
categoryRecovery
)
func (c category) String() string {
switch c {
case categoryConnectivity:
return "connectivity"
case categoryTransport:
return "transport"
case categorySecurity:
return "security"
case categoryRecovery:
return "recovery"
default:
return "unknown category"
}
}
type versionNumber protocol.Version
func (v versionNumber) String() string {
return fmt.Sprintf("%x", uint32(v))
}
func (packetHeader) IsNil() bool { return false }
func encLevelToPacketNumberSpace(encLevel protocol.EncryptionLevel) string {
switch encLevel {
case protocol.EncryptionInitial:
return "initial"
case protocol.EncryptionHandshake:
return "handshake"
case protocol.Encryption0RTT, protocol.Encryption1RTT:
return "application_data"
default:
return "unknown encryption level"
}
}
type keyType uint8
const (
keyTypeServerInitial keyType = 1 + iota
keyTypeClientInitial
keyTypeServerHandshake
keyTypeClientHandshake
keyTypeServer0RTT
keyTypeClient0RTT
keyTypeServer1RTT
keyTypeClient1RTT
)
func encLevelToKeyType(encLevel protocol.EncryptionLevel, pers protocol.Perspective) keyType {
if pers == protocol.PerspectiveServer {
switch encLevel {
case protocol.EncryptionInitial:
return keyTypeServerInitial
case protocol.EncryptionHandshake:
return keyTypeServerHandshake
case protocol.Encryption0RTT:
return keyTypeServer0RTT
case protocol.Encryption1RTT:
return keyTypeServer1RTT
default:
return 0
}
}
switch encLevel {
case protocol.EncryptionInitial:
return keyTypeClientInitial
case protocol.EncryptionHandshake:
return keyTypeClientHandshake
case protocol.Encryption0RTT:
return keyTypeClient0RTT
case protocol.Encryption1RTT:
return keyTypeClient1RTT
default:
return 0
}
}
func (t keyType) String() string {
switch t {
case keyTypeServerInitial:
return "server_initial_secret"
case keyTypeClientInitial:
return "client_initial_secret"
case keyTypeServerHandshake:
return "server_handshake_secret"
case keyTypeClientHandshake:
return "client_handshake_secret"
case keyTypeServer0RTT:
return "server_0rtt_secret"
case keyTypeClient0RTT:
return "client_0rtt_secret"
case keyTypeServer1RTT:
return "server_1rtt_secret"
case keyTypeClient1RTT:
return "client_1rtt_secret"
default:
return "unknown key type"
}
}
type keyUpdateTrigger uint8
const (
keyUpdateTLS keyUpdateTrigger = iota
keyUpdateRemote
keyUpdateLocal
)
func (t keyUpdateTrigger) String() string {
switch t {
case keyUpdateTLS:
return "tls"
case keyUpdateRemote:
return "remote_update"
case keyUpdateLocal:
return "local_update"
default:
return "unknown key update trigger"
}
}
type transportError uint64
func (e transportError) String() string {
switch qerr.TransportErrorCode(e) {
case qerr.NoError:
return "no_error"
case qerr.InternalError:
return "internal_error"
case qerr.ConnectionRefused:
return "connection_refused"
case qerr.FlowControlError:
return "flow_control_error"
case qerr.StreamLimitError:
return "stream_limit_error"
case qerr.StreamStateError:
return "stream_state_error"
case qerr.FinalSizeError:
return "final_size_error"
case qerr.FrameEncodingError:
return "frame_encoding_error"
case qerr.TransportParameterError:
return "transport_parameter_error"
case qerr.ConnectionIDLimitError:
return "connection_id_limit_error"
case qerr.ProtocolViolation:
return "protocol_violation"
case qerr.InvalidToken:
return "invalid_token"
case qerr.ApplicationErrorErrorCode:
return "application_error"
case qerr.CryptoBufferExceeded:
return "crypto_buffer_exceeded"
case qerr.KeyUpdateError:
return "key_update_error"
case qerr.AEADLimitReached:
return "aead_limit_reached"
case qerr.NoViablePathError:
return "no_viable_path"
default:
return ""
}
}
type packetType logging.PacketType
func (t packetType) String() string {
switch logging.PacketType(t) {
case logging.PacketTypeInitial:
return "initial"
case logging.PacketTypeHandshake:
return "handshake"
case logging.PacketTypeRetry:
return "retry"
case logging.PacketType0RTT:
return "0RTT"
case logging.PacketTypeVersionNegotiation:
return "version_negotiation"
case logging.PacketTypeStatelessReset:
return "stateless_reset"
case logging.PacketType1RTT:
return "1RTT"
case logging.PacketTypeNotDetermined:
return ""
default:
return "unknown packet type"
}
}
type packetLossReason logging.PacketLossReason
func (r packetLossReason) String() string {
switch logging.PacketLossReason(r) {
case logging.PacketLossReorderingThreshold:
return "reordering_threshold"
case logging.PacketLossTimeThreshold:
return "time_threshold"
default:
return "unknown loss reason"
}
}
type packetDropReason logging.PacketDropReason
func (r packetDropReason) String() string {
switch logging.PacketDropReason(r) {
case logging.PacketDropKeyUnavailable:
return "key_unavailable"
case logging.PacketDropUnknownConnectionID:
return "unknown_connection_id"
case logging.PacketDropHeaderParseError:
return "header_parse_error"
case logging.PacketDropPayloadDecryptError:
return "payload_decrypt_error"
case logging.PacketDropProtocolViolation:
return "protocol_violation"
case logging.PacketDropDOSPrevention:
return "dos_prevention"
case logging.PacketDropUnsupportedVersion:
return "unsupported_version"
case logging.PacketDropUnexpectedPacket:
return "unexpected_packet"
case logging.PacketDropUnexpectedSourceConnectionID:
return "unexpected_source_connection_id"
case logging.PacketDropUnexpectedVersion:
return "unexpected_version"
case logging.PacketDropDuplicate:
return "duplicate"
default:
return "unknown packet drop reason"
}
}
type timerType logging.TimerType
func (t timerType) String() string {
switch logging.TimerType(t) {
case logging.TimerTypeACK:
return "ack"
case logging.TimerTypePTO:
return "pto"
default:
return "unknown timer type"
}
}
type congestionState logging.CongestionState
func (s congestionState) String() string {
switch logging.CongestionState(s) {
case logging.CongestionStateSlowStart:
return "slow_start"
case logging.CongestionStateCongestionAvoidance:
return "congestion_avoidance"
case logging.CongestionStateRecovery:
return "recovery"
case logging.CongestionStateApplicationLimited:
return "application_limited"
default:
return "unknown congestion state"
}
}
type ecn logging.ECN
func (e ecn) String() string {
//nolint:exhaustive // The unsupported value is never logged.
switch logging.ECN(e) {
case logging.ECTNot:
return "Not-ECT"
case logging.ECT0:
return "ECT(0)"
case logging.ECT1:
return "ECT(1)"
case logging.ECNCE:
return "CE"
default:
return "unknown ECN"
}
}
type ecnState logging.ECNState
func (e ecnState) String() string {
switch logging.ECNState(e) {
case logging.ECNStateTesting:
return "testing"
case logging.ECNStateUnknown:
return "unknown"
case logging.ECNStateCapable:
return "capable"
case logging.ECNStateFailed:
return "failed"
default:
return "unknown ECN state"
}
}
type ecnStateTrigger logging.ECNStateTrigger
func (e ecnStateTrigger) String() string {
switch logging.ECNStateTrigger(e) {
case logging.ECNTriggerNoTrigger:
return ""
case logging.ECNFailedNoECNCounts:
return "ACK doesn't contain ECN marks"
case logging.ECNFailedDecreasedECNCounts:
return "ACK decreases ECN counts"
case logging.ECNFailedLostAllTestingPackets:
return "all ECN testing packets declared lost"
case logging.ECNFailedMoreECNCountsThanSent:
return "ACK contains more ECN counts than ECN-marked packets sent"
case logging.ECNFailedTooFewECNCounts:
return "ACK contains fewer new ECN counts than acknowledged ECN-marked packets"
case logging.ECNFailedManglingDetected:
return "ECN mangling detected"
default:
return "unknown ECN state trigger"
}
}