rwebtransport 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/Cargo.lock +666 -666
  2. package/Cargo.toml +31 -31
  3. package/LICENSE +202 -202
  4. package/NOTICE +41 -41
  5. package/README.md +550 -550
  6. package/crates/echo-server/Cargo.toml +20 -20
  7. package/crates/echo-server/src/main.rs +666 -666
  8. package/crates/native/Cargo.toml +23 -23
  9. package/crates/native/src/config.rs +129 -129
  10. package/crates/native/src/driver.rs +463 -463
  11. package/crates/native/src/lib.rs +821 -821
  12. package/crates/native/src/server.rs +718 -718
  13. package/crates/native/src/session.rs +1191 -1191
  14. package/crates/native/src/tls.rs +96 -96
  15. package/crates/wtcore/Cargo.toml +15 -15
  16. package/crates/wtcore/src/h3.rs +226 -226
  17. package/crates/wtcore/src/lib.rs +9 -9
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +80 -79
  21. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  24. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  25. package/scripts/bench.mjs +180 -180
  26. package/scripts/build.js +67 -67
  27. package/scripts/postinstall.js +67 -67
  28. package/scripts/setup-unix.sh +129 -129
  29. package/scripts/setup-windows.ps1 +229 -229
  30. package/vendor/quiche/AGENTS.md +75 -75
  31. package/vendor/quiche/COPYING +23 -23
  32. package/vendor/quiche/Cargo.lock +1212 -1212
  33. package/vendor/quiche/Cargo.toml +215 -215
  34. package/vendor/quiche/README.md +466 -466
  35. package/vendor/quiche/examples/Makefile +46 -46
  36. package/vendor/quiche/examples/README.md +20 -20
  37. package/vendor/quiche/examples/cert-big.crt +90 -90
  38. package/vendor/quiche/examples/cert.crt +18 -18
  39. package/vendor/quiche/examples/cert.key +28 -28
  40. package/vendor/quiche/examples/client.c +343 -343
  41. package/vendor/quiche/examples/client.rs +281 -281
  42. package/vendor/quiche/examples/gen-certs.sh +15 -15
  43. package/vendor/quiche/examples/http3-client.c +473 -473
  44. package/vendor/quiche/examples/http3-client.rs +349 -349
  45. package/vendor/quiche/examples/http3-server.c +614 -614
  46. package/vendor/quiche/examples/http3-server.rs +680 -680
  47. package/vendor/quiche/examples/qpack-decode.rs +87 -87
  48. package/vendor/quiche/examples/qpack-encode.rs +88 -88
  49. package/vendor/quiche/examples/rootca.crt +21 -21
  50. package/vendor/quiche/examples/server.c +529 -529
  51. package/vendor/quiche/examples/server.rs +529 -529
  52. package/vendor/quiche/include/quiche.h +1282 -1282
  53. package/vendor/quiche/src/buffers.rs +105 -105
  54. package/vendor/quiche/src/build.rs +66 -66
  55. package/vendor/quiche/src/cid.rs +1079 -1079
  56. package/vendor/quiche/src/crypto/boringssl.rs +373 -373
  57. package/vendor/quiche/src/crypto/mod.rs +671 -671
  58. package/vendor/quiche/src/dgram.rs +118 -118
  59. package/vendor/quiche/src/error.rs +263 -263
  60. package/vendor/quiche/src/ffi.rs +2290 -2290
  61. package/vendor/quiche/src/flowcontrol.rs +246 -246
  62. package/vendor/quiche/src/frame.rs +2172 -2172
  63. package/vendor/quiche/src/h3/AGENTS.md +54 -54
  64. package/vendor/quiche/src/h3/ffi.rs +442 -442
  65. package/vendor/quiche/src/h3/frame.rs +1404 -1404
  66. package/vendor/quiche/src/h3/mod.rs +8223 -8223
  67. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
  68. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
  69. package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
  70. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
  71. package/vendor/quiche/src/h3/stream.rs +1595 -1595
  72. package/vendor/quiche/src/lib.rs +9556 -9556
  73. package/vendor/quiche/src/minmax.rs +446 -446
  74. package/vendor/quiche/src/packet.rs +2334 -2334
  75. package/vendor/quiche/src/path.rs +1374 -1374
  76. package/vendor/quiche/src/pmtud.rs +652 -652
  77. package/vendor/quiche/src/rand.rs +64 -64
  78. package/vendor/quiche/src/range_buf.rs +186 -186
  79. package/vendor/quiche/src/ranges.rs +755 -755
  80. package/vendor/quiche/src/recovery/AGENTS.md +80 -80
  81. package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
  82. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
  83. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
  84. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
  85. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
  86. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
  87. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
  88. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
  89. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
  90. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
  91. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
  92. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
  93. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
  94. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
  95. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
  96. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
  97. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
  98. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
  99. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
  100. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
  101. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
  102. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
  103. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
  104. package/vendor/quiche/src/recovery/mod.rs +3086 -3086
  105. package/vendor/quiche/src/recovery/rtt.rs +152 -152
  106. package/vendor/quiche/src/stream/mod.rs +2210 -2210
  107. package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
  108. package/vendor/quiche/src/stream/send_buf.rs +849 -849
  109. package/vendor/quiche/src/test_utils.rs +681 -681
  110. package/vendor/quiche/src/tests.rs +12922 -12922
  111. package/vendor/quiche/src/tls/boringssl.rs +375 -375
  112. package/vendor/quiche/src/tls/mod.rs +1245 -1245
  113. package/vendor/quiche/src/transport_params.rs +628 -628
