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
3135Store::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
4143Store::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
7074template <typename T, typename t>
7175T 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 {
98101namespace {
99102std::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
110117QuicError::QuicError (const std::string_view reason)
111- : reason_(reason),
112- ptr_(&error_) {}
118+ : reason_(reason), ptr_(&error_) {}
113119
114120QuicError::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
123129QuicError::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
139145bool 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
170175MaybeLocal<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);
262247QuicError 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();
268251QuicError QuicError::INTERNAL_ERROR =
269252 QuicError::ForNgtcp2Error (NGTCP2_ERR_INTERNAL);
270253
0 commit comments