Skip to content

Commit 76044c4

Browse files
authored
quic: add additional QUIC implementation
Adds most of the Endpoint implementation with a few tweaks to other bits. PR-URL: #47603 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 2ac5e98 commit 76044c4

11 files changed

+2004
-14
lines changed

src/async_wrap.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ namespace node {
6060
V(PROCESSWRAP) \
6161
V(PROMISE) \
6262
V(QUERYWRAP) \
63+
V(QUIC_ENDPOINT) \
6364
V(QUIC_LOGSTREAM) \
6465
V(QUIC_PACKET) \
66+
V(QUIC_UDP) \
6567
V(SHUTDOWNWRAP) \
6668
V(SIGNALWRAP) \
6769
V(STATWATCHER) \

src/quic/bindingdata.cc

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void BindingData::Initialize(Environment* env, Local<Object> target) {
6565

6666
void BindingData::RegisterExternalReferences(
6767
ExternalReferenceRegistry* registry) {
68+
registry->Register(IllegalConstructor);
6869
registry->Register(SetCallbacks);
6970
registry->Register(FlushPacketFreelist);
7071
}
@@ -199,6 +200,15 @@ bool NgHttp3CallbackScope::in_nghttp3_callback(Environment* env) {
199200
return binding.in_nghttp3_callback_scope;
200201
}
201202

203+
CallbackScopeBase::CallbackScopeBase(Environment* env)
204+
: env(env), context_scope(env->context()), try_catch(env->isolate()) {}
205+
206+
CallbackScopeBase::~CallbackScopeBase() {
207+
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
208+
errors::TriggerUncaughtException(env->isolate(), try_catch);
209+
}
210+
}
211+
202212
void IllegalConstructor(const FunctionCallbackInfo<Value>& args) {
203213
THROW_ERR_ILLEGAL_CONSTRUCTOR(Environment::GetCurrent(args));
204214
}

src/quic/bindingdata.h

+47-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <node.h>
1313
#include <node_mem.h>
1414
#include <v8.h>
15+
#include <limits>
16+
#include <unordered_map>
1517
#include <vector>
1618

1719
namespace node {
@@ -26,6 +28,9 @@ enum class Side {
2628
};
2729

2830
constexpr size_t kDefaultMaxPacketLength = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
31+
constexpr size_t kMaxSizeT = std::numeric_limits<size_t>::max();
32+
constexpr uint64_t kMaxSafeJsInteger = 9007199254740991;
33+
constexpr auto kSocketAddressInfoTimeout = 60 * NGTCP2_SECONDS;
2934

3035
// ============================================================================
3136

@@ -44,7 +49,6 @@ constexpr size_t kDefaultMaxPacketLength = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
4449
// internalBinding('quic') is first loaded.
4550
#define QUIC_JS_CALLBACKS(V) \
4651
V(endpoint_close, EndpointClose) \
47-
V(endpoint_error, EndpointError) \
4852
V(session_new, SessionNew) \
4953
V(session_close, SessionClose) \
5054
V(session_error, SessionError) \
@@ -66,12 +70,15 @@ constexpr size_t kDefaultMaxPacketLength = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
6670
#define QUIC_STRINGS(V) \
6771
V(ack_delay_exponent, "ackDelayExponent") \
6872
V(active_connection_id_limit, "activeConnectionIDLimit") \
73+
V(address_lru_size, "addressLRUSize") \
6974
V(alpn, "alpn") \
7075
V(ca, "ca") \
7176
V(certs, "certs") \
77+
V(cc_algorithm, "cc") \
7278
V(crl, "crl") \
7379
V(ciphers, "ciphers") \
7480
V(disable_active_migration, "disableActiveMigration") \
81+
V(disable_stateless_reset, "disableStatelessReset") \
7582
V(enable_tls_trace, "tlsTrace") \
7683
V(endpoint, "Endpoint") \
7784
V(endpoint_udp, "Endpoint::UDP") \
@@ -84,18 +91,35 @@ constexpr size_t kDefaultMaxPacketLength = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
8491
V(initial_max_stream_data_uni, "initialMaxStreamDataUni") \
8592
V(initial_max_streams_bidi, "initialMaxStreamsBidi") \
8693
V(initial_max_streams_uni, "initialMaxStreamsUni") \
94+
V(ipv6_only, "ipv6Only") \
8795
V(keylog, "keylog") \
8896
V(keys, "keys") \
8997
V(logstream, "LogStream") \
9098
V(max_ack_delay, "maxAckDelay") \
99+
V(max_connections_per_host, "maxConnectionsPerHost") \
100+
V(max_connections_total, "maxConnectionsTotal") \
91101
V(max_datagram_frame_size, "maxDatagramFrameSize") \
92102
V(max_idle_timeout, "maxIdleTimeout") \
103+
V(max_payload_size, "maxPayloadSize") \
104+
V(max_retries, "maxRetries") \
105+
V(max_stateless_resets, "maxStatelessResetsPerHost") \
93106
V(packetwrap, "PacketWrap") \
94107
V(reject_unauthorized, "rejectUnauthorized") \
108+
V(retry_token_expiration, "retryTokenExpiration") \
95109
V(request_peer_certificate, "requestPeerCertificate") \
110+
V(reset_token_secret, "resetTokenSecret") \
111+
V(rx_loss, "rxDiagnosticLoss") \
96112
V(session, "Session") \
97113
V(session_id_ctx, "sessionIDContext") \
98114
V(stream, "Stream") \
115+
V(token_expiration, "tokenExpiration") \
116+
V(token_secret, "tokenSecret") \
117+
V(tx_loss, "txDiagnosticLoss") \
118+
V(udp_receive_buffer_size, "udpReceiveBufferSize") \
119+
V(udp_send_buffer_size, "udpSendBufferSize") \
120+
V(udp_ttl, "udpTTL") \
121+
V(unacknowledged_packet_threshold, "unacknowledgedPacketThreshold") \
122+
V(validate_address, "validateAddress") \
99123
V(verify_hostname_identity, "verifyHostnameIdentity")
100124

101125
// =============================================================================
@@ -133,6 +157,8 @@ class BindingData final
133157

134158
std::vector<BaseObjectPtr<BaseObject>> packet_freelist;
135159

160+
std::unordered_map<Endpoint*, BaseObjectPtr<BaseObject>> listening_endpoints;
161+
136162
// Purge the packet free list to free up memory.
137163
static void FlushPacketFreelist(
138164
const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -203,6 +229,26 @@ struct NgHttp3CallbackScope {
203229
static bool in_nghttp3_callback(Environment* env);
204230
};
205231

232+
struct CallbackScopeBase {
233+
Environment* env;
234+
v8::Context::Scope context_scope;
235+
v8::TryCatch try_catch;
236+
237+
explicit CallbackScopeBase(Environment* env);
238+
CallbackScopeBase(const CallbackScopeBase&) = delete;
239+
CallbackScopeBase(CallbackScopeBase&&) = delete;
240+
CallbackScopeBase& operator=(const CallbackScopeBase&) = delete;
241+
CallbackScopeBase& operator=(CallbackScopeBase&&) = delete;
242+
~CallbackScopeBase();
243+
};
244+
245+
template <typename T>
246+
struct CallbackScope final : public CallbackScopeBase {
247+
BaseObjectPtr<T> ref;
248+
explicit CallbackScope(const T* ptr)
249+
: CallbackScopeBase(ptr->env()), ref(ptr) {}
250+
};
251+
206252
} // namespace quic
207253
} // namespace node
208254

src/quic/defs.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,20 @@ uint64_t GetStat(Stats* stats) {
9090
return stats->*member;
9191
}
9292

93-
#define STAT_INCREMENT(Type, name) IncrementStat<Type, &Type::name>(&stats_);
93+
#define STAT_INCREMENT(Type, name) \
94+
IncrementStat<Type, &Type::name>(stats_.Data());
9495
#define STAT_INCREMENT_N(Type, name, amt) \
95-
IncrementStat<Type, &Type::name>(&stats_, amt);
96+
IncrementStat<Type, &Type::name>(stats_.Data(), amt);
9697
#define STAT_RECORD_TIMESTAMP(Type, name) \
97-
RecordTimestampStat<Type, &Type::name>(&stats_);
98-
#define STAT_SET(Type, name, val) SetStat<Type, &Type::name>(&stats_, val);
99-
#define STAT_GET(Type, name) GetStat<Type, &Type::name>(&stats_);
98+
RecordTimestampStat<Type, &Type::name>(stats_.Data());
99+
#define STAT_SET(Type, name, val) \
100+
SetStat<Type, &Type::name>(stats_.Data(), val);
101+
#define STAT_GET(Type, name) GetStat<Type, &Type::name>(stats_.Data());
102+
#define STAT_FIELD(_, name) uint64_t name;
103+
#define STAT_STRUCT(name) \
104+
struct Stats final { \
105+
name##_STATS(STAT_FIELD) \
106+
};
100107

101108
} // namespace quic
102109
} // namespace node

0 commit comments

Comments
 (0)