@fails-components/webtransport-transport-http3-quiche 1.0.0-rc.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 (67) hide show
  1. package/CMakeLists.txt +978 -0
  2. package/LICENSE +39 -0
  3. package/LICENSE.chromium +27 -0
  4. package/LICENSE.envoy +207 -0
  5. package/build.js +315 -0
  6. package/lib/clientsocket.js +80 -0
  7. package/lib/index.js +47 -0
  8. package/lib/serversocket.js +80 -0
  9. package/lib/socket.js +118 -0
  10. package/lib/types.ts +15 -0
  11. package/lib/utils.js +12 -0
  12. package/package.json +68 -0
  13. package/platform/icufix/fakedata.cpp +8 -0
  14. package/platform/quiche/quic/core/io/socket_win.inc +3 -0
  15. package/platform/quiche_platform_impl/quiche_bug_tracker_impl.h +7 -0
  16. package/platform/quiche_platform_impl/quiche_client_stats_impl.h +7 -0
  17. package/platform/quiche_platform_impl/quiche_command_line_flags_impl.h +7 -0
  18. package/platform/quiche_platform_impl/quiche_containers_impl.h +7 -0
  19. package/platform/quiche_platform_impl/quiche_event_loop_impl.h +7 -0
  20. package/platform/quiche_platform_impl/quiche_export_impl.h +6 -0
  21. package/platform/quiche_platform_impl/quiche_flag_utils_impl.h +11 -0
  22. package/platform/quiche_platform_impl/quiche_flags_impl.h +8 -0
  23. package/platform/quiche_platform_impl/quiche_googleurl_impl.h +8 -0
  24. package/platform/quiche_platform_impl/quiche_iovec_impl.h +10 -0
  25. package/platform/quiche_platform_impl/quiche_logging_impl.h +21 -0
  26. package/platform/quiche_platform_impl/quiche_mem_slice_impl.h +2 -0
  27. package/platform/quiche_platform_impl/quiche_mutex_impl.h +8 -0
  28. package/platform/quiche_platform_impl/quiche_prefetch_impl.h +11 -0
  29. package/platform/quiche_platform_impl/quiche_reference_counted_impl.h +16 -0
  30. package/platform/quiche_platform_impl/quiche_server_stats_impl.h +7 -0
  31. package/platform/quiche_platform_impl/quiche_stack_trace_impl.h +12 -0
  32. package/platform/quiche_platform_impl/quiche_stream_buffer_allocator_impl.h +8 -0
  33. package/platform/quiche_platform_impl/quiche_testvalue_impl.h +1 -0
  34. package/platform/quiche_platform_impl/quiche_thread_local_impl.h +6 -0
  35. package/platform/quiche_platform_impl/quiche_time_utils_impl.h +13 -0
  36. package/platform/quiche_platform_impl/quiche_udp_socket_platform_impl.h +39 -0
  37. package/readme.md +20 -0
  38. package/src/http3backendresponse.cc +36 -0
  39. package/src/http3backendresponse.h +109 -0
  40. package/src/http3client.cc +1402 -0
  41. package/src/http3client.h +531 -0
  42. package/src/http3clientsession.cc +65 -0
  43. package/src/http3clientsession.h +58 -0
  44. package/src/http3clientstream.cc +52 -0
  45. package/src/http3clientstream.h +42 -0
  46. package/src/http3dispatcher.cc +62 -0
  47. package/src/http3dispatcher.h +57 -0
  48. package/src/http3server.cc +529 -0
  49. package/src/http3server.h +149 -0
  50. package/src/http3serverbackend.cc +104 -0
  51. package/src/http3serverbackend.h +96 -0
  52. package/src/http3serversession.cc +123 -0
  53. package/src/http3serversession.h +95 -0
  54. package/src/http3serverstream.cc +463 -0
  55. package/src/http3serverstream.h +114 -0
  56. package/src/http3sessioncache.cc +85 -0
  57. package/src/http3sessioncache.h +59 -0
  58. package/src/http3wtsessionvisitor.cc +312 -0
  59. package/src/http3wtsessionvisitor.h +257 -0
  60. package/src/http3wtstreamvisitor.cc +286 -0
  61. package/src/http3wtstreamvisitor.h +323 -0
  62. package/src/librarymain.cc +86 -0
  63. package/src/librarymain.h +42 -0
  64. package/src/napialarmfactory.cc +51 -0
  65. package/src/napialarmfactory.h +165 -0
  66. package/src/socketjswriter.cc +46 -0
  67. package/src/socketjswriter.h +100 -0
