From 65f213b0dc3a94579ccdfdf64c46c5a3daa16b02 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 9 May 2023 10:20:30 -0700 Subject: [PATCH] quic: hopefully fixup windows build issues --- src/quic/application.cc | 5 ++--- src/quic/bindingdata.h | 2 +- src/quic/endpoint.cc | 4 ++-- src/quic/endpoint.h | 2 +- src/quic/session.cc | 16 +++++++++++++--- src/quic/session.h | 14 +++++++++----- src/quic/tlscontext.cc | 14 ++------------ test/sequential/test-async-wrap-getasyncid.js | 2 ++ 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/quic/application.cc b/src/quic/application.cc index 5924fc3b4899e7..b949a7fa99cf12 100644 --- a/src/quic/application.cc +++ b/src/quic/application.cc @@ -3,6 +3,7 @@ #include "application.h" #include #include +#include "defs.h" #include "endpoint.h" #include "packet.h" #include "session.h" @@ -378,9 +379,7 @@ class DefaultApplication final : public Session::Application { return i == cnt; }; - if (!stream_data.stream || !is_empty(stream_data.buf, stream_data.count)) - return false; - return true; + return stream_data.stream && is_empty(stream_data.buf, stream_data.count); } bool StreamCommit(StreamData* stream_data, size_t datalen) override { diff --git a/src/quic/bindingdata.h b/src/quic/bindingdata.h index 4468d29b750583..2b33642b7ad76a 100644 --- a/src/quic/bindingdata.h +++ b/src/quic/bindingdata.h @@ -149,7 +149,7 @@ constexpr size_t kMaxVectorCount = 16; V(max_connections_total, "maxConnectionsTotal") \ V(max_datagram_frame_size, "maxDatagramFrameSize") \ V(max_field_section_size, "maxFieldSectionSize") \ - V(max_header_length, "maxHeaderLength"); \ + V(max_header_length, "maxHeaderLength") \ V(max_header_pairs, "maxHeaderPairs") \ V(max_idle_timeout, "maxIdleTimeout") \ V(max_payload_size, "maxPayloadSize") \ diff --git a/src/quic/endpoint.cc b/src/quic/endpoint.cc index 6f8a8e20e029b4..bc47cfb26be9e2 100644 --- a/src/quic/endpoint.cc +++ b/src/quic/endpoint.cc @@ -298,7 +298,7 @@ class Endpoint::UDP::Impl final : public HandleWrap { return; } - impl->endpoint_->Receive(uv_buf_t{buf->base, static_cast(nread)}, + impl->endpoint_->Receive(uv_buf_init(buf->base, static_cast(nread)), SocketAddress(addr)); } @@ -459,7 +459,7 @@ void Endpoint::Initialize(Environment* env, Local target) { #undef V #define V(name, key, __) \ - auto IDX_STATE_ENDPOINT_##name = OffsetOf(&Endpoint::State::key); + auto IDX_STATE_ENDPOINT_##name = offsetof(Endpoint::State, key); ENDPOINT_STATE(V) #undef V diff --git a/src/quic/endpoint.h b/src/quic/endpoint.h index 97259aaa09c4c3..700630c2244420 100644 --- a/src/quic/endpoint.h +++ b/src/quic/endpoint.h @@ -268,10 +268,10 @@ class Endpoint final : public AsyncWrap, public Packet::Listener { SET_MEMORY_INFO_NAME(Endpoint) SET_SELF_SIZE(Endpoint) - private: struct Stats; struct State; + private: class UDP final : public MemoryRetainer { public: explicit UDP(Endpoint* endpoint); diff --git a/src/quic/session.cc b/src/quic/session.cc index 77bb6d107bf4de..4754d4cc9960eb 100644 --- a/src/quic/session.cc +++ b/src/quic/session.cc @@ -68,6 +68,7 @@ namespace quic { V(DESTROYED, destroyed, uint8_t) \ V(HANDSHAKE_COMPLETED, handshake_completed, uint8_t) \ V(HANDSHAKE_CONFIRMED, handshake_confirmed, uint8_t) \ + V(STREAM_OPEN_ALLOWED, stream_open_allowed, uint8_t) \ /* A Session is wrapped if it has been passed out to JS */ \ V(WRAPPED, wrapped, uint8_t) \ V(LAST_DATAGRAM_ID, last_datagram_id, uint64_t) @@ -1002,6 +1003,15 @@ bool Session::is_in_draining_period() const { return ngtcp2_conn_is_in_draining_period(*this); } +bool Session::wants_session_ticket() const { + return state_->session_ticket == 1; +} + +void Session::SetStreamOpenAllowed() { + // TODO(@jasnell): Might remove this. May not be needed + state_->stream_open_allowed = 1; +} + bool Session::can_send_packets() const { // We can send packets if we're not in the middle of a ngtcp2 callback, // we're not destroyed, we're not in a draining or closing period, and @@ -1273,7 +1283,7 @@ void Session::SelectPreferredAddress(PreferredAddress* preferredAddress) { switch (family) { case AF_INET: { auto ipv4 = preferredAddress->ipv4(); - if (ipv4 != std::nullopt) { + if (ipv4.has_value()) { if (ipv4->address.empty() || ipv4->port == 0) return; SocketAddress::New(AF_INET, std::string(ipv4->address).c_str(), @@ -1285,7 +1295,7 @@ void Session::SelectPreferredAddress(PreferredAddress* preferredAddress) { } case AF_INET6: { auto ipv6 = preferredAddress->ipv6(); - if (ipv6 != std::nullopt) { + if (ipv6.has_value()) { if (ipv6->address.empty() || ipv6->port == 0) return; SocketAddress::New(AF_INET, std::string(ipv6->address).c_str(), @@ -2133,7 +2143,7 @@ void Session::Initialize(Environment* env, Local target) { #undef V #define V(name, key, __) \ - auto IDX_STATE_SESSION_##name = OffsetOf(&Session::State::key); + auto IDX_STATE_SESSION_##name = offsetof(Session::State, key); SESSION_STATE(V) #undef V diff --git a/src/quic/session.h b/src/quic/session.h index 21c03096bb66b4..21af8d801d550e 100644 --- a/src/quic/session.h +++ b/src/quic/session.h @@ -68,9 +68,9 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source { // HTTP/3 specific options. uint64_t max_field_section_size = 0; - size_t qpack_max_dtable_capacity = 0; - size_t qpack_encoder_max_dtable_capacity = 0; - size_t qpack_blocked_streams = 0; + uint64_t qpack_max_dtable_capacity = 0; + uint64_t qpack_encoder_max_dtable_capacity = 0; + uint64_t qpack_blocked_streams = 0; SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(Application::Options) @@ -225,11 +225,12 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source { SET_MEMORY_INFO_NAME(Session) SET_SELF_SIZE(Session) + struct State; + struct Stats; + private: struct Impl; struct MaybeCloseConnectionScope; - struct State; - struct Stats; using StreamsMap = std::unordered_map>; using QuicConnectionPointer = DeleteFnPtr; @@ -327,6 +328,9 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source { BaseObjectPtr qlog() const; BaseObjectPtr keylog() const; + bool wants_session_ticket() const; + void SetStreamOpenAllowed(); + void set_wrapped(); void DoClose(bool silent = false); diff --git a/src/quic/tlscontext.cc b/src/quic/tlscontext.cc index 4a2ed371a3bdcb..171f6e1d259bc7 100644 --- a/src/quic/tlscontext.cc +++ b/src/quic/tlscontext.cc @@ -7,10 +7,12 @@ #include #include #include +#include #include #include #include "bindingdata.h" #include "defs.h" +#include "session.h" #include "transportparams.h" namespace node { @@ -29,18 +31,6 @@ namespace quic { const TLSContext::Options TLSContext::Options::kDefault = {}; -// TODO(@jasnell): This session class is just a placeholder. -// The real session impl will be added in a separate commit. -class Session { - public: - operator ngtcp2_conn*() { return nullptr; } - void EmitKeylog(const char* line) const {} - void EmitSessionTicket(Store&& store) {} - void SetStreamOpenAllowed() {} - bool is_destroyed() const { return false; } - bool wants_session_ticket() const { return false; } -}; - namespace { constexpr size_t kMaxAlpnLen = 255; diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 33a5bc1ed91a5e..eb5bf1453683a9 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -70,6 +70,8 @@ const { getSystemErrorName } = require('util'); delete providers.QUIC_PACKET; delete providers.QUIC_UDP; delete providers.QUIC_ENDPOINT; + delete providers.QUIC_SESSION; + delete providers.QUIC_STREAM; const objKeys = Object.keys(providers); if (objKeys.length > 0)