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
@@ -57,6 +57,36 @@ const MAX_SESSION_PARSER_MEMORY: usize = 8 * 1024 * 1024;
57
57
  const WT_GRANT_MAX_DATA: u64 = 1 << 34;
58
58
  const WT_GRANT_MAX_STREAMS: u64 = 1 << 20;
59
59
 
60
+ /// Receive work admitted to one native event batch, shared by all connections
61
+ /// on a listener. Count reads as well as bytes so tiny messages are bounded.
62
+ pub struct ReceiveBudget {
63
+ bytes: usize,
64
+ items: usize,
65
+ }
66
+
67
+ impl ReceiveBudget {
68
+ pub fn new() -> Self {
69
+ Self {
70
+ bytes: 256 * 1024,
71
+ items: 128,
72
+ }
73
+ }
74
+
75
+ pub fn exhausted(&self) -> bool {
76
+ self.bytes == 0 || self.items == 0
77
+ }
78
+
79
+ #[cfg(test)]
80
+ fn blocked() -> Self {
81
+ Self { bytes: 0, items: 0 }
82
+ }
83
+
84
+ fn record(&mut self, bytes: usize) {
85
+ self.bytes = self.bytes.saturating_sub(bytes);
86
+ self.items -= 1;
87
+ }
88
+ }
89
+
60
90
  /// Events the session emits for the driver to forward to JS.
61
91
  #[derive(Debug)]
