Skip to content

Commit 423e261

Browse files
committed
fixup! quic: extract transport logic from Application to Session
Handle mechnical cleanup review comments
1 parent e36fa90 commit 423e261

4 files changed

Lines changed: 33 additions & 32 deletions

File tree

‎src/quic/application.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class DefaultApplication final : public Session::Application {
335335
return true;
336336
}
337337

338-
int GetStreamData(StreamData* stream_data) override {
338+
int GetStreamData(Session::StreamData* stream_data) override {
339339
// Reset the state of stream_data before proceeding...
340340
stream_data->id = -1;
341341
stream_data->count = 0;
@@ -422,7 +422,7 @@ class DefaultApplication final : public Session::Application {
422422
stream->Schedule(&stream_queue_);
423423
}
424424

425-
bool StreamCommit(StreamData* stream_data, size_t datalen) override {
425+
bool StreamCommit(Session::StreamData* stream_data, size_t datalen) override {
426426
DCHECK_NOT_NULL(stream_data);
427427
CHECK(stream_data->stream);
428428
stream_data->stream->Commit(datalen, stream_data->fin);

‎src/quic/http3.cc‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ class Http3ApplicationImpl final : public Session::Application {
241241

242242
Debug(&session(), "Creating and binding HTTP/3 control streams");
243243
bool ret =
244-
session().OpenUni(&control_stream_id_) &&
245-
session().OpenUni(&qpack_enc_stream_id_) &&
246-
session().OpenUni(&qpack_dec_stream_id_) &&
244+
session().OpenUnidirectionalStream(&control_stream_id_) &&
245+
session().OpenUnidirectionalStream(&qpack_enc_stream_id_) &&
246+
session().OpenUnidirectionalStream(&qpack_dec_stream_id_) &&
247247
nghttp3_conn_bind_control_stream(*this, control_stream_id_) == 0 &&
248248
nghttp3_conn_bind_qpack_streams(
249249
*this, qpack_enc_stream_id_, qpack_dec_stream_id_) == 0;
@@ -669,7 +669,7 @@ class Http3ApplicationImpl final : public Session::Application {
669669
return {StreamPriority::DEFAULT, StreamPriorityFlags::NON_INCREMENTAL};
670670
}
671671

672-
int GetStreamData(StreamData* data) override {
672+
int GetStreamData(Session::StreamData* data) override {
673673
static_assert(
674674
sizeof(ngtcp2_vec) == sizeof(nghttp3_vec) &&
675675
alignof(ngtcp2_vec) == alignof(nghttp3_vec) &&
@@ -702,7 +702,7 @@ class Http3ApplicationImpl final : public Session::Application {
702702
return 0;
703703
}
704704

705-
bool StreamCommit(StreamData* data, size_t datalen) override {
705+
bool StreamCommit(Session::StreamData* data, size_t datalen) override {
706706
Debug(&session(),
707707
"HTTP/3 application committing stream %" PRIi64 " data %zu",
708708
data->id,

‎src/quic/session.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ Session::SendPendingDataScope::~SendPendingDataScope() {
17361736

17371737
// ============================================================================
17381738

1739-
std::string StreamData::ToString() const {
1739+
std::string Session::StreamData::ToString() const {
17401740
DebugIndentScope indent;
17411741

17421742
size_t total_bytes = 0;
@@ -3403,7 +3403,7 @@ uint64_t Session::max_data_left() const {
34033403
return ngtcp2_conn_get_max_data_left(*this);
34043404
}
34053405

3406-
bool Session::OpenUni(stream_id* id) {
3406+
bool Session::OpenUnidirectionalStream(stream_id* id) {
34073407
return ngtcp2_conn_open_uni_stream(*this, id, nullptr) == 0;
34083408
}
34093409

‎src/quic/session.h‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@ namespace node::quic {
2727

2828
class Endpoint;
2929

30-
// A block of pending outbound stream data, passed between the application
31-
// layer (which fills it via GetStreamData) and the send pump (which hands
32-
// it to ngtcp2_conn_writev_stream and commits the accepted length).
33-
struct StreamData final {
34-
// The actual number of vectors in the struct, up to kMaxVectorCount.
35-
size_t count = 0;
36-
// The stream identifier. If this is a negative value then no stream is
37-
// identified.
38-
stream_id id = -1;
39-
int fin = 0;
40-
ngtcp2_vec data[kMaxVectorCount]{};
41-
BaseObjectPtr<Stream> stream;
42-
43-
inline operator const ngtcp2_vec*() const { return data; }
44-
inline operator ngtcp2_vec*() { return data; }
45-
46-
std::string ToString() const;
47-
};
48-
4930
// A Session represents one half of a persistent connection between two QUIC
5031
// peers. Every Session is established first by performing a TLS handshake in
5132
// which the client sends an initial packet to the server containing a TLS
@@ -123,6 +104,25 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
123104
// of a QUIC Session.
124105
class Application;
125106

107+
// A block of pending outbound stream data, passed between the application
108+
// layer (which fills it via GetStreamData) and the send pump (which hands
109+
// it to ngtcp2_conn_writev_stream and commits the accepted length).
110+
struct StreamData final {
111+
// The actual number of vectors in the struct, up to kMaxVectorCount.
112+
size_t count = 0;
113+
// The stream identifier. If this is a negative value then no stream is
114+
// identified.
115+
stream_id id = -1;
116+
int fin = 0;
117+
ngtcp2_vec data[kMaxVectorCount]{};
118+
BaseObjectPtr<Stream> stream;
119+
120+
inline operator const ngtcp2_vec*() const { return data; }
121+
inline operator ngtcp2_vec*() { return data; }
122+
123+
std::string ToString() const;
124+
};
125+
126126
// Decode the first ALPN protocol name from wire format (length-prefixed).
127127
static std::string_view DecodeAlpn(std::string_view wire);
128128

@@ -446,8 +446,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
446446
Packet::Ptr CreateStreamDataPacket();
447447

448448
// Tries to pack a pending datagram into the current packet buffer.
449-
// If < 0 is returned, either NGTCP2_ERR_WRITE_MORE or a fatal error is
450-
// returned; the caller must check. If > 0 is returned, the packet is done
449+
// If a negative value is returned, it is either NGTCP2_ERR_WRITE_MORE or
450+
// fatal error; the caller must check. If > 0 is returned, the packet is done
451451
// and the value is the size of the finalized packet. If 0 is returned,
452452
// the datagram is either congestion limited or was abandoned.
453453
ssize_t TryWritePendingDatagram(PathStorage* path,
@@ -539,11 +539,12 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
539539
// the session, encapsulating ngtcp2 transport details here.
540540

541541
// Open a unidirectional stream, setting *id on success, or returning false
542-
bool OpenUni(stream_id* id);
542+
bool OpenUnidirectionalStream(stream_id* id);
543543

544544
void ExtendMaxStreams(Direction direction, uint64_t max);
545545

546-
// Signal that we've consumed $len bytes on stream $id to update flow control
546+
// Signal that we've consumed `len` bytes on stream `id` to update flow
547+
// control
547548
void Consume(stream_id id, size_t len);
548549

549550
// Record an application-level error on the connection without closing it.

0 commit comments

Comments
 (0)