rwebtransport 0.2.3 → 0.2.5

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 (96) hide show
  1. package/Cargo.lock +153 -226
  2. package/Cargo.toml +5 -5
  3. package/README.md +4 -4
  4. package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
  5. package/crates/native/Cargo.toml +1 -1
  6. package/crates/native/src/config.rs +13 -1
  7. package/crates/native/src/driver.rs +249 -91
  8. package/crates/native/src/lib.rs +9 -10
  9. package/crates/native/src/parser_memory.rs +1 -0
  10. package/crates/native/src/server.rs +197 -182
  11. package/crates/native/src/session.rs +329 -177
  12. package/crates/native/src/test_support.rs +2 -2
  13. package/crates/wtcore/src/h3.rs +166 -10
  14. package/dist/index.js +92 -45
  15. package/dist/index.js.map +2 -2
  16. package/dist/index.mjs +92 -45
  17. package/dist/index.mjs.map +2 -2
  18. package/dist/native.d.ts +9 -4
  19. package/package.json +14 -11
  20. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  21. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  23. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  24. package/scripts/build-linux-prebuilt.sh +46 -0
  25. package/scripts/build.js +10 -3
  26. package/vendor/quiche/AGENTS.md +10 -0
  27. package/vendor/quiche/Cargo.lock +239 -248
  28. package/vendor/quiche/Cargo.toml +23 -10
  29. package/vendor/quiche/examples/Makefile +4 -4
  30. package/vendor/quiche/examples/client.rs +10 -28
  31. package/vendor/quiche/examples/http3-client.rs +20 -34
  32. package/vendor/quiche/examples/http3-server.rs +47 -78
  33. package/vendor/quiche/examples/server.rs +19 -49
  34. package/vendor/quiche/include/quiche.h +35 -4
  35. package/vendor/quiche/src/build.rs +17 -0
  36. package/vendor/quiche/src/cid.rs +129 -61
  37. package/vendor/quiche/src/crypto/boringssl.rs +98 -86
  38. package/vendor/quiche/src/crypto/mod.rs +64 -77
  39. package/vendor/quiche/src/dgram.rs +2 -3
  40. package/vendor/quiche/src/error.rs +22 -20
  41. package/vendor/quiche/src/ffi.rs +558 -280
  42. package/vendor/quiche/src/flowcontrol.rs +0 -7
  43. package/vendor/quiche/src/frame.rs +134 -135
  44. package/vendor/quiche/src/h3/ffi.rs +73 -60
  45. package/vendor/quiche/src/h3/frame.rs +70 -90
  46. package/vendor/quiche/src/h3/mod.rs +1024 -593
  47. package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
  48. package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
  49. package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
  50. package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
  51. package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
  52. package/vendor/quiche/src/h3/stream.rs +1009 -194
  53. package/vendor/quiche/src/lib.rs +1346 -1195
  54. package/vendor/quiche/src/minmax.rs +2 -6
  55. package/vendor/quiche/src/packet.rs +420 -552
  56. package/vendor/quiche/src/path.rs +202 -72
  57. package/vendor/quiche/src/pmtud.rs +18 -16
  58. package/vendor/quiche/src/ranges.rs +184 -82
  59. package/vendor/quiche/src/recovery/AGENTS.md +5 -2
  60. package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
  61. package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
  62. package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
  63. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
  64. package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
  65. package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
  66. package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
  67. package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
  68. package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
  69. package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
  70. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
  71. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
  72. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
  73. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
  74. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
  75. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
  76. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
  77. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
  78. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
  79. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
  80. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
  81. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
  82. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
  83. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
  84. package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
  85. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
  86. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
  87. package/vendor/quiche/src/recovery/mod.rs +414 -173
  88. package/vendor/quiche/src/recovery/rtt.rs +8 -5
  89. package/vendor/quiche/src/stream/mod.rs +864 -133
  90. package/vendor/quiche/src/stream/recv_buf.rs +471 -172
  91. package/vendor/quiche/src/stream/send_buf.rs +338 -81
  92. package/vendor/quiche/src/test_utils.rs +78 -64
  93. package/vendor/quiche/src/tests.rs +2559 -1335
  94. package/vendor/quiche/src/tls/boringssl.rs +60 -63
  95. package/vendor/quiche/src/tls/mod.rs +146 -193
  96. package/vendor/quiche/src/transport_params.rs +87 -103
