Skip to content

Commit

Permalink
quic: fixup linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jan 7, 2024
1 parent 399b1a2 commit 9cb015e
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 71 deletions.
47 changes: 25 additions & 22 deletions src/quic/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "application.h"
#include <async_wrap-inl.h>
#include <debug_utils-inl.h>
#include <ngtcp2/ngtcp2.h>
#include <node_bob.h>
#include <node_sockaddr-inl.h>
#include <ngtcp2/ngtcp2.h>
#include <uv.h>
#include <v8.h>
#include "defs.h"
Expand Down Expand Up @@ -246,8 +246,7 @@ void Session::Application::SendPendingData() {

// The maximum number of packets to send in this call to SendPendingData.
const size_t max_packet_count = std::min(
kMaxPackets,
ngtcp2_conn_get_send_quantum(*session_) / max_packet_size);
kMaxPackets, ngtcp2_conn_get_send_quantum(*session_) / max_packet_size);

// The number of packets that have been sent in this call to SendPendingData.
size_t packet_send_count = 0;
Expand Down Expand Up @@ -295,11 +294,12 @@ void Session::Application::SendPendingData() {
Debug(session_, "Application using stream data: %s", stream_data);

// Awesome, let's write our packet!
ssize_t nwrite = WriteVStream(&path, pos, &ndatalen, max_packet_size, stream_data);
ssize_t nwrite =
WriteVStream(&path, pos, &ndatalen, max_packet_size, stream_data);
Debug(session_, "Application accepted %zu bytes into packet", ndatalen);

// A negative nwrite value indicates either an error or that there is more data
// to write into the packet.
// A negative nwrite value indicates either an error or that there is more
// data to write into the packet.
if (nwrite < 0) {
switch (nwrite) {
case NGTCP2_ERR_STREAM_DATA_BLOCKED: {
Expand All @@ -317,7 +317,8 @@ void Session::Application::SendPendingData() {
// Indicates that the writable side of the stream should be closed
// locally or the stream is being reset. In either case, we can't send
// any stream data!
Debug(session_, "Stream %" PRIi64 " should be closed for writing",
Debug(session_,
"Stream %" PRIi64 " should be closed for writing",
stream_data.id);
// ndatalen = -1 means that no stream data was accepted into the
// packet, which is what we want here.
Expand All @@ -341,7 +342,8 @@ void Session::Application::SendPendingData() {

// Some other type of error happened.
DCHECK_EQ(ndatalen, -1);
Debug(session_, "Application encountered error while writing packet: %s",
Debug(session_,
"Application encountered error while writing packet: %s",
ngtcp2_strerror(nwrite));
session_->SetLastError(QuicError::ForNgtcp2Error(nwrite));
packet->Done(UV_ECANCELED);
Expand All @@ -363,14 +365,16 @@ void Session::Application::SendPendingData() {
size_t datalen = pos - begin;
if (datalen) {
Debug(session_, "Packet has %zu bytes to send", datalen);
// At least some data had been written into the packet. We should send it.
// At least some data had been written into the packet. We should send
// it.
packet->Truncate(datalen);
session_->Send(packet, path);
} else {
packet->Done(UV_ECANCELED);
}

// If there was stream data selected, we should reschedule it to try sending again.
// If there was stream data selected, we should reschedule it to try
// sending again.
if (stream_data.id >= 0) ResumeStream(stream_data.id);

return session_->UpdatePacketTxTime();
Expand Down Expand Up @@ -403,18 +407,17 @@ ssize_t Session::Application::WriteVStream(PathStorage* path,
uint32_t flags = NGTCP2_WRITE_STREAM_FLAG_MORE;
if (stream_data.fin) flags |= NGTCP2_WRITE_STREAM_FLAG_FIN;
ngtcp2_pkt_info pi;
return ngtcp2_conn_writev_stream(
*session_,
&path->path,
&pi,
dest,
max_packet_size,
ndatalen,
flags,
stream_data.id,
stream_data.buf,
stream_data.count,
uv_hrtime());
return ngtcp2_conn_writev_stream(*session_,
&path->path,
&pi,
dest,
max_packet_size,
ndatalen,
flags,
stream_data.id,
stream_data.buf,
stream_data.count,
uv_hrtime());
}

// The DefaultApplication is the default implementation of Session::Application
Expand Down
2 changes: 1 addition & 1 deletion src/quic/cid.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "quic/defs.h"
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
#include "cid.h"
#include <crypto/crypto_util.h>
#include <memory_tracker-inl.h>
#include <node_mutex.h>
#include <string_bytes.h>
#include "quic/defs.h"

namespace node {
namespace quic {
Expand Down
11 changes: 5 additions & 6 deletions src/quic/data.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "nghttp3/nghttp3.h"
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC

#include "data.h"
Expand Down Expand Up @@ -48,7 +47,9 @@ std::string Path::ToString() const {
return res;
}

PathStorage::PathStorage() { Reset(); }
PathStorage::PathStorage() {
Reset();
}
PathStorage::operator ngtcp2_path() {
return path;
}
Expand Down Expand Up @@ -281,16 +282,14 @@ void QuicError::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackField("reason", reason_.length());
}

QuicError QuicError::ForTransport(error_code code,
std::string reason) {
QuicError QuicError::ForTransport(error_code code, std::string reason) {
QuicError error(std::move(reason));
ngtcp2_ccerr_set_transport_error(
&error.error_, code, error.reason_c_str(), reason.length());
return error;
}

QuicError QuicError::ForApplication(error_code code,
std::string reason) {
QuicError QuicError::ForApplication(error_code code, std::string reason) {
QuicError error(std::move(reason));
ngtcp2_ccerr_set_application_error(
&error.error_, code, error.reason_c_str(), reason.length());
Expand Down
6 changes: 2 additions & 4 deletions src/quic/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ class QuicError final : public MemoryRetainer {
static error_code liberr_to_code(int liberr);
static error_code h3_liberr_to_code(int liberr);

static QuicError ForTransport(error_code code,
std::string reason = "");
static QuicError ForApplication(error_code code,
std::string reason = "");
static QuicError ForTransport(error_code code, std::string reason = "");
static QuicError ForApplication(error_code code, std::string reason = "");
static QuicError ForVersionNegotiation(std::string reason = "");
static QuicError ForIdleClose(std::string reason = "");
static QuicError ForNgtcp2Error(int code, std::string reason = "");
Expand Down
4 changes: 2 additions & 2 deletions src/quic/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <aliased_struct.h>
#include <env.h>
#include <node_errors.h>
#include <ngtcp2/ngtcp2.h>
#include <nghttp3/nghttp3.h>
#include <ngtcp2/ngtcp2.h>
#include <node_errors.h>
#include <uv.h>
#include <v8.h>
#include <limits>
Expand Down
6 changes: 4 additions & 2 deletions src/quic/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ std::string Endpoint::Options::ToString() const {

auto ccalg = ([&] {
switch (cc_algorithm) {
#define V(name, label) case NGTCP2_CC_ALGO_##name: return #label;
#define V(name, label) \
case NGTCP2_CC_ALGO_##name: \
return #label;
ENDPOINT_CC(V)
#undef V
}
Expand Down Expand Up @@ -615,7 +617,7 @@ void Endpoint::InitPerIsolate(IsolateData* data, Local<ObjectTemplate> target) {

void Endpoint::InitPerContext(Realm* realm, Local<Object> target) {
#define V(name, str) \
NODE_DEFINE_CONSTANT(target, CC_ALGO_##name); \
NODE_DEFINE_CONSTANT(target, CC_ALGO_##name); \
NODE_DEFINE_STRING_CONSTANT(target, "CC_ALGO_" #name "_STR", #str);
ENDPOINT_CC(V)
#undef V
Expand Down
3 changes: 1 addition & 2 deletions src/quic/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Endpoint final : public AsyncWrap, public Packet::Listener {
static constexpr uint64_t DEFAULT_MAX_STATELESS_RESETS = 10;
static constexpr uint64_t DEFAULT_MAX_RETRY_LIMIT = 10;

#define V(name, _) \
static constexpr auto CC_ALGO_##name = NGTCP2_CC_ALGO_##name;
#define V(name, _) static constexpr auto CC_ALGO_##name = NGTCP2_CC_ALGO_##name;
ENDPOINT_CC(V)
#undef V

Expand Down
2 changes: 1 addition & 1 deletion src/quic/http3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class Http3Application final : public Session::Application {
}
}
}
DCHECK_NOT_NULL(stream_data.buf);
DCHECK_NOT_NULL(data->buf);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/quic/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Packet final : public ReqWrap<uv_udp_send_t> {
const SocketAddress& destination,
std::shared_ptr<Data> data);

DISALLOW_COPY_AND_MOVE(Packet);
DISALLOW_COPY_AND_MOVE(Packet)

const SocketAddress& destination() const;
size_t length() const;
Expand Down
8 changes: 5 additions & 3 deletions src/quic/preferredaddress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ Maybe<PreferredAddress::Policy> PreferredAddress::tryGetPolicy(
return Just(PreferredAddress::Policy::USE);
}
if (value->IsUint32()) {
switch(value.As<Uint32>()->Value()) {
case PREFERRED_ADDRESS_IGNORE: return Just(Policy::IGNORE);
case PREFERRED_ADDRESS_USE: return Just(Policy::USE);
switch (value.As<Uint32>()->Value()) {
case PREFERRED_ADDRESS_IGNORE:
return Just(Policy::IGNORE);
case PREFERRED_ADDRESS_USE:
return Just(Policy::USE);
}
}
THROW_ERR_INVALID_ARG_VALUE(env, "invalid preferred address policy");
Expand Down
22 changes: 11 additions & 11 deletions src/quic/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ bool SetOption(Environment* env,
const v8::Local<Object>& object,
const v8::Local<String>& name) {
Local<Value> value;
PreferredAddress::Policy policy =
PreferredAddress::Policy::USE;
PreferredAddress::Policy policy = PreferredAddress::Policy::USE;
if (!object->Get(env->context(), name).ToLocal(&value) ||
!PreferredAddress::tryGetPolicy(env, value).To(&policy)) {
return false;
Expand Down Expand Up @@ -472,10 +471,11 @@ bool Session::HasInstance(Environment* env, Local<Value> value) {
return GetConstructorTemplate(env)->HasInstance(value);
}

BaseObjectPtr<Session> Session::Create(Endpoint* endpoint,
const Config& config,
TLSContext* tls_context,
std::optional<SessionTicket>& ticket) {
BaseObjectPtr<Session> Session::Create(
Endpoint* endpoint,
const Config& config,
TLSContext* tls_context,
const std::optional<SessionTicket>& ticket) {
Local<Object> obj;
if (!GetConstructorTemplate(endpoint->env())
->InstanceTemplate()
Expand All @@ -492,7 +492,7 @@ Session::Session(Endpoint* endpoint,
v8::Local<v8::Object> object,
const Config& config,
TLSContext* tls_context,
std::optional<SessionTicket>& session_ticket)
const std::optional<SessionTicket>& session_ticket)
: AsyncWrap(endpoint->env(), object, AsyncWrap::PROVIDER_QUIC_SESSION),
stats_(env()->isolate()),
state_(env()->isolate()),
Expand Down Expand Up @@ -2027,8 +2027,8 @@ struct Session::Impl {
to_string(level),
session->config().dcid);

return session->application().Start() ?
NGTCP2_SUCCESS : NGTCP2_ERR_CALLBACK_FAILURE;
return session->application().Start() ? NGTCP2_SUCCESS
: NGTCP2_ERR_CALLBACK_FAILURE;
}

static int on_receive_stateless_reset(ngtcp2_conn* conn,
Expand Down Expand Up @@ -2085,8 +2085,8 @@ struct Session::Impl {
"Receiving TX key for level %d for dcid %s",
to_string(level),
session->config().dcid);
return session->application().Start() ?
NGTCP2_SUCCESS : NGTCP2_ERR_CALLBACK_FAILURE;
return session->application().Start() ? NGTCP2_SUCCESS
: NGTCP2_ERR_CALLBACK_FAILURE;
}

static int on_receive_version_negotiation(ngtcp2_conn* conn,
Expand Down
13 changes: 7 additions & 6 deletions src/quic/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,18 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
static void InitPerContext(Realm* env, v8::Local<v8::Object> target);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

static BaseObjectPtr<Session> Create(Endpoint* endpoint,
const Config& config,
TLSContext* tls_context,
std::optional<SessionTicket>& ticket);
static BaseObjectPtr<Session> Create(
Endpoint* endpoint,
const Config& config,
TLSContext* tls_context,
const std::optional<SessionTicket>& ticket);

// Really should be private but MakeDetachedBaseObject needs visibility.
Session(Endpoint* endpoint,
v8::Local<v8::Object> object,
const Config& config,
TLSContext* tls_context,
std::optional<SessionTicket>& ticket);
const std::optional<SessionTicket>& ticket);
~Session() override;

uint32_t version() const;
Expand Down Expand Up @@ -289,7 +290,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
Session* session;
explicit SendPendingDataScope(Session* session);
explicit SendPendingDataScope(const BaseObjectPtr<Session>& session);
DISALLOW_COPY_AND_MOVE(SendPendingDataScope);
DISALLOW_COPY_AND_MOVE(SendPendingDataScope)
~SendPendingDataScope();
};

Expand Down
13 changes: 7 additions & 6 deletions src/quic/tlscontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
namespace node {

using v8::ArrayBuffer;
using v8::BackingStore;
using v8::Just;
using v8::Local;
using v8::Maybe;
Expand Down Expand Up @@ -206,7 +205,8 @@ int TLSContext::OnNewSession(SSL* ssl, SSL_SESSION* sess) {

// If there is nothing listening for the session ticket, do not bother.
if (session.wants_session_ticket()) {
Debug(&session, "Preparing TLS session resumption ticket");;
Debug(&session, "Preparing TLS session resumption ticket");

// Pre-fight to see how much space we need to allocate for the session
// ticket.
size_t size = i2d_SSL_SESSION(sess, nullptr);
Expand Down Expand Up @@ -318,10 +318,11 @@ crypto::SSLCtxPointer TLSContext::Initialize() {
crypto::BIOPointer bio = crypto::NodeBIO::NewFixed(buf.base, buf.len);
CHECK(bio);
X509_STORE* cert_store = SSL_CTX_get_cert_store(ctx.get());
while (
crypto::X509Pointer x509 =
crypto::X509Pointer(PEM_read_bio_X509_AUX(
bio.get(), nullptr, crypto::NoPasswordCallback, nullptr))) {
while (crypto::X509Pointer x509 = crypto::X509Pointer(
PEM_read_bio_X509_AUX(bio.get(),
nullptr,
crypto::NoPasswordCallback,
nullptr))) {
if (cert_store == crypto::GetOrCreateRootCertStore()) {
cert_store = crypto::NewRootCertStore();
SSL_CTX_set_cert_store(ctx.get(), cert_store);
Expand Down
2 changes: 1 addition & 1 deletion test/cctest/test_quic_cid.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
#include <env-inl.h>
#include <gtest/gtest.h>
#include <ngtcp2/ngtcp2.h>
#include <quic/cid.h>
#include <util-inl.h>
#include <env-inl.h>
#include <string>
#include <unordered_map>

Expand Down
Loading

0 comments on commit 9cb015e

Please sign in to comment.