@fails-components/webtransport-transport-http3-quiche 1.1.3 → 1.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.
@@ -16,6 +16,7 @@
16
16
  #include <atomic>
17
17
 
18
18
  #include <string>
19
+ #include <queue>
19
20
 
20
21
  #include "src/librarymain.h"
21
22
  #include "src/http3wtstreamvisitor.h"
@@ -37,7 +38,7 @@ namespace quic
37
38
 
38
39
  public:
39
40
  Http3WTSession()
40
- : ordBidiStreams(0), ordUnidiStreams(0), session_(nullptr), js_(nullptr)
41
+ : session_(nullptr), js_(nullptr)
41
42
  {
42
43
  }
43
44
 
@@ -83,11 +84,14 @@ namespace quic
83
84
  };
84
85
 
85
86
  bool
86
- tryOpenBidiStream(bool waitUntilAvailable)
87
+ tryOpenBidiStream(bool waitUntilAvailable, uint64_t sendGroupId, uint64_t sendOrder)
87
88
  {
88
89
  if (session_->CanOpenNextOutgoingBidirectionalStream()
89
90
  || waitUntilAvailable) {
90
- ordBidiStreams++;
91
+ webtransport::StreamPriority priority;
92
+ priority.send_group_id = sendGroupId;
93
+ priority.send_order = sendOrder;
94
+ ordBidiStreams.push(priority);
91
95
  TrySendingBidirectionalStreams();
92
96
  return true;
93
97
  } else {
@@ -95,11 +99,14 @@ namespace quic
95
99
  }
96
100
  }
97
101
 
98
- bool tryOpenUnidiStream(bool waitUntilAvailable)
102
+ bool tryOpenUnidiStream(bool waitUntilAvailable, uint64_t sendGroupId, uint64_t sendOrder)
99
103
  {
100
104
  if (session_->CanOpenNextOutgoingUnidirectionalStream()
101
105
  || waitUntilAvailable) {
102
- ordUnidiStreams++;
106
+ webtransport::StreamPriority priority;
107
+ priority.send_group_id = sendGroupId;
108
+ priority.send_order = sendOrder;
109
+ ordUnidiStreams.push(priority);
103
110
  TrySendingUnidirectionalStreams();
104
111
  return true;
105
112
  } else {
@@ -130,18 +137,21 @@ namespace quic
130
137
 
131
138
  void orderDatagramStatsInt();
132
139
 
140
+ size_t getMaxDatagramSizeInt();
141
+
133
142
  void closeInt(int code, std::string &reason)
134
143
  {
135
144
  if (session_)
136
145
  session_->CloseSession(code, reason);
137
146
  }
138
147
 
139
- void writeDatagramInt(char *buffer, size_t len, Napi::ObjectReference *bufferhandle);
148
+ webtransport::DatagramStatus writeDatagramInt(char *buffer, size_t len, Napi::ObjectReference *bufferhandle);
140
149
 
141
150
  WebTransportSession *session_;
142
151
  bool echo_stream_opened_ = false;
143
- uint32_t ordBidiStreams;
144
- uint32_t ordUnidiStreams;
152
+
153
+ std::queue<webtransport::StreamPriority> ordBidiStreams;
154
+ std::queue<webtransport::StreamPriority> ordUnidiStreams;
145
155
  };
146
156
 
147
157
  class Http3WTSessionJS : public Napi::ObjectWrap<Http3WTSessionJS>
@@ -167,6 +177,8 @@ namespace quic
167
177
  Napi::Value orderBidiStream(const Napi::CallbackInfo &info)
168
178
  {
169
179
  bool waitUntilAvailable = false;
180
+ uint64_t sendGroupId = 0;
181
+ uint64_t sendOrder = 0;
170
182
  if (!info[0].IsUndefined())
171
183
  {
172
184
  Napi::Object lobj = info[0].ToObject();
@@ -177,9 +189,20 @@ namespace quic
177
189
  Napi::Value waitUntilAvailableValue = (lobj).Get("waitUntilAvailable");
178
190
  waitUntilAvailable = waitUntilAvailableValue.As<Napi::Boolean>().Value();
179
191
  }
192
+ if (lobj.Has("sendGroup") && !(lobj).Get("sendGroup").IsEmpty()
193
+ && !(lobj).Get("sendGroup").IsNull()) {
194
+ Napi::Value sendGroupIdValue = (lobj).Get("sendGroup").ToObject().Get("_sendGroupId");
195
+ bool lossless;
196
+ sendGroupId = sendGroupIdValue.As<Napi::BigInt>().Uint64Value(&lossless);
197
+ }
198
+ if (lobj.Has("sendOrder") && !(lobj).Get("sendOrder").IsEmpty()) {
199
+ Napi::Value sendOrderValue = (lobj).Get("sendOrder");
200
+ bool lossless;
201
+ sendOrder = sendOrderValue.As<Napi::BigInt>().Uint64Value(&lossless);
202
+ }
180
203
  }
181
204
  }