@@ -13,7 +13,7 @@
13
13
  edition = "2021"
14
14
  rust-version = "1.88"
15
15
  name = "quiche"
16
- version = "0.29.1"
16
+ version = "0.30.1"
17
17
  authors = ["Alessandro Ghedini <alessandro@ghedini.me>"]
18
18
  build = "src/build.rs"
19
19
  include = [
@@ -40,6 +40,9 @@ categories = ["network-programming"]
40
40
  license = "BSD-2-Clause"
41
41
  repository = "https://github.com/cloudflare/quiche"
42
42
 
43
+ [package.metadata.cargo-machete]
44
+ ignored = ["boring-sys"]
45
+
43
46
  [package.metadata.release]
44
47
  tag-prefix = ""
45
48
 
@@ -49,6 +52,7 @@ features = [
49
52
  "boringssl-boring-crate",
50
53
  "qlog",
51
54
  "custom-client-dcid",
55
+ "congestion_window_unchecked_available",
52
56
  ]
53
57
  rustdoc-args = [
54
58
  "--cfg",
@@ -58,8 +62,10 @@ rustdoc-args = [
58
62
  [features]
59
63
  boringssl-boring-crate = [
60
64
  "boring",
65
+ "boring-sys",
61
66
  "foreign-types-shared",
62
67
  ]
68
+ congestion_window_unchecked_available = []
63
69
  custom-client-dcid = []
64
70
  default = ["boringssl-boring-crate"]
65
71
  ffi = ["dep:cdylib-link-lines"]
@@ -108,7 +114,11 @@ name = "server"
108
114
  path = "examples/server.rs"
109
115
 
110
116
  [dependencies.boring]
111
- version = "4.3"
117
+ version = ">=4.19, <6"
118
+ optional = true
119
+
120
+ [dependencies.boring-sys]
121
+ version = ">=4.19, <6"
112
122
  optional = true
113
123
 
114
124
  [dependencies.bytes]
@@ -129,10 +139,12 @@ version = "0.3.0"
129
139
  optional = true
130
140
 
131
141
  [dependencies.intrusive-collections]
132
- version = "0.9.5"
142
+ version = "0.10.3"
133
143
 
134
144
  [dependencies.libc]
135
- version = "0.2.76"
145
+ # Upstream's temporary cap is for iOS backtrace compatibility. The npm
146
+ # package builds for Linux, macOS and Windows.
147
+ version = "0.2.191"
136
148
  default-features = false
137
149
 
138
150
  [dependencies.libm]
@@ -143,11 +155,11 @@ version = "0.4.20"
143
155
  features = ["std"]
144
156
 
145
157
  [dependencies.octets]
146
- version = "0.3.5"
158
+ version = "0.3.7"
147
159
  features = ["huffman_hpack"]
148
160
 
149
161
  [dependencies.qlog]
150
- version = "0.18.0"
162
+ version = "0.18.2"
151
163
  optional = true
152
164
 
153
165
  [dependencies.serde]
@@ -159,13 +171,13 @@ version = "1.0"
159
171
  optional = true
160
172
 
161
173
  [dependencies.serde_with]
162
- version = "3.20.0"
174
+ version = "3"
163
175
  features = ["macros"]
164
176
  optional = true
165
177
  default-features = false
166
178
 
167
179
  [dependencies.sfv]
168
- version = "0.9"
180
+ version = "0.16.1"
169
181
  optional = true
170
182
 
171
183
  [dependencies.slab]
@@ -187,7 +199,7 @@ features = [
187
199
  version = "0.17.8"
188
200
 
189
201
  [dev-dependencies.rstest]
190
- version = "0.26.1"
202
+ version = "0.28"
191
203
 
192
204
  [dev-dependencies.url]
193
205
  version = "2"
@@ -197,7 +209,7 @@ version = "0.1"
197
209
  optional = true
198
210
 
199
211
  [target."cfg(windows)".dependencies.windows-sys]
200
- version = "0.59"
212
+ version = "0.61"
201
213
  features = [
202
214
  "Win32_Networking_WinSock",
203
215
  "Win32_Security_Cryptography",
@@ -212,4 +224,5 @@ priority = 0
212
224
  check-cfg = [
213
225
  "cfg(capture_keylogs)",
214
226
  "cfg(test_invalid_len_compilation_fail)",
227
+ "cfg(boring_v5)",
215
228
  ]
@@ -28,16 +28,16 @@ LIBS = $(LIB_DIR)/libquiche.a -lev -ldl -pthread -lm
28
28
  all: client server http3-client http3-server
29
29
 
30
30
  client: client.c $(INCLUDE_DIR)/quiche.h $(LIB_DIR)/libquiche.a
31
- $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(INCS) $(LIBS)
31
+ $(CXX) $(CFLAGS) $(LDFLAGS) -x c $< -x none -o $@ $(INCS) $(LIBS)
32
32
 
33
33
  server: server.c $(INCLUDE_DIR)/quiche.h $(LIB_DIR)/libquiche.a
34
- $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(INCS) $(LIBS)
34
+ $(CXX) $(CFLAGS) $(LDFLAGS) -x c $< -x none -o $@ $(INCS) $(LIBS)
35
35
 
36
36
  http3-client: http3-client.c $(INCLUDE_DIR)/quiche.h $(LIB_DIR)/libquiche.a
37
- $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(INCS) $(LIBS)
37
+ $(CXX) $(CFLAGS) $(LDFLAGS) -x c $< -x none -o $@ $(INCS) $(LIBS)
38
38
 
39
39
  http3-server: http3-server.c $(INCLUDE_DIR)/quiche.h $(LIB_DIR)/libquiche.a
40
- $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(INCS) $(LIBS)
40
+ $(CXX) $(CFLAGS) $(LDFLAGS) -x c $< -x none -o $@ $(INCS) $(LIBS)
41
41
 
42
42
  $(LIB_DIR)/libquiche.a: $(shell find $(SOURCE_DIR) -type f -name '*.rs')
43
43
  cd .. && cargo build --target-dir $(BUILD_DIR) --features ffi
@@ -66,8 +66,7 @@ fn main() {
66
66
 
67
67
  // Create the UDP socket backing the QUIC connection, and register it with
68
68
  // the event loop.
69
- let mut socket =
70
- mio::net::UdpSocket::bind(bind_addr.parse().unwrap()).unwrap();
69
+ let mut socket = mio::net::UdpSocket::bind(bind_addr.parse().unwrap()).unwrap();
71
70
  poll.registry()
72
71
  .register(&mut socket, mio::Token(0), mio::Interest::READABLE)
73
72
  .unwrap();
@@ -79,13 +78,7 @@ fn main() {
79
78
  config.verify_peer(false);
80
79
 
81
80
  config
82
- .set_application_protos(&[
83
- b"hq-interop",
84
- b"hq-29",
85
- b"hq-28",
86
- b"hq-27",
87
- b"http/0.9",
88
- ])
81
+ .set_application_protos(&[b"hq-interop", b"hq-29", b"hq-28", b"hq-27", b"http/0.9"])
89
82
  .unwrap();
90
83
 
91
84
  config.set_max_idle_timeout(5000);
@@ -109,8 +102,7 @@ fn main() {
109
102
 
110
103
  // Create a QUIC connection and initiate handshake.
111
104
  let mut conn =
112
- quiche::connect(url.domain(), &scid, local_addr, peer_addr, &mut config)
113
- .unwrap();
105
+ quiche::connect(url.domain(), &scid, local_addr, peer_addr, &mut config).unwrap();
114
106
 
115
107
  info!(
116
108
  "connecting to {:} from {:} with scid {}",
@@ -164,7 +156,7 @@ fn main() {
164
156
  }
165
157
 
166
158
  panic!("recv() failed: {e:?}");
167
- },
159
+ }
168
160
  };
169
161
 
170
162
  debug!("got {len} bytes");
@@ -181,7 +173,7 @@ fn main() {
181
173
  Err(e) => {
182
174
  error!("recv failed: {e:?}");
183
175
  continue 'read;
184
- },
176
+ }
185
177
  };
186
178
 
187
179
  debug!("processed {read} bytes");
@@ -212,24 +204,14 @@ fn main() {
212
204
 
213
205
  let stream_buf = &buf[..read];
214
206
 
215
- debug!(
216
- "stream {} has {} bytes (fin? {})",
217
- s,
218
- stream_buf.len(),
219
- fin
220
- );
207
+ debug!("stream {} has {} bytes (fin? {})", s, stream_buf.len(), fin);
221
208
 
222
- print!("{}", unsafe {
223
- std::str::from_utf8_unchecked(stream_buf)
224
- });
209
+ print!("{}", unsafe { std::str::from_utf8_unchecked(stream_buf) });
225
210
 
226
211
  // The server reported that it has no more data to send, which
227
212
  // we got the full response. Close the connection.
228
213
  if s == HTTP_REQ_STREAM_ID && fin {
229
- info!(
230
- "response received in {:?}, closing...",
231
- req_start.elapsed()
232
- );
214
+ info!("response received in {:?}, closing...", req_start.elapsed());
233
215
 
234
216
  conn.close(true, 0x00, b"kthxbye").unwrap();
235
217
  }
@@ -245,14 +227,14 @@ fn main() {
245
227
  Err(quiche::Error::Done) => {
246
228
  debug!("done writing");
247
229
  break;
248
- },
230
+ }
249
231
 
250
232
  Err(e) => {
251
233
  error!("send failed: {e:?}");
252
234
 
253
235
  conn.close(false, 0x1, b"fail").ok();
254
236
  break;
255
- },
237
+ }
256
238
  };
257
239
 
258
240
  if let Err(e) = socket.send_to(&out[..write], send_info.to) {
@@ -66,8 +66,7 @@ fn main() {
66
66
 
67
67
  // Create the UDP socket backing the QUIC connection, and register it with
68
68
  // the event loop.
69
- let mut socket =
70
- mio::net::UdpSocket::bind(bind_addr.parse().unwrap()).unwrap();
69
+ let mut socket = mio::net::UdpSocket::bind(bind_addr.parse().unwrap()).unwrap();
71
70
  poll.registry()
72
71
  .register(&mut socket, mio::Token(0), mio::Interest::READABLE)
73
72
  .unwrap();
@@ -106,8 +105,7 @@ fn main() {
106
105
 
107
106
  // Create a QUIC connection and initiate handshake.
108
107
  let mut conn =
109
- quiche::connect(url.domain(), &scid, local_addr, peer_addr, &mut config)
110
- .unwrap();
108
+ quiche::connect(url.domain(), &scid, local_addr, peer_addr, &mut config).unwrap();
111
109
 
112
110
  info!(
113
111
  "connecting to {:} from {:} with scid {}",
@@ -142,10 +140,7 @@ fn main() {
142
140
  let req = vec![
143
141
  quiche::h3::Header::new(b":method", b"GET"),
144
142
  quiche::h3::Header::new(b":scheme", url.scheme().as_bytes()),
145
- quiche::h3::Header::new(
146
- b":authority",
147
- url.host_str().unwrap().as_bytes(),
148
- ),
143
+ quiche::h3::Header::new(b":authority", url.host_str().unwrap().as_bytes()),
149
144
  quiche::h3::Header::new(b":path", path.as_bytes()),
150
145
  quiche::h3::Header::new(b"user-agent", b"quiche"),
151
146
  ];
@@ -183,7 +178,7 @@ fn main() {
183
178
  }
184
179
 
185
180
  panic!("recv() failed: {e:?}");
186
- },
181
+ }
187
182
  };
188
183
 
189
184
  debug!("got {len} bytes");
@@ -200,7 +195,7 @@ fn main() {
200
195
  Err(e) => {
201
196
  error!("recv failed: {e:?}");
202
197
  continue 'read;
203
- },
198
+ }
204
199
  };
205
200
 
206
201
  debug!("processed {read} bytes");
@@ -213,7 +208,7 @@ fn main() {
213
208
  break;
214
209
  }
215
210
 
216
- // Create a new HTTP/3 connection once the QUIC connection is established.
211
+ // Create an HTTP/3 connection after QUIC is established.
217
212
  if conn.is_established() && http3_conn.is_none() {
218
213
  http3_conn = Some(
219
214
  quiche::h3::Connection::with_transport(&mut conn, &h3_config)
@@ -243,52 +238,43 @@ fn main() {
243
238
  hdrs_to_strings(&list),
244
239
  stream_id
245
240
  );
246
- },
241
+ }
247
242
 
248
243
  Ok((stream_id, quiche::h3::Event::Data)) => {
249
- while let Ok(read) =
250
- http3_conn.recv_body(&mut conn, stream_id, &mut buf)
251
- {
252
- debug!(
253
- "got {read} bytes of response data on stream {stream_id}"
254
- );
255
-
256
- print!("{}", unsafe {
257
- std::str::from_utf8_unchecked(&buf[..read])
258
- });
244
+ while let Ok(read) = http3_conn.recv_body(&mut conn, stream_id, &mut buf) {
245
+ debug!("got {read} bytes of response data on stream {stream_id}");
246
+
247
+ print!("{}", unsafe { std::str::from_utf8_unchecked(&buf[..read]) });
259
248
  }
260
- },
249
+ }
261
250
 
262
251
  Ok((_stream_id, quiche::h3::Event::Finished)) => {
263
- info!(
264
- "response received in {:?}, closing...",
265
- req_start.elapsed()
266
- );
252
+ info!("response received in {:?}, closing...", req_start.elapsed());
267
253
 
268
254
  conn.close(true, 0x100, b"kthxbye").unwrap();
269
- },
255
+ }
270
256
 
271
257
  Ok((_stream_id, quiche::h3::Event::Reset(e))) => {
272
258
  error!("request was reset by peer with {e}, closing...");
273
259
 
274
260
  conn.close(true, 0x100, b"kthxbye").unwrap();
275
- },
261
+ }
276
262
 
277
263
  Ok((_, quiche::h3::Event::PriorityUpdate)) => unreachable!(),
278
264
 
279
265
  Ok((goaway_id, quiche::h3::Event::GoAway)) => {
280
266
  info!("GOAWAY id={goaway_id}");
281
- },
267
+ }
282
268
 
283
269
  Err(quiche::h3::Error::Done) => {
284
270
  break;
285
- },
271
+ }
286
272
 
287
273
  Err(e) => {
288
274
  error!("HTTP/3 processing failed: {e:?}");
289
275
 
290
276
  break;
291
- },
277
+ }
292
278
  }
