@fails-components/webtransport 0.1.5 → 0.2.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 (70) hide show
  1. package/CMakeLists.txt +42 -111
  2. package/build.js +4 -4
  3. package/dist/lib/dom.d.ts +6 -0
  4. package/dist/lib/dom.d.ts.map +1 -1
  5. package/dist/lib/event-loop.d.ts +8 -3
  6. package/dist/lib/event-loop.d.ts.map +1 -1
  7. package/dist/lib/server.d.ts +3 -2
  8. package/dist/lib/server.d.ts.map +1 -1
  9. package/dist/lib/session.d.ts +78 -18
  10. package/dist/lib/session.d.ts.map +1 -1
  11. package/dist/lib/stream.d.ts +13 -5
  12. package/dist/lib/stream.d.ts.map +1 -1
  13. package/dist/lib/transport.d.ts.map +1 -1
  14. package/dist/lib/types.d.ts +11 -2
  15. package/dist/lib/types.d.ts.map +1 -1
  16. package/dist/lib/webtransport.d.ts +22 -0
  17. package/dist/lib/webtransport.d.ts.map +1 -1
  18. package/dist/test/bidirectional-streams.spec.d.ts.map +1 -1
  19. package/dist/test/datagrams.spec.d.ts.map +1 -1
  20. package/dist/test/fixtures/p-timeout.d.ts +8 -0
  21. package/dist/test/fixtures/p-timeout.d.ts.map +1 -0
  22. package/dist/test/fixtures/read-stream.d.ts.map +1 -1
  23. package/dist/test/unidirectional-streams.spec.d.ts.map +1 -1
  24. package/lib/dom.ts +7 -2
  25. package/lib/event-loop.js +13 -7
  26. package/lib/server.js +1 -1
  27. package/lib/session.js +71 -21
  28. package/lib/stream.js +137 -12
  29. package/lib/transport.js +3 -1
  30. package/lib/types.ts +13 -2
  31. package/lib/webtransport.js +31 -0
  32. package/package.json +5 -4
  33. package/platform/base/strings/utf_ostream_operators.h +5 -0
  34. package/platform/quiche/quic/core/io/socket_win.inc +3 -0
  35. package/platform/quiche_platform_impl/quiche_command_line_flags_impl.h +7 -0
  36. package/platform/quiche_platform_impl/quiche_export_impl.h +3 -9
  37. package/platform/quiche_platform_impl/quiche_server_stats_impl.h +1 -22
  38. package/platform/quiche_platform_impl/quiche_stream_buffer_allocator_impl.h +1 -4
  39. package/platform/quiche_platform_impl/quiche_time_utils_impl.h +1 -13
  40. package/platform/quiche_platform_impl/quiche_udp_socket_platform_impl.h +9 -0
  41. package/readme.md +3 -1
  42. package/src/http3client.cc +13 -29
  43. package/src/http3client.h +2 -6
  44. package/src/http3clientsession.cc +51 -40
  45. package/src/http3clientsession.h +44 -31
  46. package/src/http3clientstream.cc +17 -0
  47. package/src/http3clientstream.h +10 -0
  48. package/src/http3eventloop.cc +81 -61
  49. package/src/http3eventloop.h +10 -7
  50. package/src/http3server.cc +1 -1
  51. package/src/http3serversession.cc +1 -136
  52. package/src/http3serversession.h +7 -77
  53. package/src/http3serverstream.cc +0 -49
  54. package/src/http3serverstream.h +0 -5
  55. package/src/http3wtsessionvisitor.cc +1 -1
  56. package/src/http3wtsessionvisitor.h +24 -37
  57. package/src/http3wtstreamvisitor.cc +35 -8
  58. package/src/http3wtstreamvisitor.h +81 -3
  59. package/test/bidirectional-streams.spec.js +16 -7
  60. package/test/datagrams.spec.js +31 -20
  61. package/test/fixtures/p-timeout.js +33 -0
  62. package/test/fixtures/read-stream.js +4 -1
  63. package/test/unidirectional-streams.spec.js +24 -15
  64. package/platform/net/quiche/common/platform/impl/quiche_flags_impl.h +0 -12
  65. package/platform/poll.h +0 -2
  66. package/platform/quiche/quic/core/io/quic_poll_event_loop.h +0 -8
  67. package/platform/quiche_platform_impl/quic_testvalue_impl.h +0 -19
  68. package/platform/quiche_platform_impl/quic_udp_socket_winsock.cc +0 -732
  69. package/platform/quiche_platform_impl/quiche_time_utils_impl.cc +0 -43
  70. package/platform/quiche_platform_impl/socket_winsock.cc +0 -535
