Skip to content

src: remove redundant qualifiers in src/quic #56967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/quic/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bool Session::Application::CanAddHeader(size_t current_count,

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

SessionTicket::AppData::Status
Session::Application::ExtractSessionTicketAppData(
const SessionTicket::AppData& app_data,
SessionTicket::AppData::Source::Flag flag) {
const SessionTicket::AppData& app_data, Flag flag) {
// By default we do not have any application data to retrieve.
return flag == SessionTicket::AppData::Source::Flag::STATUS_RENEW
return flag == Flag::STATUS_RENEW
? SessionTicket::AppData::Status::TICKET_USE_RENEW
: SessionTicket::AppData::Status::TICKET_USE;
}
Expand Down Expand Up @@ -285,15 +284,15 @@ void Session::Application::SendPendingData() {
Debug(session_, "Failed to create packet for stream data");
// Doh! Could not create a packet. Time to bail.
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
return session_->Close(Session::CloseMethod::SILENT);
return session_->Close(CloseMethod::SILENT);
}

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

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

std::unique_ptr<Session::Application> Session::SelectApplication(
Session* session, const Session::Config& config) {
Session* session, const Config& config) {
if (config.options.application_provider) {
return config.options.application_provider->Create(session);
}

return std::make_unique<DefaultApplication>(
session, Session::Application_Options::kDefault);
return std::make_unique<DefaultApplication>(session,
Application_Options::kDefault);
}

} // namespace quic
Expand Down
4 changes: 2 additions & 2 deletions src/quic/bindingdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ QUIC_JS_CALLBACKS(V)
void BindingData::SetCallbacks(const FunctionCallbackInfo<Value>& args) {
auto env = Environment::GetCurrent(args);
auto isolate = env->isolate();
auto& state = BindingData::Get(env);
auto& state = Get(env);
CHECK(args[0]->IsObject());
Local<Object> obj = args[0].As<Object>();

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

void BindingData::FlushPacketFreelist(const FunctionCallbackInfo<Value>& args) {
auto env = Environment::GetCurrent(args);
auto& state = BindingData::Get(env);
auto& state = Get(env);
state.packet_freelist.clear();
}

Expand Down
27 changes: 11 additions & 16 deletions src/quic/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ Store::Store(std::unique_ptr<v8::BackingStore> store,
CHECK_LE(length_, store_->ByteLength() - offset_);
}

Store::Store(v8::Local<v8::ArrayBuffer> buffer, Option option)
Store::Store(Local<v8::ArrayBuffer> buffer, Option option)
: Store(buffer->GetBackingStore(), buffer->ByteLength()) {
if (option == Option::DETACH) {
USE(buffer->Detach(Local<Value>()));
}
}

Store::Store(v8::Local<v8::ArrayBufferView> view, Option option)
Store::Store(Local<v8::ArrayBufferView> view, Option option)
: Store(view->Buffer()->GetBackingStore(),
view->ByteLength(),
view->ByteOffset()) {
Expand All @@ -104,7 +104,7 @@ Store::Store(v8::Local<v8::ArrayBufferView> view, Option option)
}
}

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

MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const {
if ((type() == QuicError::Type::TRANSPORT && code() == NGTCP2_NO_ERROR) ||
(type() == QuicError::Type::APPLICATION &&
code() == NGTCP2_APP_NOERROR) ||
(type() == QuicError::Type::APPLICATION &&
code() == NGHTTP3_H3_NO_ERROR)) {
if ((type() == Type::TRANSPORT && code() == NGTCP2_NO_ERROR) ||
(type() == Type::APPLICATION && code() == NGTCP2_APP_NOERROR) ||
(type() == Type::APPLICATION && code() == NGHTTP3_H3_NO_ERROR)) {
return Undefined(env->isolate());
}

Expand Down Expand Up @@ -331,14 +329,11 @@ QuicError QuicError::FromConnectionClose(ngtcp2_conn* session) {
return QuicError(ngtcp2_conn_get_ccerr(session));
}

QuicError QuicError::TRANSPORT_NO_ERROR =
QuicError::ForTransport(QuicError::QUIC_NO_ERROR);
QuicError QuicError::APPLICATION_NO_ERROR =
QuicError::ForApplication(QuicError::QUIC_APP_NO_ERROR);
QuicError QuicError::VERSION_NEGOTIATION = QuicError::ForVersionNegotiation();
QuicError QuicError::IDLE_CLOSE = QuicError::ForIdleClose();
QuicError QuicError::INTERNAL_ERROR =
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL);
QuicError QuicError::TRANSPORT_NO_ERROR = ForTransport(QUIC_NO_ERROR);
QuicError QuicError::APPLICATION_NO_ERROR = ForApplication(QUIC_APP_NO_ERROR);
QuicError QuicError::VERSION_NEGOTIATION = ForVersionNegotiation();
QuicError QuicError::IDLE_CLOSE = ForIdleClose();
QuicError QuicError::INTERNAL_ERROR = ForNgtcp2Error(NGTCP2_ERR_INTERNAL);

} // namespace quic
} // namespace node
Expand Down
18 changes: 8 additions & 10 deletions src/quic/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bool SetOption(Environment* env,
Maybe<Endpoint::Options> Endpoint::Options::From(Environment* env,
Local<Value> value) {
if (value.IsEmpty() || !value->IsObject()) {
if (value->IsUndefined()) return Just(Endpoint::Options());
if (value->IsUndefined()) return Just(Options());
THROW_ERR_INVALID_ARG_TYPE(env, "options must be an object");
return Nothing<Options>();
}
Expand Down Expand Up @@ -213,7 +213,7 @@ Maybe<Endpoint::Options> Endpoint::Options::From(Environment* env,
"The address option must be a SocketAddress");
return Nothing<Options>();
}
auto addr = FromJSObject<SocketAddressBase>(address.As<v8::Object>());
auto addr = FromJSObject<SocketAddressBase>(address.As<Object>());
options.local_address = addr->address();
} else {
options.local_address = std::make_shared<SocketAddress>();
Expand Down Expand Up @@ -286,8 +286,7 @@ class Endpoint::UDP::Impl final : public HandleWrap {
if (tmpl.IsEmpty()) {
tmpl = NewFunctionTemplate(env->isolate(), IllegalConstructor);
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
tmpl->InstanceTemplate()->SetInternalFieldCount(
HandleWrap::kInternalFieldCount);
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
tmpl->SetClassName(state.endpoint_udp_string());
state.set_udp_constructor_template(tmpl);
}
Expand Down Expand Up @@ -317,7 +316,7 @@ class Endpoint::UDP::Impl final : public HandleWrap {
: HandleWrap(endpoint->env(),
object,
reinterpret_cast<uv_handle_t*>(&handle_),
AsyncWrap::PROVIDER_QUIC_UDP),
PROVIDER_QUIC_UDP),
endpoint_(endpoint) {
CHECK_EQ(uv_udp_init(endpoint->env()->event_loop(), &handle_), 0);
handle_.data = this;
Expand Down Expand Up @@ -376,7 +375,7 @@ Endpoint::UDP::~UDP() {
Close();
}

int Endpoint::UDP::Bind(const Endpoint::Options& options) {
int Endpoint::UDP::Bind(const Options& options) {
if (is_bound_) return UV_EALREADY;
if (is_closed_or_closing()) return UV_EBADF;

Expand Down Expand Up @@ -521,8 +520,7 @@ Local<FunctionTemplate> Endpoint::GetConstructorTemplate(Environment* env) {
tmpl = NewFunctionTemplate(isolate, New);
tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env));
tmpl->SetClassName(state.endpoint_string());
tmpl->InstanceTemplate()->SetInternalFieldCount(
Endpoint::kInternalFieldCount);
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
SetProtoMethod(isolate, tmpl, "listen", DoListen);
SetProtoMethod(isolate, tmpl, "closeGracefully", DoCloseGracefully);
SetProtoMethod(isolate, tmpl, "connect", DoConnect);
Expand Down Expand Up @@ -612,8 +610,8 @@ void Endpoint::RegisterExternalReferences(ExternalReferenceRegistry* registry) {

Endpoint::Endpoint(Environment* env,
Local<Object> object,
const Endpoint::Options& options)
: AsyncWrap(env, object, AsyncWrap::PROVIDER_QUIC_ENDPOINT),
const Options& options)
: AsyncWrap(env, object, PROVIDER_QUIC_ENDPOINT),
stats_(env->isolate()),
state_(env->isolate()),
options_(options),
Expand Down
10 changes: 4 additions & 6 deletions src/quic/http3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Local<FunctionTemplate> Http3Application::GetConstructorTemplate(
auto isolate = env->isolate();
tmpl = NewFunctionTemplate(isolate, New);
tmpl->SetClassName(state.http3application_string());
tmpl->InstanceTemplate()->SetInternalFieldCount(
Http3Application::kInternalFieldCount);
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
state.set_http3application_constructor_template(tmpl);
}
return tmpl;
Expand Down Expand Up @@ -169,8 +168,7 @@ using Http3Header = NgHeader<Http3HeaderTraits>;
// Implements the low-level HTTP/3 Application semantics.
class Http3ApplicationImpl final : public Session::Application {
public:
Http3ApplicationImpl(Session* session,
const Session::Application::Options& options)
Http3ApplicationImpl(Session* session, const Options& options)
: Application(session, options),
allocator_(BindingData::Get(env())),
options_(options),
Expand Down Expand Up @@ -403,7 +401,7 @@ class Http3ApplicationImpl final : public Session::Application {

bool SendHeaders(const Stream& stream,
HeadersKind kind,
const v8::Local<v8::Array>& headers,
const Local<v8::Array>& headers,
HeadersFlags flags = HeadersFlags::NONE) override {
Session::SendPendingDataScope send_scope(&session());
Http3Headers nva(env(), headers);
Expand Down Expand Up @@ -728,7 +726,7 @@ class Http3ApplicationImpl final : public Session::Application {

bool started_ = false;
nghttp3_mem allocator_;
Session::Application::Options options_;
Options options_;
Http3ConnectionPointer conn_;
int64_t control_stream_id_ = -1;
int64_t qpack_dec_stream_id_ = -1;
Expand Down
6 changes: 3 additions & 3 deletions src/quic/logstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Local<FunctionTemplate> LogStream::GetConstructorTemplate(Environment* env) {
}

BaseObjectPtr<LogStream> LogStream::Create(Environment* env) {
v8::Local<v8::Object> obj;
Local<Object> obj;
if (!GetConstructorTemplate(env)
->InstanceTemplate()
->NewInstance(env->context())
Expand All @@ -46,9 +46,9 @@ BaseObjectPtr<LogStream> LogStream::Create(Environment* env) {
}

LogStream::LogStream(Environment* env, Local<Object> obj)
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_QUIC_LOGSTREAM), StreamBase(env) {
: AsyncWrap(env, obj, PROVIDER_QUIC_LOGSTREAM), StreamBase(env) {
MakeWeak();
StreamBase::AttachToObject(GetObject());
AttachToObject(GetObject());
}

void LogStream::Emit(const uint8_t* data, size_t len, EmitOption option) {
Expand Down
5 changes: 2 additions & 3 deletions src/quic/packet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ Local<FunctionTemplate> Packet::GetConstructorTemplate(Environment* env) {
if (tmpl.IsEmpty()) {
tmpl = NewFunctionTemplate(env->isolate(), IllegalConstructor);
tmpl->Inherit(ReqWrap<uv_udp_send_t>::GetConstructorTemplate(env));
tmpl->InstanceTemplate()->SetInternalFieldCount(
Packet::kInternalFieldCount);
tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
tmpl->SetClassName(state.packetwrap_string());
state.set_packet_constructor_template(tmpl);
}
Expand Down Expand Up @@ -174,7 +173,7 @@ Packet::Packet(Environment* env,
Local<Object> object,
const SocketAddress& destination,
std::shared_ptr<Data> data)
: ReqWrap<uv_udp_send_t>(env, object, AsyncWrap::PROVIDER_QUIC_PACKET),
: ReqWrap<uv_udp_send_t>(env, object, PROVIDER_QUIC_PACKET),
listener_(listener),
destination_(destination),
data_(std::move(data)) {
Expand Down
15 changes: 9 additions & 6 deletions src/quic/preferredaddress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ void copy_to_transport_params(ngtcp2_transport_params* params,
const sockaddr* addr) {
params->preferred_addr_present = true;
if constexpr (FAMILY == AF_INET) {
const sockaddr_in* src = reinterpret_cast<const sockaddr_in*>(addr);
const auto* src = reinterpret_cast<const sockaddr_in*>(addr);
params->preferred_addr.ipv4.sin_port = SocketAddress::GetPort(addr);
memcpy(&params->preferred_addr.ipv4.sin_addr,
&src->sin_addr,
sizeof(params->preferred_addr.ipv4.sin_addr));
} else {
DCHECK_EQ(FAMILY, AF_INET6);
const sockaddr_in6* src = reinterpret_cast<const sockaddr_in6*>(addr);
const auto* src = reinterpret_cast<const sockaddr_in6*>(addr);
params->preferred_addr.ipv6.sin6_port = SocketAddress::GetPort(addr);
memcpy(&params->preferred_addr.ipv6.sin6_addr,
&src->sin6_addr,
Expand Down Expand Up @@ -136,29 +136,32 @@ void PreferredAddress::Set(ngtcp2_transport_params* params,
return copy_to_transport_params<AF_INET>(params, addr);
case AF_INET6:
return copy_to_transport_params<AF_INET6>(params, addr);
default:
UNREACHABLE("Unreachable");
}
// Any other value is just ignored.
}

Maybe<PreferredAddress::Policy> PreferredAddress::tryGetPolicy(
Environment* env, Local<Value> value) {
if (value->IsUndefined()) {
return Just(PreferredAddress::Policy::USE_PREFERRED);
return Just(Policy::USE_PREFERRED);
}
if (value->IsUint32()) {
switch (value.As<Uint32>()->Value()) {
case PREFERRED_ADDRESS_IGNORE:
return Just(Policy::IGNORE_PREFERRED);
case PREFERRED_ADDRESS_USE:
return Just(Policy::USE_PREFERRED);
default:
UNREACHABLE("Unreachable");
}
}
THROW_ERR_INVALID_ARG_VALUE(env, "invalid preferred address policy");
return Nothing<PreferredAddress::Policy>();
return Nothing<Policy>();
}

void PreferredAddress::Initialize(Environment* env,
v8::Local<v8::Object> target) {
void PreferredAddress::Initialize(Environment* env, Local<v8::Object> target) {
NODE_DEFINE_CONSTANT(target, PREFERRED_ADDRESS_IGNORE);
NODE_DEFINE_CONSTANT(target, PREFERRED_ADDRESS_USE);
NODE_DEFINE_CONSTANT(target, DEFAULT_PREFERRED_ADDRESS_POLICY);
Expand Down
Loading
Loading