Skip to content

Commit b5bf5bb

Browse files
committed
quic: refactor native object flags for better readability
Use is_* and set_* pattern for native object flags to improve readability in the code. PR-URL: #34160 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent b1750a4 commit b5bf5bb

12 files changed

+234
-299
lines changed

lib/internal/quic/core.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,11 @@ class QuicSocket extends EventEmitter {
966966
state.lookup = lookup || (type === AF_INET6 ? lookup6 : lookup4);
967967
state.server = server;
968968

969-
const socketOptions =
970-
(validateAddress ? QUICSOCKET_OPTIONS_VALIDATE_ADDRESS : 0) |
971-
(validateAddressLRU ? QUICSOCKET_OPTIONS_VALIDATE_ADDRESS_LRU : 0);
969+
let socketOptions = 0;
970+
if (validateAddress)
971+
socketOptions |= (1 << QUICSOCKET_OPTIONS_VALIDATE_ADDRESS);
972+
if (validateAddressLRU)
973+
socketOptions |= (1 << QUICSOCKET_OPTIONS_VALIDATE_ADDRESS_LRU);
972974

973975
this[kSetHandle](
974976
new QuicSocketHandle(

src/quic/node_quic_default_application.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ bool DefaultApplication::ReceiveStreamData(
9292
BaseObjectPtr<QuicStream> stream = session()->FindStream(stream_id);
9393
if (!stream) {
9494
// Shutdown the stream explicitly if the session is being closed.
95-
if (session()->is_gracefully_closing()) {
95+
if (session()->is_graceful_closing()) {
9696
ngtcp2_conn_shutdown_stream(
9797
session()->connection(),
9898
stream_id,

src/quic/node_quic_http3_application.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ BaseObjectPtr<QuicStream> Http3Application::FindOrCreateStream(
603603
int64_t stream_id) {
604604
BaseObjectPtr<QuicStream> stream = session()->FindStream(stream_id);
605605
if (!stream) {
606-
if (session()->is_gracefully_closing()) {
606+
if (session()->is_graceful_closing()) {
607607
nghttp3_conn_close_stream(connection(), stream_id, NGTCP2_ERR_CLOSING);
608608
return {};
609609
}

src/quic/node_quic_session-inl.h

+17-26
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ void QuicCryptoContext::Keylog(const char* line) {
112112
void QuicCryptoContext::OnClientHelloDone() {
113113
// Continue the TLS handshake when this function exits
114114
// otherwise it will stall and fail.
115-
TLSHandshakeScope handshake(this, &in_client_hello_);
115+
TLSHandshakeScope handshake_scope(
116+
this,
117+
[&]() { set_in_client_hello(false); });
118+
116119
// Disable the callback at this point so we don't loop continuously
117120
session_->state_[IDX_QUIC_SESSION_STATE_CLIENT_HELLO_ENABLED] = 0;
118121
}
@@ -129,8 +132,8 @@ void QuicCryptoContext::ResumeHandshake() {
129132
// For 0RTT, this sets the TLS session data from the given buffer.
130133
bool QuicCryptoContext::set_session(crypto::SSLSessionPointer session) {
131134
if (side_ == NGTCP2_CRYPTO_SIDE_CLIENT && session != nullptr) {
132-
early_data_ =
133-
SSL_SESSION_get_max_early_data(session.get()) == 0xffffffffUL;
135+
set_early_data(
136+
SSL_SESSION_get_max_early_data(session.get()) == 0xffffffffUL);
134137
}
135138
return crypto::SetTLSSession(ssl_, std::move(session));
136139
}
@@ -186,7 +189,7 @@ std::string QuicCryptoContext::selected_alpn() const {
186189

187190
bool QuicCryptoContext::early_data() const {
188191
return
189-
(early_data_ &&
192+
(is_early_data() &&
190193
SSL_get_early_data_status(ssl_.get()) == SSL_EARLY_DATA_ACCEPTED) ||
191194
SSL_get_max_early_data(ssl_.get()) == 0xffffffffUL;
192195
}
@@ -300,13 +303,13 @@ void QuicSession::ExtendOffset(size_t amount) {
300303

301304
// Copies the local transport params into the given struct for serialization.
302305
void QuicSession::GetLocalTransportParams(ngtcp2_transport_params* params) {
303-
CHECK(!is_flag_set(QUICSESSION_FLAG_DESTROYED));
306+
CHECK(!is_destroyed());
304307
ngtcp2_conn_get_local_transport_params(connection(), params);
305308
}
306309

307310
// Gets the QUIC version negotiated for this QuicSession
308311
uint32_t QuicSession::negotiated_version() const {
309-
CHECK(!is_flag_set(QUICSESSION_FLAG_DESTROYED));
312+
CHECK(!is_destroyed());
310313
return ngtcp2_conn_get_negotiated_version(connection());
311314
}
312315

@@ -328,7 +331,7 @@ void QuicSession::HandshakeConfirmed() {
328331
}
329332

330333
bool QuicSession::is_handshake_completed() const {
331-
DCHECK(!is_flag_set(QUICSESSION_FLAG_DESTROYED));
334+
DCHECK(!is_destroyed());
332335
return ngtcp2_conn_get_handshake_completed(connection());
333336
}
334337

@@ -342,7 +345,7 @@ void QuicSession::InitApplication() {
342345
// immediately closed without attempting to send any additional data to
343346
// the peer. All existing streams are abandoned and closed.
344347
void QuicSession::OnIdleTimeout() {
345-
if (!is_flag_set(QUICSESSION_FLAG_DESTROYED)) {
348+
if (!is_destroyed()) {
346349
state_[IDX_QUIC_SESSION_STATE_IDLE_TIMEOUT] = 1;
347350
Debug(this, "Idle timeout");
348351
SilentClose();
@@ -359,7 +362,7 @@ void QuicSession::GetConnectionCloseInfo() {
359362

360363
// Removes the given connection id from the QuicSession.
361364
void QuicSession::RemoveConnectionID(const QuicCID& cid) {
362-
if (!is_flag_set(QUICSESSION_FLAG_DESTROYED))
365+
if (!is_destroyed())
363366
DisassociateCID(cid);
364367
}
365368

@@ -440,24 +443,12 @@ SessionTicketAppData::Status QuicSession::GetSessionTicketAppData(
440443
return application_->GetSessionTicketAppData(app_data, flag);
441444
}
442445

443-
bool QuicSession::is_gracefully_closing() const {
444-
return is_flag_set(QUICSESSION_FLAG_GRACEFUL_CLOSING);
445-
}
446-
447-
bool QuicSession::is_destroyed() const {
448-
return is_flag_set(QUICSESSION_FLAG_DESTROYED);
449-
}
450-
451-
bool QuicSession::is_stateless_reset() const {
452-
return is_flag_set(QUICSESSION_FLAG_STATELESS_RESET);
453-
}
454-
455446
bool QuicSession::is_server() const {
456447
return crypto_context_->side() == NGTCP2_CRYPTO_SIDE_SERVER;
457448
}
458449

459450
void QuicSession::StartGracefulClose() {
460-
set_flag(QUICSESSION_FLAG_GRACEFUL_CLOSING);
451+
set_graceful_closing();
461452
RecordTimestamp(&QuicSessionStats::closing_at);
462453
}
463454

@@ -511,15 +502,15 @@ bool QuicSession::SendPacket(
511502
}
512503

513504
void QuicSession::set_local_address(const ngtcp2_addr* addr) {
514-
DCHECK(!is_flag_set(QUICSESSION_FLAG_DESTROYED));
505+
DCHECK(!is_destroyed());
515506
ngtcp2_conn_set_local_addr(connection(), addr);
516507
}
517508

518509
// Set the transport parameters received from the remote peer
519510
void QuicSession::set_remote_transport_params() {
520-
DCHECK(!is_flag_set(QUICSESSION_FLAG_DESTROYED));
511+
DCHECK(!is_destroyed());
521512
ngtcp2_conn_get_remote_transport_params(connection(), &transport_params_);
522-
set_flag(QUICSESSION_FLAG_HAS_TRANSPORT_PARAMS);
513+
set_transport_params_set();
523514
}
524515

525516
void QuicSession::StopIdleTimer() {
@@ -537,7 +528,7 @@ void QuicSession::StopRetransmitTimer() {
537528
// parameter is an array of versions supported by the remote peer.
538529
void QuicSession::VersionNegotiation(const uint32_t* sv, size_t nsv) {
539530
CHECK(!is_server());
540-
if (!is_flag_set(QUICSESSION_FLAG_DESTROYED))
531+
if (!is_destroyed())
541532
listener()->OnVersionNegotiation(NGTCP2_PROTO_VER, sv, nsv);
542533
}
543534

0 commit comments

Comments
 (0)