rwebtransport 0.1.0

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 (122) hide show
  1. package/Cargo.lock +666 -0
  2. package/Cargo.toml +31 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +41 -0
  5. package/README.md +550 -0
  6. package/crates/echo-server/Cargo.toml +20 -0
  7. package/crates/echo-server/src/main.rs +666 -0
  8. package/crates/native/Cargo.toml +23 -0
  9. package/crates/native/src/config.rs +129 -0
  10. package/crates/native/src/driver.rs +463 -0
  11. package/crates/native/src/lib.rs +821 -0
  12. package/crates/native/src/server.rs +718 -0
  13. package/crates/native/src/session.rs +1191 -0
  14. package/crates/native/src/tls.rs +96 -0
  15. package/crates/wtcore/Cargo.toml +15 -0
  16. package/crates/wtcore/src/h3.rs +226 -0
  17. package/crates/wtcore/src/lib.rs +9 -0
  18. package/dist/datagrams.d.ts +16 -0
  19. package/dist/errors.d.ts +10 -0
  20. package/dist/index.d.ts +7 -0
  21. package/dist/index.js +1512 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/index.mjs +1473 -0
  24. package/dist/index.mjs.map +1 -0
  25. package/dist/loader.d.ts +2 -0
  26. package/dist/native.d.ts +226 -0
  27. package/dist/server.d.ts +44 -0
  28. package/dist/streams.d.ts +14 -0
  29. package/dist/types.d.ts +24 -0
  30. package/dist/webtransport.d.ts +20 -0
  31. package/package.json +79 -0
  32. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  33. package/scripts/bench.mjs +180 -0
  34. package/scripts/build.js +67 -0
  35. package/scripts/postinstall.js +67 -0
  36. package/scripts/setup-unix.sh +129 -0
  37. package/scripts/setup-windows.ps1 +229 -0
  38. package/vendor/quiche/AGENTS.md +75 -0
  39. package/vendor/quiche/COPYING +23 -0
  40. package/vendor/quiche/Cargo.lock +1212 -0
  41. package/vendor/quiche/Cargo.toml +215 -0
  42. package/vendor/quiche/README.md +466 -0
  43. package/vendor/quiche/examples/Makefile +46 -0
  44. package/vendor/quiche/examples/README.md +20 -0
  45. package/vendor/quiche/examples/cert-big.crt +90 -0
  46. package/vendor/quiche/examples/cert.crt +18 -0
  47. package/vendor/quiche/examples/cert.key +28 -0
  48. package/vendor/quiche/examples/client.c +343 -0
  49. package/vendor/quiche/examples/client.rs +281 -0
  50. package/vendor/quiche/examples/gen-certs.sh +15 -0
  51. package/vendor/quiche/examples/http3-client.c +473 -0
  52. package/vendor/quiche/examples/http3-client.rs +349 -0
  53. package/vendor/quiche/examples/http3-server.c +614 -0
  54. package/vendor/quiche/examples/http3-server.rs +680 -0
  55. package/vendor/quiche/examples/qpack-decode.rs +87 -0
  56. package/vendor/quiche/examples/qpack-encode.rs +88 -0
  57. package/vendor/quiche/examples/rootca.crt +21 -0
  58. package/vendor/quiche/examples/server.c +529 -0
  59. package/vendor/quiche/examples/server.rs +529 -0
  60. package/vendor/quiche/include/quiche.h +1282 -0
  61. package/vendor/quiche/quiche.svg +1 -0
  62. package/vendor/quiche/src/buffers.rs +105 -0
  63. package/vendor/quiche/src/build.rs +66 -0
  64. package/vendor/quiche/src/cid.rs +1079 -0
  65. package/vendor/quiche/src/crypto/boringssl.rs +373 -0
  66. package/vendor/quiche/src/crypto/mod.rs +671 -0
  67. package/vendor/quiche/src/dgram.rs +118 -0
  68. package/vendor/quiche/src/error.rs +263 -0
  69. package/vendor/quiche/src/ffi.rs +2290 -0
  70. package/vendor/quiche/src/flowcontrol.rs +246 -0
  71. package/vendor/quiche/src/frame.rs +2172 -0
  72. package/vendor/quiche/src/h3/AGENTS.md +54 -0
  73. package/vendor/quiche/src/h3/ffi.rs +442 -0
  74. package/vendor/quiche/src/h3/frame.rs +1404 -0
  75. package/vendor/quiche/src/h3/mod.rs +8223 -0
  76. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -0
  77. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -0
  78. package/vendor/quiche/src/h3/qpack/mod.rs +202 -0
  79. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -0
  80. package/vendor/quiche/src/h3/stream.rs +1595 -0
  81. package/vendor/quiche/src/lib.rs +9556 -0
  82. package/vendor/quiche/src/minmax.rs +446 -0
  83. package/vendor/quiche/src/packet.rs +2334 -0
  84. package/vendor/quiche/src/path.rs +1374 -0
  85. package/vendor/quiche/src/pmtud.rs +652 -0
  86. package/vendor/quiche/src/rand.rs +64 -0
  87. package/vendor/quiche/src/range_buf.rs +186 -0
  88. package/vendor/quiche/src/ranges.rs +755 -0
  89. package/vendor/quiche/src/recovery/AGENTS.md +80 -0
  90. package/vendor/quiche/src/recovery/bandwidth.rs +565 -0
  91. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -0
  92. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -0
  93. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -0
  94. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -0
  95. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -0
  96. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -0
  97. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -0
  98. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -0
  99. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -0
  100. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -0
  101. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -0
  102. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -0
  103. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -0
  104. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -0
  105. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -0
  106. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -0
  107. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -0
  108. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -0
  109. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -0
  110. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -0
  111. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -0
  112. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -0
  113. package/vendor/quiche/src/recovery/mod.rs +3086 -0
  114. package/vendor/quiche/src/recovery/rtt.rs +152 -0
  115. package/vendor/quiche/src/stream/mod.rs +2210 -0
  116. package/vendor/quiche/src/stream/recv_buf.rs +1236 -0
  117. package/vendor/quiche/src/stream/send_buf.rs +849 -0
  118. package/vendor/quiche/src/test_utils.rs +681 -0
  119. package/vendor/quiche/src/tests.rs +12922 -0
  120. package/vendor/quiche/src/tls/boringssl.rs +375 -0
  121. package/vendor/quiche/src/tls/mod.rs +1245 -0
  122. package/vendor/quiche/src/transport_params.rs +628 -0