182
- if (wtsession_->tryOpenBidiStream(waitUntilAvailable))
205
+ if (wtsession_->tryOpenBidiStream(waitUntilAvailable, sendGroupId, sendOrder))
183
206
  {
184
207
  return Napi::Value::From(Env(), true);
185
208
  }
@@ -192,6 +215,8 @@ namespace quic
192
215
  Napi::Value orderUnidiStream(const Napi::CallbackInfo &info)
193
216
  {
194
217
  bool waitUntilAvailable = false;
218
+ uint64_t sendGroupId = 0;
219
+ uint64_t sendOrder = 0;
195
220
  if (!info[0].IsUndefined())
196
221
  {
197
222
  Napi::Object lobj = info[0].ToObject();
@@ -202,9 +227,20 @@ namespace quic
202
227
  Napi::Value waitUntilAvailableValue = (lobj).Get("waitUntilAvailable");
203
228
  waitUntilAvailable = waitUntilAvailableValue.As<Napi::Boolean>().Value();
204
229
  }
230
+ if (lobj.Has("sendGroup") && !(lobj).Get("sendGroup").IsEmpty()
231
+ && !(lobj).Get("sendGroup").IsNull()) {
232
+ Napi::Value sendGroupIdValue = (lobj).Get("sendGroup").ToObject().Get("_sendGroupId");
233
+ bool lossless;
234
+ sendGroupId = sendGroupIdValue.As<Napi::BigInt>().Uint64Value(&lossless);
235
+ }
236
+ if (lobj.Has("sendOrder") && !(lobj).Get("sendOrder").IsEmpty()) {
237
+ Napi::Value sendOrderValue = (lobj).Get("sendOrder");
238
+ bool lossless;
239
+ sendOrder = sendOrderValue.As<Napi::BigInt>().Uint64Value(&lossless);
240
+ }
205
241
  }
206
242
  }
207
- if (wtsession_->tryOpenUnidiStream(waitUntilAvailable))
243
+ if (wtsession_->tryOpenUnidiStream(waitUntilAvailable, sendGroupId, sendOrder))
208
244
  {
209
245
  return Napi::Value::From(Env(), true);
210
246
  }
@@ -214,7 +250,7 @@ namespace quic
214
250
  }
215
251
  }
216
252
 