@@ -0,0 +1,42 @@
1
+ // modifications
2
+ // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
3
+ // Use of this source code is governed by a BSD-style license that can be
4
+ // found in the LICENSE file.
5
+
6
+ // original copyright used only portions, see LICENSE.chromium
7
+ // Copyright (c) 2021 The Chromium Authors. All rights reserved.
8
+ // Use of this source code is governed by a BSD-style license that can be
9
+ // found in the LICENSE file.
10
+
11
+ #ifndef LIBARAY_MAIN_H_
12
+ #define LIBARAY_MAIN_H_
13
+
14
+ #include <napi.h>
15
+
16
+ namespace quic
17
+ {
18
+ enum NetworkTask
19
+ {
20
+ resetStream,
21
+ stopSending,
22
+ streamFinal
23
+ };
24
+
25
+ enum NetworkStatus
26
+ {
27
+ NetError,
28
+ NetClose,
29
+ NetListening
30
+ };
31
+
32
+ struct Http3Constructors
33
+ {
34
+ Napi::FunctionReference stream;
35
+ Napi::FunctionReference session;
36
+ Napi::FunctionReference napialarm;
37
+ Napi::FunctionReference quicheInit;
38
+ };
39
+
40
+
41
+ }
42
+ #endif
@@ -0,0 +1,51 @@
1
+ // modifications
2
+ // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
3
+ // Use of this source code is governed by a BSD-style license that can be
4
+ // found in the LICENSE file.
5
+
6
+ // original copyright used only portions, see LICENSE.chromium
7
+ // Copyright (c) 2021 The Chromium Authors. All rights reserved.
8
+ // Use of this source code is governed by a BSD-style license that can be
9
+ // found in the LICENSE file.
10
+
11
+ #include "src/napialarmfactory.h"
12
+ #include "quiche/quic/core/quic_alarm.h"
13
+
14
+ namespace quic
15
+ {
16
+ Napi::FunctionReference NapiAlarmJS::FAILSsetTimeoutAlarm_;
17
+ Napi::FunctionReference NapiAlarmJS::clearTimeout_;
18
+
19
+ void NapiAlarmJS::fireJS(const Napi::CallbackInfo &info)
20
+ {
21
+ alarm_->FireJS();
22
+ }
23
+
24
+ QuicAlarm *NapiAlarmFactory::CreateAlarm(
25
+ QuicAlarm::Delegate *delegate)
26
+ {
27
+ Http3Constructors *constr = envg_->getEnv().GetInstanceData<Http3Constructors>();
28
+ Napi::Object alarmobj = constr->napialarm.New({});
29
+ NapiAlarmJS *napialarmjs = Napi::ObjectWrap<NapiAlarmJS>::Unwrap(alarmobj);
30
+
31
+ NapiAlarm *alarm = new NapiAlarm(napialarmjs, clock_,
32
+ QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate));
33
+ return alarm;
34
+ }
35
+
36
+ QuicArenaScopedPtr<QuicAlarm> NapiAlarmFactory::CreateAlarm(
37
+ QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
38
+ QuicConnectionArena *arena)
39
+ {
40
+ Http3Constructors *constr = envg_->getEnv().GetInstanceData<Http3Constructors>();
41
+ Napi::Object alarmobj = constr->napialarm.New({});
42
+ NapiAlarmJS *napialarmjs = Napi::ObjectWrap<NapiAlarmJS>::Unwrap(alarmobj);
43
+ if (arena != nullptr)
44
+ {
45
+ return arena->New<NapiAlarm>(napialarmjs, clock_, std::move(delegate));
46
+ }
47
+ return QuicArenaScopedPtr<QuicAlarm>(
48
+ new NapiAlarm(napialarmjs, clock_, std::move(delegate)));
49
+ }
50
+
51
+ }
@@ -0,0 +1,165 @@
1
+ // modifications
2
+ // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
3
+ // Use of this source code is governed by a BSD-style license that can be
4
+ // found in the LICENSE file.
5
+
6
+ // original copyright used only portions, see LICENSE.chromium
7
+ // Copyright (c) 2021 The Chromium Authors. All rights reserved.
8
+ // Use of this source code is governed by a BSD-style license that can be
9
+ // found in the LICENSE file.
10
+
11
+ #ifndef NAPI_ALARM_FACTORY_H_
12
+ #define NAPI_ALARM_FACTORY_H_
13
+
14
+ #include "src/librarymain.h"
15
+ #include "quiche/quic/core/quic_clock.h"
16
+ #include "quiche/quic/core/quic_alarm.h"
17
+ #include "quiche/quic/core/quic_alarm_factory.h"
18
+ #include <napi.h>
19
+
20
+ namespace quic
21
+ {
22
+
23
+ class NapiAlarm;
24
+
25
+ class EnvGetter
26
+ {
27
+ public:
28
+ virtual Napi::Env getEnv() = 0;
29
+ virtual Napi::Object getValue() = 0;
30
+ };
31
+
32
+ class NapiAlarmFactory : public QuicAlarmFactory
33
+ {
34
+ public:
35
+ NapiAlarmFactory(QuicClock *clock, EnvGetter *envg) : clock_(clock), envg_(envg)
36
+ {
37
+ }
38
+
39
+ // QuicAlarmFactory interface.
40
+ QuicAlarm *CreateAlarm(QuicAlarm::Delegate *delegate) override;
41
+ QuicArenaScopedPtr<QuicAlarm> CreateAlarm(
42
+ QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
43
+ QuicConnectionArena *arena) override;
44
+
45
+ private:
46
+ QuicClock *clock_;
47
+ EnvGetter *envg_;
48
+ };
49
+
50
+ class NapiAlarmJS : public Napi::ObjectWrap<NapiAlarmJS>
51
+ {
52
+ friend class NapiAlarm;
53
+ public:
54
+ NapiAlarmJS(const Napi::CallbackInfo &info) : Napi::ObjectWrap<NapiAlarmJS>(info), alarm_()
55
+ {
56
+ if (FAILSsetTimeoutAlarm_.IsEmpty()) {
57
+ FAILSsetTimeoutAlarm_ = Napi::Persistent(Env().Global().Get("FAILSsetTimeoutAlarm").As<Napi::Function>());
58
+ FAILSsetTimeoutAlarm_.SuppressDestruct();
59
+ }
60
+ if (clearTimeout_.IsEmpty()) {
61
+ clearTimeout_ = Napi::Persistent(Env().Global().Get("clearTimeout").As<Napi::Function>());
62
+ clearTimeout_.SuppressDestruct();
63
+ }
64
+ }
65
+
66
+ void setAlarm(NapiAlarm *alarm)
67
+ {
68
+ alarm_ = alarm;
69
+ }
70
+
71
+ void fireJS(const Napi::CallbackInfo &info);
72
+ static void InitExports(Napi::Env env, Napi::Object exports, Http3Constructors *constr)
73
+ {
74
+ Napi::Function tplna =
75
+ DefineClass(env, "NapiAlarmJS",
76
+ {InstanceMethod<&NapiAlarmJS::fireJS>("fireJS")});
77
+ constr->napialarm = Napi::Persistent(tplna);
78
+ exports.Set("NapiAlarmJS", tplna);
79
+ }
80
+
81
+ NapiAlarm *alarm()
82
+ {
83
+ return alarm_;
84
+ }
85
+
86
+ protected:
87
+ NapiAlarm* alarm_; // unowned
88
+ static Napi::FunctionReference FAILSsetTimeoutAlarm_;
89
+ static Napi::FunctionReference clearTimeout_;
90
+ };
91
+
92
+ class NapiAlarm : public QuicAlarm
93
+ {
94
+ public:
95
+ NapiAlarm(NapiAlarmJS *alarmjs, QuicClock *clock, QuicArenaScopedPtr<QuicAlarm::Delegate> delegate)
96
+ : alarmjs_(alarmjs), clock_(clock), QuicAlarm(std::move(delegate)), timerset_(false)
97
+ {
98
+ alarmjs->setAlarm(this);
99
+ alarmjs->Ref();
100
+ }
101
+
102
+ ~NapiAlarm()
103
+ {
104
+ if (timerset_)
105
+ {
106
+ NapiAlarmJS::clearTimeout_.Call({alarmref_.Value()});
107
+ alarmref_.Unref();
108
+ timerset_ = false;
109
+ }
110
+ if (alarmjs_)
111
+ {
112
+ alarmjs_->setAlarm(nullptr);
113
+ alarmjs_->Unref();
114
+ alarmjs_ = nullptr;
115
+ }
116
+
117
+ }
118
+
119
+ void FireJS()
120
+ {
121
+ Fire();
122
+ }
123
+
124
+ protected:
125
+ void SetImpl() override
126
+ {
127
+ if (!alarmjs_)
128
+ return;
129
+ absl::Duration timeout =
130
+ absl::Microseconds((deadline() - clock_->Now()).ToMicroseconds());
131
+ double timedelay = absl::ToDoubleMilliseconds(timeout);
132
+ if (timerset_)
133
+ {
134
+ alarmref_.Unref();
135
+ timerset_ = false;
136
+ }
137
+
138
+ Napi::Value timeoutobj = NapiAlarmJS::FAILSsetTimeoutAlarm_.Call({
139
+ alarmjs_->Value().As<Napi::Object>(),
140
+ Napi::Value::From(alarmjs_->Env(), timedelay),
141
+ });
142
+ alarmref_ = Napi::Reference<Napi::Object>::New(timeoutobj.As<Napi::Object>(), 1);
143
+ timerset_ = true;
144
+ }
145
+
146
+ void CancelImpl() override
147
+ {
148
+ if (timerset_)
149
+ {
150
+ NapiAlarmJS::clearTimeout_.Call({alarmref_.Value()});
151
+ alarmref_.Unref();
152
+ timerset_ = false;
153
+ }
154
+ }
155
+
156
+ private:
157
+ NapiAlarmJS *alarmjs_;
158
+ Napi::ObjectReference alarmref_;
159
+ QuicClock *clock_;
160
+ bool timerset_;
161
+ };
162
+
163
+ }
164
+
165
+ #endif
@@ -0,0 +1,46 @@
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
+ #include "src/socketjswriter.h"
11
+
12
+ namespace quic
13
+ {
14
+ WriteResult SocketJSWriter::WritePacket(const char *buffer, size_t buf_len,
15
+ const QuicIpAddress &self_address,
16
+ const QuicSocketAddress &peer_address,
17
+ PerPacketOptions *options,
18
+ const QuicPacketWriterParams &params)
19
+ {
20
+ Napi::Object retObj = Napi::Object::New(eg_->getEnv());
21
+
22
+ Napi::Buffer<char> nbuffer = Napi::Buffer<char>::New(eg_->getEnv(), buf_len);
23
+ memcpy(nbuffer.Data(), buffer, buf_len);
24
+
25
+ retObj.Set("msg", nbuffer);
26
+ retObj.Set("length", buf_len);
27
+ retObj.Set("offset", 0);
28
+ retObj.Set("port", peer_address.port());
29
+ retObj.Set("address", peer_address.host().ToString());
30
+
31
+ Napi::Object objVal = eg_->getValue().Get("socket").As<Napi::Object>();
32
+ Napi::Value fretVal = objVal.Get("sendPacket").As<Napi::Function>().Call(objVal, {retObj});
33
+
34
+ if (!fretVal.As<Napi::Boolean>().Value())
35
+ {
36
+ // Not blocked
37
+ return WriteResult(WRITE_STATUS_OK, 0);
38
+ }
39
+ else
40
+ {
41
+ // Blocked
42
+ return WriteResult(WRITE_STATUS_BLOCKED, 0);
43
+ }
44
+ }
45
+
46
+ }
@@ -0,0 +1,100 @@
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_SOCKETJS_WRITER_H
11
+ #define WT_SOCKETJS_WRITER_H
12
+
13
+ #include "quiche/quic/core/quic_packet_writer.h"
14
+ #include "quiche/quic/core/quic_udp_socket.h"
15
+ #include "src/napialarmfactory.h"
16
+
17
+ #include <napi.h>
18
+
19
+ namespace quic
20
+ {
21
+ class Http3ServerJS;
22
+ class SocketJSWriter : public QuicPacketWriter
23
+ {
24
+ public:
25
+ SocketJSWriter(EnvGetter *eg) : writeBlocked_(false), eg_(eg)
26
+ {
27
+ }
28
+
29
+ ~SocketJSWriter() override {
30
+ }
31
+
32
+ void setCanWrite()
33
+ {
34
+ writeBlocked_ = false;
35
+ }
36
+
37
+ // QuicPacketWriter
38
+ bool SupportsEcn() const override
39
+ {
40
+ return false;
41
+ }
42
+
43
+ bool IsBatchMode() const override
44
+ {
45
+ return false;
46
+ }
47
+
48
+ bool IsWriteBlocked() const override
49
+ {
50
+ return writeBlocked_;
51
+ }
52
+
53
+ bool SupportsReleaseTime() const override
54
+ {
55
+ return false;
56
+ }
57
+
58
+ void SetWritable() override
59
+ {
60
+ writeBlocked_ = false;
61
+ }
62
+
63
+ absl::optional<int> MessageTooBigErrorCode() const override
64
+ {
65
+ return kSocketErrorMsgSize;
66
+ }
67
+
68
+ QuicByteCount GetMaxPacketSize(
69
+ const QuicSocketAddress & /*peer_address*/) const override
70
+ {
71
+ return kMaxOutgoingPacketSize;
72
+ }
73
+
74
+ WriteResult WritePacket(const char *buffer, size_t buf_len,
75
+ const QuicIpAddress &self_address,
76
+ const QuicSocketAddress &peer_address,
77
+ PerPacketOptions *options,
78
+ const QuicPacketWriterParams &params) override;
79
+
80
+ QuicPacketBuffer GetNextWriteLocation(
81
+ const QuicIpAddress &self_address,
82
+ const QuicSocketAddress &peer_address) override
83
+ {
84
+ return {nullptr, nullptr};
85
+ }
86
+
87
+ WriteResult Flush() override
88
+ {
89
+ return WriteResult(WRITE_STATUS_OK, 0);
90
+ }
91
+
92
+ protected:
93
+ bool writeBlocked_;
94
+ EnvGetter *eg_; // unowned
95
+ };
96
+
97
+
98
+ }
99
+
100
+ #endif