293
279
  }
294
280
  }
@@ -302,14 +288,14 @@ fn main() {
302
288
  Err(quiche::Error::Done) => {
303
289
  debug!("done writing");
304
290
  break;
305
- },
291
+ }
306
292
 
307
293
  Err(e) => {
308
294
  error!("send failed: {e:?}");
309
295
 
310
296
  conn.close(false, 0x1, b"fail").ok();
311
297
  break;
312
- },
298
+ }
313
299
  };
314
300
 
315
301
  if let Err(e) = socket.send_to(&out[..write], send_info.to) {
@@ -74,8 +74,7 @@ fn main() {
74
74
  let mut events = mio::Events::with_capacity(1024);
75
75
 
76
76
  // Create the UDP listening socket, and register it with the event loop.
77
- let mut socket =
78
- mio::net::UdpSocket::bind("127.0.0.1:4433".parse().unwrap()).unwrap();
77
+ let mut socket = mio::net::UdpSocket::bind("127.0.0.1:4433".parse().unwrap()).unwrap();
79
78
  poll.registry()
80
79
  .register(&mut socket, mio::Token(0), mio::Interest::READABLE)
81
80
  .unwrap();
@@ -109,8 +108,7 @@ fn main() {
109
108
  let h3_config = quiche::h3::Config::new().unwrap();
110
109
 
111
110
  let rng = SystemRandom::new();
112
- let conn_id_seed =
113
- ring::hmac::Key::generate(ring::hmac::HMAC_SHA256, &rng).unwrap();
111
+ let conn_id_seed = ring::hmac::Key::generate(ring::hmac::HMAC_SHA256, &rng).unwrap();
114
112
 
115
113
  let mut clients = ClientMap::new();
116
114
 
@@ -150,7 +148,7 @@ fn main() {
150
148
  }
151
149
 
152
150
  panic!("recv() failed: {e:?}");
153
- },
151
+ }
154
152
  };
