@fails-components/webtransport 0.3.1 → 1.0.1

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 (162) hide show
  1. package/lib/client.js +81 -40
  2. package/lib/dom.ts +7 -5
  3. package/lib/http2/browser/browser.js +168 -0
  4. package/lib/http2/browser/browserparser.js +248 -0
  5. package/lib/http2/flowcontroller.js +371 -0
  6. package/lib/http2/node/capsuleparser.js +291 -0
  7. package/lib/http2/node/client.js +239 -0
  8. package/lib/http2/node/index.js +2 -0
  9. package/lib/http2/node/server.js +499 -0
  10. package/lib/http2/node/websocketparser.js +829 -0
  11. package/lib/http2/parserbase.js +139 -0
  12. package/lib/http2/parserbasehttp2.js +128 -0
  13. package/lib/http2/session.js +225 -0
  14. package/lib/http2/stream.js +354 -0
  15. package/lib/http2/websocketcommon.js +1 -0
  16. package/lib/{index.js → index.browser.js} +6 -10
  17. package/lib/index.node.js +27 -0
  18. package/lib/server.js +252 -69
  19. package/lib/session.js +31 -68
  20. package/lib/stream.js +103 -179
  21. package/lib/types.ts +174 -87
  22. package/lib/utils.js +2 -1
  23. package/lib/webstreams.browser.js +6 -0
  24. package/lib/webstreams.js +7 -0
  25. package/lib/webtransport.browser.js +284 -0
  26. package/lib/webtransport.node.js +137 -0
  27. package/lib/{webtransport.js → webtransportbase.js} +47 -41
  28. package/old_test/test.js +31 -29
  29. package/old_test/testsuite.js +1 -1
  30. package/package.json +18 -17
  31. package/readme.md +94 -30
  32. package/test/bidirectional-streams.spec.js +51 -9
  33. package/test/datagrams.spec.js +8 -2
  34. package/test/fixtures/known-bytes.js +29 -0
  35. package/test/fixtures/read-stream.js +1 -1
  36. package/test/fixtures/reader-value.js +1 -1
  37. package/test/fixtures/server.js +24 -10
  38. package/test/fixtures/webtransport.browser.js +20 -2
  39. package/test/fixtures/webtransport.js +1 -1
  40. package/test/index.js +33 -6
  41. package/test/pw-no-https-errors.json +5 -0
  42. package/test/session.spec.js +71 -52
  43. package/test/unidirectional-streams.spec.js +20 -4
  44. package/CMakeLists.txt +0 -991
  45. package/LICENSE.chromium +0 -27
  46. package/LICENSE.envoy +0 -207
  47. package/build.js +0 -313
  48. package/dist/lib/client.d.ts +0 -78
  49. package/dist/lib/client.d.ts.map +0 -1
  50. package/dist/lib/dom.d.ts +0 -87
  51. package/dist/lib/dom.d.ts.map +0 -1
  52. package/dist/lib/error.d.ts +0 -8
  53. package/dist/lib/error.d.ts.map +0 -1
  54. package/dist/lib/event-loop.d.ts +0 -33
  55. package/dist/lib/event-loop.d.ts.map +0 -1
  56. package/dist/lib/index.d.ts +0 -79
  57. package/dist/lib/index.d.ts.map +0 -1
  58. package/dist/lib/native.d.ts +0 -2
  59. package/dist/lib/native.d.ts.map +0 -1
  60. package/dist/lib/server.d.ts +0 -92
  61. package/dist/lib/server.d.ts.map +0 -1
  62. package/dist/lib/session.d.ts +0 -298
  63. package/dist/lib/session.d.ts.map +0 -1
  64. package/dist/lib/stream.d.ts +0 -135
  65. package/dist/lib/stream.d.ts.map +0 -1
  66. package/dist/lib/transport.d.ts +0 -34
  67. package/dist/lib/transport.d.ts.map +0 -1
  68. package/dist/lib/types.d.ts +0 -212
  69. package/dist/lib/types.d.ts.map +0 -1
  70. package/dist/lib/utils.d.ts +0 -11
  71. package/dist/lib/utils.d.ts.map +0 -1
  72. package/dist/lib/webtransport.d.ts +0 -47
  73. package/dist/lib/webtransport.d.ts.map +0 -1
  74. package/dist/test/bidirectional-streams.spec.d.ts +0 -5
  75. package/dist/test/bidirectional-streams.spec.d.ts.map +0 -1
  76. package/dist/test/datagrams.spec.d.ts +0 -5
  77. package/dist/test/datagrams.spec.d.ts.map +0 -1
  78. package/dist/test/event-loop.node.d.ts +0 -2
  79. package/dist/test/event-loop.node.d.ts.map +0 -1
  80. package/dist/test/fixtures/certificate.d.ts +0 -21
  81. package/dist/test/fixtures/certificate.d.ts.map +0 -1
  82. package/dist/test/fixtures/chai.d.ts +0 -2
  83. package/dist/test/fixtures/chai.d.ts.map +0 -1
  84. package/dist/test/fixtures/known-bytes.d.ts +0 -6
  85. package/dist/test/fixtures/known-bytes.d.ts.map +0 -1
  86. package/dist/test/fixtures/p-timeout.d.ts +0 -8
  87. package/dist/test/fixtures/p-timeout.d.ts.map +0 -1
  88. package/dist/test/fixtures/read-cert-hash.d.ts +0 -6
  89. package/dist/test/fixtures/read-cert-hash.d.ts.map +0 -1
  90. package/dist/test/fixtures/read-stream.d.ts +0 -19
  91. package/dist/test/fixtures/read-stream.d.ts.map +0 -1
  92. package/dist/test/fixtures/reader-value.d.ts +0 -22
  93. package/dist/test/fixtures/reader-value.d.ts.map +0 -1
  94. package/dist/test/fixtures/server.d.ts +0 -5
  95. package/dist/test/fixtures/server.d.ts.map +0 -1
  96. package/dist/test/fixtures/webtransport.browser.d.ts +0 -3
  97. package/dist/test/fixtures/webtransport.browser.d.ts.map +0 -1
  98. package/dist/test/fixtures/webtransport.d.ts +0 -3
  99. package/dist/test/fixtures/webtransport.d.ts.map +0 -1
  100. package/dist/test/fixtures/write-stream.d.ts +0 -10
  101. package/dist/test/fixtures/write-stream.d.ts.map +0 -1
  102. package/dist/test/index.d.ts +0 -2
  103. package/dist/test/index.d.ts.map +0 -1
  104. package/dist/test/session.spec.d.ts +0 -5
  105. package/dist/test/session.spec.d.ts.map +0 -1
  106. package/dist/test/unidirectional-streams.spec.d.ts +0 -2
  107. package/dist/test/unidirectional-streams.spec.d.ts.map +0 -1
  108. package/failslogolicensereadme.txt +0 -4
  109. package/lib/event-loop.js +0 -88
  110. package/lib/native.js +0 -28
  111. package/lib/transport.js +0 -82
  112. package/platform/icufix/fakedata.cpp +0 -8
  113. package/platform/quiche/quic/core/io/socket_win.inc +0 -3
  114. package/platform/quiche_platform_impl/quiche_bug_tracker_impl.h +0 -7
  115. package/platform/quiche_platform_impl/quiche_client_stats_impl.h +0 -7
  116. package/platform/quiche_platform_impl/quiche_command_line_flags_impl.h +0 -7
  117. package/platform/quiche_platform_impl/quiche_containers_impl.h +0 -7
  118. package/platform/quiche_platform_impl/quiche_event_loop_impl.h +0 -7
  119. package/platform/quiche_platform_impl/quiche_export_impl.h +0 -6
  120. package/platform/quiche_platform_impl/quiche_flag_utils_impl.h +0 -11
  121. package/platform/quiche_platform_impl/quiche_flags_impl.h +0 -8
  122. package/platform/quiche_platform_impl/quiche_iovec_impl.h +0 -10
  123. package/platform/quiche_platform_impl/quiche_logging_impl.h +0 -21
  124. package/platform/quiche_platform_impl/quiche_mem_slice_impl.h +0 -2
  125. package/platform/quiche_platform_impl/quiche_mutex_impl.h +0 -8
  126. package/platform/quiche_platform_impl/quiche_prefetch_impl.h +0 -11
  127. package/platform/quiche_platform_impl/quiche_reference_counted_impl.h +0 -16
  128. package/platform/quiche_platform_impl/quiche_server_stats_impl.h +0 -7
  129. package/platform/quiche_platform_impl/quiche_stack_trace_impl.h +0 -12
  130. package/platform/quiche_platform_impl/quiche_stream_buffer_allocator_impl.h +0 -8
  131. package/platform/quiche_platform_impl/quiche_testvalue_impl.h +0 -1
  132. package/platform/quiche_platform_impl/quiche_thread_local_impl.h +0 -6
  133. package/platform/quiche_platform_impl/quiche_time_utils_impl.h +0 -13
  134. package/platform/quiche_platform_impl/quiche_udp_socket_platform_impl.h +0 -39
  135. package/src/http3backendresponse.cc +0 -36
  136. package/src/http3backendresponse.h +0 -109
  137. package/src/http3client.cc +0 -1529
  138. package/src/http3client.h +0 -557
  139. package/src/http3clientsession.cc +0 -65
  140. package/src/http3clientsession.h +0 -60
  141. package/src/http3clientstream.cc +0 -52
  142. package/src/http3clientstream.h +0 -42
  143. package/src/http3dispatcher.cc +0 -62
  144. package/src/http3dispatcher.h +0 -57
  145. package/src/http3eventloop.cc +0 -1107
  146. package/src/http3eventloop.h +0 -316
  147. package/src/http3server.cc +0 -514
  148. package/src/http3server.h +0 -151
  149. package/src/http3serverbackend.cc +0 -105
  150. package/src/http3serverbackend.h +0 -98
  151. package/src/http3serversession.cc +0 -123
  152. package/src/http3serversession.h +0 -95
  153. package/src/http3serverstream.cc +0 -463
  154. package/src/http3serverstream.h +0 -114
  155. package/src/http3sessioncache.cc +0 -85
  156. package/src/http3sessioncache.h +0 -59
  157. package/src/http3wtsessionvisitor.cc +0 -46
  158. package/src/http3wtsessionvisitor.h +0 -397
  159. package/src/http3wtstreamvisitor.cc +0 -155
  160. package/src/http3wtstreamvisitor.h +0 -404
  161. package/test/event-loop.node.js +0 -24
  162. package/tsconfig.json +0 -39
