Skip to content

Commit a6c5d27

Browse files
committed
quic: update more of the quic to the new compile guard
Signed-off-by: James M Snell <[email protected]> PR-URL: #59342 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
1 parent ee7b8ab commit a6c5d27

21 files changed

+240
-146
lines changed

node.gyp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,15 @@
185185
'src/udp_wrap.cc',
186186
'src/util.cc',
187187
'src/uv.cc',
188+
'src/quic/bindingdata.cc',
188189
'src/quic/cid.cc',
189190
'src/quic/data.cc',
191+
'src/quic/logstream.cc',
192+
'src/quic/packet.cc',
193+
'src/quic/preferredaddress.cc',
194+
'src/quic/sessionticket.cc',
195+
'src/quic/tokens.cc',
196+
# 'src/quic/transportparams.cc',
190197
# headers to make for a more pleasant IDE experience
191198
'src/aliased_buffer.h',
192199
'src/aliased_buffer-inl.h',
@@ -323,9 +330,16 @@
323330
'src/udp_wrap.h',
324331
'src/util.h',
325332
'src/util-inl.h',
333+
'src/quic/bindingdata.h',
326334
'src/quic/cid.h',
327335
'src/quic/data.h',
328336
'src/quic/defs.h',
337+
'src/quic/logstream.h',
338+
'src/quic/packet.h',
339+
'src/quic/preferredaddress.h',
340+
'src/quic/sessionticket.h',
341+
'src/quic/tokens.h',
342+
# 'src/quic/transportparams.h',
329343
'src/quic/guard.h',
330344
],
331345
'node_crypto_sources': [
@@ -390,31 +404,17 @@
390404
],
391405
'node_quic_sources': [
392406
'src/quic/application.cc',
393-
'src/quic/bindingdata.cc',
394407
'src/quic/endpoint.cc',
395408
'src/quic/http3.cc',
396-
'src/quic/logstream.cc',
397-
'src/quic/packet.cc',
398-
'src/quic/preferredaddress.cc',
399409
'src/quic/session.cc',
400-
'src/quic/sessionticket.cc',
401410
'src/quic/streams.cc',
402411
'src/quic/tlscontext.cc',
403-
'src/quic/tokens.cc',
404-
'src/quic/transportparams.cc',
405412
'src/quic/application.h',
406-
'src/quic/bindingdata.h',
407413
'src/quic/endpoint.h',
408414
'src/quic/http3.h',
409-
'src/quic/logstream.h',
410-
'src/quic/packet.h',
411-
'src/quic/preferredaddress.h',
412415
'src/quic/session.h',
413-
'src/quic/sessionticket.h',
414416
'src/quic/streams.h',
415417
'src/quic/tlscontext.h',
416-
'src/quic/tokens.h',
417-
'src/quic/transportparams.h',
418418
'src/quic/quic.cc',
419419
],
420420
'node_cctest_openssl_sources': [
@@ -423,6 +423,7 @@
423423
'test/cctest/test_node_crypto_env.cc',
424424
'test/cctest/test_quic_cid.cc',
425425
'test/cctest/test_quic_error.cc',
426+
'test/cctest/test_quic_preferredaddress.cc',
426427
'test/cctest/test_quic_tokens.cc',
427428
],
428429
'node_cctest_inspector_sources': [

src/quic/application.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void Session::Application::SendPendingData() {
290290
// The stream_data is the next block of data from the application stream.
291291
if (GetStreamData(&stream_data) < 0) {
292292
Debug(session_, "Application failed to get stream data");
293-
packet->Done(UV_ECANCELED);
293+
packet->CancelPacket();
294294
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
295295
return session_->Close(CloseMethod::SILENT);
296296
}
@@ -357,7 +357,7 @@ void Session::Application::SendPendingData() {
357357
if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
358358
Debug(session_,
359359
"Failed to commit stream data while writing packets");
360-
packet->Done(UV_ECANCELED);
360+
packet->CancelPacket();;
361361
session_->SetLastError(
362362
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
363363
return session_->Close(CloseMethod::SILENT);
@@ -371,11 +371,11 @@ void Session::Application::SendPendingData() {
371371
Debug(session_,
372372
"Application encountered error while writing packet: %s",
373373
ngtcp2_strerror(nwrite));
374-
packet->Done(UV_ECANCELED);
374+
packet->CancelPacket();
375375
session_->SetLastError(QuicError::ForNgtcp2Error(nwrite));
376376
return session_->Close(CloseMethod::SILENT);
377377
} else if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
378-
packet->Done(UV_ECANCELED);
378+
packet->CancelPacket();
379379
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
380380
return session_->Close(CloseMethod::SILENT);
381381
}
@@ -394,7 +394,7 @@ void Session::Application::SendPendingData() {
394394
packet->Truncate(datalen);
395395
session_->Send(packet, path);
396396
} else {
397-
packet->Done(UV_ECANCELED);
397+
packet->CancelPacket();
398398
}
399399

400400
return;

src/quic/bindingdata.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
1+
#if HAVE_OPENSSL
2+
#include "guard.h"
3+
#ifndef OPENSSL_NO_QUIC
24
#include "bindingdata.h"
35
#include <base_object-inl.h>
46
#include <env-inl.h>
@@ -49,10 +51,12 @@ void BindingData::CheckAllocatedSize(size_t previous_size) const {
4951
}
5052

5153
void BindingData::IncreaseAllocatedSize(size_t size) {
54+
CHECK_GE(current_ngtcp2_memory_ + size, current_ngtcp2_memory_);
5255
current_ngtcp2_memory_ += size;
5356
}
5457

5558
void BindingData::DecreaseAllocatedSize(size_t size) {
59+
CHECK_LE(current_ngtcp2_memory_ - size, current_ngtcp2_memory_);
5660
current_ngtcp2_memory_ -= size;
5761
}
5862

@@ -220,4 +224,5 @@ void IllegalConstructor(const FunctionCallbackInfo<Value>& args) {
220224
} // namespace quic
221225
} // namespace node
222226

223-
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
227+
#endif // OPENSSL_NO_QUIC
228+
#endif // HAVE_OPENSSL

src/quic/bindingdata.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4-
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
54

65
#include <base_object.h>
76
#include <env.h>
@@ -26,32 +25,32 @@ class Packet;
2625
// The FunctionTemplates the BindingData will store for us.
2726
#define QUIC_CONSTRUCTORS(V) \
2827
V(endpoint) \
28+
V(http3application) \
2929
V(logstream) \
3030
V(packet) \
3131
V(session) \
3232
V(stream) \
33-
V(udp) \
34-
V(http3application)
33+
V(udp)
3534

3635
// The callbacks are persistent v8::Function references that are set in the
3736
// quic::BindingState used to communicate data and events back out to the JS
3837
// environment. They are set once from the JavaScript side when the
3938
// internalBinding('quic') is first loaded.
4039
#define QUIC_JS_CALLBACKS(V) \
4140
V(endpoint_close, EndpointClose) \
42-
V(session_new, SessionNew) \
4341
V(session_close, SessionClose) \
4442
V(session_datagram, SessionDatagram) \
4543
V(session_datagram_status, SessionDatagramStatus) \
4644
V(session_handshake, SessionHandshake) \
45+
V(session_new, SessionNew) \
46+
V(session_path_validation, SessionPathValidation) \
4747
V(session_ticket, SessionTicket) \
4848
V(session_version_negotiation, SessionVersionNegotiation) \
49-
V(session_path_validation, SessionPathValidation) \
49+
V(stream_blocked, StreamBlocked) \
5050
V(stream_close, StreamClose) \
5151
V(stream_created, StreamCreated) \
52-
V(stream_reset, StreamReset) \
5352
V(stream_headers, StreamHeaders) \
54-
V(stream_blocked, StreamBlocked) \
53+
V(stream_reset, StreamReset) \
5554
V(stream_trailers, StreamTrailers)
5655

5756
// The various JS strings the implementation uses.
@@ -64,10 +63,10 @@ class Packet;
6463
V(application_provider, "provider") \
6564
V(bbr, "bbr") \
6665
V(ca, "ca") \
67-
V(certs, "certs") \
6866
V(cc_algorithm, "cc") \
69-
V(crl, "crl") \
67+
V(certs, "certs") \
7068
V(ciphers, "ciphers") \
69+
V(crl, "crl") \
7170
V(cubic, "cubic") \
7271
V(disable_stateless_reset, "disableStatelessReset") \
7372
V(enable_connect_protocol, "enableConnectProtocol") \
@@ -114,8 +113,8 @@ class Packet;
114113
V(qpack_max_dtable_capacity, "qpackMaxDTableCapacity") \
115114
V(reject_unauthorized, "rejectUnauthorized") \
116115
V(reno, "reno") \
117-
V(retry_token_expiration, "retryTokenExpiration") \
118116
V(reset_token_secret, "resetTokenSecret") \
117+
V(retry_token_expiration, "retryTokenExpiration") \
119118
V(rx_loss, "rxDiagnosticLoss") \
120119
V(servername, "servername") \
121120
V(session, "Session") \
@@ -150,6 +149,9 @@ class BindingData final
150149
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
151150

152151
static BindingData& Get(Environment* env);
152+
static inline BindingData& Get(Realm* realm) {
153+
return Get(realm->env());
154+
}
153155

154156
BindingData(Realm* realm, v8::Local<v8::Object> object);
155157
DISALLOW_COPY_AND_MOVE(BindingData)
@@ -179,6 +181,7 @@ class BindingData final
179181

180182
bool in_ngtcp2_callback_scope = false;
181183
bool in_nghttp3_callback_scope = false;
184+
size_t current_ngtcp2_memory_ = 0;
182185

183186
// The following set up various storage and accessors for common strings,
184187
// construction templates, and callbacks stored on the BindingData. These
@@ -205,8 +208,6 @@ class BindingData final
205208
QUIC_JS_CALLBACKS(V)
206209
#undef V
207210

208-
size_t current_ngtcp2_memory_ = 0;
209-
210211
#define V(name) v8::Global<v8::FunctionTemplate> name##_constructor_template_;
211212
QUIC_CONSTRUCTORS(V)
212213
#undef V
@@ -229,15 +230,15 @@ void IllegalConstructor(const v8::FunctionCallbackInfo<v8::Value>& args);
229230
// The ngtcp2 and nghttp3 callbacks have certain restrictions
230231
// that forbid re-entry. We provide the following scopes for
231232
// use in those to help protect against it.
232-
struct NgTcp2CallbackScope {
233+
struct NgTcp2CallbackScope final {
233234
Environment* env;
234235
explicit NgTcp2CallbackScope(Environment* env);
235236
DISALLOW_COPY_AND_MOVE(NgTcp2CallbackScope)
236237
~NgTcp2CallbackScope();
237238
static bool in_ngtcp2_callback(Environment* env);
238239
};
239240

240-
struct NgHttp3CallbackScope {
241+
struct NgHttp3CallbackScope final {
241242
Environment* env;
242243
explicit NgHttp3CallbackScope(Environment* env);
243244
DISALLOW_COPY_AND_MOVE(NgHttp3CallbackScope)
@@ -268,5 +269,4 @@ struct CallbackScope final : public CallbackScopeBase {
268269

269270
} // namespace node::quic
270271

271-
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
272272
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/quic/endpoint.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,14 +751,14 @@ void Endpoint::Send(const BaseObjectPtr<Packet>& packet) {
751751
// dropped. This can happen to any type of packet. We use this only in
752752
// testing to test various reliability issues.
753753
if (is_diagnostic_packet_loss(options_.tx_loss)) [[unlikely]] {
754-
packet->Done(0);
754+
packet->Done();
755755
// Simulating tx packet loss
756756
return;
757757
}
758758
#endif // DEBUG
759759

760760
if (is_closed() || is_closing() || packet->length() == 0) {
761-
packet->Done(UV_ECANCELED);
761+
packet->CancelPacket();
762762
return;
763763
}
764764
Debug(this, "Sending %s", packet->ToString());

src/quic/logstream.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
2-
1+
#if HAVE_OPENSSL
2+
#include "guard.h"
3+
#ifndef OPENSSL_NO_QUIC
34
#include "logstream.h"
45
#include <async_wrap-inl.h>
56
#include <base_object-inl.h>
@@ -149,4 +150,5 @@ void LogStream::ensure_space(size_t amt) {
149150
} // namespace quic
150151
} // namespace node
151152

152-
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
153+
#endif // OPENSSL_NO_QUIC
154+
#endif // HAVE_OPENSSL

src/quic/logstream.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#pragma once
22

33
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4-
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
54

65
#include <async_wrap.h>
76
#include <base_object.h>
87
#include <env.h>
98
#include <stream_base.h>
10-
#include <deque>
9+
#include <list>
1110

1211
namespace node::quic {
1312

1413
// The LogStream is a utility that the QUIC impl uses to publish both QLog
1514
// and Keylog diagnostic data (one instance for each).
16-
class LogStream : public AsyncWrap, public StreamBase {
15+
class LogStream final : public AsyncWrap, public StreamBase {
1716
public:
1817
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
1918
Environment* env);
@@ -22,7 +21,7 @@ class LogStream : public AsyncWrap, public StreamBase {
2221

2322
LogStream(Environment* env, v8::Local<v8::Object> obj);
2423

25-
enum class EmitOption {
24+
enum class EmitOption : uint8_t {
2625
NONE,
2726
FIN,
2827
};
@@ -61,10 +60,10 @@ class LogStream : public AsyncWrap, public StreamBase {
6160
uv_buf_t buf;
6261
};
6362
size_t total_ = 0;
63+
std::list<Chunk> buffer_;
6464
bool fin_seen_ = false;
6565
bool ended_ = false;
6666
bool reading_ = false;
67-
std::deque<Chunk> buffer_;
6867

6968
// The value here is fairly arbitrary. Once we get everything
7069
// fully implemented and start working with this, we might
@@ -77,5 +76,4 @@ class LogStream : public AsyncWrap, public StreamBase {
7776

7877
} // namespace node::quic
7978

80-
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
8179
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

0 commit comments

Comments
 (0)