155
153
 
156
154
  debug!("got {len} bytes");
@@ -158,16 +156,13 @@ fn main() {
158
156
  let pkt_buf = &mut buf[..len];
159
157
 
160
158
  // Parse the QUIC packet's header.
161
- let hdr = match quiche::Header::from_slice(
162
- pkt_buf,
163
- quiche::MAX_CONN_ID_LEN,
164
- ) {
159
+ let hdr = match quiche::Header::from_slice(pkt_buf, quiche::MAX_CONN_ID_LEN) {
165
160
  Ok(v) => v,
166
161
 
167
162
  Err(e) => {
168
163
  error!("Parsing packet header failed: {e:?}");
169
164
  continue 'read;
170
- },
165
+ }
171
166
  };
172
167
 
173
168
  trace!("got packet {hdr:?}");
@@ -178,9 +173,7 @@ fn main() {
178
173
 
179
174
  // Lookup a connection based on the packet's connection ID. If there
180
175
  // is no connection matching, create a new one.
181
- let client = if !clients.contains_key(&hdr.dcid) &&
182
- !clients.contains_key(&conn_id)
183
- {
176
+ let client = if !clients.contains_key(&hdr.dcid) && !clients.contains_key(&conn_id) {
184
177
  if hdr.ty != quiche::Type::Initial {
185
178
  error!("Packet is not Initial");
186
179
  continue 'read;
@@ -189,9 +182,7 @@ fn main() {
189
182
  if !quiche::version_is_supported(hdr.version) {
190
183
  warn!("Doing version negotiation");
191
184
 
192
- let len =
193
- quiche::negotiate_version(&hdr.scid, &hdr.dcid, &mut out)
194
- .unwrap();
185
+ let len = quiche::negotiate_version(&hdr.scid, &hdr.dcid, &mut out).unwrap();
195
186
 
196
187
  let out = &out[..len];
197
188
 
@@ -263,14 +254,8 @@ fn main() {
263
254
 
264
255
  debug!("New connection: dcid={:?} scid={:?}", hdr.dcid, scid);
265
256
 
266
- let conn = quiche::accept(
267
- &scid,
268
- odcid.as_ref(),
269
- local_addr,
270
- from,
271
- &mut config,
272
- )
273
- .unwrap();
257
+ let conn =
258
+ quiche::accept(&scid, odcid.as_ref(), local_addr, from, &mut config).unwrap();
274
259
 
275
260
  let client = Client {
276
261
  conn,
@@ -301,32 +286,30 @@ fn main() {
301
286
  Err(e) => {
302
287
  error!("{} recv failed: {:?}", client.conn.trace_id(), e);
303
288
  continue 'read;
304
- },
289
+ }
305
290
  };
306
291
 
307
292
  debug!("{} processed {} bytes", client.conn.trace_id(), read);
308
293
 
309
294
  // Create a new HTTP/3 connection as soon as the QUIC connection
310
295
  // is established.
311
- if (client.conn.is_in_early_data() || client.conn.is_established()) &&
312
- client.http3_conn.is_none()
296
+ if (client.conn.is_in_early_data() || client.conn.is_established())
297
+ && client.http3_conn.is_none()
313
298
  {
314
299
  debug!(
315
300
  "{} QUIC handshake completed, now trying HTTP/3",
316
301
  client.conn.trace_id()
317
302
  );
318
303
 
319
- let h3_conn = match quiche::h3::Connection::with_transport(
320
- &mut client.conn,
321
- &h3_config,
322
- ) {
323
- Ok(v) => v,
304
+ let h3_conn =
305
+ match quiche::h3::Connection::with_transport(&mut client.conn, &h3_config) {
306
+ Ok(v) => v,
324
307
 
325
- Err(e) => {
326
- error!("failed to create HTTP/3 connection: {e}");
327
- continue 'read;
328
- },
329
- };
308
+ Err(e) => {
309
+ error!("failed to create HTTP/3 connection: {e}");
310
+ continue 'read;
311
+ }
312
+ };
330
313
 
331
314
  // TODO: sanity check h3 connection before adding to map
332
315
  client.http3_conn = Some(h3_conn);
@@ -343,10 +326,7 @@ fn main() {
343
326
  // Process HTTP/3 events.
344
327
  loop {
345
328
  match http3_conn.poll(&mut client.conn) {
346
- Ok((
347
- stream_id,
348
- quiche::h3::Event::Headers { list, .. },
349
- )) => {
329
+ Ok((stream_id, quiche::h3::Event::Headers { list, .. })) => {
350
330
  handle_request(
351
331
  &mut client.conn,
352
332
  http3_conn,
@@ -355,7 +335,7 @@ fn main() {
355
335
  &mut client.partial_responses,
356
336
  "examples/root",
357
337
  );
358
- },
338
+ }
359
339
 
360
340
  Ok((stream_id, quiche::h3::Event::Data)) => {
361
341
  info!(
@@ -363,32 +343,25 @@ fn main() {
363
343
  client.conn.trace_id(),
364
344
  stream_id
365
345
  );
366
- },
346
+ }
367
347
 
368
348
  Ok((_stream_id, quiche::h3::Event::Finished)) => (),
369
349
 
370
350
  Ok((_stream_id, quiche::h3::Event::Reset { .. })) => (),
371
351
 
372
- Ok((
373
- _prioritized_element_id,
374
- quiche::h3::Event::PriorityUpdate,
375
- )) => (),
352
+ Ok((_prioritized_element_id, quiche::h3::Event::PriorityUpdate)) => (),
376
353
 
377
354
  Ok((_goaway_id, quiche::h3::Event::GoAway)) => (),
378
355
 
379
356
  Err(quiche::h3::Error::Done) => {
380
357
  break;
381
- },
358
+ }
382
359
 
383
360
  Err(e) => {
384
- error!(
385
- "{} HTTP/3 error {:?}",
386
- client.conn.trace_id(),
387
- e
388
- );
361
+ error!("{} HTTP/3 error {:?}", client.conn.trace_id(), e);
389
362
 
390
363
  break;
391
- },
364
+ }
392
365
  }
393
366
  }
394
367
  }
@@ -405,14 +378,14 @@ fn main() {
405
378
  Err(quiche::Error::Done) => {
406
379
  debug!("{} done writing", client.conn.trace_id());
407
380
  break;
408
- },
381
+ }
409
382
 
410
383
  Err(e) => {
411
384
  error!("{} send failed: {:?}", client.conn.trace_id(), e);
412
385
 
413
386
  client.conn.close(false, 0x1, b"fail").ok();
414
387
  break;
415
- },
388
+ }
416
389
  };
417
390
 
418
391
  if let Err(e) = socket.send_to(&out[..write], send_info.to) {
@@ -476,9 +449,7 @@ fn mint_token(hdr: &quiche::Header, src: &net::SocketAddr) -> Vec<u8> {
476
449
  ///
477
450
  /// Note that this function is only an example and doesn't do any cryptographic
478
451
  /// authenticate of the token. *It should not be used in production system*.
479
- fn validate_token<'a>(
480
- src: &net::SocketAddr, token: &'a [u8],
481
- ) -> Option<quiche::ConnectionId<'a>> {
452
+ fn validate_token<'a>(src: &net::SocketAddr, token: &'a [u8]) -> Option<quiche::ConnectionId<'a>> {
482
453
  if token.len() < 6 {
483
454
  return None;
484
455
  }
@@ -503,9 +474,12 @@ fn validate_token<'a>(
503
474
 
504
475
  /// Handles incoming HTTP/3 requests.
505
476
  fn handle_request(
506
- conn: &mut quiche::Connection, http3_conn: &mut quiche::h3::Connection,
507
- stream_id: u64, headers: &[quiche::h3::Header],
508
- partial_responses: &mut HashMap<u64, PartialResponse>, root: &str,
477
+ conn: &mut quiche::Connection,
478
+ http3_conn: &mut quiche::h3::Connection,
479
+ stream_id: u64,
480
+ headers: &[quiche::h3::Header],
481
+ partial_responses: &mut HashMap<u64, PartialResponse>,
482
+ root: &str,
509
483
  ) {
510
484
  info!(
511
485
  "{} got request {:?} on stream id {}",
@@ -534,12 +508,12 @@ fn handle_request(
534
508
 
535
509
  partial_responses.insert(stream_id, response);
536
510
  return;
537
- },
511
+ }
538
512
 
539
513
  Err(e) => {
540
514
  error!("{} stream send failed {:?}", conn.trace_id(), e);
541
515
  return;
542
- },
516
+ }
543
517
  }
544
518
 
545
519
  let written = match http3_conn.send_body(conn, stream_id, &body, true) {
@@ -550,7 +524,7 @@ fn handle_request(
550
524
  Err(e) => {
551
525
  error!("{} stream send failed {:?}", conn.trace_id(), e);
552
526
  return;
553
- },
527
+ }
554
528
  };
555
529
 
556
530
  if written < body.len() {
@@ -566,7 +540,8 @@ fn handle_request(
566
540
 
567
541
  /// Builds an HTTP/3 response given a request.
568
542
  fn build_response(
569
- root: &str, request: &[quiche::h3::Header],
543
+ root: &str,
544
+ request: &[quiche::h3::Header],
570
545
  ) -> (Vec<quiche::h3::Header>, Vec<u8>) {
571
546
  let mut file_path = std::path::PathBuf::from(root);
572
547
  let mut path = std::path::Path::new("");
@@ -575,10 +550,7 @@ fn build_response(
575
550
  // Look for the request's path and method.
576
551
  for hdr in request {
577
552
  match hdr.name() {
578
- b":path" =>
579
- path = std::path::Path::new(
580
- std::str::from_utf8(hdr.value()).unwrap(),
581
- ),
553
+ b":path" => path = std::path::Path::new(std::str::from_utf8(hdr.value()).unwrap()),
582
554
 
583
555
  b":method" => method = Some(hdr.value()),
584
556
 
@@ -599,7 +571,7 @@ fn build_response(
599
571
 
600
572
  Err(_) => (404, b"Not Found!".to_vec()),
601
573
  }
602
- },
574
+ }
603
575
 
604
576
  _ => (405, Vec::new()),
605
577
  };
@@ -607,10 +579,7 @@ fn build_response(
607
579
  let headers = vec![
608
580
  quiche::h3::Header::new(b":status", status.to_string().as_bytes()),
609
581
  quiche::h3::Header::new(b"server", b"quiche"),
610
- quiche::h3::Header::new(
611
- b"content-length",
612
- body.len().to_string().as_bytes(),
613
- ),
582
+ quiche::h3::Header::new(b"content-length", body.len().to_string().as_bytes()),
614
583
  ];
615
584
 
616
585
  (headers, body)
@@ -635,12 +604,12 @@ fn handle_writable(client: &mut Client, stream_id: u64) {
635
604
 
636
605
  Err(quiche::h3::Error::StreamBlocked) => {
637
606
  return;
638
- },
607
+ }
639
608
 
640
609
  Err(e) => {
641
610
  error!("{} stream send failed {:?}", conn.trace_id(), e);
642
611
  return;
643
- },
612
+ }
644
613
  }
645
614
  }
646
615
 
@@ -658,7 +627,7 @@ fn handle_writable(client: &mut Client, stream_id: u64) {
658
627
 
659
628
  error!("{} stream send failed {:?}", conn.trace_id(), e);
660
629
  return;
661
- },
630
+ }
662
631
  };
663
632
 
664
633
  resp.written += written;