Skip to content

Commit

Permalink
quic: hopefully fixup windows build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed May 10, 2023
1 parent ee923ac commit 30c8a6f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/quic/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "application.h"
#include <node_sockaddr-inl.h>
#include <v8.h>
#include "defs.h"
#include "endpoint.h"
#include "packet.h"
#include "session.h"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/quic/bindingdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand Down
4 changes: 2 additions & 2 deletions src/quic/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class Endpoint::UDP::Impl final : public HandleWrap {
return;
}

impl->endpoint_->Receive(uv_buf_t{buf->base, static_cast<size_t>(nread)},
impl->endpoint_->Receive(uv_buf_init(buf->base, static_cast<size_t>(nread)),
SocketAddress(addr));
}

Expand Down Expand Up @@ -459,7 +459,7 @@ void Endpoint::Initialize(Environment* env, Local<Object> 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

Expand Down
2 changes: 1 addition & 1 deletion src/quic/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 13 additions & 3 deletions src/quic/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -2133,7 +2143,7 @@ void Session::Initialize(Environment* env, Local<Object> 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

Expand Down
14 changes: 9 additions & 5 deletions src/quic/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<int64_t, BaseObjectPtr<Stream>>;
using QuicConnectionPointer = DeleteFnPtr<ngtcp2_conn, ngtcp2_conn_del>;
Expand Down Expand Up @@ -327,6 +328,9 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
BaseObjectPtr<LogStream> qlog() const;
BaseObjectPtr<LogStream> keylog() const;

bool wants_session_ticket() const;
void SetStreamOpenAllowed();

void set_wrapped();

void DoClose(bool silent = false);
Expand Down
4 changes: 3 additions & 1 deletion src/quic/streams.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
#include "streams.h"

#include <async_wrap-inl.h>
#include <base_object-inl.h>
#include <env-inl.h>
Expand Down Expand Up @@ -59,3 +59,5 @@ void Stream::Unschedule() {}

} // namespace quic
} // namespace node

#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
14 changes: 2 additions & 12 deletions src/quic/tlscontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include <ngtcp2/ngtcp2.h>
#include <ngtcp2/ngtcp2_crypto.h>
#include <ngtcp2/ngtcp2_crypto_openssl.h>
#include <node_sockaddr-inl.h>
#include <openssl/ssl.h>
#include <v8.h>
#include "bindingdata.h"
#include "defs.h"
#include "session.h"
#include "transportparams.h"

namespace node {
Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 30c8a6f

Please sign in to comment.