quic: extract transport logic from Application to Session · nodejs/node@e2e2829 · GitHub
Skip to content

Commit e2e2829

Browse files
pimterryaduh95
authored andcommitted
quic: extract transport logic from Application to Session
One small fix notably included: - Check is_destroyed() after StreamCommit, since it calls JS callbacks which could destroy the session. Signed-off-by: Tim Perry <pimterry@gmail.com> PR-URL: #64127 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7ac97fc commit e2e2829

9 files changed

Lines changed: 608 additions & 562 deletions

File tree

src/quic/README.md

Lines changed: 6 additions & 6 deletions

src/quic/application.cc

Lines changed: 6 additions & 449 deletions
Large diffs are not rendered by default.

src/quic/application.h

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ class Session::Application : public MemoryRetainer {
205205
return false;
206206
}
207207

208-
// Signals to the Application that it should serialize and transmit any
209-
// pending session and stream packets it has accumulated.
210-
void SendPendingData();
211-
212208
// Returns true if the application protocol supports sending and
213209
// receiving headers on streams (e.g. HTTP/3). Applications that
214210
// do not support headers should return false (the default).
@@ -243,10 +239,6 @@ class Session::Application : public MemoryRetainer {
243239
return {StreamPriority::DEFAULT, StreamPriorityFlags::NON_INCREMENTAL};
244240
}
245241

246-
// The StreamData struct is used by the application to pass pending stream
247-
// data to the session for transmission.
248-
struct StreamData;
249-
250242
virtual int GetStreamData(StreamData* data) = 0;
251243
virtual bool StreamCommit(StreamData* data, size_t datalen) = 0;
252244

@@ -262,57 +254,9 @@ class Session::Application : public MemoryRetainer {
262254
}
263255

264256
private:
265-
Packet::Ptr CreateStreamDataPacket();
266-
267-
// Tries to pack a pending datagram into the current packet buffer.
268-
// If < 0 is returned, either NGTCP2_ERR_WRITE_MORE or a fatal error is
269-
// returned; the caller must check. If > 0 is returned, the packet is done
270-
// and the value is the size of the finalized packet. If 0 is returned,
271-
// the datagram is either congestion limited or was abandoned
272-
ssize_t TryWritePendingDatagram(PathStorage* path,
273-
uint8_t* dest,
274-
size_t destlen,
275-
uint64_t ts);
276-
277-
// Write the given stream_data into the buffer. The PacketInfo out-param
278-
// is populated by ngtcp2 with per-packet metadata (e.g., ECN codepoint)
279-
// that should be applied when sending the packet.
280-
ssize_t WriteVStream(PathStorage* path,
281-
PacketInfo* pi,
282-
uint8_t* buf,
283-
ssize_t* ndatalen,
284-
size_t max_packet_size,
285-
const StreamData& stream_data,
286-
uint64_t ts);
287-
288257
Session* session_ = nullptr;
289258
};
290259

291-
struct Session::Application::StreamData final {
292-
// The actual number of vectors in the struct, up to kMaxVectorCount.
293-
size_t count = 0;
294-
// The stream identifier. If this is a negative value then no stream is
295-
// identified.
296-
stream_id id = -1;
297-
int fin = 0;
298-
ngtcp2_vec data[kMaxVectorCount]{};
299-
BaseObjectPtr<Stream> stream;
300-
301-
static_assert(sizeof(ngtcp2_vec) == sizeof(nghttp3_vec) &&
302-
alignof(ngtcp2_vec) == alignof(nghttp3_vec) &&
303-
offsetof(ngtcp2_vec, base) == offsetof(nghttp3_vec, base) &&
304-
offsetof(ngtcp2_vec, len) == offsetof(nghttp3_vec, len),
305-
"ngtcp2_vec and nghttp3_vec must have identical layout");
306-
inline operator nghttp3_vec*() {
307-
return reinterpret_cast<nghttp3_vec*>(data);
308-
}
309-
310-
inline operator const ngtcp2_vec*() const { return data; }
311-
inline operator ngtcp2_vec*() { return data; }
312-
313-
std::string ToString() const;
314-
};
315-
316260
// Create a DefaultApplication for the given session.
317261
std::unique_ptr<Session::Application> CreateDefaultApplication(
318262
Session* session, const Session::Application_Options& options);

src/quic/http3.cc

Lines changed: 40 additions & 46 deletions

0 commit comments

Comments
 (0)