@fails-components/webtransport 0.0.5 → 0.0.7

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.
@@ -7,6 +7,7 @@
7
7
  // Use of this source code is governed by a BSD-style license that can be
8
8
  // found in the LICENSE file.
9
9
 
10
+ #include "absl/cleanup/cleanup.h"
10
11
  #include "src/http3server.h"
11
12
  #include "src/http3dispatcher.h"
12
13
  #include "src/http3wtsessionvisitor.h"
@@ -39,7 +40,8 @@ namespace quic
39
40
  std::move(proof_source),
40
41
  KeyExchangeSource::Default()),
41
42
  expected_server_connection_id_length_(kQuicDefaultConnectionIdLength),
42
- js_(nullptr)
43
+ js_(nullptr),
44
+ connection_id_generator_(expected_server_connection_id_length_)
43
45
  {
44
46
  }
45
47
 
@@ -59,6 +61,8 @@ namespace quic
59
61
  QUIC_LOG(ERROR) << "CreateSocket() failed: " << strerror(errno);
60
62
  return false;
61
63
  }
64
+ auto closer = absl::MakeCleanup([this]
65
+ { { QuicUdpSocketApi api;api.Destroy(fd_); } });
62
66
 
63
67
  overflow_supported_ = socket_api.EnableDroppedPacketCount(fd_);
64
68
  socket_api.EnableReceiveTimestamp(fd_);
@@ -83,12 +87,16 @@ namespace quic
83
87
 
84
88
  const int kEpollFlags = kSocketEventReadable | kSocketEventWritable;
85
89
 
86
- eventloop_->getQuicEventLoop()->RegisterSocket(fd_, kEpollFlags, this);
87
- // eventloop_->SetNonblocking(fd_); // eventuelly should be part of register socket.
88
- dispatcher_.reset(CreateQuicDispatcher());
89
- dispatcher_->InitializeWithWriter(new QuicDefaultPacketWriter(fd_));
90
+ if (eventloop_->getQuicEventLoop()->RegisterSocket(fd_, kEpollFlags, this))
91
+ {
92
+ // eventloop_->SetNonblocking(fd_); // eventuelly should be part of register socket.
93
+ dispatcher_.reset(CreateQuicDispatcher());
94
+ dispatcher_->InitializeWithWriter(new QuicDefaultPacketWriter(fd_));
95
+ std::move(closer).Cancel();
96
+ return true;
97
+ }
90
98
 
91
- return true;
99
+ return false;
92
100
  }
93
101
 
94
102
  bool Http3Server::stopServerInt()
@@ -119,7 +127,7 @@ namespace quic
119
127
  new QuicSimpleCryptoServerStreamHelper()),
120
128
  std::unique_ptr<QuicAlarmFactory>(
121
129
  eventloop_->getQuicEventLoop()->CreateAlarmFactory()),
122
- &http3_server_backend_, expected_server_connection_id_length_);
130
+ &http3_server_backend_, expected_server_connection_id_length_, connection_id_generator_);
123
131
  }
124
132
 
125
133
  Http3ServerJS::Http3ServerJS(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Http3ServerJS>(info)
@@ -149,7 +157,7 @@ namespace quic
149
157
  else
150
158
  {
151
159
  Napi::Error::New(Env(), "No secret set for Http3Server").ThrowAsJavaScriptException();
152
- return ;
160
+ return;
153
161
  }
154
162
  if (lobj.Has("host") && !(lobj).Get("host").IsEmpty())
155
163
  {
@@ -183,6 +191,20 @@ namespace quic
183
191
  sconfig.SetMaxBidirectionalStreamsToSend(maxconn);
184
192
  sconfig.SetMaxUnidirectionalStreamsToSend(maxconn);
185
193
  }
194
+
195
+ if (lobj.Has("initialStreamFlowControlWindow") && !(lobj).Get("initialStreamFlowControlWindow").IsEmpty())
196
+ {
197
+ Napi::Value initialStreamFlowControlWindowValue = (lobj).Get("initialStreamFlowControlWindow");
198
+ int initialStreamFlowControlWindow = initialStreamFlowControlWindowValue.As<Napi::Number>().Int32Value();
199
+ sconfig.SetInitialStreamFlowControlWindowToSend(initialStreamFlowControlWindow);
200
+ }
201
+
202
+ if (lobj.Has("initialSessionFlowControlWindow") && !(lobj).Get("initialSessionFlowControlWindow").IsEmpty())
203
+ {
204
+ Napi::Value initialSessionFlowControlWindowValue = (lobj).Get("initialSessionFlowControlWindow");
205
+ int initialSessionFlowControlWindow = initialSessionFlowControlWindowValue.As<Napi::Number>().Int32Value();
206
+ sconfig.SetInitialSessionFlowControlWindowToSend(initialSessionFlowControlWindow);
207
+ }
186
208
  }
