Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

quic: additional cleanups and fixups #294

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -1766,8 +1766,7 @@ or writable side has closed naturally.
The callback is invoked with two arguments:

* `code` {number} The QUIC application error code used to terminate the stream.
* `finalSize` {number} The total number of bytes received by the `QuicStream`
as of the moment the stream was closed.
* `family` {number} Identifier of the error code family.

#### Event: `'close'`
<!-- YAML
Expand Down Expand Up @@ -1955,6 +1954,16 @@ added: REPLACEME

A `BigInt` representing the length of time the `QuicStream` has been active.

### quicstream.finalSize
<!-- YAML
added: REPLACEME
-->

* Type: {BigInt}

A `BigInt` specifying the total number of bytes successfully received by the
`QuicStream`.

#### quicstream.id
<!-- YAML
added: REPLACEME
Expand All @@ -1964,6 +1973,16 @@ added: REPLACEME

The numeric identifier of the `QuicStream`.

#### quicstream.maxAcknowledgedOffset
<!-- YAML
added: REPLACEME
-->

* Type: {BigInt}

A `BigInt` representing the highest acknowledged data offset received
for this `QuicStream`.

#### quicstream.maxExtendedOffset
<!-- YAML
added: REPLACEME
Expand All @@ -1974,6 +1993,15 @@ added: REPLACEME
A `BigInt` representing the maximum extended data offset that has been
reported to the connected peer.

#### quicstream.maxReceivedOffset
<!-- YAML
added: REPLACEME
-->

* Type: {BigInt}

A `BigInt` representing the maximum received offset for this `QuicStream`.

