Skip to content

Commit 6720920

Browse files
committed
src: handful of minor quic cleanups
1 parent 2b62153 commit 6720920

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
lines changed

src/quic/defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ constexpr auto kSocketAddressInfoTimeout = 60 * NGTCP2_SECONDS;
316316
constexpr size_t kMaxVectorCount = 16;
317317

318318
using error_code = uint64_t;
319+
using stream_id = int64_t;
320+
using datagram_id = uint64_t;
319321

320322
class DebugIndentScope final {
321323
public:

src/quic/session.cc

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace quic {
7171
V(STREAM_OPEN_ALLOWED, stream_open_allowed, uint8_t) \
7272
V(PRIORITY_SUPPORTED, priority_supported, uint8_t) \
7373
V(WRAPPED, wrapped, uint8_t) \
74-
V(LAST_DATAGRAM_ID, last_datagram_id, uint64_t)
74+
V(LAST_DATAGRAM_ID, last_datagram_id, datagram_id)
7575

7676
#define SESSION_STATS(V) \
7777
V(CREATED_AT, created_at) \
@@ -815,7 +815,7 @@ struct Session::Impl final : public MemoryRetainer {
815815
// Internal ngtcp2 callbacks
816816

817817
static int on_acknowledge_stream_data_offset(ngtcp2_conn* conn,
818-
int64_t stream_id,
818+
stream_id stream_id,
819819
uint64_t offset,
820820
uint64_t datalen,
821821
void* user_data,
@@ -835,7 +835,7 @@ struct Session::Impl final : public MemoryRetainer {
835835
}
836836

837837
static int on_acknowledge_datagram(ngtcp2_conn* conn,
838-
uint64_t dgram_id,
838+
datagram_id dgram_id,
839839
void* user_data) {
840840
NGTCP2_CALLBACK_SCOPE(session)
841841
session->DatagramStatus(dgram_id, DatagramStatus::ACKNOWLEDGED);
@@ -905,7 +905,7 @@ struct Session::Impl final : public MemoryRetainer {
905905
}
906906

907907
static int on_extend_max_stream_data(ngtcp2_conn* conn,
908-
int64_t stream_id,
908+
stream_id stream_id,
909909
uint64_t max_data,
910910
void* user_data,
911911
void* stream_user_data) {
@@ -938,7 +938,7 @@ struct Session::Impl final : public MemoryRetainer {
938938
}
939939

940940
static int on_lost_datagram(ngtcp2_conn* conn,
941-
uint64_t dgram_id,
941+
datagram_id dgram_id,
942942
void* user_data) {
943943
NGTCP2_CALLBACK_SCOPE(session)
944944
session->DatagramStatus(dgram_id, DatagramStatus::LOST);
@@ -1022,7 +1022,7 @@ struct Session::Impl final : public MemoryRetainer {
10221022

10231023
static int on_receive_stream_data(ngtcp2_conn* conn,
10241024
uint32_t flags,
1025-
int64_t stream_id,
1025+
stream_id stream_id,
10261026
uint64_t offset,
10271027
const uint8_t* data,
10281028
size_t datalen,
@@ -1105,8 +1105,8 @@ struct Session::Impl final : public MemoryRetainer {
11051105

11061106
static int on_stream_close(ngtcp2_conn* conn,
11071107
uint32_t flags,
1108-
int64_t stream_id,
1109-
uint64_t app_error_code,
1108+
stream_id stream_id,
1109+
error_code app_error_code,
11101110
void* user_data,
11111111
void* stream_user_data) {
11121112
NGTCP2_CALLBACK_SCOPE(session)
@@ -1121,9 +1121,9 @@ struct Session::Impl final : public MemoryRetainer {
11211121
}
11221122

11231123
static int on_stream_reset(ngtcp2_conn* conn,
1124-
int64_t stream_id,
1124+
stream_id stream_id,
11251125
uint64_t final_size,
1126-
uint64_t app_error_code,
1126+
error_code app_error_code,
11271127
void* user_data,
11281128
void* stream_user_data) {
11291129
NGTCP2_CALLBACK_SCOPE(session)
@@ -1135,8 +1135,8 @@ struct Session::Impl final : public MemoryRetainer {
11351135
}
11361136

11371137
static int on_stream_stop_sending(ngtcp2_conn* conn,
1138-
int64_t stream_id,
1139-
uint64_t app_error_code,
1138+
stream_id stream_id,
1139+
error_code app_error_code,
11401140
void* user_data,
11411141
void* stream_user_data) {
11421142
NGTCP2_CALLBACK_SCOPE(session)
@@ -1718,7 +1718,7 @@ void Session::Send(const BaseObjectPtr<Packet>& packet,
17181718
Send(packet);
17191719
}
17201720

1721-
uint64_t Session::SendDatagram(Store&& data) {
1721+
datagram_id Session::SendDatagram(Store&& data) {
17221722
DCHECK(!is_destroyed());
17231723

17241724
// Sending a datagram is best effort. If we cannot send it for any reason,
@@ -1754,7 +1754,7 @@ uint64_t Session::SendDatagram(Store&& data) {
17541754
ngtcp2_vec vec = data;
17551755
PathStorage path;
17561756
int flags = NGTCP2_WRITE_DATAGRAM_FLAG_MORE;
1757-
uint64_t did = impl_->state_->last_datagram_id + 1;
1757+
datagram_id did = impl_->state_->last_datagram_id + 1;
17581758

17591759
Debug(this, "Sending %zu-byte datagram %" PRIu64, data.length(), did);
17601760

@@ -1924,15 +1924,15 @@ void Session::UpdatePath(const PathStorage& storage) {
19241924
impl_->remote_address_);
19251925
}
19261926

1927-
BaseObjectPtr<Stream> Session::FindStream(int64_t id) const {
1927+
BaseObjectPtr<Stream> Session::FindStream(stream_id id) const {
19281928
if (is_destroyed()) return {};
19291929
auto it = impl_->streams_.find(id);
19301930
if (it == std::end(impl_->streams_)) return {};
19311931
return it->second;
19321932
}
19331933

19341934
BaseObjectPtr<Stream> Session::CreateStream(
1935-
int64_t id,
1935+
stream_id id,
19361936
CreateStreamOption option,
19371937
std::shared_ptr<DataQueue> data_source) {
19381938
if (!can_create_streams()) [[unlikely]]
@@ -1965,7 +1965,7 @@ MaybeLocal<Object> Session::OpenStream(Direction direction,
19651965
return {};
19661966
}
19671967

1968-
int64_t id = -1;
1968+
stream_id id = -1;
19691969
auto open = [&] {
19701970
switch (direction) {
19711971
case Direction::BIDIRECTIONAL: {
@@ -2061,7 +2061,7 @@ void Session::AddStream(BaseObjectPtr<Stream> stream,
20612061
}
20622062
}
20632063

2064-
void Session::RemoveStream(int64_t id) {
2064+
void Session::RemoveStream(stream_id id) {
20652065
DCHECK(!is_destroyed());
20662066
Debug(this, "Removing stream %" PRIi64 " from session", id);
20672067
if (!is_in_draining_period() && !is_in_closing_period() &&
@@ -2093,13 +2093,13 @@ void Session::RemoveStream(int64_t id) {
20932093
}
20942094
}
20952095

2096-
void Session::ResumeStream(int64_t id) {
2096+
void Session::ResumeStream(stream_id id) {
20972097
DCHECK(!is_destroyed());
20982098
SendPendingDataScope send_scope(this);
20992099
application().ResumeStream(id);
21002100
}
21012101

2102-
void Session::ShutdownStream(int64_t id, QuicError error) {
2102+
void Session::ShutdownStream(stream_id id, QuicError error) {
21032103
DCHECK(!is_destroyed());
21042104
Debug(this, "Shutting down stream %" PRIi64 " with error %s", id, error);
21052105
SendPendingDataScope send_scope(this);
@@ -2111,7 +2111,7 @@ void Session::ShutdownStream(int64_t id, QuicError error) {
21112111
: application().GetNoErrorCode());
21122112
}
21132113

2114-
void Session::ShutdownStreamWrite(int64_t id, QuicError code) {
2114+
void Session::ShutdownStreamWrite(stream_id id, QuicError code) {
21152115
DCHECK(!is_destroyed());
21162116
Debug(this, "Shutting down stream %" PRIi64 " write with error %s", id, code);
21172117
SendPendingDataScope send_scope(this);
@@ -2123,7 +2123,7 @@ void Session::ShutdownStreamWrite(int64_t id, QuicError code) {
21232123
: application().GetNoErrorCode());
21242124
}
21252125

2126-
void Session::StreamDataBlocked(int64_t id) {
2126+
void Session::StreamDataBlocked(stream_id id) {
21272127
DCHECK(!is_destroyed());
21282128
auto& stats_ = impl_->stats_;
21292129
STAT_INCREMENT(Stats, block_count);
@@ -2217,7 +2217,7 @@ void Session::set_priority_supported(bool on) {
22172217
impl_->state_->priority_supported = on ? 1 : 0;
22182218
}
22192219

2220-
void Session::ExtendStreamOffset(int64_t id, size_t amount) {
2220+
void Session::ExtendStreamOffset(stream_id id, size_t amount) {
22212221
DCHECK(!is_destroyed());
22222222
Debug(this, "Extending stream %" PRIi64 " offset by %zu bytes", id, amount);
22232223
ngtcp2_conn_extend_max_stream_offset(*this, id, amount);
@@ -2341,7 +2341,8 @@ void Session::UpdateTimer() {
23412341
impl_->timer_.Update(timeout == 0 ? 1 : timeout);
23422342
}
23432343

2344-
void Session::DatagramStatus(uint64_t datagramId, quic::DatagramStatus status) {
2344+
void Session::DatagramStatus(datagram_id datagramId,
2345+
quic::DatagramStatus status) {
23452346
DCHECK(!is_destroyed());
23462347
auto& stats_ = impl_->stats_;
23472348
switch (status) {
@@ -2478,7 +2479,7 @@ void Session::ProcessPendingBidiStreams() {
24782479
// It shouldn't be possible to get here if can_create_streams() is false.
24792480
DCHECK(can_create_streams());
24802481

2481-
int64_t id;
2482+
stream_id id;
24822483

24832484
while (!impl_->pending_bidi_stream_queue_.IsEmpty()) {
24842485
if (ngtcp2_conn_get_streams_bidi_left(*this) == 0) {
@@ -2511,7 +2512,7 @@ void Session::ProcessPendingUniStreams() {
25112512
// It shouldn't be possible to get here if can_create_streams() is false.
25122513
DCHECK(can_create_streams());
25132514

2514-
int64_t id;
2515+
stream_id id;
25152516

25162517
while (!impl_->pending_uni_stream_queue_.IsEmpty()) {
25172518
if (ngtcp2_conn_get_streams_uni_left(*this) == 0) {
@@ -2583,7 +2584,7 @@ void Session::EmitDatagram(Store&& datagram, DatagramReceivedFlags flag) {
25832584
argv);
25842585
}
25852586

2586-
void Session::EmitDatagramStatus(uint64_t id, quic::DatagramStatus status) {
2587+
void Session::EmitDatagramStatus(datagram_id id, quic::DatagramStatus status) {
25872588
DCHECK(!is_destroyed());
25882589

25892590
if (!env()->can_call_into_js()) return;

src/quic/session.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
307307
private:
308308
struct Impl;
309309

310-
using StreamsMap = std::unordered_map<int64_t, BaseObjectPtr<Stream>>;
310+
using StreamsMap = std::unordered_map<stream_id, BaseObjectPtr<Stream>>;
311311
using QuicConnectionPointer = DeleteFnPtr<ngtcp2_conn, ngtcp2_conn_del>;
312312

313313
struct PathValidationFlags final {
@@ -324,7 +324,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324324

325325
void Send(const BaseObjectPtr<Packet>& packet);
326326
void Send(const BaseObjectPtr<Packet>& packet, const PathStorage& path);
327-
uint64_t SendDatagram(Store&& data);
327+
datagram_id SendDatagram(Store&& data);
328328

329329
// A non-const variation to allow certain modifications.
330330
Config& config();
@@ -333,18 +333,18 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
333333
NOTIFY,
334334
DO_NOT_NOTIFY,
335335
};
336-
BaseObjectPtr<Stream> FindStream(int64_t id) const;
336+
BaseObjectPtr<Stream> FindStream(stream_id id) const;
337337
BaseObjectPtr<Stream> CreateStream(
338-
int64_t id,
338+
stream_id id,
339339
CreateStreamOption option = CreateStreamOption::NOTIFY,
340340
std::shared_ptr<DataQueue> data_source = nullptr);
341341
void AddStream(BaseObjectPtr<Stream> stream,
342342
CreateStreamOption option = CreateStreamOption::NOTIFY);
343-
void RemoveStream(int64_t id);
344-
void ResumeStream(int64_t id);
345-
void StreamDataBlocked(int64_t id);
346-
void ShutdownStream(int64_t id, QuicError error = QuicError());
347-
void ShutdownStreamWrite(int64_t id, QuicError code = QuicError());
343+
void RemoveStream(stream_id id);
344+
void ResumeStream(stream_id id);
345+
void StreamDataBlocked(stream_id id);
346+
void ShutdownStream(stream_id id, QuicError error = QuicError());
347+
void ShutdownStreamWrite(stream_id id, QuicError code = QuicError());
348348

349349
// Use the configured CID::Factory to generate a new CID.
350350
CID new_cid(size_t len = CID::kMaxLength) const;
@@ -364,7 +364,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
364364
v8::MaybeLocal<v8::Object> OpenStream(
365365
Direction direction, std::shared_ptr<DataQueue> data_source = nullptr);
366366

367-
void ExtendStreamOffset(int64_t id, size_t amount);
367+
void ExtendStreamOffset(stream_id id, size_t amount);
368368
void ExtendOffset(size_t amount);
369369
void SetLastError(QuicError&& error);
370370
uint64_t max_data_left() const;
@@ -463,7 +463,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
463463

464464
void EmitClose(const QuicError& error = QuicError());
465465
void EmitDatagram(Store&& datagram, DatagramReceivedFlags flag);
466-
void EmitDatagramStatus(uint64_t id, DatagramStatus status);
466+
void EmitDatagramStatus(datagram_id id, DatagramStatus status);
467467
void EmitHandshakeComplete();
468468
void EmitKeylog(const char* line);
469469

@@ -481,7 +481,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
481481
void EmitVersionNegotiation(const ngtcp2_pkt_hd& hd,
482482
const uint32_t* sv,
483483
size_t nsv);
484-
void DatagramStatus(uint64_t datagramId, DatagramStatus status);
484+
void DatagramStatus(datagram_id datagramId, DatagramStatus status);
485485
void DatagramReceived(const uint8_t* data,
486486
size_t datalen,
487487
DatagramReceivedFlags flag);

src/quic/streams.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ using Ngtcp2Source = bob::SourceImpl<ngtcp2_vec>;
2727
// or concurrency limits are temporarily reached) then the request to open the
2828
// stream is represented as a queued PendingStream.
2929
//
30-
// The PendingStream instance itself is held by the stream but sits in a linked
31-
// list in the session.
30+
// The PendingStream instance itself is owned by the stream created but a
31+
// reference sits in a linked list in the session.
3232
//
3333
// The PendingStream request can be canceled by dropping the PendingStream
3434
// instance before it can be fulfilled, at which point it is removed from the
@@ -45,7 +45,7 @@ class PendingStream final {
4545

4646
// Called when the stream has been opened. Transitions the stream from a
4747
// pending state to an opened state.
48-
void fulfill(int64_t id);
48+
void fulfill(stream_id id);
4949

5050
// Called when opening the stream fails or is canceled. Transitions the
5151
// stream into a closed/destroyed state.
@@ -153,7 +153,7 @@ class Stream final : public AsyncWrap,
153153
// Creates a new non-pending stream.
154154
static BaseObjectPtr<Stream> Create(
155155
Session* session,
156-
int64_t id,
156+
stream_id id,
157157
std::shared_ptr<DataQueue> source = nullptr);
158158

159159
// Creates a new pending stream.
@@ -166,7 +166,7 @@ class Stream final : public AsyncWrap,
166166
// Call Create to create new instances of Stream.
167167
Stream(BaseObjectWeakPtr<Session> session,
168168
v8::Local<v8::Object> obj,
169-
int64_t id,
169+
stream_id id,
170170
std::shared_ptr<DataQueue> source);
171171

172172
// Creates the stream in a pending state. The constructor is only public
@@ -180,7 +180,7 @@ class Stream final : public AsyncWrap,
180180
~Stream() override;
181181

182182
// While the stream is still pending, the id will be -1.
183-
int64_t id() const;
183+
stream_id id() const;
184184

185185
// While the stream is still pending, the origin will be invalid.
186186
Side origin() const;
@@ -297,7 +297,7 @@ class Stream final : public AsyncWrap,
297297

298298
// When a pending stream is finally opened, the NotifyStreamOpened method
299299
// will be called and the id will be assigned.
300-
void NotifyStreamOpened(int64_t id);
300+
void NotifyStreamOpened(stream_id id);
301301
void EnqueuePendingHeaders(HeadersKind kind,
302302
v8::Local<v8::Array> headers,
303303
HeadersFlags flags);

0 commit comments

Comments
 (0)