From abdf7556033b722e694ba5df6454eb18dded3891 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 27 Mar 2023 12:46:11 -0700 Subject: [PATCH] quic: apply format-cpp to multiple files --- src/quic/cid.cc | 35 +++++++---- src/quic/cid.h | 2 +- src/quic/data.cc | 115 +++++++++++++++-------------------- src/quic/data.h | 9 +-- src/quic/preferredaddress.cc | 50 +++++++-------- src/quic/preferredaddress.h | 2 +- test/cctest/test_quic_cid.cc | 4 +- 7 files changed, 107 insertions(+), 110 deletions(-) diff --git a/src/quic/cid.cc b/src/quic/cid.cc index 18232cd9177384..06c12ca4c182d9 100644 --- a/src/quic/cid.cc +++ b/src/quic/cid.cc @@ -1,8 +1,8 @@ #include "cid.h" +#include #include #include #include -#include namespace node { namespace quic { @@ -10,7 +10,9 @@ namespace quic { // ============================================================================ // CID -CID::CID() : ptr_(&cid_) { cid_.datalen = 0; } +CID::CID() : ptr_(&cid_) { + cid_.datalen = 0; +} CID::CID(const ngtcp2_cid& cid) : CID() { DCHECK_GE(cid.datalen, kMinLength); @@ -36,8 +38,7 @@ CID::CID(const CID& other) : ptr_(&cid_) { } bool CID::operator==(const CID& other) const noexcept { - if (this == &other || (length() == 0 && other.length() == 0)) - return true; + if (this == &other || (length() == 0 && other.length() == 0)) return true; if (length() != other.length()) return false; return memcmp(ptr_->data, other.ptr_->data, ptr_->datalen) == 0; } @@ -46,12 +47,22 @@ bool CID::operator!=(const CID& other) const noexcept { return !(*this == other); } -CID::operator const uint8_t*() const { return ptr_->data; } -CID::operator const ngtcp2_cid&() const { return *ptr_; } -CID::operator const ngtcp2_cid*() const { return ptr_; } -CID::operator bool() const { return ptr_->datalen >= kMinLength; } +CID::operator const uint8_t*() const { + return ptr_->data; +} +CID::operator const ngtcp2_cid&() const { + return *ptr_; +} +CID::operator const ngtcp2_cid*() const { + return ptr_; +} +CID::operator bool() const { + return ptr_->datalen >= kMinLength; +} -size_t CID::length() const { return ptr_->datalen; } +size_t CID::length() const { + return ptr_->datalen; +} std::string CID::ToString() const { char dest[kMaxLength * 2]; @@ -63,7 +74,7 @@ std::string CID::ToString() const { return std::string(dest, written); } -CID CID::kInvalid {}; +CID CID::kInvalid{}; // ============================================================================ // CID::Hash @@ -71,8 +82,8 @@ CID CID::kInvalid {}; size_t CID::Hash::operator()(const CID& cid) const { size_t hash = 0; for (size_t n = 0; n < cid.length(); n++) { - hash ^= std::hash{}(cid.ptr_->data[n] + 0x9e3779b9 + - (hash << 6) + (hash >> 2)); + hash ^= std::hash{}(cid.ptr_->data[n] + 0x9e3779b9 + (hash << 6) + + (hash >> 2)); } return hash; } diff --git a/src/quic/cid.h b/src/quic/cid.h index cc74666fc5dc6b..f50849650c873a 100644 --- a/src/quic/cid.h +++ b/src/quic/cid.h @@ -33,7 +33,7 @@ namespace quic { // While the connection is being established, it is possible for either // peer to generate additional CIDs that are also associated with the // connection. -class CID final: public MemoryRetainer { +class CID final : public MemoryRetainer { public: static constexpr size_t kMinLength = NGTCP2_MIN_CIDLEN; static constexpr size_t kMaxLength = NGTCP2_MAX_CIDLEN; diff --git a/src/quic/data.cc b/src/quic/data.cc index 4055e88a29c135..dc19dedd02d62a 100644 --- a/src/quic/data.cc +++ b/src/quic/data.cc @@ -1,8 +1,8 @@ #include "data.h" #include #include -#include #include +#include #include #include "util.h" @@ -23,27 +23,27 @@ Path::Path(const SocketAddress& local, const SocketAddress& remote) { ngtcp2_addr_init(&this->remote, remote.data(), remote.length()); } -PathStorage::PathStorage() { ngtcp2_path_storage_zero(this); } -PathStorage::operator ngtcp2_path() { return path; } +PathStorage::PathStorage() { + ngtcp2_path_storage_zero(this); +} +PathStorage::operator ngtcp2_path() { + return path; +} // ============================================================================ Store::Store(std::shared_ptr store, - size_t length, - size_t offset) - : store_(std::move(store)), - length_(length), - offset_(offset) { + size_t length, + size_t offset) + : store_(std::move(store)), length_(length), offset_(offset) { CHECK_LE(offset_, store->ByteLength()); CHECK_LE(length_, store->ByteLength() - offset_); } Store::Store(std::unique_ptr store, - size_t length, - size_t offset) - : store_(std::move(store)), - length_(length), - offset_(offset) { + size_t length, + size_t offset) + : store_(std::move(store)), length_(length), offset_(offset) { CHECK_LE(offset_, store->ByteLength()); CHECK_LE(length_, store->ByteLength() - offset_); } @@ -64,15 +64,18 @@ Store::Store(v8::Local view, Option option) } } -Store::operator bool() const { return store_ != nullptr; } -size_t Store::length() const { return length_; } +Store::operator bool() const { + return store_ != nullptr; +} +size_t Store::length() const { + return length_; +} template T Store::convert() const { T buf; - buf.base = store_ != nullptr ? - static_cast(store_->Data()) + offset_ : - nullptr; + buf.base = + store_ != nullptr ? static_cast(store_->Data()) + offset_ : nullptr; buf.len = length_; return buf; } @@ -98,18 +101,21 @@ void Store::MemoryInfo(MemoryTracker* tracker) const { namespace { std::string TypeName(QuicError::Type type) { switch (type) { - case QuicError::Type::APPLICATION: return "APPLICATION"; - case QuicError::Type::TRANSPORT: return "TRANSPORT"; - case QuicError::Type::VERSION_NEGOTIATION: return "VERSION_NEGOTIATION"; - case QuicError::Type::IDLE_CLOSE: return "IDLE_CLOSE"; + case QuicError::Type::APPLICATION: + return "APPLICATION"; + case QuicError::Type::TRANSPORT: + return "TRANSPORT"; + case QuicError::Type::VERSION_NEGOTIATION: + return "VERSION_NEGOTIATION"; + case QuicError::Type::IDLE_CLOSE: + return "IDLE_CLOSE"; } UNREACHABLE(); } } // namespace QuicError::QuicError(const std::string_view reason) - : reason_(reason), - ptr_(&error_) {} + : reason_(reason), ptr_(&error_) {} QuicError::QuicError(const ngtcp2_connection_close_error* ptr) : reason_(reinterpret_cast(ptr->reason), ptr->reasonlen), @@ -122,7 +128,7 @@ QuicError::QuicError(const ngtcp2_connection_close_error& error) QuicError::operator bool() const { if ((code() == NO_ERROR && type() == Type::TRANSPORT) || - ((code() == APP_NO_ERROR && type() == Type::APPLICATION))) { + ((code() == APP_NO_ERROR && type() == Type::APPLICATION))) { return false; } return true; @@ -138,8 +144,7 @@ bool QuicError::operator!=(const QuicError& other) const { bool QuicError::operator==(const QuicError& other) const { if (this == &other) return true; - return type() == other.type() && - code() == other.code() && + return type() == other.type() && code() == other.code() && frame_type() == other.frame_type(); } @@ -169,9 +174,9 @@ QuicError::operator const ngtcp2_connection_close_error*() const { MaybeLocal QuicError::ToV8Value(Environment* env) const { Local argv[] = { - Integer::New(env->isolate(), static_cast(type())), - BigInt::NewFromUnsigned(env->isolate(), code()), - Undefined(env->isolate()), + Integer::New(env->isolate(), static_cast(type())), + BigInt::NewFromUnsigned(env->isolate(), code()), + Undefined(env->isolate()), }; if (reason_.length() > 0 && @@ -193,61 +198,41 @@ void QuicError::MemoryInfo(MemoryTracker* tracker) const { tracker->TrackField("reason", reason_.length()); } -QuicError QuicError::ForTransport( - error_code code, - const std::string_view reason) { +QuicError QuicError::ForTransport(error_code code, + const std::string_view reason) { QuicError error(reason); ngtcp2_connection_close_error_set_transport_error( - &error.error_, - code, - error.reason_c_str(), - reason.length()); + &error.error_, code, error.reason_c_str(), reason.length()); return error; } -QuicError QuicError::ForApplication( - error_code code, - const std::string_view reason) { +QuicError QuicError::ForApplication(error_code code, + const std::string_view reason) { QuicError error(reason); ngtcp2_connection_close_error_set_application_error( - &error.error_, - code, - error.reason_c_str(), - reason.length()); + &error.error_, code, error.reason_c_str(), reason.length()); return error; } -QuicError QuicError::ForVersionNegotiation( - const std::string_view reason) { +QuicError QuicError::ForVersionNegotiation(const std::string_view reason) { return ForNgtcp2Error(NGTCP2_ERR_RECV_VERSION_NEGOTIATION, reason); } -QuicError QuicError::ForIdleClose( - const std::string_view reason) { +QuicError QuicError::ForIdleClose(const std::string_view reason) { return ForNgtcp2Error(NGTCP2_ERR_IDLE_CLOSE, reason); } -QuicError QuicError::ForNgtcp2Error( - int code, - const std::string_view reason) { +QuicError QuicError::ForNgtcp2Error(int code, const std::string_view reason) { QuicError error(reason); ngtcp2_connection_close_error_set_transport_error_liberr( - &error.error_, - code, - error.reason_c_str(), - reason.length()); + &error.error_, code, error.reason_c_str(), reason.length()); return error; } -QuicError QuicError::ForTlsAlert( - int code, - const std::string_view reason) { +QuicError QuicError::ForTlsAlert(int code, const std::string_view reason) { QuicError error(reason); ngtcp2_connection_close_error_set_transport_error_tls_alert( - &error.error_, - code, - error.reason_c_str(), - reason.length()); + &error.error_, code, error.reason_c_str(), reason.length()); return error; } @@ -261,10 +246,8 @@ QuicError QuicError::TRANSPORT_NO_ERROR = QuicError::ForTransport(QuicError::NO_ERROR); QuicError QuicError::APPLICATION_NO_ERROR = QuicError::ForApplication(QuicError::APP_NO_ERROR); -QuicError QuicError::VERSION_NEGOTIATION = - QuicError::ForVersionNegotiation(); -QuicError QuicError::IDLE_CLOSE = - QuicError::ForIdleClose(); +QuicError QuicError::VERSION_NEGOTIATION = QuicError::ForVersionNegotiation(); +QuicError QuicError::IDLE_CLOSE = QuicError::ForIdleClose(); QuicError QuicError::INTERNAL_ERROR = QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL); diff --git a/src/quic/data.h b/src/quic/data.h index ffb01a8546fa6d..019072f446bebc 100644 --- a/src/quic/data.h +++ b/src/quic/data.h @@ -3,10 +3,10 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include +#include +#include #include #include -#include -#include #include namespace node { @@ -16,7 +16,7 @@ struct Path final : public ngtcp2_path { Path(const SocketAddress& local, const SocketAddress& remote); }; -struct PathStorage final: public ngtcp2_path_storage { +struct PathStorage final : public ngtcp2_path_storage { PathStorage(); operator ngtcp2_path(); }; @@ -51,7 +51,8 @@ class Store final : public MemoryRetainer { SET_SELF_SIZE(Store); private: - template T convert() const; + template + T convert() const; std::shared_ptr store_; size_t length_ = 0; size_t offset_ = 0; diff --git a/src/quic/preferredaddress.cc b/src/quic/preferredaddress.cc index 64e39f0b086984..463605110e07e7 100644 --- a/src/quic/preferredaddress.cc +++ b/src/quic/preferredaddress.cc @@ -1,9 +1,9 @@ #include "preferredaddress.h" #include +#include #include #include #include -#include #include #include @@ -26,8 +26,8 @@ std::optional get_address_info( PreferredAddress::AddressInfo address; address.family = FAMILY; address.port = paddr.ipv4_port; - if (uv_inet_ntop(FAMILY, paddr.ipv4_addr, - address.host, sizeof(address.host)) == 0) { + if (uv_inet_ntop( + FAMILY, paddr.ipv4_addr, address.host, sizeof(address.host)) == 0) { address.address = address.host; } return address; @@ -36,8 +36,8 @@ std::optional get_address_info( PreferredAddress::AddressInfo address; address.family = FAMILY; address.port = paddr.ipv6_port; - if (uv_inet_ntop(FAMILY, paddr.ipv6_addr, - address.host, sizeof(address.host)) == 0) { + if (uv_inet_ntop( + FAMILY, paddr.ipv6_addr, address.host, sizeof(address.host)) == 0) { address.address = address.host; } return address; @@ -45,9 +45,8 @@ std::optional get_address_info( } template -void copy_to_transport_params( - ngtcp2_transport_params* params, - const sockaddr* addr) { +void copy_to_transport_params(ngtcp2_transport_params* params, + const sockaddr* addr) { params->preferred_address_present = true; if constexpr (FAMILY == AF_INET) { const sockaddr_in* src = reinterpret_cast(addr); @@ -87,23 +86,25 @@ bool resolve(const PreferredAddress::AddressInfo& address, // more efficient conversion. For now, however, this // works. std::to_string(address.port).c_str(), - &hints) == 0 && req->addrinfo != nullptr; + &hints) == 0 && + req->addrinfo != nullptr; } } // namespace Maybe PreferredAddress::GetPolicy( - Environment* env, - Local value) { + Environment* env, Local value) { CHECK(value->IsUint32()); uint32_t val = 0; if (value->Uint32Value(env->context()).To(&val)) { switch (val) { - case QUIC_PREFERRED_ADDRESS_USE: return Just(Policy::USE); - case QUIC_PREFERRED_ADDRESS_IGNORE: return Just(Policy::IGNORE); + case QUIC_PREFERRED_ADDRESS_USE: + return Just(Policy::USE); + case QUIC_PREFERRED_ADDRESS_IGNORE: + return Just(Policy::IGNORE); } } - THROW_ERR_INVALID_ARG_VALUE(env, - "%d is not a valid preferred address policy", val); + THROW_ERR_INVALID_ARG_VALUE( + env, "%d is not a valid preferred address policy", val); return Nothing(); } @@ -114,13 +115,13 @@ PreferredAddress::PreferredAddress(ngtcp2_path* dest, DCHECK_NOT_NULL(dest); } -std::optional -PreferredAddress::ipv4() const { +std::optional PreferredAddress::ipv4() + const { return get_address_info(*paddr_); } -std::optional -PreferredAddress::ipv6() const { +std::optional PreferredAddress::ipv6() + const { return get_address_info(*paddr_); } @@ -137,14 +138,15 @@ void PreferredAddress::Use(const AddressInfo& address) { } } -void PreferredAddress::Set( - ngtcp2_transport_params* params, - const sockaddr* addr) { +void PreferredAddress::Set(ngtcp2_transport_params* params, + const sockaddr* addr) { DCHECK_NOT_NULL(params); DCHECK_NOT_NULL(addr); switch (addr->sa_family) { - case AF_INET: return copy_to_transport_params(params, addr); - case AF_INET6: return copy_to_transport_params(params, addr); + case AF_INET: + return copy_to_transport_params(params, addr); + case AF_INET6: + return copy_to_transport_params(params, addr); } // Any other value is just ignored. } diff --git a/src/quic/preferredaddress.h b/src/quic/preferredaddress.h index 82c5370a58d5c4..1d1c90f2af1b8d 100644 --- a/src/quic/preferredaddress.h +++ b/src/quic/preferredaddress.h @@ -3,8 +3,8 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include -#include #include +#include #include #include diff --git a/test/cctest/test_quic_cid.cc b/test/cctest/test_quic_cid.cc index f916ebb186153e..ae5779ccafc77b 100644 --- a/test/cctest/test_quic_cid.cc +++ b/test/cctest/test_quic_cid.cc @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include #include #include