217
- void writeDatagram(const Napi::CallbackInfo &info)
253
+ Napi::Value writeDatagram(const Napi::CallbackInfo &info)
218
254
  {
219
255
  if (!info[0].IsUndefined())
220
256
  {
@@ -223,8 +259,27 @@ namespace quic
223
259
  *bufferhandle = Napi::Persistent(bufferlocal);
224
260
  char *buffer = bufferlocal.As<Napi::Buffer<char>>().Data();
225
261
  size_t len = bufferlocal.As<Napi::Buffer<char>>().Length();
226
- wtsession_->writeDatagramInt(buffer, len, bufferhandle);
262
+ webtransport::DatagramStatus status = wtsession_->writeDatagramInt(buffer, len, bufferhandle);
263
+
264
+ Napi::Object retObj = Napi::Object::New(Env());
265
+ switch (status.code) {
266
+ case webtransport::DatagramStatusCode::kBlocked:
267
+ retObj.Set("code", "blocked");
268
+ break;
269
+ case webtransport::DatagramStatusCode::kInternalError:
270
+ retObj.Set("code", "internalError");
271
+ break;
272
+ case webtransport::DatagramStatusCode::kSuccess:
273
+ retObj.Set("code", "success");
274
+ break;
275
+ case webtransport::DatagramStatusCode::kTooBig:
276
+ retObj.Set("code", "tooBig");
277
+ break;
278
+ };
279
+ retObj.Set("message", status.error_message);
280
+ return retObj;
227
281
  }
282
+ return Napi::Object::New(Env());
228
283
  }
229
284
 
230
285
  void notifySessionDraining(const Napi::CallbackInfo &info)
@@ -242,6 +297,11 @@ namespace quic
242
297
  wtsession_->orderDatagramStatsInt();
243
298
  }
244
299
 
300
+ Napi::Value getMaxDatagramSize(const Napi::CallbackInfo &info) {
301
+ size_t size = wtsession_->getMaxDatagramSizeInt();
302
+ return Napi::Value::From(Env(), size);
303
+ }
304
+
245
305
  void close(const Napi::CallbackInfo &info)
246
306
  {
247
307
  int code = 0;
@@ -284,6 +344,8 @@ namespace quic
284
344
  static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
285
345
  InstanceMethod<&Http3WTSessionJS::orderDatagramStats>("orderDatagramStats",
286
346
  static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
347
+ InstanceMethod<&Http3WTSessionJS::getMaxDatagramSize>("getMaxDatagramSize",
348
+ static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
287
349
  InstanceMethod<&Http3WTSessionJS::close>("close",
288
350
  static_cast<napi_property_attributes>(napi_writable | napi_configurable))});
289
351
  constr->session = Napi::Persistent(tplwt);
@@ -295,13 +357,13 @@ namespace quic
295
357
 
296
358
  static void freeData(Napi::Env env, void *data, std::string *hint);
297
359
 
298
- void processStream(bool incom, bool bidi, Http3WTStream *stream);
360
+ void processStream(bool incom, bool bidi, uint64_t sendOrder, uint64_t sendGroupId, Http3WTStream *stream);
299
361
  void processSessionStats(webtransport::SessionStats sessstats);
300
362
  void processDatagramStats(webtransport::DatagramStats datastats);
301
363
  void processGoawayReceived();
302
364
  void processDatagramSend(Napi::ObjectReference *bufferhandle);
303
365
  void processDatagramReceived(std::string *datagram);
304
- void processSessionReady();
366
+ void processSessionReady(std::optional<std::string> protocol);
305
367
  void processSessionClose(uint32_t errorcode, const std::string &error);
306
368
  };
307
369
 
@@ -179,6 +179,16 @@ namespace quic
179
179
  }
180
180
  }
181
181
 
182
+ void Http3WTStream::updateSendOrderAndGroupInt(uint64_t sendOrder, uint64_t sendGroupId) {
183
+ if (stream_)
184
+ {
185
+ webtransport::StreamPriority prio;
186
+ prio.send_group_id = sendGroupId;
187
+ prio.send_order = sendOrder;
188
+ stream_->SetPriority(prio);
189
+ }
190
+ }
191
+
182
192
 
183
193
  void Http3WTStreamJS::signalFinOnly() {
184
194
  Napi::HandleScope scope(Env());
@@ -127,6 +127,8 @@ namespace quic
127
127
  void stopSendingInt(unsigned int reason);
128
128
  void resetStreamInt(unsigned int reason);
129
129
 
130
+ void updateSendOrderAndGroupInt(uint64_t sendOrder, uint64_t sendGroupId);
131
+
130
132
  WebTransportStream *stream() { return stream_; }
131
133
 
132
134
  struct WChunks
@@ -281,6 +283,30 @@ namespace quic
281
283
  wtstream_->resetStreamInt(reason);
282
284
  }
