mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
quic: update more of the quic to the new compile guard
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/59342 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
1 parent
ee7b8ab29c
commit
a6c5d27739
21 files changed
+240
-146
No files matched your search
@@ -185,8 +185,15 @@
|
||||
'src/udp_wrap.cc',
|
||||
'src/util.cc',
|
||||
'src/uv.cc',
|
||||
'src/quic/bindingdata.cc',
|
||||
'src/quic/cid.cc',
|
||||
'src/quic/data.cc',
|
||||
'src/quic/logstream.cc',
|
||||
'src/quic/packet.cc',
|
||||
'src/quic/preferredaddress.cc',
|
||||
'src/quic/sessionticket.cc',
|
||||
'src/quic/tokens.cc',
|
||||
# 'src/quic/transportparams.cc',
|
||||
# headers to make for a more pleasant IDE experience
|
||||
'src/aliased_buffer.h',
|
||||
'src/aliased_buffer-inl.h',
|
||||
@@ -323,9 +330,16 @@
|
||||
'src/udp_wrap.h',
|
||||
'src/util.h',
|
||||
'src/util-inl.h',
|
||||
'src/quic/bindingdata.h',
|
||||
'src/quic/cid.h',
|
||||
'src/quic/data.h',
|
||||
'src/quic/defs.h',
|
||||
'src/quic/logstream.h',
|
||||
'src/quic/packet.h',
|
||||
'src/quic/preferredaddress.h',
|
||||
'src/quic/sessionticket.h',
|
||||
'src/quic/tokens.h',
|
||||
# 'src/quic/transportparams.h',
|
||||
'src/quic/guard.h',
|
||||
],
|
||||
'node_crypto_sources': [
|
||||
@@ -390,31 +404,17 @@
|
||||
],
|
||||
'node_quic_sources': [
|
||||
'src/quic/application.cc',
|
||||
'src/quic/bindingdata.cc',
|
||||
'src/quic/endpoint.cc',
|
||||
'src/quic/http3.cc',
|
||||
'src/quic/logstream.cc',
|
||||
'src/quic/packet.cc',
|
||||
'src/quic/preferredaddress.cc',
|
||||
'src/quic/session.cc',
|
||||
'src/quic/sessionticket.cc',
|
||||
'src/quic/streams.cc',
|
||||
'src/quic/tlscontext.cc',
|
||||
'src/quic/tokens.cc',
|
||||
'src/quic/transportparams.cc',
|
||||
'src/quic/application.h',
|
||||
'src/quic/bindingdata.h',
|
||||
'src/quic/endpoint.h',
|
||||
'src/quic/http3.h',
|
||||
'src/quic/logstream.h',
|
||||
'src/quic/packet.h',
|
||||
'src/quic/preferredaddress.h',
|
||||
'src/quic/session.h',
|
||||
'src/quic/sessionticket.h',
|
||||
'src/quic/streams.h',
|
||||
'src/quic/tlscontext.h',
|
||||
'src/quic/tokens.h',
|
||||
'src/quic/transportparams.h',
|
||||
'src/quic/quic.cc',
|
||||
],
|
||||
'node_cctest_openssl_sources': [
|
||||
@@ -423,6 +423,7 @@
|
||||
'test/cctest/test_node_crypto_env.cc',
|
||||
'test/cctest/test_quic_cid.cc',
|
||||
'test/cctest/test_quic_error.cc',
|
||||
'test/cctest/test_quic_preferredaddress.cc',
|
||||
'test/cctest/test_quic_tokens.cc',
|
||||
],
|
||||
'node_cctest_inspector_sources': [
|
||||
|
||||
@@ -290,7 +290,7 @@ void Session::Application::SendPendingData() {
|
||||
// The stream_data is the next block of data from the application stream.
|
||||
if (GetStreamData(&stream_data) < 0) {
|
||||
Debug(session_, "Application failed to get stream data");
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
|
||||
return session_->Close(CloseMethod::SILENT);
|
||||
}
|
||||
@@ -357,7 +357,7 @@ void Session::Application::SendPendingData() {
|
||||
if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
|
||||
Debug(session_,
|
||||
"Failed to commit stream data while writing packets");
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();;
|
||||
session_->SetLastError(
|
||||
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
|
||||
return session_->Close(CloseMethod::SILENT);
|
||||
@@ -371,11 +371,11 @@ void Session::Application::SendPendingData() {
|
||||
Debug(session_,
|
||||
"Application encountered error while writing packet: %s",
|
||||
ngtcp2_strerror(nwrite));
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
session_->SetLastError(QuicError::ForNgtcp2Error(nwrite));
|
||||
return session_->Close(CloseMethod::SILENT);
|
||||
} else if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
|
||||
return session_->Close(CloseMethod::SILENT);
|
||||
}
|
||||
@@ -394,7 +394,7 @@ void Session::Application::SendPendingData() {
|
||||
packet->Truncate(datalen);
|
||||
session_->Send(packet, path);
|
||||
} else {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "bindingdata.h"
|
||||
#include <base_object-inl.h>
|
||||
#include <env-inl.h>
|
||||
@@ -49,10 +51,12 @@ void BindingData::CheckAllocatedSize(size_t previous_size) const {
|
||||
}
|
||||
|
||||
void BindingData::IncreaseAllocatedSize(size_t size) {
|
||||
CHECK_GE(current_ngtcp2_memory_ + size, current_ngtcp2_memory_);
|
||||
current_ngtcp2_memory_ += size;
|
||||
}
|
||||
|
||||
void BindingData::DecreaseAllocatedSize(size_t size) {
|
||||
CHECK_LE(current_ngtcp2_memory_ - size, current_ngtcp2_memory_);
|
||||
current_ngtcp2_memory_ -= size;
|
||||
}
|
||||
|
||||
@@ -220,4 +224,5 @@ void IllegalConstructor(const FunctionCallbackInfo<Value>& args) {
|
||||
} // namespace quic
|
||||
} // namespace node
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
+15
-15
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <base_object.h>
|
||||
#include <env.h>
|
||||
@@ -26,12 +25,12 @@ class Packet;
|
||||
// The FunctionTemplates the BindingData will store for us.
|
||||
#define QUIC_CONSTRUCTORS(V) \
|
||||
V(endpoint) \
|
||||
V(http3application) \
|
||||
V(logstream) \
|
||||
V(packet) \
|
||||
V(session) \
|
||||
V(stream) \
|
||||
V(udp) \
|
||||
V(http3application)
|
||||
V(udp)
|
||||
|
||||
// The callbacks are persistent v8::Function references that are set in the
|
||||
// quic::BindingState used to communicate data and events back out to the JS
|
||||
@@ -39,19 +38,19 @@ class Packet;
|
||||
// internalBinding('quic') is first loaded.
|
||||
#define QUIC_JS_CALLBACKS(V) \
|
||||
V(endpoint_close, EndpointClose) \
|
||||
V(session_new, SessionNew) \
|
||||
V(session_close, SessionClose) \
|
||||
V(session_datagram, SessionDatagram) \
|
||||
V(session_datagram_status, SessionDatagramStatus) \
|
||||
V(session_handshake, SessionHandshake) \
|
||||
V(session_new, SessionNew) \
|
||||
V(session_path_validation, SessionPathValidation) \
|
||||
V(session_ticket, SessionTicket) \
|
||||
V(session_version_negotiation, SessionVersionNegotiation) \
|
||||
V(session_path_validation, SessionPathValidation) \
|
||||
V(stream_blocked, StreamBlocked) \
|
||||
V(stream_close, StreamClose) \
|
||||
V(stream_created, StreamCreated) \
|
||||
V(stream_reset, StreamReset) \
|
||||
V(stream_headers, StreamHeaders) \
|
||||
V(stream_blocked, StreamBlocked) \
|
||||
V(stream_reset, StreamReset) \
|
||||
V(stream_trailers, StreamTrailers)
|
||||
|
||||
// The various JS strings the implementation uses.
|
||||
@@ -64,10 +63,10 @@ class Packet;
|
||||
V(application_provider, "provider") \
|
||||
V(bbr, "bbr") \
|
||||
V(ca, "ca") \
|
||||
V(certs, "certs") \
|
||||
V(cc_algorithm, "cc") \
|
||||
V(crl, "crl") \
|
||||
V(certs, "certs") \
|
||||
V(ciphers, "ciphers") \
|
||||
V(crl, "crl") \
|
||||
V(cubic, "cubic") \
|
||||
V(disable_stateless_reset, "disableStatelessReset") \
|
||||
V(enable_connect_protocol, "enableConnectProtocol") \
|
||||
@@ -114,8 +113,8 @@ class Packet;
|
||||
V(qpack_max_dtable_capacity, "qpackMaxDTableCapacity") \
|
||||
V(reject_unauthorized, "rejectUnauthorized") \
|
||||
V(reno, "reno") \
|
||||
V(retry_token_expiration, "retryTokenExpiration") \
|
||||
V(reset_token_secret, "resetTokenSecret") \
|
||||
V(retry_token_expiration, "retryTokenExpiration") \
|
||||
V(rx_loss, "rxDiagnosticLoss") \
|
||||
V(servername, "servername") \
|
||||
V(session, "Session") \
|
||||
@@ -150,6 +149,9 @@ class BindingData final
|
||||
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
||||
|
||||
static BindingData& Get(Environment* env);
|
||||
static inline BindingData& Get(Realm* realm) {
|
||||
return Get(realm->env());
|
||||
}
|
||||
|
||||
BindingData(Realm* realm, v8::Local<v8::Object> object);
|
||||
DISALLOW_COPY_AND_MOVE(BindingData)
|
||||
@@ -179,6 +181,7 @@ class BindingData final
|
||||
|
||||
bool in_ngtcp2_callback_scope = false;
|
||||
bool in_nghttp3_callback_scope = false;
|
||||
size_t current_ngtcp2_memory_ = 0;
|
||||
|
||||
// The following set up various storage and accessors for common strings,
|
||||
// construction templates, and callbacks stored on the BindingData. These
|
||||
@@ -205,8 +208,6 @@ class BindingData final
|
||||
QUIC_JS_CALLBACKS(V)
|
||||
#undef V
|
||||
|
||||
size_t current_ngtcp2_memory_ = 0;
|
||||
|
||||
#define V(name) v8::Global<v8::FunctionTemplate> name##_constructor_template_;
|
||||
QUIC_CONSTRUCTORS(V)
|
||||
#undef V
|
||||
@@ -229,7 +230,7 @@ void IllegalConstructor(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
// The ngtcp2 and nghttp3 callbacks have certain restrictions
|
||||
// that forbid re-entry. We provide the following scopes for
|
||||
// use in those to help protect against it.
|
||||
struct NgTcp2CallbackScope {
|
||||
struct NgTcp2CallbackScope final {
|
||||
Environment* env;
|
||||
explicit NgTcp2CallbackScope(Environment* env);
|
||||
DISALLOW_COPY_AND_MOVE(NgTcp2CallbackScope)
|
||||
@@ -237,7 +238,7 @@ struct NgTcp2CallbackScope {
|
||||
static bool in_ngtcp2_callback(Environment* env);
|
||||
};
|
||||
|
||||
struct NgHttp3CallbackScope {
|
||||
struct NgHttp3CallbackScope final {
|
||||
Environment* env;
|
||||
explicit NgHttp3CallbackScope(Environment* env);
|
||||
DISALLOW_COPY_AND_MOVE(NgHttp3CallbackScope)
|
||||
@@ -268,5 +269,4 @@ struct CallbackScope final : public CallbackScopeBase {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
@@ -751,14 +751,14 @@ void Endpoint::Send(const BaseObjectPtr<Packet>& packet) {
|
||||
// dropped. This can happen to any type of packet. We use this only in
|
||||
// testing to test various reliability issues.
|
||||
if (is_diagnostic_packet_loss(options_.tx_loss)) [[unlikely]] {
|
||||
packet->Done(0);
|
||||
packet->Done();
|
||||
// Simulating tx packet loss
|
||||
return;
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
if (is_closed() || is_closing() || packet->length() == 0) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return;
|
||||
}
|
||||
Debug(this, "Sending %s", packet->ToString());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "logstream.h"
|
||||
#include <async_wrap-inl.h>
|
||||
#include <base_object-inl.h>
|
||||
@@ -149,4 +150,5 @@ void LogStream::ensure_space(size_t amt) {
|
||||
} // namespace quic
|
||||
} // namespace node
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
@@ -1,19 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <async_wrap.h>
|
||||
#include <base_object.h>
|
||||
#include <env.h>
|
||||
#include <stream_base.h>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
|
||||
namespace node::quic {
|
||||
|
||||
// The LogStream is a utility that the QUIC impl uses to publish both QLog
|
||||
// and Keylog diagnostic data (one instance for each).
|
||||
class LogStream : public AsyncWrap, public StreamBase {
|
||||
class LogStream final : public AsyncWrap, public StreamBase {
|
||||
public:
|
||||
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
||||
Environment* env);
|
||||
@@ -22,7 +21,7 @@ class LogStream : public AsyncWrap, public StreamBase {
|
||||
|
||||
LogStream(Environment* env, v8::Local<v8::Object> obj);
|
||||
|
||||
enum class EmitOption {
|
||||
enum class EmitOption : uint8_t {
|
||||
NONE,
|
||||
FIN,
|
||||
};
|
||||
@@ -61,10 +60,10 @@ class LogStream : public AsyncWrap, public StreamBase {
|
||||
uv_buf_t buf;
|
||||
};
|
||||
size_t total_ = 0;
|
||||
std::list<Chunk> buffer_;
|
||||
bool fin_seen_ = false;
|
||||
bool ended_ = false;
|
||||
bool reading_ = false;
|
||||
std::deque<Chunk> buffer_;
|
||||
|
||||
// The value here is fairly arbitrary. Once we get everything
|
||||
// fully implemented and start working with this, we might
|
||||
@@ -77,5 +76,4 @@ class LogStream : public AsyncWrap, public StreamBase {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
+10
-8
@@ -1,5 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "packet.h"
|
||||
#include <base_object-inl.h>
|
||||
#include <crypto/crypto_util.h>
|
||||
@@ -260,7 +261,7 @@ BaseObjectPtr<Packet> Packet::CreateRetryPacket(
|
||||
vec.base,
|
||||
vec.len);
|
||||
if (nwrite <= 0) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return {};
|
||||
}
|
||||
packet->Truncate(static_cast<size_t>(nwrite));
|
||||
@@ -281,7 +282,7 @@ BaseObjectPtr<Packet> Packet::CreateConnectionClosePacket(
|
||||
ssize_t nwrite = ngtcp2_conn_write_connection_close(
|
||||
conn, nullptr, nullptr, vec.base, vec.len, error, uv_hrtime());
|
||||
if (nwrite < 0) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return {};
|
||||
}
|
||||
packet->Truncate(static_cast<size_t>(nwrite));
|
||||
@@ -312,7 +313,7 @@ BaseObjectPtr<Packet> Packet::CreateImmediateConnectionClosePacket(
|
||||
nullptr,
|
||||
0);
|
||||
if (nwrite <= 0) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return {};
|
||||
}
|
||||
packet->Truncate(static_cast<size_t>(nwrite));
|
||||
@@ -349,7 +350,7 @@ BaseObjectPtr<Packet> Packet::CreateStatelessResetPacket(
|
||||
ssize_t nwrite = ngtcp2_pkt_write_stateless_reset(
|
||||
vec.base, pktlen, token, random, kRandlen);
|
||||
if (nwrite <= static_cast<ssize_t>(kMinStatelessResetLen)) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -407,7 +408,7 @@ BaseObjectPtr<Packet> Packet::CreateVersionNegotiationPacket(
|
||||
sv,
|
||||
arraysize(sv));
|
||||
if (nwrite <= 0) {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return {};
|
||||
}
|
||||
packet->Truncate(static_cast<size_t>(nwrite));
|
||||
@@ -417,4 +418,5 @@ BaseObjectPtr<Packet> Packet::CreateVersionNegotiationPacket(
|
||||
} // namespace quic
|
||||
} // namespace node
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
+3
-4
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <base_object.h>
|
||||
#include <env.h>
|
||||
@@ -20,7 +19,7 @@
|
||||
|
||||
namespace node::quic {
|
||||
|
||||
struct PathDescriptor {
|
||||
struct PathDescriptor final {
|
||||
uint32_t version;
|
||||
const CID& dcid;
|
||||
const CID& scid;
|
||||
@@ -136,7 +135,8 @@ class Packet final : public ReqWrap<uv_udp_send_t> {
|
||||
const PathDescriptor& path_descriptor);
|
||||
|
||||
// Called when the packet is done being sent.
|
||||
void Done(int status);
|
||||
void Done(int status = 0);
|
||||
inline void CancelPacket() { Done(UV_ECANCELED); }
|
||||
|
||||
private:
|
||||
static BaseObjectPtr<Packet> FromFreeList(Environment* env,
|
||||
@@ -151,5 +151,4 @@ class Packet final : public ReqWrap<uv_udp_send_t> {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
@@ -1,7 +1,10 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "cid.h"
|
||||
#include "preferredaddress.h"
|
||||
#include <env-inl.h>
|
||||
#include <node_realm-inl.h>
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
#include <node_errors.h>
|
||||
#include <node_sockaddr-inl.h>
|
||||
@@ -14,8 +17,6 @@ namespace node {
|
||||
using v8::Just;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::Nothing;
|
||||
using v8::Uint32;
|
||||
using v8::Value;
|
||||
|
||||
namespace quic {
|
||||
@@ -24,21 +25,20 @@ namespace {
|
||||
template <int FAMILY>
|
||||
std::optional<const PreferredAddress::AddressInfo> get_address_info(
|
||||
const ngtcp2_preferred_addr& paddr) {
|
||||
PreferredAddress::AddressInfo address;
|
||||
address.family = FAMILY;
|
||||
if constexpr (FAMILY == AF_INET) {
|
||||
if (!paddr.ipv4_present) return std::nullopt;
|
||||
PreferredAddress::AddressInfo address;
|
||||
address.family = FAMILY;
|
||||
address.port = paddr.ipv4.sin_port;
|
||||
if (uv_inet_ntop(
|
||||
FAMILY, &paddr.ipv4.sin_addr, address.host, sizeof(address.host)) ==
|
||||
if (uv_inet_ntop(FAMILY,
|
||||
&paddr.ipv4.sin_addr,
|
||||
address.host,
|
||||
sizeof(address.host)) ==
|
||||
0) {
|
||||
address.address = address.host;
|
||||
}
|
||||
return address;
|
||||
} else {
|
||||
if (!paddr.ipv6_present) return std::nullopt;
|
||||
PreferredAddress::AddressInfo address;
|
||||
address.family = FAMILY;
|
||||
address.port = paddr.ipv6.sin6_port;
|
||||
if (uv_inet_ntop(FAMILY,
|
||||
&paddr.ipv6.sin6_addr,
|
||||
@@ -46,29 +46,22 @@ std::optional<const PreferredAddress::AddressInfo> get_address_info(
|
||||
sizeof(address.host)) == 0) {
|
||||
address.address = address.host;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
template <int FAMILY>
|
||||
void copy_to_transport_params(ngtcp2_transport_params* params,
|
||||
const sockaddr* addr) {
|
||||
params->preferred_addr_present = true;
|
||||
params->preferred_addr_present = 1;
|
||||
if constexpr (FAMILY == AF_INET) {
|
||||
const auto* src = reinterpret_cast<const sockaddr_in*>(addr);
|
||||
params->preferred_addr.ipv4.sin_port = SocketAddress::GetPort(addr);
|
||||
memcpy(¶ms->preferred_addr.ipv4.sin_addr,
|
||||
&src->sin_addr,
|
||||
sizeof(params->preferred_addr.ipv4.sin_addr));
|
||||
params->preferred_addr.ipv4_present = 1;
|
||||
memcpy(¶ms->preferred_addr.ipv4, addr, sizeof(sockaddr_in));
|
||||
} else {
|
||||
DCHECK_EQ(FAMILY, AF_INET6);
|
||||
const auto* src = reinterpret_cast<const sockaddr_in6*>(addr);
|
||||
params->preferred_addr.ipv6.sin6_port = SocketAddress::GetPort(addr);
|
||||
memcpy(¶ms->preferred_addr.ipv6.sin6_addr,
|
||||
&src->sin6_addr,
|
||||
sizeof(params->preferred_addr.ipv4.sin_addr));
|
||||
params->preferred_addr.ipv6_present = 1;
|
||||
memcpy(¶ms->preferred_addr.ipv6, addr, sizeof(sockaddr_in6));
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
bool resolve(const PreferredAddress::AddressInfo& address,
|
||||
@@ -85,13 +78,7 @@ bool resolve(const PreferredAddress::AddressInfo& address,
|
||||
req,
|
||||
nullptr,
|
||||
address.host,
|
||||
// TODO(@jasnell): The to_string here is not really
|
||||
// the most performant way of converting the uint16_t
|
||||
// port into a string. Depending on execution count,
|
||||
// the potential cost here could be mitigated with a
|
||||
// more efficient conversion. For now, however, this
|
||||
// works.
|
||||
std::to_string(address.port).c_str(),
|
||||
std::to_string(address.port).data(),
|
||||
&hints) == 0 &&
|
||||
req->addrinfo != nullptr;
|
||||
}
|
||||
@@ -144,30 +131,32 @@ void PreferredAddress::Set(ngtcp2_transport_params* params,
|
||||
|
||||
Maybe<PreferredAddress::Policy> PreferredAddress::tryGetPolicy(
|
||||
Environment* env, Local<Value> value) {
|
||||
if (value->IsUndefined()) {
|
||||
return Just(Policy::USE_PREFERRED);
|
||||
}
|
||||
if (value->IsUint32()) {
|
||||
switch (value.As<Uint32>()->Value()) {
|
||||
case PREFERRED_ADDRESS_IGNORE:
|
||||
return Just(Policy::IGNORE_PREFERRED);
|
||||
case PREFERRED_ADDRESS_USE:
|
||||
return Just(Policy::USE_PREFERRED);
|
||||
default:
|
||||
UNREACHABLE("Unreachable");
|
||||
}
|
||||
}
|
||||
THROW_ERR_INVALID_ARG_VALUE(env, "invalid preferred address policy");
|
||||
return Nothing<Policy>();
|
||||
return value->IsUndefined()
|
||||
? Just(Policy::USE_PREFERRED)
|
||||
: Just(FromV8Value<Policy>(value));
|
||||
}
|
||||
|
||||
void PreferredAddress::Initialize(Environment* env, Local<v8::Object> target) {
|
||||
// The QUIC_* constants are expected to be exported out to be used on
|
||||
// the JavaScript side of the API.
|
||||
static constexpr auto PREFERRED_ADDRESS_USE =
|
||||
static_cast<uint8_t>(Policy::USE_PREFERRED);
|
||||
static constexpr auto PREFERRED_ADDRESS_IGNORE =
|
||||
static_cast<uint8_t>(Policy::IGNORE_PREFERRED);
|
||||
static constexpr auto DEFAULT_PREFERRED_ADDRESS_POLICY =
|
||||
static_cast<uint8_t>(Policy::USE_PREFERRED);
|
||||
|
||||
NODE_DEFINE_CONSTANT(target, PREFERRED_ADDRESS_IGNORE);
|
||||
NODE_DEFINE_CONSTANT(target, PREFERRED_ADDRESS_USE);
|
||||
NODE_DEFINE_CONSTANT(target, DEFAULT_PREFERRED_ADDRESS_POLICY);
|
||||
}
|
||||
|
||||
const CID PreferredAddress::cid() const {
|
||||
return CID(&paddr_->cid);
|
||||
}
|
||||
|
||||
} // namespace quic
|
||||
} // namespace node
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
+14
-12
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <env.h>
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
#include <node_internals.h>
|
||||
#include <node_realm.h>
|
||||
#include <v8.h>
|
||||
#include <string>
|
||||
#include "defs.h"
|
||||
@@ -18,7 +18,7 @@ namespace node::quic {
|
||||
// the preferred address to be selected.
|
||||
class PreferredAddress final {
|
||||
public:
|
||||
enum class Policy : uint32_t {
|
||||
enum class Policy : uint8_t {
|
||||
// Ignore the server-advertised preferred address.
|
||||
IGNORE_PREFERRED,
|
||||
// Use the server-advertised preferred address.
|
||||
@@ -27,17 +27,16 @@ class PreferredAddress final {
|
||||
|
||||
static v8::Maybe<Policy> tryGetPolicy(Environment* env,
|
||||
v8::Local<v8::Value> value);
|
||||
|
||||
// The QUIC_* constants are expected to be exported out to be used on
|
||||
// the JavaScript side of the API.
|
||||
static constexpr auto PREFERRED_ADDRESS_USE =
|
||||
static_cast<uint32_t>(Policy::USE_PREFERRED);
|
||||
static constexpr auto PREFERRED_ADDRESS_IGNORE =
|
||||
static_cast<uint32_t>(Policy::IGNORE_PREFERRED);
|
||||
static constexpr auto DEFAULT_PREFERRED_ADDRESS_POLICY =
|
||||
static_cast<uint32_t>(Policy::USE_PREFERRED);
|
||||
static inline v8::Maybe<Policy> tryGetPolicy(Realm* realm,
|
||||
v8::Local<v8::Value> value) {
|
||||
return tryGetPolicy(realm->env(), value);
|
||||
}
|
||||
|
||||
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
||||
static inline void Initialize(Realm* realm,
|
||||
v8::Local<v8::Object> target) {
|
||||
return Initialize(realm->env(), target);
|
||||
}
|
||||
|
||||
struct AddressInfo final {
|
||||
char host[NI_MAXHOST];
|
||||
@@ -49,12 +48,16 @@ class PreferredAddress final {
|
||||
explicit PreferredAddress(ngtcp2_path* dest,
|
||||
const ngtcp2_preferred_addr* paddr);
|
||||
DISALLOW_COPY_AND_MOVE(PreferredAddress)
|
||||
void* operator new(size_t) = delete;
|
||||
void operator delete(void*) = delete;
|
||||
|
||||
void Use(const AddressInfo& address);
|
||||
|
||||
std::optional<const AddressInfo> ipv4() const;
|
||||
std::optional<const AddressInfo> ipv6() const;
|
||||
|
||||
const CID cid() const;
|
||||
|
||||
// Set the preferred address in the transport params.
|
||||
// The address family (ipv4 or ipv6) will be automatically
|
||||
// detected from the given addr. Any other address family
|
||||
@@ -68,5 +71,4 @@ class PreferredAddress final {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
+6
-6
@@ -1698,7 +1698,7 @@ void Session::Send(const BaseObjectPtr<Packet>& packet) {
|
||||
DCHECK(!is_in_draining_period());
|
||||
|
||||
if (!can_send_packets()) [[unlikely]] {
|
||||
return packet->Done(UV_ECANCELED);
|
||||
return packet->CancelPacket();
|
||||
}
|
||||
|
||||
Debug(this, "Session is sending %s", packet->ToString());
|
||||
@@ -1799,7 +1799,7 @@ uint64_t Session::SendDatagram(Store&& data) {
|
||||
// not fit. Since datagrams are best effort, we are going to abandon
|
||||
// the attempt and just return.
|
||||
CHECK_EQ(accepted, 0);
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return 0;
|
||||
}
|
||||
case NGTCP2_ERR_WRITE_MORE: {
|
||||
@@ -1809,13 +1809,13 @@ uint64_t Session::SendDatagram(Store&& data) {
|
||||
case NGTCP2_ERR_INVALID_STATE: {
|
||||
// The remote endpoint does not want to accept datagrams. That's ok,
|
||||
// just return 0.
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return 0;
|
||||
}
|
||||
case NGTCP2_ERR_INVALID_ARGUMENT: {
|
||||
// The datagram is too large. That should have been caught above but
|
||||
// that's ok. We'll just abandon the attempt and return.
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return 0;
|
||||
}
|
||||
case NGTCP2_ERR_PKT_NUM_EXHAUSTED: {
|
||||
@@ -1829,7 +1829,7 @@ uint64_t Session::SendDatagram(Store&& data) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
SetLastError(QuicError::ForTransport(nwrite));
|
||||
Close(CloseMethod::SILENT);
|
||||
return 0;
|
||||
@@ -2260,7 +2260,7 @@ void Session::SendConnectionClose() {
|
||||
uv_hrtime());
|
||||
|
||||
if (nwrite < 0) [[unlikely]] {
|
||||
packet->Done(UV_ECANCELED);
|
||||
packet->CancelPacket();
|
||||
return ErrorAndSilentClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "sessionticket.h"
|
||||
#include <env-inl.h>
|
||||
#include <memory_tracker-inl.h>
|
||||
@@ -44,7 +45,10 @@ Maybe<SessionTicket> SessionTicket::FromV8Value(Environment* env,
|
||||
return Nothing<SessionTicket>();
|
||||
}
|
||||
|
||||
Store content(value.As<ArrayBufferView>());
|
||||
auto view = value.As<ArrayBufferView>();
|
||||
Store content(view->Buffer()->GetBackingStore(),
|
||||
view->ByteLength(),
|
||||
view->ByteOffset());
|
||||
ngtcp2_vec vec = content;
|
||||
|
||||
ValueDeserializer des(env->isolate(), vec.base, vec.len);
|
||||
@@ -76,8 +80,16 @@ Maybe<SessionTicket> SessionTicket::FromV8Value(Environment* env,
|
||||
return Nothing<SessionTicket>();
|
||||
}
|
||||
|
||||
return Just(SessionTicket(Store(ticket.As<ArrayBufferView>()),
|
||||
Store(transport_params.As<ArrayBufferView>())));
|
||||
auto ticketview = ticket.As<ArrayBufferView>();
|
||||
auto transport_params_view = transport_params.As<ArrayBufferView>();
|
||||
|
||||
return Just(SessionTicket(
|
||||
Store(ticketview->Buffer()->GetBackingStore(),
|
||||
ticketview->ByteLength(),
|
||||
ticketview->ByteOffset()),
|
||||
Store(transport_params_view->Buffer()->GetBackingStore(),
|
||||
transport_params_view->ByteLength(),
|
||||
transport_params_view->ByteOffset())));
|
||||
}
|
||||
|
||||
MaybeLocal<Object> SessionTicket::encode(Environment* env) const {
|
||||
@@ -172,4 +184,5 @@ SessionTicket::AppData::Status SessionTicket::AppData::Extract(SSL* ssl) {
|
||||
} // namespace quic
|
||||
} // namespace node
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <crypto/crypto_common.h>
|
||||
#include <env.h>
|
||||
@@ -104,5 +103,4 @@ class SessionTicket::AppData final {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
+5
-3
@@ -1,5 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "tokens.h"
|
||||
#include <crypto/crypto_util.h>
|
||||
#include <ngtcp2/ngtcp2_crypto.h>
|
||||
@@ -301,4 +302,5 @@ RegularToken::operator const char*() const {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <memory_tracker.h>
|
||||
#include <ngtcp2/ngtcp2_crypto.h>
|
||||
@@ -252,5 +251,4 @@ class RegularToken final : public MemoryRetainer {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
@@ -1,5 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
#include "guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include "transportparams.h"
|
||||
#include <env-inl.h>
|
||||
#include <memory_tracker-inl.h>
|
||||
@@ -291,4 +292,5 @@ void TransportParams::Initialize(Environment* env, Local<Object> target) {
|
||||
} // namespace quic
|
||||
} // namespace node
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
|
||||
#include <env.h>
|
||||
#include <memory_tracker.h>
|
||||
@@ -162,5 +161,4 @@ class TransportParams final {
|
||||
|
||||
} // namespace node::quic
|
||||
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
@@ -113,8 +113,6 @@ TEST(QuicError, InternalError) {
|
||||
CHECK_EQ(err.type(), QuicError::Type::TRANSPORT);
|
||||
CHECK_EQ(err.reason(), "a reason");
|
||||
CHECK_EQ(err.ToString(), "QuicError(transport) 1: a reason");
|
||||
|
||||
printf("%s\n", QuicError::INTERNAL_ERROR.ToString().c_str());
|
||||
CHECK_EQ(err, QuicError::INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#if HAVE_OPENSSL
|
||||
#include "quic/guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include <env-inl.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
#include <node_sockaddr-inl.h>
|
||||
#include <quic/cid.h>
|
||||
#include <quic/data.h>
|
||||
#include <quic/preferredaddress.h>
|
||||
#include <util-inl.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using node::quic::CID;
|
||||
using node::quic::Path;
|
||||
using node::quic::PreferredAddress;
|
||||
using node::SocketAddress;
|
||||
|
||||
TEST(PreferredAddress, Basic) {
|
||||
const auto cid = CID::Factory::random().Generate();
|
||||
ngtcp2_preferred_addr paddr;
|
||||
paddr.cid = cid;
|
||||
|
||||
sockaddr_storage storage;
|
||||
sockaddr_storage storage6;
|
||||
SocketAddress::ToSockAddr(AF_INET, "123.123.123.123", 443, &storage);
|
||||
SocketAddress::ToSockAddr(AF_INET6, "2001:db8::1", 123, &storage6);
|
||||
|
||||
memcpy(&paddr.ipv4, &storage, sizeof(sockaddr_in));
|
||||
paddr.ipv4.sin_family = AF_INET;
|
||||
paddr.ipv4_present = 1;
|
||||
paddr.ipv6_present = 0;
|
||||
|
||||
sockaddr_storage storage1;
|
||||
sockaddr_storage storage2;
|
||||
SocketAddress::ToSockAddr(AF_INET, "123.123.123.123", 443, &storage1);
|
||||
SocketAddress::ToSockAddr(AF_INET, "123.123.123.124", 443, &storage2);
|
||||
SocketAddress addr1(reinterpret_cast<const sockaddr*>(&storage1));
|
||||
SocketAddress addr2(reinterpret_cast<const sockaddr*>(&storage2));
|
||||
Path path(addr1, addr2);
|
||||
|
||||
PreferredAddress preferred_address(&path, &paddr);
|
||||
|
||||
CHECK_EQ(preferred_address.ipv4().has_value(), true);
|
||||
CHECK_EQ(preferred_address.ipv6().has_value(), false);
|
||||
|
||||
const auto ipv4 = preferred_address.ipv4().value();
|
||||
CHECK_EQ(ipv4.family, AF_INET);
|
||||
CHECK_EQ(htons(ipv4.port), 443);
|
||||
CHECK_EQ(ipv4.address, "123.123.123.123");
|
||||
|
||||
memcpy(&paddr.ipv6, &storage6, sizeof(sockaddr_in6));
|
||||
paddr.ipv6_present = 1;
|
||||
|
||||
CHECK_EQ(preferred_address.ipv6().has_value(), true);
|
||||
const auto ipv6 = preferred_address.ipv6().value();
|
||||
CHECK_EQ(ipv6.family, AF_INET6);
|
||||
CHECK_EQ(htons(ipv6.port), 123);
|
||||
CHECK_EQ(ipv6.address, "2001:db8::1");
|
||||
|
||||
CHECK_EQ(preferred_address.cid(), cid);
|
||||
}
|
||||
|
||||
TEST(PreferredAddress, SetTransportParams) {
|
||||
sockaddr_storage storage1;
|
||||
SocketAddress::ToSockAddr(AF_INET, "123.123.123.123", 443, &storage1);
|
||||
SocketAddress addr1(reinterpret_cast<const sockaddr*>(&storage1));
|
||||
Path path(addr1, addr1);
|
||||
ngtcp2_transport_params params;
|
||||
ngtcp2_transport_params_default(¶ms);
|
||||
PreferredAddress::Set(¶ms, addr1.data());
|
||||
|
||||
CHECK_EQ(params.preferred_addr_present, 1);
|
||||
|
||||
PreferredAddress paddr2(&path, ¶ms.preferred_addr);
|
||||
CHECK_EQ(paddr2.ipv4().has_value(), true);
|
||||
const auto ipv4_2 = paddr2.ipv4().value();
|
||||
CHECK_EQ(ipv4_2.family, AF_INET);
|
||||
CHECK_EQ(htons(ipv4_2.port), 443);
|
||||
CHECK_EQ(ipv4_2.address, "123.123.123.123");
|
||||
}
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
@@ -1,4 +1,6 @@
|
||||
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#if HAVE_OPENSSL
|
||||
#include "quic/guard.h"
|
||||
#ifndef OPENSSL_NO_QUIC
|
||||
#include <gtest/gtest.h>
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
#include <node_sockaddr-inl.h>
|
||||
@@ -166,4 +168,5 @@ TEST(RegularToken, Basic) {
|
||||
|
||||
CHECK(!token.Validate(NGTCP2_PROTO_VER_MAX, address, secret, 10000000000));
|
||||
}
|
||||
#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
|
||||
#endif // OPENSSL_NO_QUIC
|
||||
#endif // HAVE_OPENSSL
|
||||
Reference in new issue
Block a user