1
2
3
4
5 package quic
6
7 import (
8 "fmt"
9 )
10
11
12
13
14
15
16 type transportError uint64
17
18
19 const (
20 errNo = transportError(0x00)
21 errInternal = transportError(0x01)
22 errConnectionRefused = transportError(0x02)
23 errFlowControl = transportError(0x03)
24 errStreamLimit = transportError(0x04)
25 errStreamState = transportError(0x05)
26 errFinalSize = transportError(0x06)
27 errFrameEncoding = transportError(0x07)
28 errTransportParameter = transportError(0x08)
29 errConnectionIDLimit = transportError(0x09)
30 errProtocolViolation = transportError(0x0a)
31 errInvalidToken = transportError(0x0b)
32 errApplicationError = transportError(0x0c)
33 errCryptoBufferExceeded = transportError(0x0d)
34 errKeyUpdateError = transportError(0x0e)
35 errAEADLimitReached = transportError(0x0f)
36 errNoViablePath = transportError(0x10)
37 errTLSBase = transportError(0x0100)
38 )
39
40 func (e transportError) String() string {
41 switch e {
42 case errNo:
43 return "NO_ERROR"
44 case errInternal:
45 return "INTERNAL_ERROR"
46 case errConnectionRefused:
47 return "CONNECTION_REFUSED"
48 case errFlowControl:
49 return "FLOW_CONTROL_ERROR"
50 case errStreamLimit:
51 return "STREAM_LIMIT_ERROR"
52 case errStreamState:
53 return "STREAM_STATE_ERROR"
54 case errFinalSize:
55 return "FINAL_SIZE_ERROR"
56 case errFrameEncoding:
57 return "FRAME_ENCODING_ERROR"
58 case errTransportParameter:
59 return "TRANSPORT_PARAMETER_ERROR"
60 case errConnectionIDLimit:
61 return "CONNECTION_ID_LIMIT_ERROR"
62 case errProtocolViolation:
63 return "PROTOCOL_VIOLATION"
64 case errInvalidToken:
65 return "INVALID_TOKEN"
66 case errApplicationError:
67 return "APPLICATION_ERROR"
68 case errCryptoBufferExceeded:
69 return "CRYPTO_BUFFER_EXCEEDED"
70 case errKeyUpdateError:
71 return "KEY_UPDATE_ERROR"
72 case errAEADLimitReached:
73 return "AEAD_LIMIT_REACHED"
74 case errNoViablePath:
75 return "NO_VIABLE_PATH"
76 }
77 if e >= 0x0100 && e <= 0x01ff {
78 return fmt.Sprintf("CRYPTO_ERROR(%v)", uint64(e)&0xff)
79 }
80 return fmt.Sprintf("ERROR %d", uint64(e))
81 }
82
83
84 type localTransportError struct {
85 code transportError
86 reason string
87 }
88
89 func (e localTransportError) Error() string {
90 if e.reason == "" {
91 return fmt.Sprintf("closed connection: %v", e.code)
92 }
93 return fmt.Sprintf("closed connection: %v: %q", e.code, e.reason)
94 }
95
96
97 type peerTransportError struct {
98 code transportError
99 reason string
100 }
101
102 func (e peerTransportError) Error() string {
103 return fmt.Sprintf("peer closed connection: %v: %q", e.code, e.reason)
104 }
105
106
107
108 type StreamErrorCode uint64
109
110 func (e StreamErrorCode) Error() string {
111 return fmt.Sprintf("stream error code %v", uint64(e))
112 }
113
114
115
116 type ApplicationError struct {
117 Code uint64
118 Reason string
119 }
120
121 func (e *ApplicationError) Error() string {
122 return fmt.Sprintf("peer closed connection: %v: %q", e.Code, e.Reason)
123 }
124
125
126 func (e *ApplicationError) Is(err error) bool {
127 e2, ok := err.(*ApplicationError)
128 return ok && e2.Code == e.Code
129 }
130
View as plain text