283
285
 
286
+ void updateSendOrderAndGroup(const Napi::CallbackInfo &info)
287
+ {
288
+ if (!info[0].IsUndefined())
289
+ {
290
+ Napi::Object obj = info[0].ToObject();
291
+ uint64_t sendOrder = 0;
292
+ uint64_t sendGroupId = 0;
293
+
294
+ if (obj.Has("sendOrder") && !(obj).Get("sendOrder").IsEmpty())
295
+ {
296
+ Napi::Value sendOrderValue = (obj).Get("sendOrder");
297
+ bool approx;
298
+ sendOrder = sendOrderValue.As<Napi::BigInt>().Uint64Value(&approx);
299
+ }
300
+ if (obj.Has("sendGroupId") && !(obj).Get("sendGroupId").IsEmpty())
301
+ {
302
+ Napi::Value sendGroupIdValue = (obj).Get("sendGroupId");
303
+ bool approx;
304
+ sendGroupId = sendGroupIdValue.As<Napi::BigInt>().Uint64Value(&approx);
305
+ }
306
+ wtstream_->updateSendOrderAndGroupInt(sendOrder, sendGroupId);
307
+ }
308
+ }
309
+
284
310
  static void InitExports(Napi::Env env, Napi::Object exports, Http3Constructors *constr)
285
311
  {
286
312
  Napi::Function tplwtsv =
@@ -296,7 +322,10 @@ namespace quic
296
322
  InstanceMethod<&Http3WTStreamJS::startReading>("drainReads",
297
323
  static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
298
324
  InstanceMethod<&Http3WTStreamJS::stopReading>("stopReading",
299
- static_cast<napi_property_attributes>(napi_writable | napi_configurable))});
325
+ static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
326
+ InstanceMethod<&Http3WTStreamJS::updateSendOrderAndGroup>("updateSendOrderAndGroup",
327
+ static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
328
+ });
300
329
  constr->stream = Napi::Persistent(tplwtsv);
301
330
  exports.Set("Http3WTStreamVisitor", tplwtsv);
302
331
  }
@@ -14,6 +14,7 @@
14
14
  #include "src/http3wtsessionvisitor.h"
15
15
  #include "src/napialarmfactory.h"
16
16
  #include "quiche/common/platform/api/quiche_command_line_flags.h"
17
+ #include "quiche/common/platform/api/quiche_flags.h"
17
18
 
18
19
  #include "absl/log/initialize.h"
19
20
  #include "absl/strings/string_view.h"
@@ -58,6 +59,7 @@ namespace quic
58
59
  {
59
60
  quiche_cmd_line_char.push_back((*cur).c_str());
60
61
  }
62
+ SetQuicheReloadableFlag(quic_deliver_stop_sending_to_zombie_streams, true); // enable patch
61
63
  if (!hasSetLogging)
62
64
  {
63
65
  quiche::QuicheParseCommandLineFlags("No use instruction.", quiche_cmd_line.size(), &(*quiche_cmd_line_char.begin()));
@@ -1,8 +0,0 @@
1
- // from envoy so LICENSE.envoy applies
2
- // use default impl
3
- #ifndef QUICHE_MUTEX_IMPL
4
- #define QUICHE_MUTEX_IMPL
5
-
6
- #include "third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_mutex_impl.h"
7
-
8
- #endif
@@ -1,11 +0,0 @@
1
- // Copyright 2017 The Chromium Authors. 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
- #ifndef QUICHE_PREFETCH_IMPL_H_
6
- #define QUICHE_PREFETCH_IMPL_H_
7
-
8
- #include "third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_prefetch_impl.h"
9
-
10
-
11
- #endif