quic: cache the timestamp on send and receive · nodejs/node@aec1e17 · GitHub
Skip to content

Commit aec1e17

Browse files
jasnelladuh95
authored andcommitted
quic: cache the timestamp on send and receive
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode:Opus 4.6 PR-URL: #63267 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 9560084 commit aec1e17

4 files changed

Lines changed: 39 additions & 15 deletions

File tree

src/quic/application.cc

Lines changed: 17 additions & 7 deletions

src/quic/application.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ class Session::Application : public MemoryRetainer {
267267
// the datagram is either congestion limited or was abandoned
268268
ssize_t TryWritePendingDatagram(PathStorage* path,
269269
uint8_t* dest,
270-
size_t destlen);
270+
size_t destlen,
271+
uint64_t ts);
271272

272273
// Write the given stream_data into the buffer. The PacketInfo out-param
273274
// is populated by ngtcp2 with per-packet metadata (e.g., ECN codepoint)
@@ -277,7 +278,8 @@ class Session::Application : public MemoryRetainer {
277278
uint8_t* buf,
278279
ssize_t* ndatalen,
279280
size_t max_packet_size,
280-
const StreamData& stream_data);
281+
const StreamData& stream_data,
282+
uint64_t ts);
281283

282284
Session* session_ = nullptr;
283285
};

src/quic/session.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,20 +2104,23 @@ void Session::SetLastError(QuicError&& error) {
21042104
bool Session::Receive(Store&& store,
21052105
const SocketAddress& local_address,
21062106
const SocketAddress& remote_address,
2107-
const PacketInfo& pkt_info) {
2107+
const PacketInfo& pkt_info,
2108+
uint64_t ts) {
21082109
// Convenience wrapper: reads the packet and immediately triggers
21092110
// SendPendingData. Used by paths that need an immediate response
21102111
// (e.g., Endpoint::Connect for client Initial packets).
21112112
// The hot receive path uses ReadPacket() directly with deferred
21122113
// flush via BindingData's uv_check callback.
21132114
SendPendingDataScope send_scope(this);
2114-
return ReadPacket(std::move(store), local_address, remote_address, pkt_info);
2115+
return ReadPacket(
2116+
std::move(store), local_address, remote_address, pkt_info, ts);
21152117
}
21162118

21172119
bool Session::ReadPacket(Store&& store,
21182120
const SocketAddress& local_address,
21192121
const SocketAddress& remote_address,
2120-
const PacketInfo& pkt_info) {
2122+
const PacketInfo& pkt_info,
2123+
uint64_t ts) {
21212124
DCHECK(!is_destroyed());
21222125
impl_->remote_address_ = remote_address;
21232126

@@ -2143,8 +2146,12 @@ bool Session::ReadPacket(Store&& store,
21432146
// When libuv gains per-packet ECN reporting, the caller should
21442147
// populate pkt_info from the receive metadata before calling
21452148
// ReadPacket().
2149+
// When ts is 0 (the default), call uv_hrtime() here. The batched
2150+
// receive path caches a timestamp and passes it to all ReadPacket()
2151+
// calls in the same I/O burst.
2152+
if (ts == 0) ts = uv_hrtime();
21462153
err = ngtcp2_conn_read_pkt(
2147-
*this, &path, pkt_info, vec.base, vec.len, uv_hrtime());
2154+
*this, &path, pkt_info, vec.base, vec.len, ts);
21482155
}
21492156
if (is_destroyed()) return false;
21502157

src/quic/session.h

Lines changed: 7 additions & 2 deletions

0 commit comments

Comments
 (0)