quic: update http3 impl details

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode/Opus 4.6
PR-URL: https://github.com/nodejs/node/pull/62387
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
James M Snell authored and Antoine du Hamel committed 2026-05-07 17:32:44 +02:00
1 parent 7f3a85e6aa
commit edeed4303b
1 file changed
+111 -26
+111 -26
View File
@@ -319,14 +319,20 @@ class Http3ApplicationImpl final : public Session::Application {
void CollectSessionTicketAppData(
SessionTicket::AppData* app_data) const override {
// TODO(@jasnell): There's currently nothing to store but there may be
// later.
// TODO(@jasnell): When HTTP/3 settings become dynamic or
// configurable per-connection, store them here so they can be
// validated on 0-RTT resumption. Candidates include:
// max_field_section_size, qpack_max_dtable_capacity,
// qpack_encoder_max_dtable_capacity, qpack_blocked_streams,
// enable_connect_protocol, and enable_datagrams. On extraction,
// compare stored values against current settings and return
// TICKET_IGNORE_RENEW if incompatible.
}
SessionTicket::AppData::Status ExtractSessionTicketAppData(
const SessionTicket::AppData& app_data,
SessionTicket::AppData::Source::Flag flag) override {
// There's currently nothing stored here but we might do so later.
// See CollectSessionTicketAppData above.
return flag == SessionTicket::AppData::Source::Flag::STATUS_RENEW
? SessionTicket::AppData::Status::TICKET_USE_RENEW
: SessionTicket::AppData::Status::TICKET_USE;
@@ -448,10 +454,42 @@ class Http3ApplicationImpl final : public Session::Application {
return false;
}
void SetStreamPriority(const Stream& stream,
StreamPriority priority,
StreamPriorityFlags flags) override {
nghttp3_pri pri;
pri.inc = (flags == StreamPriorityFlags::NON_INCREMENTAL) ? 0 : 1;
switch (priority) {
case StreamPriority::HIGH:
pri.urgency = NGHTTP3_URGENCY_HIGH;
break;
case StreamPriority::LOW:
pri.urgency = NGHTTP3_URGENCY_LOW;
break;
default:
pri.urgency = NGHTTP3_DEFAULT_URGENCY;
break;
}
if (session().is_server()) {
nghttp3_conn_set_server_stream_priority(
*this, stream.id(), &pri);
}
// Client-side priority is set at request submission time via
// nghttp3_conn_submit_request and is not typically changed
// after the fact. The client API takes a serialized RFC 9218
// field value rather than an nghttp3_pri struct.
}
StreamPriority GetStreamPriority(const Stream& stream) override {
nghttp3_pri pri;
if (nghttp3_conn_get_stream_priority(*this, &pri, stream.id()) == 0) {
// TODO(@jasnell): Support the incremental flag
// TODO(@jasnell): The nghttp3_pri.inc (incremental) flag is
// not yet exposed. When priority-based stream scheduling is
// implemented, GetStreamPriority should return both urgency
// and the incremental flag (making get/set symmetrical).
// The inc flag determines whether the server should interleave
// data from this stream with others of the same urgency
// (inc=1) or complete it first (inc=0).
switch (pri.urgency) {
case NGHTTP3_URGENCY_HIGH:
return StreamPriority::HIGH;
@@ -673,22 +711,23 @@ class Http3ApplicationImpl final : public Session::Application {
stream->ReceiveStreamReset(0, QuicError::ForApplication(app_error_code));
}
void OnShutdown() {
// This callback is invoked when we receive a request to gracefully shutdown
// the http3 connection. For client, the id is the stream id of a client
// initiated stream. For server, the id is the stream id of a server
// initiated stream. Once received, the other side is guaranteed not to
// process any more data.
// On the client side, if id is equal to NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID,
// or on the server if the id is equal to NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID,
// then this is a request to begin a graceful shutdown.
// This can be called multiple times but the id can only stay the same or
// *decrease*.
// TODO(@jasnell): Need to determine exactly how to handle.
Debug(&session(), "HTTP/3 application received shutdown notice");
void OnShutdown(int64_t id) {
// The peer has sent a GOAWAY frame initiating a graceful shutdown.
// For a client, id is the stream ID beyond which the server will
// not process requests. For a server, id is a push ID (server
// push is not implemented). Streams/pushes with IDs >= id will
// not be processed by the peer.
//
// When id equals NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID (client) or
// NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID (server), this is a notice of
// intent to shut down rather than an immediate refusal.
//
// This can be called multiple times with a decreasing id as the
// peer progressively reduces the set of streams it will process.
Debug(&session(),
"HTTP/3 received GOAWAY (id=%" PRIi64 ")",
id);
session().Close(Session::CloseMethod::GRACEFUL);
}
void OnReceiveSettings(const nghttp3_settings* settings) {
@@ -747,9 +786,55 @@ class Http3ApplicationImpl final : public Session::Application {
uint32_t* pflags,
void* conn_user_data,
void* stream_user_data) {
return NGTCP2_SUCCESS;
auto ptr = From(conn, conn_user_data);
CHECK_NOT_NULL(ptr);
auto& app = *ptr;
NgHttp3CallbackScope scope(app.env());
auto stream = app.session().FindStream(stream_id);
if (!stream) return NGHTTP3_ERR_CALLBACK_FAILURE;
if (stream->is_eos()) {
*pflags |= NGHTTP3_DATA_FLAG_EOF;
return 0;
}
size_t max_count = std::min(veccnt,
static_cast<size_t>(kMaxVectorCount));
nghttp3_ssize result = 0;
auto next = [&](int status,
const ngtcp2_vec* data,
size_t count,
bob::Done done) {
switch (status) {
case bob::Status::STATUS_BLOCK:
case bob::Status::STATUS_WAIT:
result = NGHTTP3_ERR_WOULDBLOCK;
return;
case bob::Status::STATUS_EOS:
*pflags |= NGHTTP3_DATA_FLAG_EOF;
break;
}
count = std::min(count, max_count);
for (size_t n = 0; n < count; n++) {
vec[n].base = data[n].base;
vec[n].len = data[n].len;
}
result = static_cast<nghttp3_ssize>(count);
};
ngtcp2_vec data[kMaxVectorCount];
stream->Pull(std::move(next),
bob::Options::OPTIONS_SYNC,
data,
max_count,
max_count);
return result;
}
static int on_acked_stream_data(nghttp3_conn* conn,
int64_t stream_id,
uint64_t datalen,
@@ -934,7 +1019,7 @@ class Http3ApplicationImpl final : public Session::Application {
static int on_shutdown(nghttp3_conn* conn, int64_t id, void* conn_user_data) {
NGHTTP3_CALLBACK_SCOPE(app);
app.OnShutdown();
app.OnShutdown(id);
return NGTCP2_SUCCESS;
}
@@ -950,14 +1035,14 @@ class Http3ApplicationImpl final : public Session::Application {
const uint8_t* origin,
size_t originlen,
void* conn_user_data) {
// TODO(@jasnell): Handle the origin callback. This is called
// when a single origin in an ORIGIN frame is received.
// ORIGIN frames (RFC 8336) are used for connection coalescing
// across multiple origins. Not yet implemented u2014 requires
// connection pooling and multi-origin reuse support.
return NGTCP2_SUCCESS;
}
static int on_end_origin(nghttp3_conn* conn, void* conn_user_data) {
// TODO(@jasnell): Handle the end of origin callback. This is called
// when the end of an ORIGIN frame is received.
// See on_receive_origin above.
return NGTCP2_SUCCESS;
}