@@ -0,0 +1,238 @@
1
+ // Copyright (C) 2021, 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
+ //! Proportional Rate Reduction
28
+ //!
29
+ //! This implementation is based on the following RFC:
30
+ //!
31
+ //! <https://datatracker.ietf.org/doc/html/rfc6937>
32
+
33
+ use std::cmp;
34
+
35
+ #[derive(Default, Debug)]
36
+ pub struct PRR {
37
+ // Total bytes delivered during recovery.
38
+ prr_delivered: usize,
39
+
40
+ // FlightSize at the start of recovery.
41
+ recoverfs: usize,
42
+
43
+ // Total bytes sent during recovery.
44
+ prr_out: usize,
45
+
46
+ // Total additional bytes can be sent for retransmit during recovery.
47
+ pub snd_cnt: usize,
48
+ }
49
+
50
+ impl PRR {
51
+ pub fn on_packet_sent(&mut self, sent_bytes: usize) {
52
+ self.prr_out += sent_bytes;
53
+
54
+ self.snd_cnt = self.snd_cnt.saturating_sub(sent_bytes);
55
+ }
56
+
57
+ pub fn congestion_event(&mut self, bytes_in_flight: usize) {
58
+ self.prr_delivered = 0;
59
+
60
+ self.recoverfs = bytes_in_flight;
61
+
62
+ self.prr_out = 0;
63
+
64
+ self.snd_cnt = 0;
65
+ }
66
+
67
+ pub fn on_packet_acked(
68
+ &mut self, delivered_data: usize, pipe: usize, ssthresh: usize,
69
+ max_datagram_size: usize,
70
+ ) {
71
+ self.prr_delivered += delivered_data;
72
+
73
+ self.snd_cnt = if pipe > ssthresh {
74
+ // Proportional Rate Reduction.
75
+ if self.recoverfs > 0 {
76
+ (self.prr_delivered * ssthresh)
77
+ .div_ceil(self.recoverfs)
78
+ .saturating_sub(self.prr_out)
79
+ } else {
80
+ 0
81
+ }
82
+ } else {
83
+ // PRR-SSRB.
84
+ let limit = cmp::max(
85
+ self.prr_delivered.saturating_sub(self.prr_out),
86
+ delivered_data,
87
+ ) + max_datagram_size;
88
+
89
+ // Attempt to catch up, as permitted by limit
90
+ cmp::min(ssthresh - pipe, limit)
91
+ };
92
+
93
+ // snd_cnt should be a positive number.
94
+ self.snd_cnt = cmp::max(self.snd_cnt, 0);
95
+ }
96
+ }
97
+
98
+ #[cfg(test)]
99
+ mod tests {
100
+ use super::*;
101
+
102
+ #[test]
103
+ fn congestion_event() {
104
+ let mut prr = PRR::default();
105
+ let bytes_in_flight = 1000;
106
+
107
+ prr.congestion_event(bytes_in_flight);
108
+
109
+ assert_eq!(prr.recoverfs, bytes_in_flight);
110
+ assert_eq!(prr.snd_cnt, 0);
111
+ }
112
+
113
+ #[test]
114
+ fn on_packet_sent() {
115
+ let mut prr = PRR::default();
116
+ let bytes_in_flight = 1000;
117
+ let bytes_sent = 500;
118
+
119
+ prr.congestion_event(bytes_in_flight);
120
+
121
+ prr.on_packet_sent(bytes_sent);
122
+
123
+ assert_eq!(prr.prr_out, bytes_sent);
124
+ assert_eq!(prr.snd_cnt, 0);
125
+ }
126
+
127
+ #[test]
128
+ fn on_packet_acked_prr() {
129
+ let mut prr = PRR::default();
130
+ let max_datagram_size = 1000;
131
+ let bytes_in_flight = max_datagram_size * 10;
132
+ let ssthresh = bytes_in_flight / 2;
133
+ let acked = 1000;
134
+
135
+ prr.congestion_event(bytes_in_flight);
136
+
137
+ // pipe > ssthresh uses PRR algorithm.
138
+ let pipe = bytes_in_flight;
139
+
140
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
141
+
142
+ assert_eq!(prr.snd_cnt, 500);
143
+
144
+ let snd_cnt = prr.snd_cnt;
145
+
146
+ // send one more allowed by snd_cnt
147
+ prr.on_packet_sent(snd_cnt);
148
+
149
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
150
+
151
+ assert_eq!(prr.snd_cnt, 500);
152
+ }
153
+
154
+ #[test]
155
+ fn on_packet_acked_prr_overflow() {
156
+ let mut prr = PRR::default();
157
+ let max_datagram_size = 1000;
158
+ let bytes_in_flight = max_datagram_size * 10;
159
+ let ssthresh = bytes_in_flight / 2;
160
+ let acked = 1000;
161
+
162
+ prr.congestion_event(bytes_in_flight);
163
+
164
+ prr.on_packet_sent(max_datagram_size);
165
+
166
+ // pipe > ssthresh uses PRR algorithm.
167
+ let pipe = bytes_in_flight + max_datagram_size;
168
+
169
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
170
+
171
+ assert_eq!(prr.snd_cnt, 0);
172
+ }
173
+
174
+ #[test]
175
+ fn on_packet_acked_prr_zero_in_flight() {
176
+ let mut prr = PRR::default();
177
+ let max_datagram_size = 1000;
178
+ let bytes_in_flight = 0;
179
+ let ssthresh = 3000;
180
+ let acked = 1000;
181
+
182
+ prr.congestion_event(bytes_in_flight);
183
+
184
+ // pipe > ssthresh uses PRR algorithm.
185
+ let pipe = ssthresh + 1000;
186
+
187
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
188
+
189
+ assert_eq!(prr.snd_cnt, 0);
190
+ }
191
+
192
+ #[test]
193
+ fn on_packet_acked_prr_ssrb() {
194
+ let mut prr = PRR::default();
195
+ let max_datagram_size = 1000;
196
+ let bytes_in_flight = max_datagram_size * 10;
197
+ let ssthresh = bytes_in_flight / 2;
198
+ let acked = 1000;
199
+
200
+ prr.congestion_event(bytes_in_flight);
201
+
202
+ // pipe <= ssthresh uses PRR-SSRB algorithm.
203
+ let pipe = max_datagram_size;
204
+
205
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
206
+
207
+ assert_eq!(prr.snd_cnt, 2000);
208
+
209
+ let snd_cnt = prr.snd_cnt;
210
+
211
+ // send one more allowed by snd_cnt
212
+ prr.on_packet_sent(snd_cnt);
213
+
214
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
215
+
216
+ assert_eq!(prr.snd_cnt, 2000);
217
+ }
218
+
219
+ #[test]
220
+ fn on_packet_acked_prr_ssrb_overflow() {
221
+ let mut prr = PRR::default();
222
+ let max_datagram_size = 1000;
223
+ let bytes_in_flight = max_datagram_size * 10;
224
+ let ssthresh = bytes_in_flight / 2;
225
+ let acked = 500;
226
+
227
+ prr.congestion_event(bytes_in_flight);
228
+
229
+ // pipe <= ssthresh uses PRR-SSRB algorithm.
230
+ let pipe = max_datagram_size;
231
+
232
+ prr.on_packet_sent(max_datagram_size);
233
+
234
+ prr.on_packet_acked(acked, pipe, ssthresh, max_datagram_size);
235
+
236
+ assert_eq!(prr.snd_cnt, 1500);
237
+ }
238
+ }