@@ -1,316 +0,0 @@
1
- // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- // portions taken from libquiche, original copyright, see LICENSE.chromium
6
- // Copyright (c) The Chromium Authors. All rights reserved.
7
- // Use of this source code is governed by a BSD-style license that can be
8
- // found in the LICENSE file.
9
-
10
- #ifndef WT_HTTP3_EVENTLOOP_H
11
- #define WT_HTTP3_EVENTLOOP_H
12
-
13
- #include <memory>
14
-
15
- #include <napi.h>
16
- #include <uv.h>
17
-
18
- #include "src/http3serverbackend.h"
19
- #include "quiche/quic/core/crypto/quic_crypto_server_config.h"
20
- #include "quiche/quic/core/quic_udp_socket.h"
21
- #include "quiche/quic/core/quic_dispatcher.h"
22
- #include "quiche/quic/core/quic_packet_reader.h"
23
- #include "quiche/quic/platform/api/quic_socket_address.h"
24
- #include "quiche/quic/core/io/quic_default_event_loop.h"
25
-
26
- using namespace Napi;
27
-
28
- namespace quic
29
- {
30
-
31
- class Http3Server;
32
- class Http3Client;
33
- class Http3WTSession;
34
- class Http3WTStream;
35
- class Http3EventLoop;
36
- class WebTransportRespPromise;
37
-
38
- class LifetimeHelper
39
- {
40
- public:
41
- virtual void doUnref() = 0;
42
- };
43
-
44
- enum NetworkTask
45
- {
46
- resetStream,
47
- stopSending,
48
- streamFinal
49
- };
50
-
51
- enum NetworkStatus
52
- {
53
- NetError,
54
- NetClose,
55
- NetListening
56
- };
57
-
58
- struct Http3Constructors
59
- {
60
- Napi::FunctionReference stream;
61
- Napi::FunctionReference session;
62
- };
63
-
64
- struct ServerStatusDetails
65
- {
66
- std::string host;
67
- int port;
68
- };
69
-
70
- class Http3ProgressReport // actually struct would be a better fit but make napi happy
71
- {
72
- public:
73
- using WebTransportRespPromise = JSlikePromise<Http3ServerBackend::WebTransportResponse>;
74
- using WebTransportRespPromisePtr = std::shared_ptr<Http3ServerBackend::WebTransportRespPromise>;
75
- enum
76
- {
77
- ClientConnected,
78
- ClientWebTransportSupport,
79
- NewClientSession,
80
- NewSession,
81
- NewSessionRequest,
82
- SessionReady,
83
- SessionClosed,
84
- IncomBiDiStream,
85
- IncomUniDiStream,
86
- OutgoBiDiStream,
87
- OutgoUniDiStream,
88
- ServerStatus,
89
- StreamRecvSignal,
90
- StreamRead,
91
- StreamWrite,
92
- StreamReset,
93
- StreamNetworkFinish,
94
- DatagramReceived,
95
- DatagramSend,
96
- GoawayReceived,
97
- SessionStats,
98
- DatagramStats,
99
- Unref
100
- } type;
101
- union
102
- { // always the originating obj
103
- Http3WTStream *streamobj;
104
- Http3WTSession *sessionobj;
105
- Http3Server *serverobj;
106
- Http3Client *clientobj;
107
- LifetimeHelper *obj;
108
- };
109
- union
110
- {
111
- WebTransportSessionError wtecode;
112
- NetworkTask nettask;
113
- NetworkStatus status;
114
- WebTransportSession *webtsession;
115
- uint32_t buffergrow;
116
- };
117
- union
118
- {
119
- Http3WTStream *stream; // unowned
120
- Http3WTSession *session; // unowned
121
- spdy::Http2HeaderBlock *headerblock; // we own it and must delete it after return from js
122
- Napi::ObjectReference *bufferhandle; // we own it and must delete it if present
123
- bool fin;
124
- WebTransportStreamError wtscode;
125
- };
126
- union
127
- {
128
- std::string *para = nullptr; // for session and others, we own it, and must delete it
129
- ServerStatusDetails *details;
130
- webtransport::SessionStats * sessionStats; // we own it and must delete it after return from js
131
- webtransport::DatagramStats * datagramStats; // we own it and must delete it after return from js
132
- };
133
- union
134
- {
135
- bool success;
136
- WebTransportRespPromisePtr *promise;
137
- Napi::Reference<Napi::Value> *header;
138
- absl::Duration *timestamp; // for session and others, we own it, and must delete it
139
- };
140
- };
141
-
142
- class Http3EventLoop : // may be replace char later
143
- public Napi::ObjectWrap<Http3EventLoop>
144
- {
145
- private:
146
- class QueueWorker : public AsyncProgressQueueWorker<Http3ProgressReport>
147
- {
148
- public:
149
- QueueWorker(Http3EventLoop *eventloop, Napi::Function cb) : AsyncProgressQueueWorker(cb),
150
- eventloop_(eventloop)
151
- {
152
- }
153
-
154
- ~QueueWorker()
155
- {
156
- eventloop_->removeQw();
157
- }
158
-
159
- void Execute(const AsyncProgressQueueWorker::ExecutionProgress &progress)
160
- {
161
- eventloop_->Execute(progress);
162
- }
163
-
164
- void OnProgress(const Http3ProgressReport *data, size_t count) override
165
- {
166
- eventloop_->HandleProgressCallback(data, count);
167
- }
168
-
169
- void OnOK() override
170
- {
171
- eventloop_->Destroy();
172
- }
173
-
174
- void OnError(const Error &e) override
175
- {
176
- eventloop_->Destroy();
177
- }
178
-
179
- protected:
180
- Http3EventLoop *eventloop_;
181
- };
182
-
183
- public:
184
- Http3EventLoop(const Napi::CallbackInfo &info);
185
-
186
- Http3EventLoop(const Http3EventLoop &) = delete;
187
- Http3EventLoop &operator=(const Http3EventLoop &) = delete;
188
-
189
- ~Http3EventLoop();
190
-
191
- static void Init(Napi::Env env, Napi::Object exports);
192
-
193
- void Execute(const AsyncProgressQueueWorker<Http3ProgressReport>::ExecutionProgress &progress);
194
-
195
- // call into javascript, if necessary
196
- void HandleProgressCallback(const Http3ProgressReport *data, size_t count);
197
-
198
- // Server deletion is imminent. Start cleaning up the epoll server.
199
- void Destroy();
200
-
201
- QuicEventLoop *getQuicEventLoop() { return quic_event_loop_.get(); };
202
-
203
- void informAboutClientConnected(Http3Client *client, bool success);
204
- void informClientWebtransportSupport(Http3Client *client);
205
- void informNewClientSession(Http3Client *client, Http3WTSession *session);
206
-
207
- using WebTransportRespPromise = JSlikePromise<Http3ServerBackend::WebTransportResponse>;
208
- using WebTransportRespPromisePtr = std::shared_ptr<Http3ServerBackend::WebTransportRespPromise>;
209
-
210
- void informAboutNewSessionRequest(Http3Server *server, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr promise);
211
- void informAboutNewSession(Http3Server *server, Http3WTSession *session, absl::string_view path, Napi::Reference<Napi::Value> *header);
212
- void informSessionClosed(Http3WTSession *sessionobj, WebTransportSessionError error_code, absl::string_view error_message);
213
- void informSessionReady(Http3WTSession *sessionobj);
214
-
215
- void informServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details);
216
-
217
- void informAboutStream(bool incom, bool bidir, Http3WTSession *sessionobj, Http3WTStream *stream);
218
- void informStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task);
219
- void informAboutStreamRead(Http3WTStream *streamobj, uint32_t buffergrow, bool fin, bool success);
220
- void informAboutStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success);
221
- void informAboutStreamReset(Http3WTStream *streamobj);
222
- void informAboutStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task);
223
-
224
- void informDatagramReceived(Http3WTSession *sessionobj, absl::string_view datagram);
225
- void informDatagramSend(Http3WTSession *sessionobj, Napi::ObjectReference *bufferhandle);
226
-
227
- void informSessionStats(Http3WTSession *sessionobj, webtransport::SessionStats * sessstats);
228
- void informDatagramStats(Http3WTSession *sessionobj, webtransport::DatagramStats * datastats);
229
-
230
- void informGoawayReceived(Http3WTSession *sessionobj);
231
-
232
- void informUnref(LifetimeHelper *obj);
233
-
234
- void Schedule(std::function<void()> action);
235
-
236
- void startEventLoop(const Napi::CallbackInfo &info);
237
- void shutDownEventLoop(const Napi::CallbackInfo &info);
238
-
239
- private:
240
- QueueWorker *qw_;
241
-
242
- bool checkQw()
243
- {
244
- if (!qw_)
245
- {
246
- Napi::Error::New(Env(), "Queueworker gone").ThrowAsJavaScriptException();
247
- return false;
248
- }
249
- return true;
250
- }
251
-
252
- void removeQw()
253
- {
254
- qw_ = nullptr;
255
- }
256
-
257
- static Napi::Value New(const Napi::CallbackInfo &info);
258
-
259
- static void freeData(Napi::Env env, void *data, std::string *hint);
260
-
261
- static inline Napi::FunctionReference &constructor()
262
- {
263
- static Napi::FunctionReference my_constructor;
264
- return my_constructor;
265
- }
266
-
267
- static bool hasSetLogging;
268
-
269
- void ExecuteScheduledActions();
270
-
271
- QuicMutex scheduled_actions_lock_;
272
- quiche::QuicheCircularDeque<std::function<void()>> scheduled_actions_
273
- QUIC_GUARDED_BY(scheduled_actions_lock_);
274
-
275
- QuicPacketCount packets_dropped_;
276
- std::unique_ptr<QuicEventLoop> quic_event_loop_;
277
-
278
- void processClientConnected(Http3Client *clientobj, bool success);
279
- void processClientWebtransportSupport(Http3Client *client);
280
- void processNewClientSession(Http3Client *client, Http3WTSession *session);
281
-
282
- void processNewSessionRequest(Http3Server *server, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr *promise);
283
- void processNewSession(Http3Server *serverobj, Http3WTSession *session, const std::string &path, Napi::Reference<Napi::Value> *header);
284
- void processSessionClose(Http3WTSession *sessionobj, uint32_t errorcode, const std::string &path);
285
- void processSessionReady(Http3WTSession *sessionobj);
286
-
287
- void processServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details);
288
-
289
- void processStream(bool incom, bool bidi, Http3WTSession *sessionobj, Http3WTStream *stream);
290
- void processStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task);
291
- void processStreamRead(Http3WTStream *streamobj, size_t buffergrow, bool fin, bool success);
292
- void processStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success);
293
- void processStreamReset(Http3WTStream *streamobj);
294
- void processStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task);
295
-
296
- void processDatagramReceived(Http3WTSession *sessionobj, std::string *datagram);
297
- void processDatagramSend(Http3WTSession *sessionobj, Napi::ObjectReference *bufferhandle);
298
-
299
- void processSessionStats(Http3WTSession *sessionobj, absl::Duration* timestamp, webtransport::SessionStats * sessstats);
300
- void processDatagramStats(Http3WTSession *sessionobj, absl::Duration* timestamp, webtransport::DatagramStats * datastats);
301
-
302
- void processGoawayReceived(Http3WTSession *sessionobj);
303
-
304
- bool shutDownEventLoopInt();
305
-
306
- const AsyncProgressQueueWorker<Http3ProgressReport>::ExecutionProgress *progress_;
307
-
308
- Napi::FunctionReference cbstream_;
309
- Napi::FunctionReference cbsession_;
310
- Napi::FunctionReference cbtransport_;
311
-
312
- bool loop_running_;
313
- };
314
- }
315
-
316
- #endif