187
209
  // Callback *callback, int port, std::unique_ptr<ProofSource> proof_source, const char *secret
188
210
 
@@ -202,7 +224,7 @@ namespace quic
202
224
  if (proofsource == nullptr)
203
225
  {
204
226
  Napi::Error::New(Env(), "LoadPemFromStream cert failed for Http3Server").ThrowAsJavaScriptException();
205
- return ;
227
+ return;
206
228
  }
207
229
  Http3EventLoop *eventloop = nullptr;
208
230
  if (!info[1].IsUndefined())
@@ -213,7 +235,7 @@ namespace quic
213
235
  else
214
236
  {
215
237
  Napi::Error::New(Env(), "No eventloop arguments passed to Http3Server").ThrowAsJavaScriptException();
216
- return ;
238
+ return;
217
239
  }
218
240
 
219
241
  server_ = std::make_unique<Http3Server>(eventloop, host, port, std::move(proofsource), secret.c_str(), sconfig);
@@ -270,6 +292,21 @@ namespace quic
270
292
  freeaddrinfo(servinfo);
271
293
  }
272
294
 
295
+ const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024; // 1 MB
296
+ const uint32_t kInitialStreamFlowControlWindow = 64 * 1024; // 64 KB
297
+ if (config_.GetInitialStreamFlowControlWindowToSend() ==
298
+ kDefaultFlowControlSendWindow)
299
+ {
300
+ config_.SetInitialStreamFlowControlWindowToSend(
301
+ kInitialStreamFlowControlWindow);
302
+ }
303
+ if (config_.GetInitialSessionFlowControlWindowToSend() ==
304
+ kDefaultFlowControlSendWindow)
305
+ {
306
+ config_.SetInitialSessionFlowControlWindowToSend(
307
+ kInitialSessionFlowControlWindow);
308
+ }
309
+
273
310
  QuicSocketAddress address(ipaddress, port_);
274
311
  if (!CreateUDPSocketAndListen(address))
275
312
  return false; // move to this class
package/src/http3server.h CHANGED
@@ -18,6 +18,7 @@
18
18
  #include "src/http3serverbackend.h"
19
19
  #include "src/http3eventloop.h"
20
20
  #include "quiche/quic/core/crypto/quic_crypto_server_config.h"
21
+ #include "quiche/quic/core/deterministic_connection_id_generator.h"
21
22
  #include "quiche/quic/core/quic_udp_socket.h"
22
23
  #include "quiche/quic/core/quic_dispatcher.h"
23
24
  #include "quiche/quic/core/quic_packet_reader.h"
@@ -61,7 +62,6 @@ namespace quic
61
62
  exports.Set("Http3WebTransportServer", tplsrv);
62
63
  }
63
64
 
64
-
65
65
  void doUnref() override
66
66
  {
67
67
  Unref();
@@ -127,6 +127,7 @@ namespace quic
127
127
  QuicDispatcher *CreateQuicDispatcher();
128
128
 
129
129
  Http3EventLoop *eventloop_;
130
+ DeterministicConnectionIdGenerator connection_id_generator_;
130
131
  };
131
132
 
132
133
  }
@@ -15,7 +15,7 @@
15
15
 
16
16
  #include "quiche/quic/core/quic_types.h"
17
17
  #include "quiche/quic/core/web_transport_interface.h"