62
92
  pub enum Ev {
@@ -95,6 +125,8 @@ pub enum Ev {
95
125
  Error(String),
96
126
  /// A WebTransport datagram was received.
97
127
  Datagram(Vec<u8>),
128
+ /// Updated maximum datagram payload for one server connection.
129
+ DatagramSize(usize),
98
130
  /// The peer opened a WebTransport stream.
99
131
  IncomingStream { id: u64, bidi: bool },
100
132
  /// Application data arrived on a WebTransport stream.
@@ -108,7 +140,7 @@ pub enum Ev {
108
140
  /// A locally requested stream open completed; `id` is the QUIC stream id.
109
141
  StreamOpened { request_id: u64, id: u64 },
110
142
  /// A write's bytes were fully handed to quiche (backpressure signal).
111
- WriteAck { request_id: u64 },
143
+ WriteAck { request_id: u64, accepted: bool },
112
144
  /// A datagram send request was processed (sent or intentionally dropped).
113
145
  DatagramAck { request_id: u64, sent: bool },
114
146
  /// Result of a getStats() request.
@@ -156,31 +188,6 @@ pub fn build_stats(conn: &quiche::Connection, request_id: u64) -> Ev {
156
188
  }
157
189
  }
158
190
 
159
- /// Export `length` bytes of TLS keying material (RFC 5705) into a
160
- /// [`Ev::KeyingMaterial`] for `request_id`. `data` is `None` if the export
161
- /// failed. WebTransport always supplies a context, so it is passed through even
162
- /// when empty (an empty context differs from no context per RFC 5705).
163
- pub fn build_keying_material(
164
- conn: &mut quiche::Connection,
165
- request_id: u64,
166
- label: &[u8],
167
- context: &[u8],
168
- length: u32,
169
- ) -> Ev {
170
- if !(1..=4096).contains(&length) {
171
- return Ev::KeyingMaterial {
172
- request_id,
173
- data: None,
174
- };
175
- }
176
- let mut out = vec![0u8; length as usize];
177
- let data = match conn.export_keying_material(&mut out, label, Some(context)) {
178
- Ok(()) => Some(out),
179
- Err(_) => None,
180
- };
181
- Ev::KeyingMaterial { request_id, data }
182
- }
183
-
184
191
  /// One queued outbound chunk on a stream.
185
192
  struct OutChunk {
186
193
  data: Vec<u8>,
@@ -227,6 +234,7 @@ struct Stream {
227
234
  /// Application asked to FIN once `out` drains.
228
235
  fin_queued: bool,
229
236
  fin_sent: bool,
237
+ reset_pending: Option<u64>,
230
238
  /// Peer already reset/finished, stop touching recv.
231
239
  recv_dead: bool,
232
240
  recv_payload: u64,
@@ -242,10 +250,11 @@ impl Stream {
242
250
  class_buf: ParserBuffer::new(memory.clone()),
243
251
  frames: FrameParser::new(memory),
244
252
  headers_done: false,
245
- paused: false,
253
+ paused: matches!(role, Role::WtData { .. }),
246
254
  out: VecDeque::new(),
247
255
  fin_queued: false,
248
256
  fin_sent: false,
257
+ reset_pending: None,
249
258
  recv_dead: false,
250
259
  recv_payload: 0,
251
260
  recv_prefix: 0,
@@ -353,6 +362,7 @@ pub struct WtSession {
353
362
  pending_opens: VecDeque<(bool, u64)>,
354
363
 
355
364
  setup_sent: bool,
365
+ latest_protocol: bool,
356
366
  ready: bool,
357
367
  closed: bool,
358
368
  /// Client role only: the Extended CONNECT is built but deferred until the
@@ -392,6 +402,7 @@ pub struct WtSession {
392
402
  peer_settings: Option<h3::PeerSettings>,
393
403
 
394
404
  streams: HashMap<u64, Stream>,
405
+ next_read_stream: u64,
395
406
 
396
407
  close_req: Option<CloseReq>,
397
408
  /// Set once the QUIC connection should be closed (after connect FIN flush).
@@ -408,6 +419,33 @@ pub struct WtSession {
408
419
  }
409
420
 
410
421
  impl WtSession {
422
+ pub fn build_keying_material(
423
+ &self,
424
+ conn: &mut quiche::Connection,
425
+ request_id: u64,
426
+ label: &[u8],
427
+ context: &[u8],
428
+ length: u32,
429
+ ) -> Ev {
430
+ let data = (|| {
431
+ if !self.ready || self.closed || !(1..=4096).contains(&length) {
432
+ return None;
433
+ }
434
+ let mut out = vec![0; length as usize];
435
+ let context_buf;
436
+ let (label, context) = if self.latest_protocol {
437
+ context_buf = h3::exporter_context(CONNECT_ID, label, context)?;
438
+ (h3::WT_EXPORTER_LABEL, context_buf.as_slice())
439
+ } else {
440
+ (label, context)
441
+ };
442
+ conn.export_keying_material(&mut out, label, Some(context))
443
+ .ok()?;
444
+ Some(out)
445
+ })();
446
+ Ev::KeyingMaterial { request_id, data }
447
+ }
448
+
411
449
  /// A client-role session that will send an Extended CONNECT.
412
450
  pub fn new_client(
413
451
  authority: String,
@@ -431,6 +469,7 @@ impl WtSession {
431
469
  next_uni: CLIENT_FIRST_WT_UNI_ID,
432
470
  pending_opens: VecDeque::new(),
433
471
  setup_sent: false,
472
+ latest_protocol: false,
434
473
  ready: false,
435
474
  closed: false,
436
475
  connect_pending: false,
@@ -453,6 +492,7 @@ impl WtSession {
453
492
  parser_memory,
454
493
  peer_settings: None,
455
494
  streams: HashMap::new(),
495
+ next_read_stream: 0,
456
496
  close_req: None,
457
497
  want_quic_close: None,
458
498
  close_deferred_once: false,
@@ -486,6 +526,7 @@ impl WtSession {
486
526
  next_uni: SERVER_FIRST_WT_UNI_ID,
487
527
  pending_opens: VecDeque::new(),
488
528
  setup_sent: false,
529
+ latest_protocol: false,
489
530
  ready: false,
490
531
  closed: false,
491
532
  connect_pending: false,
@@ -508,6 +549,7 @@ impl WtSession {
508
549
  parser_memory,
509
550
  peer_settings: None,
510
551
  streams: HashMap::new(),
552
+ next_read_stream: 0,
511
553
  close_req: None,
512
554
  want_quic_close: None,
513
555
  close_deferred_once: false,
@@ -524,7 +566,7 @@ impl WtSession {
524
566
  /// control-plane streams and advertise SETTINGS. A client waits for the
525
567
  /// server's SETTINGS before sending CONNECT; a server waits for the client's
526
568
  /// CONNECT on bidi stream 0.
527
- pub fn on_established(&mut self) {
569
+ pub fn on_established(&mut self, reliable_reset: bool) {
528
570
  if self.setup_sent {
529
571
  return;
530
572
  }
@@ -541,7 +583,7 @@ impl WtSession {
541
583
  control_id,
542
584
  Stream::with_prefix(
543
585
  Role::LocalControlPlane,
544
- h3::control_stream_prefix(),
586
+ h3::control_stream_prefix_for(reliable_reset),
545
587
  self.parser_memory.clone(),
546
588
  ),
547
589
  );
@@ -574,15 +616,21 @@ impl WtSession {
574
616
  }
575
617
  }
576
618
 
577
- /// Process a readable QUIC stream. `backpressured` is a global signal that
578
- /// the JS thread is behind; when set, resolved WebTransport data streams are
579
- /// left unread (flow-controlling the peer) while control-plane streams still
580
- /// drain.
581
- pub fn on_readable(
619
+ #[cfg(test)]
620
+ fn on_readable(&mut self, conn: &mut quiche::Connection, id: u64, ev: &mut Vec<Ev>) {
621
+ let mut budget = ReceiveBudget::new();
622
+ self.read_stream(conn, id, &mut budget, ev);
623
+ if !self.closed && self.streams.get(&id).is_some_and(|s| s.paused) {
624
+ self.set_paused(id, false);
625
+ self.read_stream(conn, id, &mut budget, ev);
626
+ }
627
+ }
628
+
629
+ fn read_stream(
582
630
  &mut self,
583
631
  conn: &mut quiche::Connection,
584
632
  id: u64,
585
- backpressured: bool,
633
+ budget: &mut ReceiveBudget,
586
634
  ev: &mut Vec<Ev>,
587
635
  ) {
588
636
  if self.closed {
@@ -593,54 +641,52 @@ impl WtSession {
593
641
  Stream::new(classify_new(id, is_server), self.parser_memory.clone())
594
642
  });
595
643
 
596
- // Respect per-stream and global read backpressure for resolved data
597
- // streams (leave the bytes in quiche so the peer is flow-controlled).
598
- let (paused, is_data, recv_dead) = {
599
- let st = &self.streams[&id];
600
- (
601
- st.paused,
602
- matches!(st.role, Role::WtData { .. }),
603
- st.recv_dead,
604
- )
605
- };
606
- if recv_dead {
644
+ let st = &self.streams[&id];
645
+ if st.recv_dead {
607
646
  return;
608
647
  }
609
- if (paused || backpressured) && is_data {
648
+ if !self.ready && st.role == Role::PendingBidi {
610
649
  return;
611
650
  }
612
651
 
613
- // Pending bidi streams are application data. Under global pressure,
614
- // classify uni stream types one byte at a time, then leave WT headers
615
- // and payload in QUIC while allowing critical streams to drain.
616
- if backpressured && matches!(self.streams[&id].role, Role::PendingBidi) {
617
- return;
618
- }
619
-
620
- // Drain everything quiche currently has for this stream.
621
652
  let mut reset: Option<u64> = None;
622
653
  let mut buf = [0u8; 16 * 1024];
623
- loop {
624
- let st = &self.streams[&id];
625
- if backpressured
626
- && (matches!(st.role, Role::WtData { .. })
627
- || (matches!(st.role, Role::PendingUni)
628
- && h3::read_varint(&st.class_buf)
629
- .is_some_and(|(ty, _)| ty == h3::WT_UNI_STREAM_TYPE)))
630
- {
654
+ while !budget.exhausted() {
655
+ let Some(st) = self.streams.get(&id) else {
656
+ return;
657
+ };
658
+ if st.paused && !conn.stream_finished(id) {
659
+ // Leave data in QUIC until the JS reader asks for one chunk.
660
+ // Empty FIN and RESET_STREAM do not require read credit.
631
661
  return;
632
662
  }
633
- let read_len = if backpressured && matches!(st.role, Role::PendingUni) {
663
+ let read_len = if matches!(st.role, Role::PendingUni | Role::PendingBidi) {
664
+ // Classify the stream without consuming WebTransport payload
665
+ // before CONNECT has been accepted and reported to Node.
666
+ if !self.ready
667
+ && h3::read_varint(&st.class_buf)
668
+ .is_some_and(|(ty, _)| ty == h3::WT_UNI_STREAM_TYPE)
669
+ {
670
+ return;
671
+ }
634
672
  1
635
673
  } else {
636
- buf.len()
674
+ buf.len().min(budget.bytes)
637
675
  };
638
676
  let final_size = conn.stream_recv_final_size(id);
639
677
  match conn.stream_recv(id, &mut buf[..read_len]) {
640
678
  Ok((n, f)) => {
679
+ budget.record(n);
641
680
  // Parse bounded chunks immediately. Do not build an entire
642
681
  // stream-sized scratch allocation outside the parser budget.
682
+ let was_ready = self.ready;
643
683
  self.process_recv(conn, id, buf[..n].to_vec(), f, ev);
684
+ if !was_ready && self.ready {
685
+ // Decoded headers can span reads and expand on decode.
686
+ budget.bytes = budget
687
+ .bytes
688
+ .saturating_sub(4 * h3::MAX_HEADER_BLOCK as usize);
689
+ }
644
690
  if self.closed {
645
691
  return;
646
692
  }
@@ -653,6 +699,7 @@ impl WtSession {
653
699
  }
654
700
  Err(quiche::Error::Done) => break,
655
701
  Err(quiche::Error::StreamReset(code)) => {
702
+ budget.record(0);
656
703
  if let Some(size) = final_size {
657
704
  let st = &self.streams[&id];
658
705
  if matches!(st.role, Role::WtData { .. }) {
@@ -696,12 +743,20 @@ impl WtSession {
696
743
  }
697
744
  self.mark_closed(ev, code as u32, Vec::new(), true);
698
745
  }
746
+ Some(Role::PendingBidi | Role::PendingUni) => self.ignore_stream(conn, id),
699
747
  _ => {}
700
748
  }
701
- return;
702
749
  }
703
750
  }
704
751
 
752
+ fn ignore_stream(&mut self, conn: &mut quiche::Connection, id: u64) {
753
+ let _ = conn.stream_shutdown(id, quiche::Shutdown::Read, 0);
754
+ if id & 2 == 0 {
755
+ let _ = conn.stream_shutdown(id, quiche::Shutdown::Write, 0);
756
+ }
757
+ self.streams.remove(&id);
758
+ }
759
+
705
760
  fn process_recv(
706
761
  &mut self,
707
762
  conn: &mut quiche::Connection,
@@ -789,6 +844,7 @@ impl WtSession {
789
844
  return;
790
845
  }
791
846
  if !chunk.is_empty() {
847
+ self.streams.get_mut(&id).unwrap().paused = true;
792
848
  ev.push(Ev::StreamData { id, data: chunk });
793
849
  }
794
850
  if fin {
@@ -845,13 +901,19 @@ impl WtSession {
845
901
  // otherwise reject the session.
846
902
  if self.connect_pending {
847
903
  self.connect_pending = false;
848
- if settings.webtransport_ok() {
904
+ self.latest_protocol = settings.enable_connect_protocol
905
+ && settings.h3_datagram
906
+ && (settings.wt_enabled || settings.wt_enabled_draft15)
907
+ && conn.dgram_max_writable_len().is_some()
908
+ && conn.reliable_stream_reset_negotiated();
909
+ if self.latest_protocol || settings.webtransport_ok() {
849
910
  self.queue_connect(ev);
850
911
  } else {
851
912
  ev.push(Ev::Error(
852
913
  "server does not advertise WebTransport support".to_string(),
853
914
  ));
854
915
  self.mark_closed(ev, 0, b"webtransport not supported".to_vec(), false);
916
+ let _ = conn.close(true, h3::H3_NO_ERROR, b"webtransport not supported");
855
917
  }
856
918
  }
857
919
  if self.is_server && self.streams.contains_key(&CONNECT_ID) {
@@ -876,7 +938,12 @@ impl WtSession {
876
938
  /// Build and queue the client's Extended CONNECT on the session (bidi 0)
877
939
  /// stream. Called once the server's SETTINGS have confirmed WebTransport.
878
940
  fn queue_connect(&mut self, ev: &mut Vec<Ev>) {
879
- let headers = h3::connect_headers(
941
+ let headers = h3::connect_headers_for(
942
+ if self.latest_protocol {
943
+ h3::WT_H3_TOKEN
944
+ } else {
945
+ h3::LEGACY_WT_TOKEN
946
+ },
880
947
  &self.authority,
881
948
  &self.path,
882
949
  self.origin.as_deref(),
@@ -908,12 +975,23 @@ impl WtSession {
908
975
  eprintln!("[rwt-session] connect frame ty={ty} len={}", payload.len());
909
976
  }
910
977
  if ty == h3::FRAME_HEADERS && !headers_done {
911
- if let Some(st) = self.streams.get_mut(&id) {
912
- st.headers_done = true;
913
- }
914
978
  match h3::decode_header_block(&payload) {
915
979
  Ok(headers) => {
916
- let status = h3::status_of(&headers).unwrap_or(0);
980
+ let Some(status) = h3::status_of(&headers) else {
981
+ self.protocol_error(
982
+ conn,
983
+ ev,
984
+ 0x10e,
985
+ "malformed CONNECT response headers",
986
+ );
987
+ return;
988
+ };
989
+ if (100..200).contains(&status) {
990
+ continue;
991
+ }
992
+ if let Some(st) = self.streams.get_mut(&id) {
993
+ st.headers_done = true;
994
+ }
917
995
  if dbg_on() {
918
996
  eprintln!("[rwt-session] CONNECT response status={status}");
919
997
  }
@@ -948,12 +1026,20 @@ impl WtSession {
948
1026
  }
949
1027
  }
950
1028
  Err(e) => {
951
- ev.push(Ev::Error(format!("failed to decode CONNECT response: {e}")));
1029
+ self.protocol_error(
1030
+ conn,
1031
+ ev,
1032
+ 0x10e,
1033
+ &format!("failed to decode CONNECT response: {e}"),
1034
+ );
1035
+ return;
952
1036
  }
953
1037
  }
954
- } else if ty == h3::FRAME_DATA {
955
- // Capsule-protocol content. Best-effort scan for a session close.
1038
+ } else if ty == h3::FRAME_DATA && self.ready {
956
1039
  self.scan_capsules(&payload, ev);
1040
+ } else if ty == h3::FRAME_DATA || ty == h3::FRAME_HEADERS {
1041
+ self.protocol_error(conn, ev, 0x105, "unexpected frame on CONNECT stream");
1042
+ return;
957
1043
  }
958
1044
  }
959
1045
  }
@@ -1020,6 +1106,9 @@ impl WtSession {
1020
1106
  | h3::WT_STREAMS_BLOCKED_BIDI_CAPSULE
1021
1107
  | h3::WT_STREAMS_BLOCKED_UNI_CAPSULE
1022
1108
  ) {
1109
+ if self.latest_protocol && !self.uses_session_flow_control() {
1110
+ continue;
1111
+ }
1023
1112
  let Some((v, n)) = h3::read_varint(&value) else {
1024
1113
  self.flow_error(ev, "truncated flow-control capsule");
1025
1114
  return;
@@ -1060,15 +1149,7 @@ impl WtSession {
1060
1149
  if self.peer_settings.is_none() {
1061
1150
  return;
1062
1151
  }
1063
- let settings = self.peer_settings.unwrap();
1064
- // ENABLE_CONNECT_PROTOCOL is advertised by the server; browsers need
1065
- // not advertise it when acting as clients.
1066
- if !settings.h3_datagram || !(settings.enable_webtransport || settings.wt_max_sessions > 0)
1067
- {
1068
- self.reject_connect(conn, id, 400, ev);
1069
- return;
1070
- }
1071
- while !self.closed {
1152
+ while !self.closed && (self.ready || self.close_req.is_none()) {
1072
1153
  let (frame, headers_done) = {
1073
1154
  let Some(st) = self.streams.get_mut(&id) else {
1074
1155
  return;
@@ -1088,8 +1169,11 @@ impl WtSession {
1088
1169
  self.reject_connect(conn, id, 400, ev);
1089
1170
  }
1090
1171
  }
1091
- } else if ty == h3::FRAME_DATA {
1172
+ } else if ty == h3::FRAME_DATA && self.ready {
1092
1173
  self.scan_capsules(&payload, ev);
1174
+ } else if ty == h3::FRAME_DATA || ty == h3::FRAME_HEADERS {
1175
+ self.protocol_error(conn, ev, 0x105, "unexpected frame on CONNECT stream");
1176
+ return;
1093
1177
  }
1094
1178
  }
1095
1179
  }
@@ -1102,22 +1186,30 @@ impl WtSession {
1102
1186
  ev: &mut Vec<Ev>,
1103
1187
  ) {
1104
1188
  use quiche::h3::NameValue;
1105
- let mut method: Option<&[u8]> = None;
1106
- let mut protocol: Option<&[u8]> = None;
1107
- let mut authority = String::new();
1108
- let mut path = String::from("/");
1109
- let mut origin: Option<String> = None;
1189
+ let Some(target) = h3::validate_connect_headers(headers) else {
1190
+ self.reject_connect(conn, id, 400, ev);
1191
+ return;
1192
+ };
1193
+ let Some(settings) = self.peer_settings else {
1194
+ return;
1195
+ };
1196
+ let latest = target.protocol == h3::WT_H3_TOKEN
1197
+ && conn.reliable_stream_reset_negotiated()
1198
+ && conn.dgram_max_writable_len().is_some();
1199
+ let legacy = target.protocol == h3::LEGACY_WT_TOKEN
1200
+ && (settings.enable_webtransport || settings.wt_max_sessions > 0);
1201
+ if !settings.h3_datagram || !(latest || legacy) {
1202
+ self.reject_connect(conn, id, 400, ev);
1203
+ return;
1204
+ }
1205
+ self.latest_protocol = latest;
1110
1206
  let mut protocol_fields: Vec<String> = Vec::new();
1111
1207
  let mut extra: Vec<(String, String)> = Vec::new();
1112
1208
  for h in headers {
1113
1209
  let name = h.name();
1114
1210
  let value = h.value();
1115
1211
  match name {
1116
- b":method" => method = Some(value),
1117
- b":protocol" => protocol = Some(value),
1118
- b":authority" => authority = String::from_utf8_lossy(value).into_owned(),
1119
- b":path" => path = String::from_utf8_lossy(value).into_owned(),
1120
- b"origin" => origin = Some(String::from_utf8_lossy(value).into_owned()),
1212
+ b"origin" => {}
1121
1213
  _ if name == h3::WT_AVAILABLE_PROTOCOLS => {
1122
1214
  protocol_fields.push(String::from_utf8_lossy(value).into_owned());
1123
1215
  }
@@ -1130,17 +1222,12 @@ impl WtSession {
1130
1222
  }
1131
1223
 
1132
1224
  let requested_protocols = h3::parse_sf_string_list(&protocol_fields.join(", "));
1133
- let ok = method == Some(b"CONNECT".as_ref()) && protocol == Some(b"webtransport".as_ref());
1134
- if !ok {
1135
- self.reject_connect(conn, id, 400, ev);
1136
- return;
1137
- }
1138
1225
 
1139
1226
  // Origin verification (draft-ietf-webtrans-http3 3.3): if an allowlist is
1140
1227
  // configured, the request's origin must be present in it.
1141
1228
  if let Some(allowed) = &self.allowed_origins {
1142
- let permitted = origin
1143
- .as_deref()
1229
+ let permitted = target
1230
+ .origin
1144
1231
  .map(|o| allowed.iter().any(|a| a == o))
1145
1232
  .unwrap_or(false);
1146
1233
  if !permitted {
@@ -1185,9 +1272,9 @@ impl WtSession {
1185
1272
  None => (String::new(), 0),
1186
1273
  };
1187
1274
  ev.push(Ev::ServerReady {
1188
- authority,
1189
- path,
1190
- origin,
1275
+ authority: target.authority.to_owned(),
1276
+ path: target.path.to_owned(),
1277
+ origin: target.origin.map(str::to_owned),
1191
1278
  headers: extra,
1192
1279
  requested_protocols,
1193
1280
  protocol: selected,
@@ -1221,7 +1308,13 @@ impl WtSession {
1221
1308
  if !self.ready && !self.closed {
1222
1309
  ev.push(Ev::Error(format!("rejected CONNECT with status {status}")));
1223
1310
  }
1224
- self.mark_closed(ev, 0, Vec::new(), false);
1311
+ // Keep the queued HTTP response until it has been flushed. Marking
1312
+ // the session closed here would clear CONNECT's send queue.
1313
+ self.close_req = Some(CloseReq {
1314
+ code: 0,
1315
+ reason: Vec::new(),
1316
+ capsule_queued: true,
1317
+ });
1225
1318
  let _ = conn;
1226
1319
  }
1227
1320
 
@@ -1297,12 +1390,7 @@ impl WtSession {
1297
1390
  return; // need session id
1298
1391
  };
1299
1392
  if session != CONNECT_ID {
1300
- let _ = conn.stream_shutdown(id, quiche::Shutdown::Read, 0);
1301
- let Some(st) = self.streams.get_mut(&id) else {
1302
- return;
1303
- };
1304
- st.role = Role::Ignored;
1305
- st.class_buf.clear();
1393
+ self.ignore_stream(conn, id);
1306
1394
  return;
1307
1395
  }
1308
1396
  let data = buf[n + n2..].to_vec();
@@ -1311,6 +1399,7 @@ impl WtSession {
1311
1399
  return;
1312
1400
  };
1313
1401
  st.role = Role::WtData { bidi: false };
1402
+ st.paused = true;
1314
1403
  st.class_buf.clear();
1315
1404
  }
1316
1405
  self.streams.get_mut(&id).unwrap().recv_prefix = (n + n2) as u64;
@@ -1330,13 +1419,7 @@ impl WtSession {
1330
1419
  ev.push(Ev::StreamFinished { id });
1331
1420
  }
1332
1421
  }
1333
- _ => {
1334
- let Some(st) = self.streams.get_mut(&id) else {
1335
- return;
1336
- };
1337
- st.role = Role::Ignored;
1338
- st.class_buf.clear();
1339
- }
1422
+ _ => self.ignore_stream(conn, id),
1340
1423
  }
1341
1424
  }
1342
1425
 
@@ -1359,35 +1442,25 @@ impl WtSession {
1359
1442
  st.class_buf.to_vec()
1360
1443
  };
1361
1444
  let Some((signal, n)) = h3::read_varint(&buf) else {
1362
- // Peer FIN'd before we could classify: reclaim the entry.
1445
+ // Peer FIN'd before we could classify: release both halves.
1363
1446
  if fin {
1364
- self.streams.remove(&id);
1447
+ self.ignore_stream(conn, id);
1365
1448
  }
1366
1449
  return;
1367
1450
  };
1368
1451
  if signal != h3::WT_BIDI_FRAME_TYPE {
1369
- let _ = conn.stream_shutdown(id, quiche::Shutdown::Read, 0);
1370
- let Some(st) = self.streams.get_mut(&id) else {
1371
- return;
1372
- };
1373
- st.role = Role::Ignored;
1374
- st.class_buf.clear();
1452
+ self.ignore_stream(conn, id);
1375
1453
  return;
1376
1454
  }
1377
1455
  let Some((session, n2)) = h3::read_varint(&buf[n..]) else {
1378
- // Peer FIN'd mid-header: reclaim the entry instead of leaking.
1456
+ // Peer FIN'd mid-header: release both halves.
1379
1457
  if fin {
1380
- self.streams.remove(&id);
1458
+ self.ignore_stream(conn, id);
1381
1459
  }
1382
1460
  return;
1383
1461
  };
1384
1462
  if session != CONNECT_ID {
1385
- let _ = conn.stream_shutdown(id, quiche::Shutdown::Read, 0);
1386
- let Some(st) = self.streams.get_mut(&id) else {
1387
- return;
1388
- };
1389
- st.role = Role::Ignored;
1390
- st.class_buf.clear();
1463
+ self.ignore_stream(conn, id);
1391
1464
  return;
1392
1465
  }
1393
1466
  let data = buf[n + n2..].to_vec();
@@ -1396,9 +1469,13 @@ impl WtSession {
1396
1469
  return;
1397
1470
  };
1398
1471
  st.role = Role::WtData { bidi: true };
1472
+ st.paused = true;
1399
1473
  st.class_buf.clear();
1400
1474
  }
1401
1475
  self.streams.get_mut(&id).unwrap().recv_prefix = (n + n2) as u64;
1476
+ if self.latest_protocol {
1477
+ let _ = conn.stream_set_reliable_reset(id, 0);
1478
+ }
1402
1479
  if !self.account_incoming(true, ev) || !self.account_receive(id, data.len() as u64, ev) {
1403
1480
  return;
1404
1481
  }
@@ -1414,11 +1491,45 @@ impl WtSession {
1414
1491
  }
1415
1492
  }
1416
1493
 
1417
- pub fn on_datagrams(&mut self, conn: &mut quiche::Connection, ev: &mut Vec<Ev>) {
1418
- let mut buf = [0u8; 65_536];
1419
- loop {
1494
+ /// Read reliable data before datagrams so the latter cannot starve streams.
1495
+ pub fn read_pending(
1496
+ &mut self,
1497
+ conn: &mut quiche::Connection,
1498
+ budget: &mut ReceiveBudget,
1499
+ ev: &mut Vec<Ev>,
1500
+ ) {
1501
+ if self.closed || (!self.ready && self.close_req.is_some()) || budget.exhausted() {
1502
+ return;
1503
+ }
1504
+ let mut readable: Vec<_> = conn.readable().collect();
1505
+ // Start with the remaining streams from the previous pass when a busy
1506
+ // connection exhausted the budget before reaching the end of the list.
1507
+ readable.sort_unstable();
1508
+ let start = readable.partition_point(|&id| id < self.next_read_stream);
1509
+ readable.rotate_left(start);
1510
+ for id in readable {
1511
+ self.read_stream(conn, id, budget, ev);
1512
+ if budget.exhausted() {
1513
+ self.next_read_stream = id + 1;
1514
+ return;
1515
+ }
1516
+ }
1517
+ if self.ready && !self.closed {
1518
+ self.on_datagrams(conn, budget, ev);
1519
+ }
1520
+ }
1521
+
1522
+ fn on_datagrams(
1523
+ &mut self,
1524
+ conn: &mut quiche::Connection,
1525
+ budget: &mut ReceiveBudget,
1526
+ ev: &mut Vec<Ev>,
1527
+ ) {
1528
+ let mut buf = [0u8; crate::driver::MAX_RECV_UDP_PAYLOAD];
1529
+ while !budget.exhausted() {
1420
1530
  match conn.dgram_recv(&mut buf) {
1421
1531
  Ok(n) => {
1532
+ budget.record(n);
1422
1533
  let data = &buf[..n];
1423
1534
  if let Some((qsi, off)) = h3::read_varint(data) {
1424
1535
  // quarter-stream-id for our session is CONNECT_ID / 4 = 0.
@@ -1458,8 +1569,15 @@ impl WtSession {
1458
1569
  }
1459
1570
 
1460
1571
  fn uses_session_flow_control(&self) -> bool {
1461
- self.peer_settings
1462
- .is_some_and(|settings| settings.wt_max_sessions > 0)
1572
+ self.peer_settings.is_some_and(|settings| {
1573
+ if self.latest_protocol {
1574
+ settings.wt_initial_max_data != 0
1575
+ || settings.wt_initial_max_streams_bidi != 0
1576
+ || settings.wt_initial_max_streams_uni != 0
1577
+ } else {
1578
+ settings.wt_max_sessions > 0
1579
+ }
1580
+ })
1463
1581
  }
1464
1582
 
1465
1583
  fn release_pending_opens(&mut self, ev: &mut Vec<Ev>) {
@@ -1520,12 +1638,15 @@ impl WtSession {
1520
1638
 
1521
1639
  pub fn stream_write(&mut self, id: u64, data: Vec<u8>, request_id: u64, ev: &mut Vec<Ev>) {
1522
1640
  match self.streams.get_mut(&id) {
1523
- Some(st) => st.out.push_back(OutChunk {
1641
+ Some(st) if !st.fin_sent && st.reset_pending.is_none() => st.out.push_back(OutChunk {
1524
1642
  data,
1525
1643
  off: 0,
1526
1644
  request_id: Some(request_id),
1527
1645
  }),
1528
- None => ev.push(Ev::WriteAck { request_id }),
1646
+ _ => ev.push(Ev::WriteAck {
1647
+ request_id,
1648
+ accepted: false,
1649
+ }),
1529
1650
  }
1530
1651
  }
1531
1652
 
@@ -1536,10 +1657,17 @@ impl WtSession {
1536
1657
  }
1537
1658
 
1538
1659
  pub fn stream_reset(&mut self, conn: &mut quiche::Connection, id: u64, code: u64) {
1660
+ let h = h3::webtransport_code_to_http_code(code);
1661
+ if self.latest_protocol {
1662
+ if let Some(st) = self.streams.get_mut(&id) {
1663
+ st.out.retain(|chunk| chunk.request_id.is_none());
1664
+ st.reset_pending.get_or_insert(h);
1665
+ }
1666
+ return;
1667
+ }
1539
1668
  if self.streams.contains_key(&id) {
1540
1669
  // The QUIC RESET_STREAM code must be the WebTransport application code
1541
1670
  // mapped into the HTTP/3 error space.
1542
- let h = h3::webtransport_code_to_http_code(code);
1543
1671
  let _ = conn.stream_shutdown(id, quiche::Shutdown::Write, h);
1544
1672
  self.reconcile_send_final_size(conn, id);
1545
1673
  if let Some(st) = self.streams.get_mut(&id) {
@@ -1629,7 +1757,11 @@ impl WtSession {
1629
1757
  // connection-level flow control is the real limit; granting a large WT
1630
1758
  // credit here keeps a strict peer that honors our advertised session
1631
1759
  // limits from stalling, while QUIC does the actual enforcement.
1632
- if self.ready && !self.fc_credit_granted && !self.closed {
1760
+ if self.ready
1761
+ && !self.fc_credit_granted
1762
+ && !self.closed
1763
+ && (!self.latest_protocol || self.uses_session_flow_control())
1764
+ {
1633
1765
  self.fc_credit_granted = true;
1634
1766
  self.fc_max_data_local = WT_GRANT_MAX_DATA;
1635
1767
  self.fc_max_streams_local = [WT_GRANT_MAX_STREAMS; 2];
@@ -1846,6 +1978,17 @@ impl WtSession {
1846
1978
  // chunks) counts toward WT_MAX_DATA; the stream-signal prefix and CONNECT
1847
1979
  // capsules do not.
1848
1980
  let is_wt_data = matches!(st.role, Role::WtData { .. });
1981
+ if is_wt_data {
1982
+ if let Err(quiche::Error::StreamStopped(code)) = conn.stream_capacity(id) {
1983
+ if !st.fin_sent {
1984
+ let app = h3::http_code_to_webtransport_code(code).unwrap_or(code);
1985
+ ev.push(Ev::StreamStopSending { id, code: app });
1986
+ st.out.clear();
1987
+ st.fin_sent = true;
1988
+ }
1989
+ return;
1990
+ }
1991
+ }
1849
1992
  // Note: we call `stream_send` directly rather than pre-checking
1850
1993
  // `stream_capacity`, because a stream does not exist in quiche until its
1851
1994
  // first `stream_send`, and `stream_capacity` errors (InvalidStreamState)
@@ -1874,7 +2017,12 @@ impl WtSession {
1874
2017
  if front.off >= front.data.len() {
1875
2018
  let done = st.out.pop_front().unwrap();
1876
2019
  if let Some(rid) = done.request_id {
1877
- ev.push(Ev::WriteAck { request_id: rid });
2020
+ ev.push(Ev::WriteAck {
2021
+ request_id: rid,
2022
+ accepted: true,
2023
+ });
2024
+ } else if is_wt_data && self.latest_protocol {
2025
+ let _ = conn.stream_set_reliable_reset(id, st.send_prefix);
1878
2026
  }
1879
2027
  }
1880
2028
  if sent < remaining_len {
@@ -1883,23 +2031,18 @@ impl WtSession {
1883
2031
  }
1884
2032
  Err(quiche::Error::Done) => return,
1885
2033
  Err(quiche::Error::StreamLimit) => return, // no stream credit yet; retry next loop
1886
- Err(quiche::Error::StreamStopped(code)) => {
1887
- let app = h3::http_code_to_webtransport_code(code).unwrap_or(code);
1888
- ev.push(Ev::StreamStopSending { id, code: app });
1889
- // Settle every queued write's promise so a stalled write()
1890
- // (and its WritableStream) cannot hang forever.
1891
- for chunk in st.out.drain(..) {
1892
- if let Some(rid) = chunk.request_id {
1893
- ev.push(Ev::WriteAck { request_id: rid });
1894
- }
1895
- }
1896
- st.fin_sent = true;
1897
- return;
1898
- }
1899
2034
  Err(_) => return,
1900
2035
  }
1901
2036
  }
1902
2037
 
2038
+ if let Some(code) = st.reset_pending.take() {
2039
+ let reset = conn.stream_shutdown(id, quiche::Shutdown::Write, code);
2040
+ st.fin_sent = true;
2041
+ if reset.is_ok() {
2042
+ self.reconcile_send_final_size(conn, id);
2043
+ }
2044
+ return;
2045
+ }
1903
2046
  if st.out.is_empty()
1904
2047
  && st.fin_queued
1905
2048
  && !st.fin_sent
@@ -1917,11 +2060,8 @@ impl WtSession {
1917
2060
  // Closed connections can linger during QUIC draining. Release receive
1918
2061
  // allocations immediately rather than tying the budget to that timer.
1919
2062
  self.capsule_buf.clear();
1920
- for stream in self.streams.values_mut() {
1921
- stream.frames.buf.clear();
1922
- stream.class_buf.clear();
1923
- stream.recv_dead = true;
1924
- }
2063
+ self.streams.clear();
2064
+ self.pending_opens.clear();
1925
2065
  ev.push(Ev::Closed {
1926
2066
  code,
1927
2067
  reason,
@@ -2084,7 +2224,7 @@ mod tests {
2084
2224
  let mut session = server_with_connect(ParserMemory::new(64 * 1024 * 1024));
2085
2225
  session.ready = false;
2086
2226
  session.peer_settings = None;
2087
- session.on_established();
2227
+ session.on_established(false);
2088
2228
  let mut control = vec![0];
2089
2229
  control.extend_from_slice(&h3::frame(h3::FRAME_SETTINGS, &settings));
2090
2230
  client.stream_send(2, &control, false).unwrap();
@@ -2095,9 +2235,9 @@ mod tests {
2095
2235
  crate::test_support::exchange(&mut client, &mut server);
2096
2236
  let mut events = Vec::new();
2097
2237
  // Exercise out-of-order arrival: CONNECT must wait for SETTINGS.
2098
- session.on_readable(&mut server, 0, false, &mut events);
2238
+ session.on_readable(&mut server, 0, &mut events);
2099
2239
  assert!(!session.ready);
2100
- session.on_readable(&mut server, 2, false, &mut events);
2240
+ session.on_readable(&mut server, 2, &mut events);
2101
2241
  assert!(session.ready);
2102
2242
  (client, server, session)
2103
2243
  }
@@ -2134,7 +2274,7 @@ mod tests {
2134
2274
  h3::put_varint(0, &mut prefix);
2135
2275
  client.stream_send(14, &prefix, false).unwrap();
2136
2276
  crate::test_support::exchange(&mut client, &mut server);
2137
- session.on_readable(&mut server, 14, false, &mut Vec::new());
2277
+ session.on_readable(&mut server, 14, &mut Vec::new());
2138
2278
  client.stream_send(14, &[5; 8192], false).unwrap();
2139
2279
  // Serialize the bytes into QUIC without delivering them to the app.
2140
2280
  crate::test_support::exchange(&mut client, &mut server);
@@ -2143,7 +2283,7 @@ mod tests {
2143
2283
  .unwrap();
2144
2284
  crate::test_support::exchange(&mut client, &mut server);
2145
2285
  let mut events = Vec::new();
2146
- session.on_readable(&mut server, 14, false, &mut events);
2286
+ session.on_readable(&mut server, 14, &mut events);
2147
2287
  assert_eq!(session.fc_data_received, 8192);
2148
2288
  assert!(events
2149
2289
  .iter()
@@ -2167,11 +2307,14 @@ mod tests {
2167
2307
  client.stream_send(14, &stream, true).unwrap();
2168
2308
  crate::test_support::exchange(&mut client, &mut server);
2169
2309
  let mut events = Vec::new();
2170
- session.on_readable(&mut server, 14, false, &mut events);
2310
+ session.on_readable(&mut server, 14, &mut events);
2171
2311
  assert!(session.closed);
2172
- assert!(!events
2173
- .iter()
2174
- .any(|e| matches!(e, Ev::IncomingStream { .. } | Ev::StreamData { .. })));
2312
+ assert!(!events.iter().any(|e| matches!(e, Ev::StreamData { .. })));
2313
+ if !data_limit {
2314
+ assert!(!events
2315
+ .iter()
2316
+ .any(|e| matches!(e, Ev::IncomingStream { .. })));
2317
+ }
2175
2318
  }
2176
2319
  }
2177
2320
 
@@ -2195,7 +2338,7 @@ mod tests {
2195
2338
  let id = if bidi { 4 + i * 4 } else { 14 + i * 4 };
2196
2339
  client.stream_send(id, &prefix, true).unwrap();
2197
2340
  crate::test_support::exchange(&mut client, &mut server);
2198
- session.on_readable(&mut server, id, true, &mut events);
2341
+ session.read_pending(&mut server, &mut ReceiveBudget::blocked(), &mut events);
2199
2342
  session.flush(&mut server, &mut Vec::new());
2200
2343
  crate::test_support::exchange(&mut client, &mut server);
2201
2344
  }
@@ -2203,10 +2346,13 @@ mod tests {
2203
2346
  events.is_empty(),
2204
2347
  "application events leaked while backpressured"
2205
2348
  );
2349
+ session.read_pending(&mut server, &mut ReceiveBudget::new(), &mut events);
2350
+ assert!(!events.iter().any(|e| matches!(e, Ev::StreamData { .. })));
2206
2351
  for i in 0..20 {
2207
2352
  let id = if bidi { 4 + i * 4 } else { 14 + i * 4 };
2208
- session.on_readable(&mut server, id, false, &mut events);
2353
+ session.set_paused(id, false);
2209
2354
  }
2355
+ session.read_pending(&mut server, &mut ReceiveBudget::new(), &mut events);
2210
2356
  let bytes: usize = events
2211
2357
  .iter()
2212
2358
  .filter_map(|e| match e {
@@ -2279,7 +2425,7 @@ mod tests {
2279
2425
  assert!(!fin);
2280
2426
  assert!(!events
2281
2427
  .iter()
2282
- .any(|e| matches!(e, Ev::WriteAck { request_id: 13 })));
2428
+ .any(|e| matches!(e, Ev::WriteAck { request_id: 13, .. })));
2283
2429
  session.scan_capsules(&capsule(h3::WT_MAX_DATA_CAPSULE, 8), &mut events);
2284
2430
  session.scan_capsules(&capsule(h3::WT_MAX_STREAMS_BIDI_CAPSULE, 1), &mut events);
2285
2431
  session.flush(&mut server, &mut events);
@@ -2291,7 +2437,13 @@ mod tests {
2291
2437
  assert_eq!(
2292
2438
  events
2293
2439
  .iter()
2294
- .filter(|e| matches!(e, Ev::WriteAck { request_id: 13 }))
2440
+ .filter(|e| matches!(
2441
+ e,
2442
+ Ev::WriteAck {
2443
+ request_id: 13,
2444
+ accepted: true
2445
+ }
2446
+ ))
2295
2447
  .count(),
2296
2448
  1
2297
2449
  );
@@ -2367,7 +2519,7 @@ mod tests {
2367
2519
  .unwrap();
2368
2520
  crate::test_support::exchange(&mut client, &mut server);
2369
2521
  let mut events = Vec::new();
2370
- session.on_readable(&mut server, 2, false, &mut events);
2522
+ session.on_readable(&mut server, 2, &mut events);
2371
2523
  assert!(session.closed);
2372
2524
  assert!(events
2373
2525
  .iter()