Skip to content

Commit abdf755

Browse files
committed
quic: apply format-cpp to multiple files
1 parent 6e1b1b8 commit abdf755

File tree

7 files changed

+107
-110
lines changed

7 files changed

+107
-110
lines changed

src/quic/cid.cc

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#include "cid.h"
2+
#include <crypto/crypto_util.h>
23
#include <memory_tracker-inl.h>
34
#include <node_mutex.h>
45
#include <string_bytes.h>
5-
#include <crypto/crypto_util.h>
66

77
namespace node {
88
namespace quic {
99

1010
// ============================================================================
1111
// CID
1212

13-
CID::CID() : ptr_(&cid_) { cid_.datalen = 0; }
13+
CID::CID() : ptr_(&cid_) {
14+
cid_.datalen = 0;
15+
}
1416

1517
CID::CID(const ngtcp2_cid& cid) : CID() {
1618
DCHECK_GE(cid.datalen, kMinLength);
@@ -36,8 +38,7 @@ CID::CID(const CID& other) : ptr_(&cid_) {
3638
}
3739

3840
bool CID::operator==(const CID& other) const noexcept {
39-
if (this == &other || (length() == 0 && other.length() == 0))
40-
return true;
41+
if (this == &other || (length() == 0 && other.length() == 0)) return true;
4142
if (length() != other.length()) return false;
4243
return memcmp(ptr_->data, other.ptr_->data, ptr_->datalen) == 0;
4344
}
@@ -46,12 +47,22 @@ bool CID::operator!=(const CID& other) const noexcept {
4647
return !(*this == other);
4748
}
4849

49-
CID::operator const uint8_t*() const { return ptr_->data; }
50-
CID::operator const ngtcp2_cid&() const { return *ptr_; }
51-
CID::operator const ngtcp2_cid*() const { return ptr_; }
52-
CID::operator bool() const { return ptr_->datalen >= kMinLength; }
50+
CID::operator const uint8_t*() const {
51+
return ptr_->data;
52+
}
53+
CID::operator const ngtcp2_cid&() const {
54+
return *ptr_;
55+
}
56+
CID::operator const ngtcp2_cid*() const {
57+
return ptr_;
58+
}
59+
CID::operator bool() const {
60+
return ptr_->datalen >= kMinLength;
61+
}
5362

54-
size_t CID::length() const { return ptr_->datalen; }
63+
size_t CID::length() const {
64+
return ptr_->datalen;
65+
}
5566

5667
std::string CID::ToString() const {
5768
char dest[kMaxLength * 2];
@@ -63,16 +74,16 @@ std::string CID::ToString() const {
6374
return std::string(dest, written);
6475
}
6576

66-
CID CID::kInvalid {};
77+
CID CID::kInvalid{};
6778

6879
// ============================================================================
6980
// CID::Hash
7081

7182
size_t CID::Hash::operator()(const CID& cid) const {
7283
size_t hash = 0;
7384
for (size_t n = 0; n < cid.length(); n++) {
74-
hash ^= std::hash<uint8_t>{}(cid.ptr_->data[n] + 0x9e3779b9 +
75-
(hash << 6) + (hash >> 2));
85+
hash ^= std::hash<uint8_t>{}(cid.ptr_->data[n] + 0x9e3779b9 + (hash << 6) +
86+
(hash >> 2));
7687
}
7788
return hash;
7889
}

src/quic/cid.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace quic {
3333
// While the connection is being established, it is possible for either
3434
// peer to generate additional CIDs that are also associated with the
3535
// connection.
36-
class CID final: public MemoryRetainer {
36+
class CID final : public MemoryRetainer {
3737
public:
3838
static constexpr size_t kMinLength = NGTCP2_MIN_CIDLEN;
3939
static constexpr size_t kMaxLength = NGTCP2_MAX_CIDLEN;

src/quic/data.cc

+49-66
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "data.h"
22
#include <env-inl.h>
33
#include <memory_tracker-inl.h>
4-
#include <node_sockaddr-inl.h>
54
#include <ngtcp2/ngtcp2.h>
5+
#include <node_sockaddr-inl.h>
66
#include <v8.h>
77
#include "util.h"
88

@@ -23,27 +23,27 @@ Path::Path(const SocketAddress& local, const SocketAddress& remote) {
2323
ngtcp2_addr_init(&this->remote, remote.data(), remote.length());
2424
}
2525

26-
PathStorage::PathStorage() { ngtcp2_path_storage_zero(this); }
27-
PathStorage::operator ngtcp2_path() { return path; }
26+
PathStorage::PathStorage() {
27+
ngtcp2_path_storage_zero(this);
28+
}
29+
PathStorage::operator ngtcp2_path() {
30+
return path;
31+
}
2832

2933
// ============================================================================
3034

3135
Store::Store(std::shared_ptr<v8::BackingStore> store,
32-
size_t length,
33-
size_t offset)
34-
: store_(std::move(store)),
35-
length_(length),
36-
offset_(offset) {
36+
size_t length,
37+
size_t offset)
38+
: store_(std::move(store)), length_(length), offset_(offset) {
3739
CHECK_LE(offset_, store->ByteLength());
3840
CHECK_LE(length_, store->ByteLength() - offset_);
3941
}
4042

4143
Store::Store(std::unique_ptr<v8::BackingStore> store,
42-
size_t length,
43-
size_t offset)
44-
: store_(std::move(store)),
45-
length_(length),
46-
offset_(offset) {
44+
size_t length,
45+
size_t offset)
46+
: store_(std::move(store)), length_(length), offset_(offset) {
4747
CHECK_LE(offset_, store->ByteLength());
4848
CHECK_LE(length_, store->ByteLength() - offset_);
4949
}
@@ -64,15 +64,18 @@ Store::Store(v8::Local<v8::ArrayBufferView> view, Option option)
6464
}
6565
}
6666

67-
Store::operator bool() const { return store_ != nullptr; }
68-
size_t Store::length() const { return length_; }
67+
Store::operator bool() const {
68+
return store_ != nullptr;
69+
}
70+
size_t Store::length() const {
71+
return length_;
72+
}
6973

7074
template <typename T, typename t>
7175
T Store::convert() const {
7276
T buf;
73-
buf.base = store_ != nullptr ?
74-
static_cast<t*>(store_->Data()) + offset_ :
75-
nullptr;
77+
buf.base =
78+
store_ != nullptr ? static_cast<t*>(store_->Data()) + offset_ : nullptr;
7679
buf.len = length_;
7780
return buf;
7881
}
@@ -98,18 +101,21 @@ void Store::MemoryInfo(MemoryTracker* tracker) const {
98101
namespace {
99102
std::string TypeName(QuicError::Type type) {
100103
switch (type) {
101-
case QuicError::Type::APPLICATION: return "APPLICATION";
102-
case QuicError::Type::TRANSPORT: return "TRANSPORT";
103-
case QuicError::Type::VERSION_NEGOTIATION: return "VERSION_NEGOTIATION";
104-
case QuicError::Type::IDLE_CLOSE: return "IDLE_CLOSE";
104+
case QuicError::Type::APPLICATION:
105+
return "APPLICATION";
106+
case QuicError::Type::TRANSPORT:
107+
return "TRANSPORT";
108+
case QuicError::Type::VERSION_NEGOTIATION:
109+
return "VERSION_NEGOTIATION";
110+
case QuicError::Type::IDLE_CLOSE:
111+
return "IDLE_CLOSE";
105112
}
106113
UNREACHABLE();
107114
}
108115
} // namespace
109116

110117
QuicError::QuicError(const std::string_view reason)
111-
: reason_(reason),
112-
ptr_(&error_) {}
118+
: reason_(reason), ptr_(&error_) {}
113119

114120
QuicError::QuicError(const ngtcp2_connection_close_error* ptr)
115121
: reason_(reinterpret_cast<const char*>(ptr->reason), ptr->reasonlen),
@@ -122,7 +128,7 @@ QuicError::QuicError(const ngtcp2_connection_close_error& error)
122128

123129
QuicError::operator bool() const {
124130
if ((code() == NO_ERROR && type() == Type::TRANSPORT) ||
125-
((code() == APP_NO_ERROR && type() == Type::APPLICATION))) {
131+
((code() == APP_NO_ERROR && type() == Type::APPLICATION))) {
126132
return false;
127133
}
128134
return true;
@@ -138,8 +144,7 @@ bool QuicError::operator!=(const QuicError& other) const {
138144

139145
bool QuicError::operator==(const QuicError& other) const {
140146
if (this == &other) return true;
141-
return type() == other.type() &&
142-
code() == other.code() &&
147+
return type() == other.type() && code() == other.code() &&
143148
frame_type() == other.frame_type();
144149
}
145150

@@ -169,9 +174,9 @@ QuicError::operator const ngtcp2_connection_close_error*() const {
169174

170175
MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const {
171176
Local<Value> argv[] = {
172-
Integer::New(env->isolate(), static_cast<int>(type())),
173-
BigInt::NewFromUnsigned(env->isolate(), code()),
174-
Undefined(env->isolate()),
177+
Integer::New(env->isolate(), static_cast<int>(type())),
178+
BigInt::NewFromUnsigned(env->isolate(), code()),
179+
Undefined(env->isolate()),
175180
};
176181

177182
if (reason_.length() > 0 &&
@@ -193,61 +198,41 @@ void QuicError::MemoryInfo(MemoryTracker* tracker) const {
193198
tracker->TrackField("reason", reason_.length());
194199
}
195200

196-
QuicError QuicError::ForTransport(
197-
error_code code,
198-
const std::string_view reason) {
201+
QuicError QuicError::ForTransport(error_code code,
202+
const std::string_view reason) {
199203
QuicError error(reason);
200204
ngtcp2_connection_close_error_set_transport_error(
201-
&error.error_,
202-
code,
203-
error.reason_c_str(),
204-
reason.length());
205+
&error.error_, code, error.reason_c_str(), reason.length());
205206
return error;
206207
}
207208

208-
QuicError QuicError::ForApplication(
209-
error_code code,
210-
const std::string_view reason) {
209+
QuicError QuicError::ForApplication(error_code code,
210+
const std::string_view reason) {
211211
QuicError error(reason);
212212
ngtcp2_connection_close_error_set_application_error(
213-
&error.error_,
214-
code,
215-
error.reason_c_str(),
216-
reason.length());
213+
&error.error_, code, error.reason_c_str(), reason.length());
217214
return error;
218215
}
219216

220-
QuicError QuicError::ForVersionNegotiation(
221-
const std::string_view reason) {
217+
QuicError QuicError::ForVersionNegotiation(const std::string_view reason) {
222218
return ForNgtcp2Error(NGTCP2_ERR_RECV_VERSION_NEGOTIATION, reason);
223219
}
224220

225-
QuicError QuicError::ForIdleClose(
226-
const std::string_view reason) {
221+
QuicError QuicError::ForIdleClose(const std::string_view reason) {
227222
return ForNgtcp2Error(NGTCP2_ERR_IDLE_CLOSE, reason);
228223
}
229224

230-
QuicError QuicError::ForNgtcp2Error(
231-
int code,
232-
const std::string_view reason) {
225+
QuicError QuicError::ForNgtcp2Error(int code, const std::string_view reason) {
233226
QuicError error(reason);
234227
ngtcp2_connection_close_error_set_transport_error_liberr(
235-
&error.error_,
236-
code,
237-
error.reason_c_str(),
238-
reason.length());
228+
&error.error_, code, error.reason_c_str(), reason.length());
239229
return error;
240230
}
241231

242-
QuicError QuicError::ForTlsAlert(
243-
int code,
244-
const std::string_view reason) {
232+
QuicError QuicError::ForTlsAlert(int code, const std::string_view reason) {
245233
QuicError error(reason);
246234
ngtcp2_connection_close_error_set_transport_error_tls_alert(
247-
&error.error_,
248-
code,
249-
error.reason_c_str(),
250-
reason.length());
235+
&error.error_, code, error.reason_c_str(), reason.length());
251236
return error;
252237
}
253238

@@ -261,10 +246,8 @@ QuicError QuicError::TRANSPORT_NO_ERROR =
261246
QuicError::ForTransport(QuicError::NO_ERROR);
262247
QuicError QuicError::APPLICATION_NO_ERROR =
263248
QuicError::ForApplication(QuicError::APP_NO_ERROR);
264-
QuicError QuicError::VERSION_NEGOTIATION =
265-
QuicError::ForVersionNegotiation();
266-
QuicError QuicError::IDLE_CLOSE =
267-
QuicError::ForIdleClose();
249+
QuicError QuicError::VERSION_NEGOTIATION = QuicError::ForVersionNegotiation();
250+
QuicError QuicError::IDLE_CLOSE = QuicError::ForIdleClose();
268251
QuicError QuicError::INTERNAL_ERROR =
269252
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL);
270253

src/quic/data.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
44

55
#include <memory_tracker.h>
6+
#include <nghttp3/nghttp3.h>
7+
#include <ngtcp2/ngtcp2.h>
68
#include <node_internals.h>
79
#include <node_sockaddr.h>
8-
#include <ngtcp2/ngtcp2.h>
9-
#include <nghttp3/nghttp3.h>
1010
#include <v8.h>
1111

1212
namespace node {
@@ -16,7 +16,7 @@ struct Path final : public ngtcp2_path {
1616
Path(const SocketAddress& local, const SocketAddress& remote);
1717
};
1818

19-
struct PathStorage final: public ngtcp2_path_storage {
19+
struct PathStorage final : public ngtcp2_path_storage {
2020
PathStorage();
2121
operator ngtcp2_path();
2222
};
@@ -51,7 +51,8 @@ class Store final : public MemoryRetainer {
5151
SET_SELF_SIZE(Store);
5252

5353
private:
54-
template <typename T, typename t> T convert() const;
54+
template <typename T, typename t>
55+
T convert() const;
5556
std::shared_ptr<v8::BackingStore> store_;
5657
size_t length_ = 0;
5758
size_t offset_ = 0;

0 commit comments

Comments
 (0)