@@ -12,43 +12,54 @@
12
12
 
13
13
  #include <utility>
14
14
 
15
- namespace quic {
16
-
17
- Http3ClientSession::Http3ClientSession(
18
- const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
19
- QuicConnection* connection, const QuicServerId& server_id,
20
- QuicCryptoClientConfig* crypto_config,
21
- QuicClientPushPromiseIndex* push_promise_index, bool drop_response_body)
22
- : Http3ClientSession(config, supported_versions, connection, server_id,
23
- crypto_config, push_promise_index,
24
- drop_response_body,
25
- /*enable_web_transport=*/false) {}
26
-
27
- Http3ClientSession::Http3ClientSession(
28
- const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
29
- QuicConnection* connection, const QuicServerId& server_id,
30
- QuicCryptoClientConfig* crypto_config,
31
- QuicClientPushPromiseIndex* push_promise_index, bool drop_response_body,
32
- bool enable_web_transport)
33
- : QuicSpdyClientSession(config, supported_versions, connection, server_id,
34
- crypto_config, push_promise_index),
35
- drop_response_body_(drop_response_body),
36
- enable_web_transport_(enable_web_transport) {}
37
-
38
- std::unique_ptr<QuicSpdyClientStream>
39
- Http3ClientSession::CreateClientStream() {
40
- return std::make_unique<Http3ClientStream>(
41
- GetNextOutgoingBidirectionalStreamId(), this, BIDIRECTIONAL,
42
- drop_response_body_);
43
- }
44
-
45
- bool Http3ClientSession::ShouldNegotiateWebTransport() {
46
- return enable_web_transport_;
47
- }
48
-
49
- HttpDatagramSupport Http3ClientSession::LocalHttpDatagramSupport() {
50
- return enable_web_transport_ ? HttpDatagramSupport::kDraft04
51
- : HttpDatagramSupport::kNone;
52
- }
53
-
54
- } // namespace quic
15
+ namespace quic
16
+ {
17
+
18
+ Http3ClientSession::Http3ClientSession(
19
+ const QuicConfig &config, const ParsedQuicVersionVector &supported_versions,
20
+ QuicConnection *connection, const QuicServerId &server_id,
21
+ QuicCryptoClientConfig *crypto_config,
22
+ QuicClientPushPromiseIndex *push_promise_index, bool drop_response_body)
23
+ : Http3ClientSession(config, supported_versions, connection, server_id,
24
+ crypto_config, push_promise_index,
25
+ drop_response_body,
26
+ /*enable_web_transport=*/false)
27
+ {
28
+ }
29
+
30
+ Http3ClientSession::Http3ClientSession(
31
+ const QuicConfig &config, const ParsedQuicVersionVector &supported_versions,
32
+ QuicConnection *connection, const QuicServerId &server_id,
33
+ QuicCryptoClientConfig *crypto_config,
34
+ QuicClientPushPromiseIndex *push_promise_index, bool drop_response_body,
35
+ bool enable_web_transport)
36
+ : QuicSpdyClientSession(config, supported_versions, connection, server_id,
37
+ crypto_config, push_promise_index),
38
+ drop_response_body_(drop_response_body),
39
+ enable_web_transport_(enable_web_transport) {}
40
+
41
+ std::unique_ptr<QuicSpdyClientStream>
42
+ Http3ClientSession::CreateClientStream()
43
+ {
44
+ auto stream = std::make_unique<Http3ClientStream>(
45
+ GetNextOutgoingBidirectionalStreamId(), this, BIDIRECTIONAL,
46
+ drop_response_body_);
47
+ stream->set_on_interim_headers(on_interim_headers_);
48
+ return stream;
49
+ }
50
+
51
+ WebTransportHttp3VersionSet Http3ClientSession::LocallySupportedWebTransportVersions()
52
+ const
53
+ {
54
+ return enable_web_transport_
55
+ ? kDefaultSupportedWebTransportVersions
56
+ : WebTransportHttp3VersionSet();
57
+ }
58
+
59
+ HttpDatagramSupport Http3ClientSession::LocalHttpDatagramSupport()
60
+ {
61
+ return enable_web_transport_ ? HttpDatagramSupport::kRfcAndDraft04
62
+ : HttpDatagramSupport::kNone;
63
+ }
64
+
65
+ } // namespace quic
@@ -11,37 +11,50 @@
11
11
  #ifndef HTTP3_CLIENT_SESSION_H