18
- #include "quiche/spdy/core/spdy_header_block.h"
18
+ #include "quiche/spdy/core/http2_header_block.h"
19
19
 
20
20
  namespace quic
21
21
  {
@@ -25,7 +25,7 @@ namespace quic
25
25
  session_->eventloop_->informSessionClosed(session_, error_code, error_message);
26
26
  }
27
27
 
28
- void Http3WTSession::Visitor::OnSessionReady(const spdy::SpdyHeaderBlock &)
28
+ void Http3WTSession::Visitor::OnSessionReady(const spdy::Http2HeaderBlock &)
29
29
  {
30
30
  session_->eventloop_->informSessionReady(session_);
31
31
 
@@ -62,7 +62,7 @@ namespace quic
62
62
 
63
63
  ~Visitor();
64
64
 
65
- void OnSessionReady(const spdy::SpdyHeaderBlock &) override;
65
+ void OnSessionReady(const spdy::Http2HeaderBlock &) override;
66
66
 
67
67
  void OnSessionClosed(WebTransportSessionError error_code,
68
68
  const std::string &error_message) override;
@@ -24,6 +24,7 @@ if (
24
24
  ) {
25
25
  wtpath = buildpath + '/Debug/webtransport.node'
26
26
  }
27
+ console.log('load webtransport binary:', wtpath)
27
28
 
28
29
  const wtrouter = require(wtpath)
29
30
 
package/test/testsuite.js CHANGED
@@ -123,7 +123,7 @@ export async function echoTestsConnection(transport) {
123
123
  refArray1.set(data2, data1.length)
124
124
 
125
125
  const resultArray1 = new Uint8Array(i)
126
- console.log("TEST 1: start")
126
+ console.log('TEST 1: start')
127
127
 
128
128
  while (true && i > 0) {
129
129
  const { done, value } = await reader.read()
@@ -155,8 +155,8 @@ export async function echoTestsConnection(transport) {
155
155
  testArraysEqual(refArray1, resultArray1)
156
156
 
157
157
  console.log('webtransport sending bidistream success')
158
- console.log("TEST 1: finish")
159
- console.log("TEST 2: start")
158
+ console.log('TEST 1: finish')
159
+ console.log('TEST 2: start')
160
160
  const bidiReader = transport.incomingBidirectionalStreams.getReader()
161
161
  const incombidi = await bidiReader.read()
162
162
  if (incombidi.value) {
@@ -204,9 +204,9 @@ export async function echoTestsConnection(transport) {
204
204
  }
205
205
  testArraysEqual(refArray2, resultArray2)
206
206
  }
207
- console.log("TEST 2: finish")
207
+ console.log('TEST 2: finish')
208
208
 
209
- console.log("TEST 3: start")
209
+ console.log('TEST 3: start')
210
210
  console.log('now unidirectional tests')
211
211
  const unidioutstream = await transport.createUnidirectionalStream()
212
212
  const unidiwrite = unidioutstream.getWriter()
@@ -262,8 +262,8 @@ export async function echoTestsConnection(transport) {
262
262
  throw new Error('incoming unidi stream test failed')
263
263
  }
264
264
  }
265
- console.log("TEST 3: finish")
266
- console.log("TEST 4: start")
265
+ console.log('TEST 3: finish')
266
+ console.log('TEST 4: start')
267
267
  console.log('finally test datagrams')
268
268
  const datawrite = await transport.datagrams.writable.getWriter()
269
269
  const data7 = new Uint8Array([83, 84, 85])
@@ -300,6 +300,6 @@ export async function echoTestsConnection(transport) {
300
300
  throw new Error('datagram stream test failed')
301
301
  }
302
302
  console.log('test datagrams finished')
303
- console.log("TEST 4: finish")
303
+ console.log('TEST 4: finish')
304
304
  console.log('start close stream tests')
305
305
  }
@@ -1,9 +0,0 @@
1
- // from envoy so LICENSE.envoy applies
2
- #ifndef QUIC_FLAGS_IMPL
3
- #define QUIC_FLAGS_IMPL
4
-
5
-
6
- #include "third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quic_flags_impl.h"
7
-
8
-
9
- #endif