@fails-components/webtransport 0.0.7 → 0.0.9

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.
package/CMakeLists.txt CHANGED
@@ -740,8 +740,6 @@ third_party/quiche/quiche/quic/core/quic_idle_network_detector.h
740
740
  third_party/quiche/quiche/quic/core/quic_interval.h
741
741
  third_party/quiche/quiche/quic/core/quic_interval_deque.h
742
742
  third_party/quiche/quiche/quic/core/quic_interval_set.h
743
- third_party/quiche/quiche/quic/core/quic_legacy_version_encapsulator.cc
744
- third_party/quiche/quiche/quic/core/quic_legacy_version_encapsulator.h
745
743
  third_party/quiche/quiche/quic/core/quic_lru_cache.h
746
744
  third_party/quiche/quiche/quic/core/quic_mtu_discovery.cc
747
745
  third_party/quiche/quiche/quic/core/quic_mtu_discovery.h
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fails-components/webtransport",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A component to add webtransport support (server and client) to node.js using libquiche",
5
5
  "main": "src/webtransport.js",
6
6
  "module": "src/webtransport.js",
@@ -303,12 +303,13 @@ namespace quic
303
303
 
304
304
  void Http3EventLoop::processClientConnected(Http3Client *clientobj, bool success)
305
305
  {
306
- HandleScope scope(qw->Env());
306
+ if (!checkQw()) return;
307
+ HandleScope scope(qw_->Env());
307
308
  auto client = clientobj->getJS();
308
309
 
309
310
  Napi::Object objVal = client->Value();
310
311
 
311
- Napi::Object retObj = Napi::Object::New(qw->Env());
312
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
312
313
  retObj.Set("purpose", "ClientConnected");
313
314
  retObj.Set("success", success);
314
315
  retObj.Set("object", objVal);
@@ -318,12 +319,13 @@ namespace quic
318
319
 
319
320
  void Http3EventLoop::processClientWebtransportSupport(Http3Client *clientobj)
320
321
  {
321
- HandleScope scope(qw->Env());
322
+ if (!checkQw()) return;
323
+ HandleScope scope(qw_->Env());
322
324
 
323
325
  auto client = clientobj->getJS();
324
326
  Napi::Object objVal = client->Value();
325
327
 
326
- Napi::Object retObj = Napi::Object::New(qw->Env());
328
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
327
329
  retObj.Set("purpose", "ClientWebtransportSupport");
328
330
  retObj.Set("object", objVal);
329
331
 
@@ -332,9 +334,10 @@ namespace quic
332
334
 
333
335
  void Http3EventLoop::processStream(bool incom, bool bidi, Http3WTSession *sessionobj, Http3WTStream *stream)
334
336
  {
335
- HandleScope scope(qw->Env());
337
+ if (!checkQw()) return;
338
+ HandleScope scope(qw_->Env());
336
339
 
337
- Http3Constructors *constr = qw->Env().GetInstanceData<Http3Constructors>();
340
+ Http3Constructors *constr = qw_->Env().GetInstanceData<Http3Constructors>();
338
341
  Napi::Object strobj = constr->stream.New({});
339
342
  Http3WTStreamJS *strjs = Napi::ObjectWrap<Http3WTStreamJS>::Unwrap(strobj);
340
343
  strjs->setObj(stream);
@@ -343,7 +346,7 @@ namespace quic
343
346
 
344
347
  Napi::Object objVal = sessionobj->getJS()->Value();
345
348
 
346
- Napi::Object retObj = Napi::Object::New(qw->Env());
349
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
347
350
  retObj.Set("purpose", "Http3WTStreamVisitor");
348
351
  retObj.Set("stream", strobj);
349
352
  retObj.Set("incoming", incom);
@@ -355,7 +358,8 @@ namespace quic
355
358
 
356
359
  void Http3EventLoop::processStreamRecvSignal(Http3WTStream *streamobj, WebTransportStreamError error_code, NetworkTask task)
357
360
  {
358
- HandleScope scope(qw->Env());
361
+ if (!checkQw()) return;
362
+ HandleScope scope(qw_->Env());
359
363
  auto stream = streamobj->getJS();
360
364
  if (!stream)
361
365
  return;
@@ -383,7 +387,7 @@ namespace quic
383
387
  return;
384
388
  };
385
389
 
386
- Napi::Object retObj = Napi::Object::New(qw->Env());
390
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
387
391
  retObj.Set("purpose", "StreamRecvSignal");
388
392
  retObj.Set("code", error_code);
389
393
  retObj.Set("object", objVal);
@@ -394,12 +398,13 @@ namespace quic
394
398
 
395
399
  void Http3EventLoop::processStreamRead(Http3WTStream *streamobj, std::string *data, bool fin)
396
400
  {
397
- HandleScope scope(qw->Env());
401
+ if (!checkQw()) return;
402
+ HandleScope scope(qw_->Env());
398
403
 
399
404
  Napi::Object dataVal =
400
- Napi::Uint8Array::New(qw->Env(),
405
+ Napi::Uint8Array::New(qw_->Env(),
401
406
  data->length(),
402
- Napi::ArrayBuffer::New(qw->Env(), &(*data)[0], data->length(),
407
+ Napi::ArrayBuffer::New(qw_->Env(), &(*data)[0], data->length(),
403
408
  freeData, data),
404
409
  0);
405
410
 
@@ -408,7 +413,7 @@ namespace quic
408
413
  return;
409
414
  Napi::Object objVal = stream->Value();
410
415
 
411
- Napi::Object retObj = Napi::Object::New(qw->Env());
416
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
412
417
  retObj.Set("purpose", "StreamRead");
413
418
  retObj.Set("fin", fin);
414
419
  retObj.Set("data", dataVal);
@@ -419,7 +424,8 @@ namespace quic
419
424
 
420
425
  void Http3EventLoop::processStreamWrite(Http3WTStream *streamobj, Napi::ObjectReference *bufferhandle, bool success)
421
426
  {
422
- HandleScope scope(qw->Env());
427
+ if (!checkQw()) return;
428
+ HandleScope scope(qw_->Env());
423
429
 
424
430
  auto stream = streamobj->getJS();
425
431
  if (!stream)
@@ -429,7 +435,7 @@ namespace quic
429
435
  bufferhandle->Unref(); // release the outgoing buffer
430
436
  delete bufferhandle; // free the handle object
431
437
 
432
- Napi::Object retObj = Napi::Object::New(qw->Env());
438
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
433
439
  retObj.Set("purpose", "StreamWrite");
434
440
  retObj.Set("success", success);
435
441
  retObj.Set("object", objVal);
@@ -439,7 +445,8 @@ namespace quic
439
445
 
440
446
  void Http3EventLoop::processStreamReset(Http3WTStream *streamobj)
441
447
  {
442
- HandleScope scope(qw->Env());
448
+ if (!checkQw()) return;
449
+ HandleScope scope(qw_->Env());
443
450
 
444
451
  auto stream = streamobj->getJS();
445
452
  if (!stream)
@@ -447,7 +454,7 @@ namespace quic
447
454
 
448
455
  Napi::Object objVal = stream->Value();
449
456
 
450
- Napi::Object retObj = Napi::Object::New(qw->Env());
457
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
451
458
  retObj.Set("purpose", "StreamReset");
452
459
  retObj.Set("object", objVal);
453
460
 
@@ -456,7 +463,8 @@ namespace quic
456
463
 
457
464
  void Http3EventLoop::processStreamNetworkFinish(Http3WTStream *streamobj, NetworkTask task)
458
465
  {
459
- HandleScope scope(qw->Env());
466
+ if (!checkQw()) return;
467
+ HandleScope scope(qw_->Env());
460
468
 
461
469
  auto stream = streamobj->getJS();
462
470
  if (!stream)
@@ -485,7 +493,7 @@ namespace quic
485
493
  return;
486
494
  };
487
495
 
488
- Napi::Object retObj = Napi::Object::New(qw->Env());
496
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
489
497
  retObj.Set("purpose", "StreamNetworkFinish");
490
498
  retObj.Set("object", objVal);
491
499
  retObj.Set("nettask", nettaskstr);
@@ -501,11 +509,12 @@ namespace quic
501
509
 
502
510
  void Http3EventLoop::processDatagramReceived(Http3WTSession *sessionobj, std::string *datagram)
503
511
  {
504
- HandleScope scope(qw->Env());
512
+ if (!checkQw()) return;
513
+ HandleScope scope(qw_->Env());
505
514
  Napi::Object datagramVal =
506
- Napi::Uint8Array::New(qw->Env(),
515
+ Napi::Uint8Array::New(qw_->Env(),
507
516
  datagram->length(),
508
- Napi::ArrayBuffer::New(qw->Env(), &(*datagram)[0], datagram->length(),
517
+ Napi::ArrayBuffer::New(qw_->Env(), &(*datagram)[0], datagram->length(),
509
518
  freeData, datagram),
510
519
  0);
511
520
 
@@ -514,7 +523,7 @@ namespace quic
514
523
  return;
515
524
  Napi::Object objVal = session->Value();
516
525
 
517
- Napi::Object retObj = Napi::Object::New(qw->Env());
526
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
518
527
  retObj.Set("purpose", "DatagramReceived");
519
528
  retObj.Set("datagram", datagramVal);
520
529
  retObj.Set("object", objVal);
@@ -524,13 +533,14 @@ namespace quic
524
533
 
525
534
  void Http3EventLoop::processDatagramSend(Http3WTSession *sessionobj)
526
535
  {
527
- HandleScope scope(qw->Env());
536
+ if (!checkQw()) return;
537
+ HandleScope scope(qw_->Env());
528
538
  auto session = sessionobj->getJS();
529
539
  if (!session)
530
540
  return;
531
541
  Napi::Object objVal = session->Value();
532
542
 
533
- Napi::Object retObj = Napi::Object::New(qw->Env());
543
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
534
544
  retObj.Set("purpose", "DatagramSend");
535
545
  retObj.Set("object", objVal);
536
546
 
@@ -539,9 +549,10 @@ namespace quic
539
549
 
540
550
  void Http3EventLoop::processNewSession(Http3Server *serverobj, Http3WTSession *session, const std::string &path)
541
551
  {
542
- HandleScope scope(qw->Env());
552
+ if (!checkQw()) return;
553
+ HandleScope scope(qw_->Env());
543
554
 
544
- Http3Constructors *constr = qw->Env().GetInstanceData<Http3Constructors>();
555
+ Http3Constructors *constr = qw_->Env().GetInstanceData<Http3Constructors>();
545
556
  Napi::Object sessionobj = constr->session.New({});
546
557
  Http3WTSessionJS *sessionjs = Napi::ObjectWrap<Http3WTSessionJS>::Unwrap(sessionobj);
547
558
  sessionjs->setObj(session);
@@ -550,7 +561,7 @@ namespace quic
550
561
 
551
562
  Napi::Object objVal = serverobj->getJS()->Value();
552
563
 
553
- Napi::Object retObj = Napi::Object::New(qw->Env());
564
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
554
565
  retObj.Set("purpose", "Http3WTSessionVisitor");
555
566
  retObj.Set("session", sessionobj);
556
567
  retObj.Set("path", path);
@@ -561,13 +572,14 @@ namespace quic
561
572
 
562
573
  void Http3EventLoop::processNewClientSession(Http3Client *clientobj, Http3WTSession *session)
563
574
  {
564
- HandleScope scope(qw->Env());
575
+ if (!checkQw()) return;
576
+ HandleScope scope(qw_->Env());
565
577
 
566
- Napi::Object retObj = Napi::Object::New(qw->Env());
578
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
567
579
  retObj.Set("purpose", "Http3WTSessionVisitor");
568
580
  if (session != nullptr)
569
581
  {
570
- Http3Constructors *constr = qw->Env().GetInstanceData<Http3Constructors>();
582
+ Http3Constructors *constr = qw_->Env().GetInstanceData<Http3Constructors>();
571
583
  Napi::Object sessionobj = constr->session.New({});
572
584
  Http3WTSessionJS *sessionjs = Napi::ObjectWrap<Http3WTSessionJS>::Unwrap(sessionobj);
573
585
  sessionjs->setObj(session);
@@ -584,13 +596,14 @@ namespace quic
584
596
 
585
597
  void Http3EventLoop::processSessionReady(Http3WTSession *sessionobj)
586
598
  {
587
- HandleScope scope(qw->Env());
599
+ if (!checkQw()) return;
600
+ HandleScope scope(qw_->Env());
588
601
  auto session = sessionobj->getJS();
589
602
  if (!session)
590
603
  return;
591
604
  Napi::Object objVal = session->Value();
592
605
 
593
- Napi::Object retObj = Napi::Object::New(qw->Env());
606
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
594
607
  retObj.Set("purpose", "SessionReady");
595
608
  retObj.Set("object", objVal);
596
609
 
@@ -599,7 +612,8 @@ namespace quic
599
612
 
600
613
  void Http3EventLoop::processSessionClose(Http3WTSession *sessionobj, uint32_t errorcode, const std::string &error)
601
614
  {
602
- HandleScope scope(qw->Env());
615
+ if (!checkQw()) return;
616
+ HandleScope scope(qw_->Env());
603
617
 
604
618
  auto session = sessionobj->getJS();
605
619
  if (!session)
@@ -607,7 +621,7 @@ namespace quic
607
621
 
608
622
  Napi::Object objVal = session->Value();
609
623
 
610
- Napi::Object retObj = Napi::Object::New(qw->Env());
624
+ Napi::Object retObj = Napi::Object::New(qw_->Env());
611
625
  retObj.Set("purpose", "SessionClose");
612
626
  retObj.Set("error", error);
613
627
  retObj.Set("errorcode", errorcode);
@@ -749,11 +763,12 @@ namespace quic
749
763
  if (lobj.Has("eventloopCallback") && (lobj).Get("eventloopCallback").IsFunction())
750
764
  {
751
765
  Napi::Function cbeventloop = lobj.Get("eventloopCallback").As<Napi::Function>();
752
- qw = std::make_unique<QueueWorker>(this, cbeventloop);
766
+ qw_ = new QueueWorker(this, cbeventloop);
753
767
  }
754
768
  else
755
769
  {
756
770
  Napi::Error::New(Env(), "No eventloop callback").ThrowAsJavaScriptException();
771
+ qw_ = nullptr;
757
772
  return;
758
773
  }
759
774
 
@@ -799,7 +814,8 @@ namespace quic
799
814
  // got the object we can now start the server
800
815
  Ref(); // do not garbage collect
801
816
  // epoll_server_.set_timeout_in_us(-1); // negative values would mean wait forever
802
- qw->Queue(); // from asyncprogressqueue worker
817
+ if (!checkQw()) return;
818
+ qw_->Queue(); // from asyncprogressqueue worker
803
819
  }
804
820
 
805
821
  void Http3EventLoop::shutDownEventLoop(const Napi::CallbackInfo &info)
@@ -120,6 +120,11 @@ namespace quic
120
120
  {
121
121
  }
122
122
 
123
+ ~QueueWorker()
124
+ {
125
+ eventloop_->removeQw();
126
+ }
127
+
123
128
  void Execute(const AsyncProgressQueueWorker::ExecutionProgress &progress)
124
129
  {
125
130
  eventloop_->Execute(progress);
@@ -193,7 +198,19 @@ namespace quic
193
198
  void shutDownEventLoop(const Napi::CallbackInfo &info);
194
199
 
195
200
  private:
196
- std::unique_ptr<QueueWorker> qw;
201
+ QueueWorker *qw_;
202
+
203
+ bool checkQw() {
204
+ if (!qw_) {
205
+ Napi::Error::New(Env(), "Queueworker gone").ThrowAsJavaScriptException();
206
+ return false;
207
+ }
208
+ return true;
209
+ }
210
+
211
+ void removeQw() {
212
+ qw_ = nullptr;
213
+ }
197
214
 
198
215
  static Napi::Value New(const Napi::CallbackInfo &info);
199
216
 
@@ -222,7 +222,7 @@ namespace quic
222
222
  void closeInt(int code, std::string &reason)
223
223
  {
224
224
  std::function<void()> task = [this, code, reason]()
225
- { session_->CloseSession(code, reason); };
225
+ { if (session_) session_->CloseSession(code, reason); };
226
226
  eventloop_->Schedule(task);
227
227
  }
228
228
 
@@ -72,17 +72,14 @@ namespace quic
72
72
  return; // back pressure folks!
73
73
  // first figure out if we have readable data
74
74
  size_t readable = stream_->ReadableBytes();
75
- if (readable > 0)
76
- {
77
- // ok create a string obj to hold the data
78
- std::string *data = new std::string();
79
- data->resize(readable);
80
- WebTransportStream::ReadResult result = stream_->Read(&(*data)[0], readable);
81
- data->resize(result.bytes_read);
82
- QUIC_DVLOG(1) << "Attempted reading on WebTransport bidirectional stream "
83
- << ", bytes read: " << result.bytes_read;
84
- eventloop_->informAboutStreamRead(this, data, result.fin);
85
- }
75
+ // ok create a string obj to hold the data
76
+ std::string *data = new std::string();
77
+ data->resize(readable);
78
+ WebTransportStream::ReadResult result = stream_->Read(&(*data)[0], readable);
79
+ data->resize(result.bytes_read);
80
+ QUIC_DVLOG(1) << "Attempted reading on WebTransport bidirectional stream "
81
+ << ", bytes read: " << result.bytes_read;
82
+ eventloop_->informAboutStreamRead(this, data, result.fin);
86
83
  }
87
84
 
88
85
  void Http3WTStream::doCanWrite()
@@ -173,14 +173,21 @@ class Http3WTStream {
173
173
  }
174
174
 
175
175
  onStreamRead(args) {
176
- if (args.data && !this.readableclosed) {
176
+ if (args.data && args.data.length && !this.readableclosed) {
177
177
  // console.log('stream read received', args.data, Date.now())
178
178
  this.readableController.enqueue(args.data)
179
179
  if (this.readableController.desiredSize < 0) this.objint.stopReading()
180
180
  }
181
181
  if (args.fin) {
182
- this.readableController.close()
183
- this.readableclosed = true
182
+ if (this.cancelres) {
183
+ const res = this.cancelres
184
+ this.cancelres = null
185
+ res()
186
+ }
187
+ if (!this.readableclosed) {
188
+ this.readableController.close()
189
+ this.readableclosed = true
190
+ }
184
191
  }
185
192
  }
186
193
 
@@ -218,6 +225,7 @@ class Http3WTStream {
218
225
  this.cancelres = null
219
226
  res()
220
227
  }
228
+ this.stopSendingRecv = true
221
229
  break
222
230
  case 'resetStream':
223
231
  if (this.abortres) {