Skip to content

Commit

Permalink
quic: use getter/setter for stateless reset toggle
Browse files Browse the repository at this point in the history
PR-URL: #34247
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Jul 9, 2020
1 parent f2753c7 commit d08e99d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
24 changes: 14 additions & 10 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ class QuicSocket extends EventEmitter {
serverSecureContext: undefined,
sessions: new Set(),
state: kSocketUnbound,
statelessResetEnabled: true,
stats: undefined,
};

Expand Down Expand Up @@ -1613,16 +1614,19 @@ class QuicSocket extends EventEmitter {
this[kHandle].setDiagnosticPacketLoss(rx, tx);
}

// Toggles stateless reset on/off. By default, stateless reset tokens
// are generated when necessary. The disableStatelessReset option may
// be used when the QuicSocket is created to disable generation of
// stateless resets. The toggleStatelessReset method allows the setting
// to be switched on/off dynamically through the lifetime of the
// socket.
toggleStatelessReset() {
if (this[kInternalState].state === kSocketDestroyed)
throw new ERR_QUICSOCKET_DESTROYED('toggleStatelessReset');
return this[kHandle].toggleStatelessReset();
get statelessResetEnabled() {
return this[kInternalState].statelessResetEnabled;
}

set statelessResetEnabled(on) {
const state = this[kInternalState];
if (state.state === kSocketDestroyed)
throw new ERR_QUICSOCKET_DESTROYED('serverBusy');
validateBoolean(on, 'on');
if (state.statelessResetEnabled !== on) {
this[kHandle].enableStatelessReset(on);
state.statelessResetEnabled = on;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/quic/node_quic_socket-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void QuicSocket::set_diagnostic_packet_loss(double rx, double tx) {
tx_loss_ = tx;
}

bool QuicSocket::ToggleStatelessReset() {
set_stateless_reset_disabled(!is_stateless_reset_disabled());
bool QuicSocket::EnableStatelessReset(bool on) {
set_stateless_reset_disabled(!on);
return !is_stateless_reset_disabled();
}

Expand Down
9 changes: 5 additions & 4 deletions src/quic/node_quic_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,11 @@ void QuicSocketSetServerBusy(const FunctionCallbackInfo<Value>& args) {
socket->ServerBusy(args[0]->IsTrue());
}

void QuicSocketToggleStatelessReset(const FunctionCallbackInfo<Value>& args) {
void QuicSocketEnableStatelessReset(const FunctionCallbackInfo<Value>& args) {
QuicSocket* socket;
ASSIGN_OR_RETURN_UNWRAP(&socket, args.Holder());
args.GetReturnValue().Set(socket->ToggleStatelessReset());
CHECK_EQ(args.Length(), 1);
args.GetReturnValue().Set(socket->EnableStatelessReset(args[0]->IsTrue()));
}

void QuicEndpointWaitForPendingCallbacks(
Expand Down Expand Up @@ -1197,8 +1198,8 @@ void QuicSocket::Initialize(
"stopListening",
QuicSocketStopListening);
env->SetProtoMethod(socket,
"toggleStatelessReset",
QuicSocketToggleStatelessReset);
"enableStatelessReset",
QuicSocketEnableStatelessReset);
socket->Inherit(HandleWrap::GetConstructorTemplate(env));
target->Set(context, class_name,
socket->GetFunction(env->context()).ToLocalChecked()).FromJust();
Expand Down
2 changes: 1 addition & 1 deletion src/quic/node_quic_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class QuicSocket : public AsyncWrap,
// Toggles whether or not stateless reset is enabled or not.
// Returns true if stateless reset is enabled, false if it
// is not.
inline bool ToggleStatelessReset();
inline bool EnableStatelessReset(bool on = true);

BaseObjectPtr<crypto::SecureContext> server_secure_context() const {
return server_secure_context_;
Expand Down

0 comments on commit d08e99d

Please sign in to comment.