12
12
  #define HTTP3_CLIENT_SESSION_H
13
13
 
14
+ #include <functional>
15
+ #include <utility>
16
+
14
17
  #include "quiche/quic/core/http/quic_spdy_client_session.h"
15
18
  #include "src/http3clientstream.h"
16
19
 
17
- namespace quic {
18
-
19
- class Http3ClientSession : public QuicSpdyClientSession {
20
- public:
21
- Http3ClientSession(const QuicConfig& config,
22
- const ParsedQuicVersionVector& supported_versions,
23
- QuicConnection* connection,
24
- const QuicServerId& server_id,
25
- QuicCryptoClientConfig* crypto_config,
26
- QuicClientPushPromiseIndex* push_promise_index,
27
- bool drop_response_body);
28
- Http3ClientSession(const QuicConfig& config,
29
- const ParsedQuicVersionVector& supported_versions,
30
- QuicConnection* connection,
31
- const QuicServerId& server_id,
32
- QuicCryptoClientConfig* crypto_config,
33
- QuicClientPushPromiseIndex* push_promise_index,
34
- bool drop_response_body, bool enable_web_transport);
35
-
36
- std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override;
37
- bool ShouldNegotiateWebTransport() override;
38
- HttpDatagramSupport LocalHttpDatagramSupport() override;
39
-
40
- private:
41
- const bool drop_response_body_;
42
- const bool enable_web_transport_;
43
- };
44
-
45
- } // namespace quic
46
-
47
- #endif // QUICHE_QUIC_TOOLS_QUIC_SIMPLE_CLIENT_SESSION_H_
20
+ namespace quic
21
+ {
22
+
23
+ class Http3ClientSession : public QuicSpdyClientSession
24
+ {
25
+ public:
26
+ Http3ClientSession(const QuicConfig &config,
27
+ const ParsedQuicVersionVector &supported_versions,
28
+ QuicConnection *connection,
29
+ const QuicServerId &server_id,
30
+ QuicCryptoClientConfig *crypto_config,
31
+ QuicClientPushPromiseIndex *push_promise_index,
32
+ bool drop_response_body);
33
+ Http3ClientSession(const QuicConfig &config,
34
+ const ParsedQuicVersionVector &supported_versions,
35
+ QuicConnection *connection,
36
+ const QuicServerId &server_id,
37
+ QuicCryptoClientConfig *crypto_config,
38
+ QuicClientPushPromiseIndex *push_promise_index,
39
+ bool drop_response_body, bool enable_web_transport);
40
+
41
+ std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override;
42
+ WebTransportHttp3VersionSet LocallySupportedWebTransportVersions()
43
+ const override;
44
+ HttpDatagramSupport LocalHttpDatagramSupport() override;
45
+
46
+ void set_on_interim_headers(
47
+ std::function<void(const spdy::Http2HeaderBlock &)> on_interim_headers)
48
+ {
49
+ on_interim_headers_ = std::move(on_interim_headers);
50
+ }
51
+
52
+ private:
53
+ std::function<void(const spdy::Http2HeaderBlock &)> on_interim_headers_;
54
+ const bool drop_response_body_;
55
+ const bool enable_web_transport_;
56
+ };
57
+
58
+ } // namespace quic
59
+
60
+ #endif // QUICHE_QUIC_TOOLS_QUIC_SIMPLE_CLIENT_SESSION_H_
@@ -9,6 +9,7 @@
9
9
  // found in the LICENSE file.
10
10
 
11
11
  #include "src/http3clientstream.h"
12
+ #include "quiche/common/platform/api/quiche_logging.h"
12
13
 
13
14
  namespace quic {
14
15
 
@@ -32,4 +33,20 @@ void Http3ClientStream::OnBodyAvailable() {
32
33
  }
33
34
  }
34
35
 
36
+ bool Http3ClientStream::ParseAndValidateStatusCode() {
37
+ const size_t num_previous_interim_headers = preliminary_headers().size();
38
+ if (!QuicSpdyClientStream::ParseAndValidateStatusCode()) {
39
+ return false;
40
+ }
41
+ // The base ParseAndValidateStatusCode() may have added a preliminary header.
42
+ if (preliminary_headers().size() > num_previous_interim_headers) {
43
+ QUICHE_DCHECK_EQ(preliminary_headers().size(),
44
+ num_previous_interim_headers + 1);
45
+ if (on_interim_headers_) {
46
+ on_interim_headers_(preliminary_headers().back());
47
+ }
48
+ }
49
+ return true;
50
+ }
51
+
35
52
  } // namespace quic
