Skip to content

Commit 4d86a42

Browse files
anonrigaduh95
authored andcommitted
src: remove redundant qualifiers in src/quic
PR-URL: #56967 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e178acf commit 4d86a42

13 files changed

+82
-97
lines changed

src/quic/application.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ bool Session::Application::CanAddHeader(size_t current_count,
155155

156156
bool Session::Application::SendHeaders(const Stream& stream,
157157
HeadersKind kind,
158-
const v8::Local<v8::Array>& headers,
158+
const Local<v8::Array>& headers,
159159
HeadersFlags flags) {
160160
// By default do nothing.
161161
return false;
@@ -184,10 +184,9 @@ void Session::Application::CollectSessionTicketAppData(
184184

185185
SessionTicket::AppData::Status
186186
Session::Application::ExtractSessionTicketAppData(
187-
const SessionTicket::AppData& app_data,
188-
SessionTicket::AppData::Source::Flag flag) {
187+
const SessionTicket::AppData& app_data, Flag flag) {
189188
// By default we do not have any application data to retrieve.
190-
return flag == SessionTicket::AppData::Source::Flag::STATUS_RENEW
189+
return flag == Flag::STATUS_RENEW
191190
? SessionTicket::AppData::Status::TICKET_USE_RENEW
192191
: SessionTicket::AppData::Status::TICKET_USE;
193192
}
@@ -285,15 +284,15 @@ void Session::Application::SendPendingData() {
285284
Debug(session_, "Failed to create packet for stream data");
286285
// Doh! Could not create a packet. Time to bail.
287286
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
288-
return session_->Close(Session::CloseMethod::SILENT);
287+
return session_->Close(CloseMethod::SILENT);
289288
}
290289

291290
// The stream_data is the next block of data from the application stream.
292291
if (GetStreamData(&stream_data) < 0) {
293292
Debug(session_, "Application failed to get stream data");
294293
packet->Done(UV_ECANCELED);
295294
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
296-
return session_->Close(Session::CloseMethod::SILENT);
295+
return session_->Close(CloseMethod::SILENT);
297296
}
298297

299298
// If we got here, we were at least successful in checking for stream data.
@@ -374,7 +373,7 @@ void Session::Application::SendPendingData() {
374373
ngtcp2_strerror(nwrite));
375374
packet->Done(UV_ECANCELED);
376375
session_->SetLastError(QuicError::ForNgtcp2Error(nwrite));
377-
return session_->Close(Session::CloseMethod::SILENT);
376+
return session_->Close(CloseMethod::SILENT);
378377
} else if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
379378
packet->Done(UV_ECANCELED);
380379
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
@@ -601,13 +600,13 @@ class DefaultApplication final : public Session::Application {
601600
};
602601

603602
std::unique_ptr<Session::Application> Session::SelectApplication(
604-
Session* session, const Session::Config& config) {
603+
Session* session, const Config& config) {
605604
if (config.options.application_provider) {
606605
return config.options.application_provider->Create(session);
607606
}
608607

609-
return std::make_unique<DefaultApplication>(
610-
session, Session::Application_Options::kDefault);
608+
return std::make_unique<DefaultApplication>(session,
609+
Application_Options::kDefault);
611610
}
612611

613612
} // namespace quic

src/quic/bindingdata.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ QUIC_JS_CALLBACKS(V)
143143
void BindingData::SetCallbacks(const FunctionCallbackInfo<Value>& args) {
144144
auto env = Environment::GetCurrent(args);
145145
auto isolate = env->isolate();
146-
auto& state = BindingData::Get(env);
146+
auto& state = Get(env);
147147
CHECK(args[0]->IsObject());
148148
Local<Object> obj = args[0].As<Object>();
149149

@@ -164,7 +164,7 @@ void BindingData::SetCallbacks(const FunctionCallbackInfo<Value>& args) {
164164

165165
void BindingData::FlushPacketFreelist(const FunctionCallbackInfo<Value>& args) {
166166
auto env = Environment::GetCurrent(args);
167-
auto& state = BindingData::Get(env);
167+
auto& state = Get(env);
168168
state.packet_freelist.clear();
169169
}
170170

src/quic/data.cc

+11-16
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ Store::Store(std::unique_ptr<v8::BackingStore> store,
8888
CHECK_LE(length_, store_->ByteLength() - offset_);
8989
}
9090

91-
Store::Store(v8::Local<v8::ArrayBuffer> buffer, Option option)
91+
Store::Store(Local<v8::ArrayBuffer> buffer, Option option)
9292
: Store(buffer->GetBackingStore(), buffer->ByteLength()) {
9393
if (option == Option::DETACH) {
9494
USE(buffer->Detach(Local<Value>()));
9595
}
9696
}
9797

98-
Store::Store(v8::Local<v8::ArrayBufferView> view, Option option)
98+
Store::Store(Local<v8::ArrayBufferView> view, Option option)
9999
: Store(view->Buffer()->GetBackingStore(),
100100
view->ByteLength(),
101101
view->ByteOffset()) {
@@ -104,7 +104,7 @@ Store::Store(v8::Local<v8::ArrayBufferView> view, Option option)
104104
}
105105
}
106106

107-
v8::Local<v8::Uint8Array> Store::ToUint8Array(Environment* env) const {
107+
Local<Uint8Array> Store::ToUint8Array(Environment* env) const {
108108
return !store_
109109
? Uint8Array::New(v8::ArrayBuffer::New(env->isolate(), 0), 0, 0)
110110
: Uint8Array::New(v8::ArrayBuffer::New(env->isolate(), store_),
@@ -257,11 +257,9 @@ std::optional<int> QuicError::crypto_error() const {
257257
}
258258

259259
MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const {
260-
if ((type() == QuicError::Type::TRANSPORT && code() == NGTCP2_NO_ERROR) ||
261-
(type() == QuicError::Type::APPLICATION &&
262-
code() == NGTCP2_APP_NOERROR) ||
263-
(type() == QuicError::Type::APPLICATION &&
264-
code() == NGHTTP3_H3_NO_ERROR)) {
260+
if ((type() == Type::TRANSPORT && code() == NGTCP2_NO_ERROR) ||
261+
(type() == Type::APPLICATION && code() == NGTCP2_APP_NOERROR) ||
262+
(type() == Type::APPLICATION && code() == NGHTTP3_H3_NO_ERROR)) {
265263
return Undefined(env->isolate());
266264
}
267265

@@ -331,14 +329,11 @@ QuicError QuicError::FromConnectionClose(ngtcp2_conn* session) {
331329
return QuicError(ngtcp2_conn_get_ccerr(session));
332330
}
333331

334-
QuicError QuicError::TRANSPORT_NO_ERROR =
335-
QuicError::ForTransport(QuicError::QUIC_NO_ERROR);
336-
QuicError QuicError::APPLICATION_NO_ERROR =
337-
QuicError::ForApplication(QuicError::QUIC_APP_NO_ERROR);
338-
QuicError QuicError::VERSION_NEGOTIATION = QuicError::ForVersionNegotiation();
339-
QuicError QuicError::IDLE_CLOSE = QuicError::ForIdleClose();
340-
QuicError QuicError::INTERNAL_ERROR =
341-
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL);
332+
QuicError QuicError::TRANSPORT_NO_ERROR = ForTransport(QUIC_NO_ERROR);
333+
QuicError QuicError::APPLICATION_NO_ERROR = ForApplication(QUIC_APP_NO_ERROR);
334+
QuicError QuicError::VERSION_NEGOTIATION = ForVersionNegotiation();
335+
QuicError QuicError::IDLE_CLOSE = ForIdleClose();
336+
QuicError QuicError::INTERNAL_ERROR = ForNgtcp2Error(NGTCP2_ERR_INTERNAL);
342337

343338
} // namespace quic
344339
} // namespace node

src/quic/endpoint.cc

+8-10
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ bool SetOption(Environment* env,
177177
Maybe<Endpoint::Options> Endpoint::Options::From(Environment* env,
178178
Local<Value> value) {
179179
if (value.IsEmpty() || !value->IsObject()) {
180-
if (value->IsUndefined()) return Just(Endpoint::Options());
180+
if (value->IsUndefined()) return Just(Options());
181181
THROW_ERR_INVALID_ARG_TYPE(env, "options must be an object");
182182
return Nothing<Options>();
183183
}
@@ -213,7 +213,7 @@ Maybe<Endpoint::Options> Endpoint::Options::From(Environment* env,
213213
"The address option must be a SocketAddress");
214214
return Nothing<Options>();
215215
}
216-
auto addr = FromJSObject<SocketAddressBase>(address.As<v8::Object>());
216+
auto addr = FromJSObject<SocketAddressBase>(address.As<Object>());
217217
options.local_address = addr->address();
218218
} else {
219219
options.local_address = std::make_shared<SocketAddress>();
@@ -286,8 +286,7 @@ class Endpoint::UDP::Impl final : public HandleWrap {
286286
if (tmpl.IsEmpty()) {
287287
tmpl = NewFunctionTemplate(env->isolate(), IllegalConstructor);
288288
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
289-
tmpl->InstanceTemplate()->SetInternalFieldCount(
290-
HandleWrap::kInternalFieldCount);
289+
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
291290
tmpl->SetClassName(state.endpoint_udp_string());
292291
state.set_udp_constructor_template(tmpl);
293292
}
@@ -317,7 +316,7 @@ class Endpoint::UDP::Impl final : public HandleWrap {
317316
: HandleWrap(endpoint->env(),
318317
object,
319318
reinterpret_cast<uv_handle_t*>(&handle_),
320-
AsyncWrap::PROVIDER_QUIC_UDP),
319+
PROVIDER_QUIC_UDP),
321320
endpoint_(endpoint) {
322321
CHECK_EQ(uv_udp_init(endpoint->env()->event_loop(), &handle_), 0);
323322
handle_.data = this;
@@ -376,7 +375,7 @@ Endpoint::UDP::~UDP() {
376375
Close();
377376
}
378377

379-
int Endpoint::UDP::Bind(const Endpoint::Options& options) {
378+
int Endpoint::UDP::Bind(const Options& options) {
380379
if (is_bound_) return UV_EALREADY;
381380
if (is_closed_or_closing()) return UV_EBADF;
382381

@@ -521,8 +520,7 @@ Local<FunctionTemplate> Endpoint::GetConstructorTemplate(Environment* env) {
521520
tmpl = NewFunctionTemplate(isolate, New);
522521
tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env));
523522
tmpl->SetClassName(state.endpoint_string());
524-
tmpl->InstanceTemplate()->SetInternalFieldCount(
525-
Endpoint::kInternalFieldCount);
523+
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
526524
SetProtoMethod(isolate, tmpl, "listen", DoListen);
527525
SetProtoMethod(isolate, tmpl, "closeGracefully", DoCloseGracefully);
528526
SetProtoMethod(isolate, tmpl, "connect", DoConnect);
@@ -612,8 +610,8 @@ void Endpoint::RegisterExternalReferences(ExternalReferenceRegistry* registry) {
612610

613611
Endpoint::Endpoint(Environment* env,
614612
Local<Object> object,
615-
const Endpoint::Options& options)
616-
: AsyncWrap(env, object, AsyncWrap::PROVIDER_QUIC_ENDPOINT),
613+
const Options& options)
614+
: AsyncWrap(env, object, PROVIDER_QUIC_ENDPOINT),
617615
stats_(env->isolate()),
618616
state_(env->isolate()),
619617
options_(options),

src/quic/http3.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ Local<FunctionTemplate> Http3Application::GetConstructorTemplate(
4242
auto isolate = env->isolate();
4343
tmpl = NewFunctionTemplate(isolate, New);
4444
tmpl->SetClassName(state.http3application_string());
45-
tmpl->InstanceTemplate()->SetInternalFieldCount(
46-
Http3Application::kInternalFieldCount);
45+
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
4746
state.set_http3application_constructor_template(tmpl);
4847
}
4948
return tmpl;
@@ -169,8 +168,7 @@ using Http3Header = NgHeader<Http3HeaderTraits>;
169168
// Implements the low-level HTTP/3 Application semantics.
170169
class Http3ApplicationImpl final : public Session::Application {
171170
public:
172-
Http3ApplicationImpl(Session* session,
173-
const Session::Application::Options& options)
171+
Http3ApplicationImpl(Session* session, const Options& options)
174172
: Application(session, options),
175173
allocator_(BindingData::Get(env())),
176174
options_(options),
@@ -403,7 +401,7 @@ class Http3ApplicationImpl final : public Session::Application {
403401

404402
bool SendHeaders(const Stream& stream,
405403
HeadersKind kind,
406-
const v8::Local<v8::Array>& headers,
404+
const Local<v8::Array>& headers,
407405
HeadersFlags flags = HeadersFlags::NONE) override {
408406
Session::SendPendingDataScope send_scope(&session());
409407
Http3Headers nva(env(), headers);
@@ -728,7 +726,7 @@ class Http3ApplicationImpl final : public Session::Application {
728726

729727
bool started_ = false;
730728
nghttp3_mem allocator_;
731-
Session::Application::Options options_;
729+
Options options_;
732730
Http3ConnectionPointer conn_;
733731
int64_t control_stream_id_ = -1;
734732
int64_t qpack_dec_stream_id_ = -1;

src/quic/logstream.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Local<FunctionTemplate> LogStream::GetConstructorTemplate(Environment* env) {
3535
}
3636

3737
BaseObjectPtr<LogStream> LogStream::Create(Environment* env) {
38-
v8::Local<v8::Object> obj;
38+
Local<Object> obj;
3939
if (!GetConstructorTemplate(env)
4040
->InstanceTemplate()
4141
->NewInstance(env->context())
@@ -46,9 +46,9 @@ BaseObjectPtr<LogStream> LogStream::Create(Environment* env) {
4646
}
4747

4848
LogStream::LogStream(Environment* env, Local<Object> obj)
49-
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_QUIC_LOGSTREAM), StreamBase(env) {
49+
: AsyncWrap(env, obj, PROVIDER_QUIC_LOGSTREAM), StreamBase(env) {
5050
MakeWeak();
51-
StreamBase::AttachToObject(GetObject());
51+
AttachToObject(GetObject());
5252
}
5353

5454
void LogStream::Emit(const uint8_t* data, size_t len, EmitOption option) {

src/quic/packet.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ Local<FunctionTemplate> Packet::GetConstructorTemplate(Environment* env) {
102102
if (tmpl.IsEmpty()) {
103103
tmpl = NewFunctionTemplate(env->isolate(), IllegalConstructor);
104104
tmpl->Inherit(ReqWrap<uv_udp_send_t>::GetConstructorTemplate(env));
105-
tmpl->InstanceTemplate()->SetInternalFieldCount(
106-
Packet::kInternalFieldCount);
105+
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
107106
tmpl->SetClassName(state.packetwrap_string());
108107
state.set_packet_constructor_template(tmpl);
109108
}
@@ -174,7 +173,7 @@ Packet::Packet(Environment* env,
174173
Local<Object> object,
175174
const SocketAddress& destination,
176175
std::shared_ptr<Data> data)
177-
: ReqWrap<uv_udp_send_t>(env, object, AsyncWrap::PROVIDER_QUIC_PACKET),
176+
: ReqWrap<uv_udp_send_t>(env, object, PROVIDER_QUIC_PACKET),
178177
listener_(listener),
179178
destination_(destination),
180179
data_(std::move(data)) {

src/quic/preferredaddress.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ void copy_to_transport_params(ngtcp2_transport_params* params,
5555
const sockaddr* addr) {
5656
params->preferred_addr_present = true;
5757
if constexpr (FAMILY == AF_INET) {
58-
const sockaddr_in* src = reinterpret_cast<const sockaddr_in*>(addr);
58+
const auto* src = reinterpret_cast<const sockaddr_in*>(addr);
5959
params->preferred_addr.ipv4.sin_port = SocketAddress::GetPort(addr);
6060
memcpy(&params->preferred_addr.ipv4.sin_addr,
6161
&src->sin_addr,
6262
sizeof(params->preferred_addr.ipv4.sin_addr));
6363
} else {
6464
DCHECK_EQ(FAMILY, AF_INET6);
65-
const sockaddr_in6* src = reinterpret_cast<const sockaddr_in6*>(addr);
65+
const auto* src = reinterpret_cast<const sockaddr_in6*>(addr);
6666
params->preferred_addr.ipv6.sin6_port = SocketAddress::GetPort(addr);
6767
memcpy(&params->preferred_addr.ipv6.sin6_addr,
6868
&src->sin6_addr,
@@ -136,29 +136,32 @@ void PreferredAddress::Set(ngtcp2_transport_params* params,
136136
return copy_to_transport_params<AF_INET>(params, addr);
137137
case AF_INET6:
138138
return copy_to_transport_params<AF_INET6>(params, addr);
139+
default:
140+
UNREACHABLE("Unreachable");
139141
}
140142
// Any other value is just ignored.
141143
}
142144

143145
Maybe<PreferredAddress::Policy> PreferredAddress::tryGetPolicy(
144146
Environment* env, Local<Value> value) {
145147
if (value->IsUndefined()) {
146-
return Just(PreferredAddress::Policy::USE_PREFERRED);
148+
return Just(Policy::USE_PREFERRED);
147149
}
148150
if (value->IsUint32()) {
149151
switch (value.As<Uint32>()->Value()) {
150152
case PREFERRED_ADDRESS_IGNORE:
151153
return Just(Policy::IGNORE_PREFERRED);
152154
case PREFERRED_ADDRESS_USE:
153155
return Just(Policy::USE_PREFERRED);
156+
default:
157+
UNREACHABLE("Unreachable");
154158
}
155159
}
156160
THROW_ERR_INVALID_ARG_VALUE(env, "invalid preferred address policy");
157-
return Nothing<PreferredAddress::Policy>();
161+
return Nothing<Policy>();
158162
}
159163

160-
void PreferredAddress::Initialize(Environment* env,
161-
v8::Local<v8::Object> target) {
164+
void PreferredAddress::Initialize(Environment* env, Local<v8::Object> target) {
162165
NODE_DEFINE_CONSTANT(target, PREFERRED_ADDRESS_IGNORE);
163166
NODE_DEFINE_CONSTANT(target, PREFERRED_ADDRESS_USE);
164167
NODE_DEFINE_CONSTANT(target, DEFAULT_PREFERRED_ADDRESS_POLICY);

0 commit comments

Comments
 (0)