#### quicstream.pending
<!-- YAML
added: REPLACEME
Expand Down
32 changes: 24 additions & 8 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ const {
IDX_QUIC_STREAM_STATS_BYTES_RECEIVED,
IDX_QUIC_STREAM_STATS_BYTES_SENT,
IDX_QUIC_STREAM_STATS_MAX_OFFSET,
IDX_QUIC_STREAM_STATS_FINAL_SIZE,
IDX_QUIC_STREAM_STATS_MAX_OFFSET_ACK,
IDX_QUIC_STREAM_STATS_MAX_OFFSET_RECV,
IDX_QUIC_SOCKET_STATS_CREATED_AT,
IDX_QUIC_SOCKET_STATS_BOUND_AT,
IDX_QUIC_SOCKET_STATS_LISTEN_AT,
Expand Down Expand Up @@ -506,8 +509,8 @@ function onStreamClose(id, appErrorCode) {
}

// Called by the C++ internals when a stream has been reset
function onStreamReset(id, appErrorCode, finalSize) {
this[owner_symbol][kStreamReset](id, appErrorCode, finalSize);
function onStreamReset(id, appErrorCode) {
this[owner_symbol][kStreamReset](id, appErrorCode);
}

// Called when an error occurs in a QuicStream
Expand Down Expand Up @@ -1605,12 +1608,12 @@ class QuicSession extends EventEmitter {
stream[kHeaders](headers, kind, push_id);
}

[kStreamReset](id, code, finalSize) {
[kStreamReset](id, code) {
const stream = this.#streams.get(id);
if (stream === undefined)
return;

stream[kStreamReset](code, finalSize);
stream[kStreamReset](code);
}

[kInspect]() {
Expand Down Expand Up @@ -2318,7 +2321,6 @@ class QuicStream extends Duplex {
#id = undefined;
#push_id = undefined;
#resetCode = undefined;
#resetFinalSize = undefined;
#session = undefined;
#dataRateHistogram = undefined;
#dataSizeHistogram = undefined;
Expand Down Expand Up @@ -2380,9 +2382,8 @@ class QuicStream extends Duplex {
}
}

[kStreamReset](code, finalSize) {
[kStreamReset](code) {
this.#resetCode = code | 0;
this.#resetFinalSize = finalSize | 0;
this.push(null);
this.read();
}
Expand Down Expand Up @@ -2664,7 +2665,7 @@ class QuicStream extends Duplex {

get resetReceived() {
return (this.#resetCode !== undefined) ?
{ code: this.#resetCode | 0, finalSize: this.#resetFinalSize | 0 } :
{ code: this.#resetCode | 0 } :
undefined;
}

Expand Down Expand Up @@ -2853,6 +2854,21 @@ class QuicStream extends Duplex {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_MAX_OFFSET];
}

get finalSize() {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_FINAL_SIZE];
}

get maxAcknowledgedOffset() {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_MAX_OFFSET_ACK];
}

get maxReceivedOffset() {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_MAX_OFFSET_RECV];
}
}

function createSocket(options) {
Expand Down
6 changes: 3 additions & 3 deletions src/quic/node_quic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ void Initialize(Local<Object> target,
V(QUICSTREAM_HEADERS_KIND_TRAILING) \
V(UV_EBADF)

#define V(name, _) \
#define V(name, _, __) \
NODE_DEFINE_CONSTANT(constants, IDX_QUIC_SESSION_STATS_##name);
SESSION_STATS(V)
#undef V

#define V(name, _) \
#define V(name, _, __) \
NODE_DEFINE_CONSTANT(constants, IDX_QUIC_SOCKET_STATS_##name);
SOCKET_STATS(V)
#undef V

#define V(name, _) \
#define V(name, _, __) \
NODE_DEFINE_CONSTANT(constants, IDX_QUIC_STREAM_STATS_##name);
STREAM_STATS(V)
#undef V
Expand Down
3 changes: 1 addition & 2 deletions src/quic/node_quic_http3_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,9 @@ void Http3Application::StreamClose(

void Http3Application::StreamReset(
int64_t stream_id,
uint64_t final_size,
uint64_t app_error_code) {
nghttp3_conn_reset_stream(connection(), stream_id);
QuicApplication::StreamReset(stream_id, final_size, app_error_code);
QuicApplication::StreamReset(stream_id, app_error_code);
}

// When SendPendingData tries to send data for a given stream and there
Expand Down
1 change: 0 additions & 1 deletion src/quic/node_quic_http3_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class Http3Application final :

void StreamReset(
int64_t stream_id,
uint64_t final_size,
uint64_t app_error_code) override;

void ResumeStream(int64_t stream_id) override;
Expand Down
31 changes: 9 additions & 22 deletions src/quic/node_quic_session-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,26 @@ using crypto::SecureContext;
namespace quic {

void QuicSessionConfig::GenerateStatelessResetToken(
StatelessResetTokenStrategy strategy,
QuicSession* session,
const QuicCID& cid) {
transport_params.stateless_reset_token_present = 1;
strategy(
session,
cid,
transport_params.stateless_reset_token,
NGTCP2_STATELESS_RESET_TOKENLEN);
StatelessResetToken(
transport_params.stateless_reset_token,
session->socket()->session_reset_secret(),
cid);
}

void QuicSessionConfig::GeneratePreferredAddressToken(
ConnectionIDStrategy connection_id_strategy,
StatelessResetTokenStrategy stateless_reset_strategy,
QuicSession* session,
QuicCID* pscid) {

connection_id_strategy(session, pscid->cid(), kScidLen);
stateless_reset_strategy(
session,
*pscid,
transport_params.preferred_address.stateless_reset_token,
NGTCP2_STATELESS_RESET_TOKENLEN);
transport_params.preferred_address.cid = **pscid;

StatelessResetToken(
transport_params.preferred_address.stateless_reset_token,
session->socket()->session_reset_secret(),
*pscid);
}

void QuicSessionConfig::set_original_connection_id(const QuicCID& ocid) {
Expand Down Expand Up @@ -376,15 +372,6 @@ void QuicSession::set_connection_id_strategy(ConnectionIDStrategy strategy) {
connection_id_strategy_ = strategy;
}

// The stateless reset token strategy is a function that generates
// stateless reset tokens. By default these are cryptographically
// derived by the CID.
void QuicSession::set_stateless_reset_token_strategy(
StatelessResetTokenStrategy strategy) {
CHECK_NOT_NULL(strategy);
stateless_reset_strategy_ = strategy;
}

void QuicSession::set_preferred_address_strategy(
PreferredAddressStrategy strategy) {
preferred_address_strategy_ = strategy;
Expand Down
Loading