1
1
#include " data.h"
2
2
#include < env-inl.h>
3
3
#include < memory_tracker-inl.h>
4
- #include < node_sockaddr-inl.h>
5
4
#include < ngtcp2/ngtcp2.h>
5
+ #include < node_sockaddr-inl.h>
6
6
#include < v8.h>
7
7
#include " util.h"
8
8
@@ -23,27 +23,27 @@ Path::Path(const SocketAddress& local, const SocketAddress& remote) {
23
23
ngtcp2_addr_init (&this ->remote , remote.data (), remote.length ());
24
24
}
25
25
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
+ }
28
32
29
33
// ============================================================================
30
34
31
35
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) {
37
39
CHECK_LE (offset_, store->ByteLength ());
38
40
CHECK_LE (length_, store->ByteLength () - offset_);
39
41
}
40
42
41
43
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) {
47
47
CHECK_LE (offset_, store->ByteLength ());
48
48
CHECK_LE (length_, store->ByteLength () - offset_);
49
49
}
@@ -64,15 +64,18 @@ Store::Store(v8::Local<v8::ArrayBufferView> view, Option option)
64
64
}
65
65
}
66
66
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
+ }
69
73
70
74
template <typename T, typename t>
71
75
T Store::convert () const {
72
76
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 ;
76
79
buf.len = length_;
77
80
return buf;
78
81
}
@@ -98,18 +101,21 @@ void Store::MemoryInfo(MemoryTracker* tracker) const {
98
101
namespace {
99
102
std::string TypeName (QuicError::Type type) {
100
103
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" ;
105
112
}
106
113
UNREACHABLE ();
107
114
}
108
115
} // namespace
109
116
110
117
QuicError::QuicError (const std::string_view reason)
111
- : reason_(reason),
112
- ptr_(&error_) {}
118
+ : reason_(reason), ptr_(&error_) {}
113
119
114
120
QuicError::QuicError (const ngtcp2_connection_close_error* ptr)
115
121
: reason_(reinterpret_cast <const char *>(ptr->reason), ptr->reasonlen),
@@ -122,7 +128,7 @@ QuicError::QuicError(const ngtcp2_connection_close_error& error)
122
128
123
129
QuicError::operator bool () const {
124
130
if ((code () == NO_ERROR && type () == Type::TRANSPORT) ||
125
- ((code () == APP_NO_ERROR && type () == Type::APPLICATION))) {
131
+ ((code () == APP_NO_ERROR && type () == Type::APPLICATION))) {
126
132
return false ;
127
133
}
128
134
return true ;
@@ -138,8 +144,7 @@ bool QuicError::operator!=(const QuicError& other) const {
138
144
139
145
bool QuicError::operator ==(const QuicError& other) const {
140
146
if (this == &other) return true ;
141
- return type () == other.type () &&
142
- code () == other.code () &&
147
+ return type () == other.type () && code () == other.code () &&
143
148
frame_type () == other.frame_type ();
144
149
}
145
150
@@ -169,9 +174,9 @@ QuicError::operator const ngtcp2_connection_close_error*() const {
169
174
170
175
MaybeLocal<Value> QuicError::ToV8Value (Environment* env) const {
171
176
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 ()),
175
180
};
176
181
177
182
if (reason_.length () > 0 &&
@@ -193,61 +198,41 @@ void QuicError::MemoryInfo(MemoryTracker* tracker) const {
193
198
tracker->TrackField (" reason" , reason_.length ());
194
199
}
195
200
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) {
199
203
QuicError error (reason);
200
204
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 ());
205
206
return error;
206
207
}
207
208
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) {
211
211
QuicError error (reason);
212
212
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 ());
217
214
return error;
218
215
}
219
216
220
- QuicError QuicError::ForVersionNegotiation (
221
- const std::string_view reason) {
217
+ QuicError QuicError::ForVersionNegotiation (const std::string_view reason) {
222
218
return ForNgtcp2Error (NGTCP2_ERR_RECV_VERSION_NEGOTIATION, reason);
223
219
}
224
220
225
- QuicError QuicError::ForIdleClose (
226
- const std::string_view reason) {
221
+ QuicError QuicError::ForIdleClose (const std::string_view reason) {
227
222
return ForNgtcp2Error (NGTCP2_ERR_IDLE_CLOSE, reason);
228
223
}
229
224
230
- QuicError QuicError::ForNgtcp2Error (
231
- int code,
232
- const std::string_view reason) {
225
+ QuicError QuicError::ForNgtcp2Error (int code, const std::string_view reason) {
233
226
QuicError error (reason);
234
227
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 ());
239
229
return error;
240
230
}
241
231
242
- QuicError QuicError::ForTlsAlert (
243
- int code,
244
- const std::string_view reason) {
232
+ QuicError QuicError::ForTlsAlert (int code, const std::string_view reason) {
245
233
QuicError error (reason);
246
234
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 ());
251
236
return error;
252
237
}
253
238
@@ -261,10 +246,8 @@ QuicError QuicError::TRANSPORT_NO_ERROR =
261
246
QuicError::ForTransport (QuicError::NO_ERROR);
262
247
QuicError QuicError::APPLICATION_NO_ERROR =
263
248
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();
268
251
QuicError QuicError::INTERNAL_ERROR =
269
252
QuicError::ForNgtcp2Error (NGTCP2_ERR_INTERNAL);
270
253
0 commit comments