@@ -23,7 +23,17 @@ class Http3ClientStream : public QuicSpdyClientStream {
23
23
  drop_response_body_(drop_response_body) {}
24
24
  void OnBodyAvailable() override;
25
25
 
26
+ void set_on_interim_headers(
27
+ std::function<void(const spdy::Http2HeaderBlock&)> on_interim_headers) {
28
+ on_interim_headers_ = std::move(on_interim_headers);
29
+ }
30
+
31
+ protected:
32
+ bool ParseAndValidateStatusCode() override;
33
+
34
+
26
35
  private:
36
+ std::function<void(const spdy::Http2HeaderBlock&)> on_interim_headers_;
27
37
  const bool drop_response_body_;
28
38
  };
29
39
 
@@ -17,19 +17,16 @@
17
17
  #include "quiche/common/platform/api/quiche_reference_counted.h"
18
18
  #include "quiche/quic/core/quic_default_clock.h"
19
19
  #include "quiche/quic/bindings/quic_libevent.h"
20
+ #include "quiche/common/platform/api/quiche_command_line_flags.h"
21
+
22
+ #include "absl/log/initialize.h"
23
+ #include "absl/strings/string_view.h"
20
24
 
21
25
  using namespace Napi;
22
26
 
23
27
  namespace quic
24
28
  {
25
29
 
26
- #ifdef WIN32
27
-
28
- bool initSockets();
29
- bool destroySockets();
30
-
31
- #endif
32
-
33
30
  // hack since the header is faulty
34
31
  QUICHE_NO_EXPORT QuicEventLoopFactory *GetDefaultEventLoop();
35
32
 
@@ -40,9 +37,6 @@ namespace quic
40
37
  Http3EventLoop::~Http3EventLoop()
41
38
  {
42
39
  printf("Destructor eventloop\n");
43
- #ifdef WIN32
44
- destroySockets();
45
- #endif
46
40
  }
47
41
 
48
42
  void Http3EventLoop::Init(Napi::Env env, Napi::Object exports)
@@ -61,7 +55,6 @@ namespace quic
61
55
  Http3ClientJS::InitExports(env, exports);
62
56
  Http3WTSessionJS::InitExports(env, exports, constr);
63
57
  Http3WTStreamJS::InitExports(env, exports, constr);
64
- Napi::ObjectReference *exportref = new Napi::ObjectReference();
65
58
 
66
59
  env.SetInstanceData<Http3Constructors>(constr);
67
60
  }
@@ -116,7 +109,7 @@ namespace quic
116
109
 
117
110
  void Http3EventLoop::informAboutStream(bool incom, bool bidir, Http3WTSession *sessionobj, Http3WTStream *stream)
118
111
  {
119
- struct Http3ProgressReport report;
112
+ Http3ProgressReport report;
120
113
  if (incom)
121
114
  {
122
115
  if (bidir)
@@ -147,7 +140,7 @@ namespace quic
147
140
 
148
141
  void Http3EventLoop::informStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task)
149
142
  {
150
- struct Http3ProgressReport report;
143
+ Http3ProgressReport report;
151
144
  report.type = Http3ProgressReport::StreamRecvSignal;
152
145
  report.streamobj = streamobj;
153
146
  report.wtscode = error_code;
@@ -156,20 +149,21 @@ namespace quic
156
149
  progress_->Send(&report, 1);
157
150
  }
158
151
 
159
- void Http3EventLoop::informAboutStreamRead(Http3WTStream *streamobj, std::string *data, bool fin)
152
+ void Http3EventLoop::informAboutStreamRead(Http3WTStream *streamobj, uint32_t buffergrow, bool fin, bool success)
160
153
  {
161
- struct Http3ProgressReport report;
154
+ Http3ProgressReport report;
162
155
  report.type = Http3ProgressReport::StreamRead;
163
156
  report.streamobj = streamobj;
164
- report.para = data;
165
157
  report.fin = fin;
158
+ report.buffergrow = buffergrow;
159
+ report.success = success;
166
160
  if (progress_)
167
161
  progress_->Send(&report, 1);
168
162
  }
169
163
 
170
164
  void Http3EventLoop::informAboutStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success)
