@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,59 +0,0 @@
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, see LICENSE.chromium
7
- // Copyright (c) 2019 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
-
12
- #ifndef HTTP3_SESSION_CACHE_H
13
- #define HTTP3_SESSION_CACHE_H
14
-
15
- #include <memory>
16
-
17
- #include "quiche/quic/core/crypto/quic_crypto_client_config.h"
18
- #include "quiche/quic/core/crypto/transport_parameters.h"
19
-
20
- namespace quic {
21
-
22
- // Http3SessionCache provides a simple implementation of SessionCache that
23
- // stores only one QuicResumptionState per QuicServerId. No limit is placed on
24
- // the total number of entries in the cache. When Lookup is called, if a cache
25
- // entry exists for the provided QuicServerId, the entry will be removed from
26
- // the cached when it is returned.
27
- // TODO(fayang): Remove Http3SessionCache by using QuicClientSessionCache.
28
- class Http3SessionCache : public SessionCache {
29
- public:
30
- Http3SessionCache() = default;
31
- ~Http3SessionCache() override = default;
32
-
33
- void Insert(const QuicServerId& server_id,
34
- bssl::UniquePtr<SSL_SESSION> session,
35
- const TransportParameters& params,
36
- const ApplicationState* application_state) override;
37
- std::unique_ptr<QuicResumptionState> Lookup(const QuicServerId& server_id,
38
- QuicWallTime now,
39
- const SSL_CTX* ctx) override;
40
- void ClearEarlyData(const QuicServerId& server_id) override;
41
- void OnNewTokenReceived(const QuicServerId& server_id,
42
- absl::string_view token) override;
43
- void RemoveExpiredEntries(QuicWallTime now) override;
44
- void Clear() override;
45
-
46
- private:
47
- struct Entry {
48
- bssl::UniquePtr<SSL_SESSION> session;
49
- std::unique_ptr<TransportParameters> params;
50
- std::unique_ptr<ApplicationState> application_state;
51
- std::string token;
52
- };
53
- std::map<QuicServerId, Entry> cache_entries_;
54
- };
55
-
56
-
57
- } // namespace quic
58
-
59
- #endif // QUICHE_QUIC_TEST_TOOLS_SIMPLE_SESSION_CACHE_H_
@@ -1,46 +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
- #include "src/http3wtsessionvisitor.h"
6
- #include "src/http3eventloop.h"
7
-
8
- namespace quic
9
- {
10
-
11
- Http3WTSession::Visitor::~Visitor()
12
- {
13
- // printf("~Visitor %d %x %x\n", getpid(), this, session_);
14
- Http3WTSessionJS *sessobj = session_->getJS();
15
- if (sessobj)
16
- session_->eventloop_->informUnref(sessobj);
17
- else
18
- delete session_;
19
- session_ = nullptr;
20
- }
21
-
22
- void Http3WTSession::Visitor::OnSessionClosed(WebTransportSessionError error_code,
23
- const std::string &error_message)
24
- {
25
- // printf("OnSessionClosed %d %x %x\n", getpid(), this, session_);
26
- session_->session_ = nullptr;
27
- session_->eventloop_->informSessionClosed(session_, error_code, error_message);
28
- }
29
-
30
- void Http3WTSession::Visitor::OnSessionReady()
31
- {
32
- session_->eventloop_->informSessionReady(session_);
33
-
34
- if (!session_->session_) return;
35
-
36
- if (session_->session_->CanOpenNextOutgoingBidirectionalStream())
37
- {
38
- OnCanCreateNewOutgoingBidirectionalStream();
39
- }
40
- if (session_->session_->CanOpenNextOutgoingUnidirectionalStream())
41
- {
42
- OnCanCreateNewOutgoingUnidirectionalStream();
43
- }
44
- }
45
-
46
- }
@@ -1,397 +0,0 @@
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, 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 HTTP3_WT_SESSION_VISITOR_H_
12
- #define HTTP3_WT_SESSION_VISITOR_H_
13
-
14
- #include <napi.h>
15
- #include <uv.h>
16
-
17
- #include <atomic>
18
-
19
- #include <string>
20
-
21
- #include "src/http3wtstreamvisitor.h"
22
-
23
- #include "quiche/quic/core/web_transport_interface.h"
24
- #include "quiche/quic/platform/api/quic_logging.h"
25
- #include "quiche/common/quiche_circular_deque.h"
26
- #include "quiche/common/platform/api/quiche_mem_slice.h"
27
-
28
- #include "src/http3eventloop.h"
29
-
30
- namespace quic
31
- {
32
- // class Http3Server;
33
- class Http3WTSessionJS;
34
-
35
- class Http3WTSession
36
- {
37
- friend Http3WTSessionJS;
38
-
39
- public:
40
- Http3WTSession()
41
- : ordBidiStreams(0), ordUnidiStreams(0), session_(nullptr), eventloop_(nullptr), js_(nullptr)
42
- {
43
- }
44
-
45
- ~Http3WTSession()
46
- {
47
- // printf("session destruct %x\n", this);
48
- }
49
-
50
- // need to be called immediately after new
51
- void init(WebTransportSession *session, Http3EventLoop *eventloop)
52
- {
53
- session_ = session;
54
- eventloop_ = eventloop;
55
- if (session_) {
56
- session_->SetOnDraining([this]() {
57
- eventloop_->informGoawayReceived(this);
58
- });
59
- }
60
- }
61
-
62
- class Visitor : public WebTransportVisitor
63
- {
64
- public:
65
- Visitor(Http3WTSession *session) : session_(session) {}
66
-
67
- ~Visitor();
68
-
69
- void OnSessionReady() override;
70
-
71
- void OnSessionClosed(WebTransportSessionError error_code,
72
- const std::string &error_message) override;
73
-
74
- void OnIncomingBidirectionalStreamAvailable() override
75
- {
76
- if (!session_->session_)
77
- return;
78
- while (true)
79
- {
80
- WebTransportStream *stream =
81
- session_->session_->AcceptIncomingBidirectionalStream();
82
- if (stream == nullptr)
83
- {
84
- return;
85
- }
86
- Http3WTStream *wtstream = new Http3WTStream(stream, session_->eventloop_);
87
- QUIC_DVLOG(1)
88
- << "Http3WTSession received a bidirectional stream "
89
- << stream->GetStreamId();
90
- stream->SetVisitor(
91
- std::make_unique<Http3WTStream::Visitor>(wtstream));
92
- session_->eventloop_->informAboutStream(true, true, session_, static_cast<Http3WTStream *>(wtstream));
93
- stream->visitor()->OnCanRead();
94
- }
95
- }
96
-
97
- void OnIncomingUnidirectionalStreamAvailable() override
98
- {
99
- if (!session_->session_)
100
- return;
101
- while (true)
102
- {
103
- WebTransportStream *stream =
104
- session_->session_->AcceptIncomingUnidirectionalStream();
105
- if (stream == nullptr)
106
- {
107
- return;
108
- }
109
- Http3WTStream *wtstream = new Http3WTStream(stream, session_->eventloop_);
110
- QUIC_DVLOG(1)
111
- << "Http3WTSession received a unidirectional stream";
112
- stream->SetVisitor(
113
- std::make_unique<Http3WTStream::Visitor>(wtstream));
114
- session_->eventloop_->informAboutStream(true, false, session_, static_cast<Http3WTStream *>(wtstream));
115
- stream->visitor()->OnCanRead();
116
- }
117
- }
118
-
119
- void OnDatagramReceived(absl::string_view datagram) override
120
- {
121
- // printf("OnDatagramReceived %d %x %x\n", getpid(), this, session_);
122
- session_->eventloop_->informDatagramReceived(session_, datagram);
123
- /*auto buffer = MakeUniqueBuffer(&allocator_, datagram.size());
124
- memcpy(buffer.get(), datagram.data(), datagram.size());
125
- quiche::QuicheMemSlice slice(std::move(buffer), datagram.size());
126
- session_->SendOrQueueDatagram(std::move(slice));*/
127
- }
128
-
129
- void OnCanCreateNewOutgoingBidirectionalStream() override
130
- {
131
- // unclear how we can stich this together?
132
- session_->TrySendingBidirectionalStreams();
133
- }
134
-
135
- void OnCanCreateNewOutgoingUnidirectionalStream() override
136
- {
137
- session_->TrySendingUnidirectionalStreams();
138
- }
139
-
140
- protected:
141
- Http3WTSession *session_;
142
- };
143
-
144
- void
145
- tryOpenBidiStream()
146
- {
147
- ordBidiStreams++;
148
- TrySendingBidirectionalStreams();
149
- }
150
-
151
- void tryOpenUnidiStream()
152
- {
153
- ordUnidiStreams++;
154
- TrySendingUnidirectionalStreams();
155
- }
156
-
157
- void TrySendingBidirectionalStreams()
158
- {
159
- if (!session_)
160
- return;
161
- while (ordBidiStreams > 0 &&
162
- session_->CanOpenNextOutgoingBidirectionalStream())
163
- {
164
- QUIC_DVLOG(1)
165
- << "Http3WTSessionVisitor opens a bidirectional stream";
166
- WebTransportStream *stream = session_->OpenOutgoingBidirectionalStream();
167
- Http3WTStream *wtstream = new Http3WTStream(stream, eventloop_);
168
- stream->SetVisitor(
169
- std::make_unique<Http3WTStream::Visitor>(wtstream));
170
- eventloop_->informAboutStream(false, true, this, static_cast<Http3WTStream *>(wtstream));
171
- stream->visitor()->OnCanWrite();
172
- ordBidiStreams--;
173
- }
174
- }
175
-
176
- void TrySendingUnidirectionalStreams()
177
- {
178
- if (!session_)
179
- return;
180
- // move to some where else?
181
- while (ordUnidiStreams > 0 &&
182
- session_->CanOpenNextOutgoingUnidirectionalStream())
183
- {
184
- QUIC_DVLOG(1)
185
- << "Http3WTSessionVisitor opened a unidirectional stream";
186
- WebTransportStream *stream = session_->OpenOutgoingUnidirectionalStream();
187
- Http3WTStream *wtstream = new Http3WTStream(stream, eventloop_);
188
- stream->SetVisitor(
189
- std::make_unique<Http3WTStream::Visitor>(wtstream));
190
-
191
- eventloop_->informAboutStream(false, false, this, static_cast<Http3WTStream *>(wtstream));
192
- stream->visitor()->OnCanWrite();
193
- ordUnidiStreams--;
194
- }
195
- }
196
-
197
- Http3WTSessionJS *getJS() { return js_; };
198
- void setJS(Http3WTSessionJS *js) {
199
- js_ = js;
200
- };
201
-
202
- private:
203
-
204
- Http3WTSessionJS *js_;
205
-
206
- void orderBidiStreamInt()
207
- {
208
- std::function<void()> task = [this]()
209
- { tryOpenBidiStream(); };
210
- eventloop_->Schedule(task);
211
- }
212
-
213
- void orderUnidiStreamInt()
214
- {
215
- std::function<void()> task = [this]()
216
- { tryOpenUnidiStream(); };
217
- eventloop_->Schedule(task);
218
- }
219
-
220
- void writeDatagramIntJS(char *buffer, size_t len, Napi::ObjectReference *bufferhandle)
221
- {
222
- std::function<void()> task = [this, bufferhandle, buffer, len]()
223
- { writeDatagramInt(buffer, len, bufferhandle); };
224
- eventloop_->Schedule(task);
225
- }
226
-
227
- void notifySessionDrainingInt()
228
- {
229
- std::function<void()> task = [this]()
230
- { if (session_) session_->NotifySessionDraining(); };
231
- eventloop_->Schedule(task);
232
- }
233
-
234
- void orderSessionStatsInt()
235
- {
236
- std::function<void()> task = [this](){
237
- if (session_) {
238
- webtransport::SessionStats * stats = new webtransport::SessionStats();
239
- *stats = session_->GetSessionStats();
240
- eventloop_->informSessionStats(this, stats);
241
- }};
242
- eventloop_->Schedule(task);
243
- }
244
-
245
- void orderDatagramStatsInt()
246
- {
247
- std::function<void()> task = [this]()
248
- { if (session_) {
249
- webtransport::DatagramStats * stats = new webtransport::DatagramStats();
250
- *stats = session_->GetDatagramStats();
251
- eventloop_->informDatagramStats(this, stats);
252
- } };
253
- eventloop_->Schedule(task);
254
- }
255
-
256
- void closeInt(int code, std::string &reason)
257
- {
258
- std::function<void()> task = [this, code, reason]()
259
- { if (session_) session_->CloseSession(code, reason); };
260
- eventloop_->Schedule(task);
261
- }
262
-
263
- void writeDatagramInt(char *buffer, size_t len, Napi::ObjectReference *bufferhandle)
264
- {
265
- // printf("Datagram write %d %x %x\n", getpid(), this, session_ );
266
- if (!session_)
267
- {
268
- // printf("Datagram session gone %d %x %x\n", getpid(), this, session_);
269
- eventloop_->informDatagramSend(this, bufferhandle);
270
- return;
271
- }
272
- auto status=session_->SendOrQueueDatagram(absl::string_view(buffer, len));
273
- // printf("Datagram status %d %d %s %x %x\n", getpid(), status.code, status.error_message.c_str(), this, session_);
274
- eventloop_->informDatagramSend(this, bufferhandle);
275
- }
276
-
277
- WebTransportSession *session_;
278
- bool echo_stream_opened_ = false;
279
- Http3EventLoop *eventloop_;
280
- uint32_t ordBidiStreams;
281
- uint32_t ordUnidiStreams;
282
- };
283
-
284
- class Http3WTSessionJS : public Napi::ObjectWrap<Http3WTSessionJS>, public LifetimeHelper
285
- {
286
- public:
287
- Http3WTSessionJS(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Http3WTSessionJS>(info)
288
- {
289
- }
290
-
291
- void setObj(Http3WTSession *wtsession)
292
- {
293
- wtsession_ = std::unique_ptr<Http3WTSession>(wtsession);
294
- }
295
-
296
- Http3WTSession *getObj()
297
- {
298
- return wtsession_.get();
299
- }
300
-
301
- void orderBidiStream(const Napi::CallbackInfo &info)
302
- {
303
- wtsession_->orderBidiStreamInt();
304
- }
305
-
306
- void orderUnidiStream(const Napi::CallbackInfo &info)
307
- {
308
- wtsession_->orderUnidiStreamInt();
309
- }
310
-
311
- void writeDatagram(const Napi::CallbackInfo &info)
312
- {
313
- if (!info[0].IsUndefined())
314
- {
315
- Napi::Object bufferlocal = info[0].ToObject();
316
- Napi::ObjectReference *bufferhandle = new Napi::ObjectReference();
317
- *bufferhandle = Napi::Persistent(bufferlocal);
318
- char *buffer = bufferlocal.As<Napi::Buffer<char>>().Data();
319
- size_t len = bufferlocal.As<Napi::Buffer<char>>().Length();
320
- wtsession_->writeDatagramIntJS(buffer, len, bufferhandle);
321
- }
322
- }
323
-
324
- void notifySessionDraining(const Napi::CallbackInfo &info)
325
- {
326
- wtsession_->notifySessionDrainingInt();
327
- }
328
-
329
- void orderSessionStats(const Napi::CallbackInfo &info)
330
- {
331
- wtsession_->orderSessionStatsInt();
332
- }
333
-
334
- void orderDatagramStats(const Napi::CallbackInfo &info)
335
- {
336
- wtsession_->orderDatagramStatsInt();
337
- }
338
-
339
- void close(const Napi::CallbackInfo &info)
340
- {
341
- int code = 0;
342
- std::string reason("unknown reason");
343
-
344
- if (!info[0].IsUndefined())
345
- {
346
- Napi::Object obj = info[0].ToObject();
347
- if (!obj.IsEmpty())
348
- {
349
- if (obj.Has("code") && !(obj).Get("code").IsEmpty())
350
- {
351
- Napi::Value codeValue = (obj).Get("code");
352
- code = codeValue.As<Napi::Number>().Int32Value();
353
- }
354
- if (obj.Has("reason") && !(obj).Get("reason").IsEmpty())
355
- {
356
- Napi::Value reasonValue = (obj).Get("reason");
357
- reason = reasonValue.ToString().Utf8Value();
358
- }
359
- }
360
- }
361
-
362
- wtsession_->closeInt(code, reason);
363
- }
364
-
365
- static void InitExports(Napi::Env env, Napi::Object exports, Http3Constructors * constr)
366
- {
367
- Napi::Function tplwt =
368
- ObjectWrap<Http3WTSessionJS>::DefineClass(env, "Http3WTSessionVisitor",
369
- {InstanceMethod<&Http3WTSessionJS::orderBidiStream>("orderBidiStream",
370
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
371
- InstanceMethod<&Http3WTSessionJS::orderUnidiStream>("orderUnidiStream",
372
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
373
- InstanceMethod<&Http3WTSessionJS::writeDatagram>("writeDatagram",
374
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
375
- InstanceMethod<&Http3WTSessionJS::notifySessionDraining>("notifySessionDraining",
376
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
377
- InstanceMethod<&Http3WTSessionJS::orderSessionStats>("orderSessionStats",
378
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
379
- InstanceMethod<&Http3WTSessionJS::orderDatagramStats>("orderDatagramStats",
380
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
381
- InstanceMethod<&Http3WTSessionJS::close>("close",
382
- static_cast<napi_property_attributes>(napi_writable | napi_configurable))});
383
- constr->session = Napi::Persistent(tplwt);
384
- exports.Set("Http3WTSessionVisitor", tplwt);
385
-
386
- }
387
-
388
- void doUnref() override
389
- {
390
- Unref();
391
- }
392
-
393
- protected:
394
- std::unique_ptr<Http3WTSession> wtsession_;
395
- };
396
- }
397
- #endif
@@ -1,155 +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
- #include "src/http3wtstreamvisitor.h"
6
- #include "src/http3server.h"
7
-
8
- namespace quic
9
- {
10
- void Http3WTStreamJS::init(Http3WTStream * wtstream)
11
- {
12
- wtstream_ = std::unique_ptr<Http3WTStream>(wtstream);
13
- }
14
-
15
- Http3WTStream::Visitor::~Visitor()
16
- {
17
- while (stream_->chunks_.size() > 0)
18
- {
19
- auto cur = stream_->chunks_.front();
20
-
21
- // now we have to inform the server TODO
22
- stream_->eventloop_->informAboutStreamWrite(stream_, cur.bufferhandle, false);
23
-
24
- stream_->chunks_.pop_front();
25
- }
26
-
27
- stream_->eventloop_->informAboutStreamRead(stream_, 0, false, false);
28
-
29
- if (!stream_->stop_sending_received_)
30
- {
31
- stream_->eventloop_->informStreamRecvSignal(stream_, 0, NetworkTask::stopSending);
32
- }
33
- if (!stream_->stream_was_reset_)
34
- {
35
- stream_->eventloop_->informStreamRecvSignal(stream_, 0, NetworkTask::resetStream);
36
- }
37
- Http3WTStreamJS *strobj = stream_->getJS();
38
- if (strobj) {
39
- stream_->stream_ = nullptr;
40
- stream_->eventloop_->informUnref(strobj);
41
- } else {
42
- stream_->stream_ = nullptr;
43
- }
44
- }
45
-
46
- void Http3WTStream::Visitor::OnWriteSideInDataRecvdState() // called if everything is written to the client and it is closed
47
- {
48
- if (stream_->send_fin_)
49
- stream_->eventloop_->informAboutStreamNetworkFinish(stream_, NetworkTask::streamFinal);
50
- }
51
-
52
- void Http3WTStream::Visitor::OnResetStreamReceived(WebTransportStreamError error)
53
- {
54
- // should this be removed
55
- /*
56
-
57
- // Send FIN in response to a stream reset. We want to test that we can
58
- // operate one side of the stream cleanly while the other is reset, thus
59
- // replying with a FIN rather than a RESET_STREAM is more appropriate here.
60
- stream_->send_fin_ = true;
61
- OnCanWrite();*/
62
- stream_->stream_was_reset_ = true;
63
- lasterror = error;
64
- stream_->eventloop_->informStreamRecvSignal(stream_, error, NetworkTask::resetStream); // may be move below
65
- }
66
-
67
- void Http3WTStream::Visitor::OnStopSendingReceived(WebTransportStreamError error)
68
- {
69
- stream_->stop_sending_received_ = true;
70
- stream_->eventloop_->informStreamRecvSignal(stream_, error, NetworkTask::stopSending); // may be move below
71
- // we should also finallize the stream, so send a fin
72
- stream_->send_fin_ = true;
73
- OnCanWrite();
74
- }
75
-
76
- void Http3WTStream::cancelWrite(Napi::ObjectReference *handle)
77
- {
78
- eventloop_->informAboutStreamWrite(this, handle, false);
79
- }
80
-
81
- void Http3WTStream::doCanRead()
82
- {
83
- // if (pause_reading_) return ; // back pressure folks!
84
-
85
- if (pause_reading_)
86
- {
87
- can_read_pending_ = true;
88
- return; // back pressure folks!
89
- }
90
- // first figure out if we have readable data
91
- if (bufferlen_ >= readbufsize_ || !readbufdata_) {
92
- can_read_pending_ = true;
93
- return; // no space here
94
- }
95
- size_t readable = stream_->ReadableBytes();
96
- bool read = false;
97
- while (readable > 0 && bufferlen_ < readbufsize_)
98
- {
99
- if (writepos_ >= readpos_) {
100
- size_t len = readbufsize_ - writepos_;
101
- WebTransportStream::ReadResult result =
102
- stream_->Read(absl::Span<char>(((char*) readbufdata_) + writepos_, len));
103
- QUIC_DVLOG(1) << "Attempted reading on WebTransport stream "
104
- << ", bytes read: " << result.bytes_read;
105
- writepos_ = (writepos_ + result.bytes_read) % readbufsize_;
106
- bufferlen_ = bufferlen_ + result.bytes_read;
107
- eventloop_->informAboutStreamRead(this, result.bytes_read,
108
- result.fin, true);
109
- } else { // readpos_ > writepos_
110
- size_t len = writepos_ - readpos_;
111
- WebTransportStream::ReadResult result =
112
- stream_->Read(absl::Span<char>(((char*) readbufdata_) + writepos_, len));
113
- QUIC_DVLOG(1) << "Attempted reading on WebTransport stream "
114
- << ", bytes read: " << result.bytes_read;
115
- writepos_ = (writepos_ + result.bytes_read) % readbufsize_;
116
- bufferlen_ = bufferlen_ + result.bytes_read;
117
- eventloop_->informAboutStreamRead(this, result.bytes_read,
118
- result.fin, true);
119
- }
120
- readable = stream_->ReadableBytes();
121
- }
122
- }
123
-
124
- void Http3WTStream::doCanWrite()
125
- {
126
- /* if (/* stop_sending_received_ || * pause_reading_)
127
- {
128
- return;
129
- } */
130
- if (fin_was_sent_) return;
131
-
132
- while (chunks_.size() > 0)
133
- {
134
- auto cur = chunks_.front();
135
- bool success = stream_->Write(absl::string_view(cur.buffer, cur.len));
136
- QUIC_DVLOG(1) << "Attempted writing on WebTransport bidirectional stream "
137
- << ", success: " << (success ? "yes" : "no");
138
- if (!success)
139
- {
140
- return;
141
- }
142
- // now we have to inform the server TODO
143
- eventloop_->informAboutStreamWrite(this, cur.bufferhandle, true);
144
-
145
- chunks_.pop_front();
146
- }
147
-
148
- if (send_fin_)
149
- {
150
- bool success = stream_->SendFin();
151
- if (success) fin_was_sent_ = true;
152
- }
153
- }
154
-
155
- }