@@ -1,263 +1,263 @@
1
- // Copyright (C) 2018-2019, Cloudflare, Inc.
2
- // All rights reserved.
3
- //
4
- // Redistribution and use in source and binary forms, with or without
5
- // modification, are permitted provided that the following conditions are
6
- // met:
7
- //
8
- // * Redistributions of source code must retain the above copyright notice,
9
- // this list of conditions and the following disclaimer.
10
- //
11
- // * Redistributions in binary form must reproduce the above copyright
12
- // notice, this list of conditions and the following disclaimer in the
13
- // documentation and/or other materials provided with the distribution.
14
- //
15
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
- // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
- // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
- // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
- // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
- // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
- // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
- // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
- // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
- /// A specialized [`Result`] type for quiche operations.
28
- ///
29
- /// This type is used throughout quiche's public API for any operation that
30
- /// can produce an error.
31
- ///
32
- /// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
33
- pub type Result<T> = std::result::Result<T, Error>;
34
-
35
- /// A QUIC error.
36
- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
37
- pub enum Error {
38
- /// There is no more work to do.
39
- Done,
40
-
41
- /// The provided buffer is too short.
42
- BufferTooShort,
43
-
44
- /// The provided packet cannot be parsed because its version is unknown.
45
- UnknownVersion,
46
-
47
- /// The provided packet cannot be parsed because it contains an invalid
48
- /// frame.
49
- InvalidFrame,
50
-
51
- /// The provided packet cannot be parsed.
52
- InvalidPacket,
53
-
54
- /// The operation cannot be completed because the connection is in an
55
- /// invalid state.
56
- InvalidState,
57
-
58
- /// The operation cannot be completed because the stream is in an
59
- /// invalid state.
60
- ///
61
- /// The stream ID is provided as associated data.
62
- InvalidStreamState(u64),
63
-
64
- /// The peer's transport params cannot be parsed.
65
- InvalidTransportParam,
66
-
67
- /// A cryptographic operation failed.
68
- CryptoFail,
69
-
70
- /// The TLS handshake failed.
71
- TlsFail,
72
-
73
- /// The peer violated the local flow control limits.
74
- FlowControl,
75
-
76
- /// The peer violated the local stream limits.
77
- StreamLimit,
78
-
79
- /// The specified stream was stopped by the peer.
80
- ///
81
- /// The error code sent as part of the `STOP_SENDING` frame is provided as
82
- /// associated data.
83
- StreamStopped(u64),
84
-
85
- /// The specified stream was reset by the peer.
86
- ///
87
- /// The error code sent as part of the `RESET_STREAM` frame is provided as
88
- /// associated data.
89
- StreamReset(u64),
90
-
91
- /// The received data exceeds the stream's final size.
92
- FinalSize,
93
-
94
- /// Error in congestion control.
95
- CongestionControl,
96
-
97
- /// Too many identifiers were provided.
98
- IdLimit,
99
-
100
- /// Not enough available identifiers.
101
- OutOfIdentifiers,
102
-
103
- /// Error in key update.
104
- KeyUpdate,
105
-
106
- /// The peer sent more data in CRYPTO frames than we can buffer.
107
- CryptoBufferExceeded,
108
-
109
- /// The peer sent an ACK frame with an invalid range.
110
- InvalidAckRange,
111
-
112
- /// The peer send an ACK frame for a skipped packet used for Optimistic ACK
113
- /// mitigation.
114
- OptimisticAckDetected,
115
-
116
- /// An invalid DCID was used when connecting to a remote peer.
117
- InvalidDcidInitialization,
118
- }
119
-
120
- /// QUIC error codes sent on the wire.
121
- ///
122
- /// As defined in [RFC9000](https://www.rfc-editor.org/rfc/rfc9000.html#name-error-codes).
123
- #[derive(Copy, Clone, Debug, Eq, PartialEq)]
124
- pub enum WireErrorCode {
125
- /// An endpoint uses this with CONNECTION_CLOSE to signal that the
126
- /// connection is being closed abruptly in the absence of any error.
127
- NoError = 0x0,
128
- /// The endpoint encountered an internal error and cannot continue with the
129
- /// connection.
130
- InternalError = 0x1,
131
- /// The server refused to accept a new connection.
132
- ConnectionRefused = 0x2,
133
- /// An endpoint received more data than it permitted in its advertised data
134
- /// limits; see Section 4.
135
- FlowControlError = 0x3,
136
- /// An endpoint received a frame for a stream identifier that exceeded its
137
- /// advertised stream limit for the corresponding stream type.
138
- StreamLimitError = 0x4,
139
- /// An endpoint received a frame for a stream that was not in a state that
140
- /// permitted that frame.
141
- StreamStateError = 0x5,
142
- /// (1) An endpoint received a STREAM frame containing data that exceeded
143
- /// the previously established final size, (2) an endpoint received a
144
- /// STREAM frame or a RESET_STREAM frame containing a final size that
145
- /// was lower than the size of stream data that was already received, or
146
- /// (3) an endpoint received a STREAM frame or a RESET_STREAM frame
147
- /// containing a different final size to the one already established.
148
- FinalSizeError = 0x6,
149
- /// An endpoint received a frame that was badly formatted -- for instance, a
150
- /// frame of an unknown type or an ACK frame that has more
151
- /// acknowledgment ranges than the remainder of the packet could carry.
152
- FrameEncodingError = 0x7,
153
- /// An endpoint received transport parameters that were badly formatted,
154
- /// included an invalid value, omitted a mandatory transport parameter,
155
- /// included a forbidden transport parameter, or were otherwise in
156
- /// error.
157
- TransportParameterError = 0x8,
158
- /// The number of connection IDs provided by the peer exceeds the advertised
159
- /// active_connection_id_limit.
160
- ConnectionIdLimitError = 0x9,
161
- /// An endpoint detected an error with protocol compliance that was not
162
- /// covered by more specific error codes.
163
- ProtocolViolation = 0xa,
164
- /// A server received a client Initial that contained an invalid Token
165
- /// field.
166
- InvalidToken = 0xb,
167
- /// The application or application protocol caused the connection to be
168
- /// closed.
169
- ApplicationError = 0xc,
170
- /// An endpoint has received more data in CRYPTO frames than it can buffer.
171
- CryptoBufferExceeded = 0xd,
172
- /// An endpoint detected errors in performing key updates.
173
- KeyUpdateError = 0xe,
174
- /// An endpoint has reached the confidentiality or integrity limit for the
175
- /// AEAD algorithm used by the given connection.
176
- AeadLimitReached = 0xf,
177
- /// An endpoint has determined that the network path is incapable of
178
- /// supporting QUIC. An endpoint is unlikely to receive a
179
- /// CONNECTION_CLOSE frame carrying this code except when the path does
180
- /// not support a large enough MTU.
181
- NoViablePath = 0x10,
182
- }
183
-
184
- impl Error {
185
- pub(crate) fn to_wire(self) -> u64 {
186
- match self {
187
- Error::Done => WireErrorCode::NoError as u64,
188
- Error::InvalidFrame => WireErrorCode::FrameEncodingError as u64,
189
- Error::InvalidStreamState(..) =>
190
- WireErrorCode::StreamStateError as u64,
191
- Error::InvalidTransportParam =>
192
- WireErrorCode::TransportParameterError as u64,
193
- Error::FlowControl => WireErrorCode::FlowControlError as u64,
194
- Error::StreamLimit => WireErrorCode::StreamLimitError as u64,
195
- Error::IdLimit => WireErrorCode::ConnectionIdLimitError as u64,
196
- Error::FinalSize => WireErrorCode::FinalSizeError as u64,
197
- Error::CryptoBufferExceeded =>
198
- WireErrorCode::CryptoBufferExceeded as u64,
199
- Error::KeyUpdate => WireErrorCode::KeyUpdateError as u64,
200
- _ => WireErrorCode::ProtocolViolation as u64,
201
- }
202
- }
203
-
204
- #[cfg(feature = "ffi")]
205
- pub(crate) fn to_c(self) -> libc::ssize_t {
206
- match self {
207
- Error::Done => -1,
208
- Error::BufferTooShort => -2,
209
- Error::UnknownVersion => -3,
210
- Error::InvalidFrame => -4,
211
- Error::InvalidPacket => -5,
212
- Error::InvalidState => -6,
213
- Error::InvalidStreamState(_) => -7,
214
- Error::InvalidTransportParam => -8,
215
- Error::CryptoFail => -9,
216
- Error::TlsFail => -10,
217
- Error::FlowControl => -11,
218
- Error::StreamLimit => -12,
219
- Error::FinalSize => -13,
220
- Error::CongestionControl => -14,
221
- Error::StreamStopped { .. } => -15,
222
- Error::StreamReset { .. } => -16,
223
- Error::IdLimit => -17,
224
- Error::OutOfIdentifiers => -18,
225
- Error::KeyUpdate => -19,
226
- Error::CryptoBufferExceeded => -20,
227
- Error::InvalidAckRange => -21,
228
- Error::OptimisticAckDetected => -22,
229
- Error::InvalidDcidInitialization => -23,
230
- }
231
- }
232
- }
233
-
234
- impl std::fmt::Display for Error {
235
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236
- write!(f, "{self:?}")
237
- }
238
- }
239
-
240
- impl std::error::Error for Error {
241
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
242
- None
243
- }
244
- }
245
-
246
- impl From<octets::BufferTooShortError> for Error {
247
- fn from(_err: octets::BufferTooShortError) -> Self {
248
- Error::BufferTooShort
249
- }
250
- }
251
-
252
- /// Represents information carried by `CONNECTION_CLOSE` frames.
253
- #[derive(Clone, Debug, PartialEq, Eq)]
254
- pub struct ConnectionError {
255
- /// Whether the error came from the application or the transport layer.
256
- pub is_app: bool,
257
-
258
- /// The error code carried by the `CONNECTION_CLOSE` frame.
259
- pub error_code: u64,
260
-
261
- /// The reason carried by the `CONNECTION_CLOSE` frame.
262
- pub reason: Vec<u8>,
263
- }
1
+ // Copyright (C) 2018-2019, Cloudflare, Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright notice,
9
+ // this list of conditions and the following disclaimer.
10
+ //
11
+ // * Redistributions in binary form must reproduce the above copyright
12
+ // notice, this list of conditions and the following disclaimer in the
13
+ // documentation and/or other materials provided with the distribution.
14
+ //
15
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
+ // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
+ // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
+ // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ /// A specialized [`Result`] type for quiche operations.
28
+ ///
29
+ /// This type is used throughout quiche's public API for any operation that
30
+ /// can produce an error.
31
+ ///
32
+ /// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
33
+ pub type Result<T> = std::result::Result<T, Error>;
34
+
35
+ /// A QUIC error.
36
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
37
+ pub enum Error {
38
+ /// There is no more work to do.
39
+ Done,
40
+
41
+ /// The provided buffer is too short.
42
+ BufferTooShort,
43
+
44
+ /// The provided packet cannot be parsed because its version is unknown.
45
+ UnknownVersion,
46
+
47
+ /// The provided packet cannot be parsed because it contains an invalid
48
+ /// frame.
49
+ InvalidFrame,
50
+
51
+ /// The provided packet cannot be parsed.
52
+ InvalidPacket,
53
+
54
+ /// The operation cannot be completed because the connection is in an
55
+ /// invalid state.
56
+ InvalidState,
57
+
58
+ /// The operation cannot be completed because the stream is in an
59
+ /// invalid state.
60
+ ///
61
+ /// The stream ID is provided as associated data.
62
+ InvalidStreamState(u64),
63
+
64
+ /// The peer's transport params cannot be parsed.
65
+ InvalidTransportParam,
66
+
67
+ /// A cryptographic operation failed.
68
+ CryptoFail,
69
+
70
+ /// The TLS handshake failed.
71
+ TlsFail,
72
+
73
+ /// The peer violated the local flow control limits.
74
+ FlowControl,
75
+
76
+ /// The peer violated the local stream limits.
77
+ StreamLimit,
78
+
79
+ /// The specified stream was stopped by the peer.
80
+ ///
81
+ /// The error code sent as part of the `STOP_SENDING` frame is provided as
82
+ /// associated data.
83
+ StreamStopped(u64),
84
+
85
+ /// The specified stream was reset by the peer.
86
+ ///
87
+ /// The error code sent as part of the `RESET_STREAM` frame is provided as
88
+ /// associated data.
89
+ StreamReset(u64),
90
+
91
+ /// The received data exceeds the stream's final size.
92
+ FinalSize,
93
+
94
+ /// Error in congestion control.
95
+ CongestionControl,
96
+
97
+ /// Too many identifiers were provided.
98
+ IdLimit,
99
+
100
+ /// Not enough available identifiers.
101
+ OutOfIdentifiers,
102
+
103
+ /// Error in key update.
104
+ KeyUpdate,
105
+
106
+ /// The peer sent more data in CRYPTO frames than we can buffer.
107
+ CryptoBufferExceeded,
108
+
109
+ /// The peer sent an ACK frame with an invalid range.
110
+ InvalidAckRange,
111
+
112
+ /// The peer send an ACK frame for a skipped packet used for Optimistic ACK
113
+ /// mitigation.
114
+ OptimisticAckDetected,
115
+
116
+ /// An invalid DCID was used when connecting to a remote peer.
117
+ InvalidDcidInitialization,
118
+ }
119
+
120
+ /// QUIC error codes sent on the wire.
121
+ ///
122
+ /// As defined in [RFC9000](https://www.rfc-editor.org/rfc/rfc9000.html#name-error-codes).
123
+ #[derive(Copy, Clone, Debug, Eq, PartialEq)]
124
+ pub enum WireErrorCode {
125
+ /// An endpoint uses this with CONNECTION_CLOSE to signal that the
126
+ /// connection is being closed abruptly in the absence of any error.
127
+ NoError = 0x0,
128
+ /// The endpoint encountered an internal error and cannot continue with the
129
+ /// connection.
130
+ InternalError = 0x1,
131
+ /// The server refused to accept a new connection.
132
+ ConnectionRefused = 0x2,
133
+ /// An endpoint received more data than it permitted in its advertised data
134
+ /// limits; see Section 4.
135
+ FlowControlError = 0x3,
136
+ /// An endpoint received a frame for a stream identifier that exceeded its
137
+ /// advertised stream limit for the corresponding stream type.
138
+ StreamLimitError = 0x4,
139
+ /// An endpoint received a frame for a stream that was not in a state that
140
+ /// permitted that frame.
141
+ StreamStateError = 0x5,
142
+ /// (1) An endpoint received a STREAM frame containing data that exceeded
143
+ /// the previously established final size, (2) an endpoint received a
144
+ /// STREAM frame or a RESET_STREAM frame containing a final size that
145
+ /// was lower than the size of stream data that was already received, or
146
+ /// (3) an endpoint received a STREAM frame or a RESET_STREAM frame
147
+ /// containing a different final size to the one already established.
148
+ FinalSizeError = 0x6,
149
+ /// An endpoint received a frame that was badly formatted -- for instance, a
150
+ /// frame of an unknown type or an ACK frame that has more
151
+ /// acknowledgment ranges than the remainder of the packet could carry.
152
+ FrameEncodingError = 0x7,
153
+ /// An endpoint received transport parameters that were badly formatted,
154
+ /// included an invalid value, omitted a mandatory transport parameter,
155
+ /// included a forbidden transport parameter, or were otherwise in
156
+ /// error.
157
+ TransportParameterError = 0x8,
158
+ /// The number of connection IDs provided by the peer exceeds the advertised
159
+ /// active_connection_id_limit.
160
+ ConnectionIdLimitError = 0x9,
161
+ /// An endpoint detected an error with protocol compliance that was not
162
+ /// covered by more specific error codes.
163
+ ProtocolViolation = 0xa,
164
+ /// A server received a client Initial that contained an invalid Token
165
+ /// field.
166
+ InvalidToken = 0xb,
167
+ /// The application or application protocol caused the connection to be
168
+ /// closed.
169
+ ApplicationError = 0xc,
170
+ /// An endpoint has received more data in CRYPTO frames than it can buffer.
171
+ CryptoBufferExceeded = 0xd,
172
+ /// An endpoint detected errors in performing key updates.
173
+ KeyUpdateError = 0xe,
174
+ /// An endpoint has reached the confidentiality or integrity limit for the
175
+ /// AEAD algorithm used by the given connection.
176
+ AeadLimitReached = 0xf,
177
+ /// An endpoint has determined that the network path is incapable of
178
+ /// supporting QUIC. An endpoint is unlikely to receive a
179
+ /// CONNECTION_CLOSE frame carrying this code except when the path does
180
+ /// not support a large enough MTU.
181
+ NoViablePath = 0x10,
182
+ }
183
+
184
+ impl Error {
185
+ pub(crate) fn to_wire(self) -> u64 {
186
+ match self {
187
+ Error::Done => WireErrorCode::NoError as u64,
188
+ Error::InvalidFrame => WireErrorCode::FrameEncodingError as u64,
189
+ Error::InvalidStreamState(..) =>
190
+ WireErrorCode::StreamStateError as u64,
191
+ Error::InvalidTransportParam =>
192
+ WireErrorCode::TransportParameterError as u64,
193
+ Error::FlowControl => WireErrorCode::FlowControlError as u64,
194
+ Error::StreamLimit => WireErrorCode::StreamLimitError as u64,
195
+ Error::IdLimit => WireErrorCode::ConnectionIdLimitError as u64,
196
+ Error::FinalSize => WireErrorCode::FinalSizeError as u64,
197
+ Error::CryptoBufferExceeded =>
198
+ WireErrorCode::CryptoBufferExceeded as u64,
199
+ Error::KeyUpdate => WireErrorCode::KeyUpdateError as u64,
200
+ _ => WireErrorCode::ProtocolViolation as u64,
201
+ }
202
+ }
203
+
204
+ #[cfg(feature = "ffi")]
205
+ pub(crate) fn to_c(self) -> libc::ssize_t {
206
+ match self {
207
+ Error::Done => -1,
208
+ Error::BufferTooShort => -2,
209
+ Error::UnknownVersion => -3,
210
+ Error::InvalidFrame => -4,
211
+ Error::InvalidPacket => -5,
212
+ Error::InvalidState => -6,
213
+ Error::InvalidStreamState(_) => -7,
214
+ Error::InvalidTransportParam => -8,
215
+ Error::CryptoFail => -9,
216
+ Error::TlsFail => -10,
217
+ Error::FlowControl => -11,
218
+ Error::StreamLimit => -12,
219
+ Error::FinalSize => -13,
220
+ Error::CongestionControl => -14,
221
+ Error::StreamStopped { .. } => -15,
222
+ Error::StreamReset { .. } => -16,
223
+ Error::IdLimit => -17,
224
+ Error::OutOfIdentifiers => -18,
225
+ Error::KeyUpdate => -19,
226
+ Error::CryptoBufferExceeded => -20,
227
+ Error::InvalidAckRange => -21,
228
+ Error::OptimisticAckDetected => -22,
229
+ Error::InvalidDcidInitialization => -23,
230
+ }
231
+ }
232
+ }
233
+
234
+ impl std::fmt::Display for Error {
235
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236
+ write!(f, "{self:?}")
237
+ }
238
+ }
239
+
240
+ impl std::error::Error for Error {
241
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
242
+ None
243
+ }
244
+ }
245
+
246
+ impl From<octets::BufferTooShortError> for Error {
247
+ fn from(_err: octets::BufferTooShortError) -> Self {
248
+ Error::BufferTooShort
249
+ }
250
+ }
251
+
252
+ /// Represents information carried by `CONNECTION_CLOSE` frames.
253
+ #[derive(Clone, Debug, PartialEq, Eq)]
254
+ pub struct ConnectionError {
255
+ /// Whether the error came from the application or the transport layer.
256
+ pub is_app: bool,
257
+
258
+ /// The error code carried by the `CONNECTION_CLOSE` frame.
259
+ pub error_code: u64,
260
+
261
+ /// The reason carried by the `CONNECTION_CLOSE` frame.
262
+ pub reason: Vec<u8>,
263
+ }