171
165
  {
172
- struct Http3ProgressReport report;
166
+ Http3ProgressReport report;
173
167
  report.type = Http3ProgressReport::StreamWrite;
174
168
  report.streamobj = streamobj;
175
169
  report.bufferhandle = bufferhandle;
@@ -180,7 +174,7 @@ namespace quic
180
174
 
181
175
  void Http3EventLoop::informAboutStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task)
182
176
  {
183
- struct Http3ProgressReport report;
177
+ Http3ProgressReport report;
184
178
  report.type = Http3ProgressReport::StreamNetworkFinish;
185
179
  report.streamobj = streamobj;
186
180
  report.nettask = task;
@@ -190,7 +184,7 @@ namespace quic
190
184
 
191
185
  void Http3EventLoop::informAboutStreamReset(Http3WTStream *streamobj)
192
186
  {
193
- struct Http3ProgressReport report;
187
+ Http3ProgressReport report;
194
188
  report.type = Http3ProgressReport::StreamReset;
195
189
  report.streamobj = streamobj;
196
190
  if (progress_)
@@ -199,7 +193,7 @@ namespace quic
199
193
 
200
194
  void Http3EventLoop::informDatagramReceived(Http3WTSession *sessionobj, absl::string_view datagram)
201
195
  {
202
- struct Http3ProgressReport report;
196
+ Http3ProgressReport report;
203
197
  report.type = Http3ProgressReport::DatagramReceived;
204
198
  report.sessionobj = sessionobj;
205
199
  report.para = new std::string(datagram);
@@ -207,28 +201,28 @@ namespace quic
207
201
  progress_->Send(&report, 1);
208
202
  }
209
203
 
210
- void Http3EventLoop::informDatagramSend(Http3WTSession *sessionobj)
204
+ void Http3EventLoop::informDatagramSend(Http3WTSession *sessionobj, Napi::ObjectReference *bufferhandle)
211
205
  {
212
- struct Http3ProgressReport report;
206
+ Http3ProgressReport report;
213
207
  report.type = Http3ProgressReport::DatagramSend;
214
208
  report.sessionobj = sessionobj;
209
+ report.bufferhandle = bufferhandle;
215
210
  if (progress_)
216
211
  progress_->Send(&report, 1);
217
212
  }
218
213
 
219
- void Http3EventLoop::informDatagramBufferFree(Napi::ObjectReference *bufferhandle)
214
+ void Http3EventLoop::informGoawayReceived(Http3WTSession *sessionobj)
220
215
  {
221
- struct Http3ProgressReport report;
222
- report.type = Http3ProgressReport::DatagramBufferFree;
223
- report.bufferhandle = bufferhandle;
224
-
216
+ Http3ProgressReport report;
217
+ report.type = Http3ProgressReport::GoawayReceived;
218
+ report.sessionobj = sessionobj;
225
219
  if (progress_)
226
220
  progress_->Send(&report, 1);
227
221
  }
228
222
 
229
223
  void Http3EventLoop::informUnref(LifetimeHelper *obj)
230
224
  {
231
- struct Http3ProgressReport report;
225
+ Http3ProgressReport report;
232
226
  report.type = Http3ProgressReport::Unref;
233
227
  report.obj = obj;
234
228
 
@@ -238,7 +232,7 @@ namespace quic
238
232
 
239
233
  void Http3EventLoop::informAboutClientConnected(Http3Client *client, bool success)
240
234
  {
241
- struct Http3ProgressReport report;
235
+ Http3ProgressReport report;
242
236
  report.type = Http3ProgressReport::ClientConnected;
243
237
  report.clientobj = client;
244
238
  report.success = success;
@@ -248,7 +242,7 @@ namespace quic
248
242
 
249
243
  void Http3EventLoop::informClientWebtransportSupport(Http3Client *client)
250
244
  {
251
- struct Http3ProgressReport report;
245
+ Http3ProgressReport report;
252
246
  report.type = Http3ProgressReport::ClientWebTransportSupport;
253
247
  report.clientobj = client;
254
248
  if (progress_)
@@ -257,7 +251,7 @@ namespace quic
257
251
 
258
252
  void Http3EventLoop::informAboutNewSessionRequest(Http3Server *server, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr promise)
259
253
  {
260
- struct Http3ProgressReport report;
254
+ Http3ProgressReport report;
261
255
  report.type = Http3ProgressReport::NewSessionRequest;
262
256
  report.webtsession = session;
263
257
  report.serverobj = server;
@@ -269,7 +263,7 @@ namespace quic
269
263
 
270
264
  void Http3EventLoop::informAboutNewSession(Http3Server *server, Http3WTSession *session, absl::string_view path, Napi::Reference<Napi::Value> *header)
271
265
  {
272
- struct Http3ProgressReport report;
266
+ Http3ProgressReport report;
273
267
  report.type = Http3ProgressReport::NewSession;
274
268
  report.serverobj = server;
275
269
  report.session = session;
@@ -281,7 +275,7 @@ namespace quic
281
275
 
282
276
  void Http3EventLoop::informNewClientSession(Http3Client *client, Http3WTSession *session)
283
277
  {
284
- struct Http3ProgressReport report;
278
+ Http3ProgressReport report;
285
279
  report.type = Http3ProgressReport::NewClientSession;
286
280
  report.clientobj = client;
287
281
  report.session = session;
@@ -292,7 +286,7 @@ namespace quic
292
286
  void Http3EventLoop::informSessionClosed(Http3WTSession *sessionobj, WebTransportSessionError error_code,
293
287
  absl::string_view error_message)
294
288
  {
295
- struct Http3ProgressReport report;
289
+ Http3ProgressReport report;
296
290
  report.type = Http3ProgressReport::SessionClosed;
297
291
  report.sessionobj = sessionobj;
298
292
  report.para = new std::string(error_message);
@@ -303,7 +297,7 @@ namespace quic
303
297
 
304
298
  void Http3EventLoop::informSessionReady(Http3WTSession *sessionobj)
305
299
  {
306
- struct Http3ProgressReport report;
300
+ Http3ProgressReport report;
307
301
  report.type = Http3ProgressReport::SessionReady;
308
302
  report.sessionobj = sessionobj;
309
303
  if (progress_)
@@ -312,7 +306,7 @@ namespace quic
312
306
 
313
307
  void Http3EventLoop::informServerStatus(Http3Server *serverobj, NetworkStatus status, ServerStatusDetails *details)
314
308
  {
315
- struct Http3ProgressReport report;
309
+ Http3ProgressReport report;
316
310
  report.type = Http3ProgressReport::ServerStatus;
317
311
  report.serverobj = serverobj;
318
312
  report.status = status;
@@ -370,6 +364,13 @@ namespace quic
370
364
  Http3WTStreamJS *strjs = Napi::ObjectWrap<Http3WTStreamJS>::Unwrap(strobj);
371
365
  strjs->setObj(stream);
372
366
  if (!stream->gone()) strjs->Ref();
367
+
368
+ if (incom || bidi) { // we have a read stream
369
+ // same size of a pipe in chromium, but the WT Pipe thre is 256 kbyte, the default 64 kbyte
370
+ Napi::ArrayBuffer arraybuf = Napi::ArrayBuffer::New(qw_->Env(), 64 * 1024);
371
+ strobj.Set("readbuffer", arraybuf); // so the lifecycle is bound to the JS Obj!
372
+ stream->setReadBuffer(arraybuf.Data(), arraybuf.ByteLength());
373
+ }
373
374
  stream->setJS(strjs);
374
375
 
375
376
  Napi::Object objVal = sessionobj->getJS()->Value();
@@ -425,19 +426,12 @@ namespace quic
425
426
  cbstream_.Call({retObj});
426
427
  }
427
428
 
428
- void Http3EventLoop::processStreamRead(Http3WTStream *streamobj, std::string *data, bool fin)
429
+ void Http3EventLoop::processStreamRead(Http3WTStream *streamobj, size_t buffergrow, bool fin, bool success)
429
430
  {
430
431
  if (!checkQw())
431
432
  return;
432
433
  HandleScope scope(qw_->Env());
433
434
 
434
- Napi::Object dataVal =
435
- Napi::Uint8Array::New(qw_->Env(),
436
- data->length(),
437
- Napi::ArrayBuffer::New(qw_->Env(), &(*data)[0], data->length(),
438
- freeData, data),
439
- 0);
440
-
441
435
  auto stream = streamobj->getJS();
442
436
  if (!stream)
443
437
  return;
@@ -446,8 +440,9 @@ namespace quic
446
440
  Napi::Object retObj = Napi::Object::New(qw_->Env());
447
441
  retObj.Set("purpose", "StreamRead");
448
442
  retObj.Set("fin", fin);
449
- retObj.Set("data", dataVal);
443
+ retObj.Set("buffergrow", buffergrow);
450
444
  retObj.Set("object", objVal);
445
+ retObj.Set("success", success);
451
446
 
452
447
  cbstream_.Call({retObj});
453
448
  }
@@ -534,12 +529,6 @@ namespace quic
534
529
  cbstream_.Call({retObj});
535
530
  }
536
531
 
537
- void Http3EventLoop::processDatagramBufferFree(Napi::ObjectReference *bufferhandle)
538
- {
539
- bufferhandle->Unref(); // release the outgoing buffer
540
- delete bufferhandle; // free the handle object
541
- }
542
-
543
532
  void Http3EventLoop::processDatagramReceived(Http3WTSession *sessionobj, std::string *datagram)
544
533
  {
545
534
  if (!checkQw())
@@ -565,8 +554,10 @@ namespace quic
565
554
  cbsession_.Call({retObj});
566
555
  }
567
556
 
568
- void Http3EventLoop::processDatagramSend(Http3WTSession *sessionobj)
557
+ void Http3EventLoop::processDatagramSend(Http3WTSession *sessionobj, Napi::ObjectReference *bufferhandle)
569
558
  {
559
+ bufferhandle->Unref(); // release the outgoing buffer
560
+ delete bufferhandle; // free the handle object
570
561
  if (!checkQw())
571
562
  return;
572
563
  HandleScope scope(qw_->Env());
@@ -582,6 +573,24 @@ namespace quic
582
573
  cbsession_.Call({retObj});
583
574
  }
584
575
 
576
+ void Http3EventLoop::processGoawayReceived(Http3WTSession *sessionobj)
577
+ {
578
+ if (!checkQw())
579
+ return;
580
+ HandleScope scope(qw_->Env());
581
+
582
+
583
+ auto session = sessionobj->getJS();
584
+ if (!session)
585
+ return;
586
+ Napi::Object objVal = session->Value();
587
+
588
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
589
+ retObj.Set("purpose", "GoawayReceived");
590
+ retObj.Set("object", objVal);
591
+ cbsession_.Call({retObj});
592
+ }
593
+
585
594
  void Http3EventLoop::processNewSessionRequest(Http3Server *serverobj, WebTransportSession *session, spdy::Http2HeaderBlock *reqheadcopy, WebTransportRespPromisePtr *promise)
586
595
  {
587
596
  if (!checkQw())
@@ -840,8 +849,7 @@ namespace quic
840
849
  break;
841
850
  case Http3ProgressReport::StreamRead:
842
851
  {
843
- processStreamRead(cur.streamobj, cur.para, cur.fin);
844
- cur.para = nullptr; // take ownership of the data
852
+ processStreamRead(cur.streamobj, cur.buffergrow, cur.fin, cur.success);
845
853
  }
846
854
  break;
847
855
  case Http3ProgressReport::StreamWrite:
@@ -867,12 +875,12 @@ namespace quic
867
875
  break;
868
876
  case Http3ProgressReport::DatagramSend:
869
877
  {
870
- processDatagramSend(cur.sessionobj);
878
+ processDatagramSend(cur.sessionobj, cur.bufferhandle);
871
879
  }
872
880
  break;
873
- case Http3ProgressReport::DatagramBufferFree:
881
+ case Http3ProgressReport::GoawayReceived:
874
882
  {
875
- processDatagramBufferFree(cur.bufferhandle);
883
+ processGoawayReceived(cur.sessionobj);
876
884
  }
877
885
  break;
878
886
  case Http3ProgressReport::Unref:
@@ -891,10 +899,8 @@ namespace quic
891
899
  progress_(nullptr),
892
900
  quic_event_loop_(GetDefaultEventLoop()->Create(QuicDefaultClock::Get()))
893
901
  {
894
- #ifdef WIN32
895
- initSockets();
896
- #endif
897
-
902
+ std::vector<std::string> quiche_cmd_line;
903
+ quiche_cmd_line.push_back(std::string("webtransport.node"));
898
904
  if (!info[0].IsUndefined() /*|| info[1].IsFunction()*/)
899
905
  {
900
906
  Napi::Object lobj = info[0].ToObject();
@@ -945,12 +951,26 @@ namespace quic
945
951
  Napi::Error::New(Env(), "No session callback").ThrowAsJavaScriptException();
946
952
  return;
947
953
  }
954
+ quiche_cmd_line.push_back(std::string("-v"));
955
+ if (lobj.Has("quicheLogVerbose") && lobj.Get("quicheLogVerbose").IsFunction())
956
+ {
957
+ Napi::Value verboseValue = (lobj).Get("quicheLogVerbose");
958
+ quiche_cmd_line.push_back(verboseValue.ToString().Utf8Value());
959
+ } else {
960
+ quiche_cmd_line.push_back(std::string("-1"));
961
+ }
948
962
  }
949
963
  else
950
964
  {
951
965
  Napi::Error::New(Env(), "Callback not passed to Http3EventLoop internal").ThrowAsJavaScriptException();
952
966
  return;
953
967
  }
968
+ std::vector<const char*> quiche_cmd_line_char;
969
+ for (auto cur= quiche_cmd_line.begin(); cur != quiche_cmd_line.end(); cur++) {
970
+ quiche_cmd_line_char.push_back((*cur).c_str());
971
+ }
972
+
973
+ quiche::QuicheParseCommandLineFlags("No use instruction.", quiche_cmd_line.size(), &(*quiche_cmd_line_char.begin()));
954
974
  }
955
975
 
956
976
  void Http3EventLoop::startEventLoop(const Napi::CallbackInfo &info)
@@ -93,7 +93,7 @@ namespace quic
93
93
  StreamNetworkFinish,
94
94
  DatagramReceived,
95
95
  DatagramSend,
96
- DatagramBufferFree,
96
+ GoawayReceived,
97
97
  Unref
98
98
  } type;
99
99
  union
@@ -110,6 +110,7 @@ namespace quic
110
110
  NetworkTask nettask;
111
111
  NetworkStatus status;
112
112
  WebTransportSession *webtsession;
113
+ uint32_t buffergrow;
113
114
  };
114
115
  union
115
116
  {
@@ -210,14 +211,15 @@ namespace quic
210
211
 
211
212
  void informAboutStream(bool incom, bool bidir, Http3WTSession *sessionobj, Http3WTStream *stream);
212
213
  void informStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task);
213
- void informAboutStreamRead(Http3WTStream *streamobj, std::string *data, bool fin);
214
+ void informAboutStreamRead(Http3WTStream *streamobj, uint32_t buffergrow, bool fin, bool success);
214
215
  void informAboutStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success);
215
216
  void informAboutStreamReset(Http3WTStream *streamobj);
216
217
  void informAboutStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task);
217
218
 
218
219
  void informDatagramReceived(Http3WTSession *sessionobj, absl::string_view datagram);
219
- void informDatagramBufferFree(Napi::ObjectReference *bufferhandle);
220
- void informDatagramSend(Http3WTSession *sessionobj);
220
+ void informDatagramSend(Http3WTSession *sessionobj, Napi::ObjectReference *bufferhandle);
221
+
222
+ void informGoawayReceived(Http3WTSession *sessionobj);
221
223
 
222
224
  void informUnref(LifetimeHelper *obj);
223
225
 
@@ -276,14 +278,15 @@ namespace quic
276
278
 
277
279
  void processStream(bool incom, bool bidi, Http3WTSession *sessionobj, Http3WTStream *stream);
278
280
  void processStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task);
279
- void processStreamRead(Http3WTStream *streamobj, std::string *data, bool fin);
281
+ void processStreamRead(Http3WTStream *streamobj, size_t buffergrow, bool fin, bool success);
280
282
  void processStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success);
281
283
  void processStreamReset(Http3WTStream *streamobj);
282
284
  void processStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task);
283
285
 
284
286
  void processDatagramReceived(Http3WTSession *sessionobj, std::string *datagram);
285
- void processDatagramSend(Http3WTSession *sessionobj);
286
- void processDatagramBufferFree(Napi::ObjectReference *bufferhandle);
287
+ void processDatagramSend(Http3WTSession *sessionobj, Napi::ObjectReference *bufferhandle);
288
+
289
+ void processGoawayReceived(Http3WTSession *sessionobj);
287
290
 
288
291
  bool shutDownEventLoopInt();
289
292
 
@@ -69,7 +69,7 @@ namespace quic
69
69
 
70
70
  if (!socket_api.Bind(fd_, address))
71
71
  {
72
- QUIC_LOG(ERROR) << "Bind failed: " << strerror(errno) << "\n";
72
+ QUIC_LOG(ERROR) << "Bind failed: " << strerror(errno) << " for " << address.ToString() << "\n";
73
73
  return false;
74
74
  }
75
75
  QUIC_LOG(INFO) << "Listening on " << address.ToString() << "\n";