Skip to content

Commit

Permalink
deps: update ngtcp2 to 1.3.0
Browse files Browse the repository at this point in the history
PR-URL: #51796
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
nodejs-github-bot authored and marco-ippolito committed Feb 27, 2024
1 parent 88e08bb commit 3b29dff
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 93 deletions.
4 changes: 2 additions & 2 deletions deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* Version number of the ngtcp2 library release.
*/
#define NGTCP2_VERSION "1.2.0"
#define NGTCP2_VERSION "1.3.0"

/**
* @macro
Expand All @@ -46,6 +46,6 @@
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
#define NGTCP2_VERSION_NUM 0x010200
#define NGTCP2_VERSION_NUM 0x010300

#endif /* VERSION_H */
2 changes: 1 addition & 1 deletion deps/ngtcp2/ngtcp2/lib/ngtcp2_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct ngtcp2_buf {
uint8_t *begin;
/* end points to the one beyond of the last byte of the buffer */
uint8_t *end;
/* pos pointers to the start of data. Typically, this points to the
/* pos points to the start of data. Typically, this points to the
point that next data should be read. Initially, it points to
|begin|. */
uint8_t *pos;
Expand Down
50 changes: 17 additions & 33 deletions deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include <assert.h>
#include <string.h>

#if defined(_MSC_VER)
# include <intrin.h>
#endif

#include "ngtcp2_log.h"
#include "ngtcp2_macro.h"
#include "ngtcp2_mem.h"
Expand Down Expand Up @@ -235,39 +231,27 @@ void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cubic, ngtcp2_log *log) {
}

uint64_t ngtcp2_cbrt(uint64_t n) {
int d;
uint64_t a;

if (n == 0) {
return 0;
}

#if defined(_MSC_VER)
{
unsigned long index;
# if defined(_WIN64)
if (_BitScanReverse64(&index, n)) {
d = 61 - index;
} else {
ngtcp2_unreachable();
}
# else /* !defined(_WIN64) */
if (_BitScanReverse(&index, (unsigned int)(n >> 32))) {
d = 31 - index;
} else {
d = 32 + 31 - _BitScanReverse(&index, (unsigned int)n);
size_t s;
uint64_t y = 0;
uint64_t b;

for (s = 63; s > 0; s -= 3) {
y <<= 1;
b = 3 * y * (y + 1) + 1;
if ((n >> s) >= b) {
n -= b << s;
y++;
}
# endif /* !defined(_WIN64) */
}
#else /* !defined(_MSC_VER) */
d = __builtin_clzll(n);
#endif /* !defined(_MSC_VER) */
a = 1ULL << ((64 - d) / 3 + 1);

for (; a * a * a > n;) {
a = (2 * a + n / a / a) / 3;
y <<= 1;
b = 3 * y * (y + 1) + 1;
if (n >= b) {
n -= b;
y++;
}
return a;

return y;
}

/* HyStart++ constants */
Expand Down
63 changes: 33 additions & 30 deletions deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3441,12 +3441,22 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
}

switch ((*pfrc)->fr.type) {
case NGTCP2_FRAME_RESET_STREAM:
strm =
ngtcp2_conn_find_stream(conn, (*pfrc)->fr.reset_stream.stream_id);
if (strm == NULL ||
!ngtcp2_strm_require_retransmit_reset_stream(strm)) {
frc = *pfrc;
*pfrc = (*pfrc)->next;
ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem);
continue;
}
break;
case NGTCP2_FRAME_STOP_SENDING:
strm =
ngtcp2_conn_find_stream(conn, (*pfrc)->fr.stop_sending.stream_id);
if (strm == NULL ||
((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) &&
ngtcp2_strm_rx_offset(strm) == strm->rx.last_offset)) {
!ngtcp2_strm_require_retransmit_stop_sending(strm)) {
frc = *pfrc;
*pfrc = (*pfrc)->next;
ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem);
Expand Down Expand Up @@ -3476,10 +3486,8 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
case NGTCP2_FRAME_MAX_STREAM_DATA:
strm = ngtcp2_conn_find_stream(conn,
(*pfrc)->fr.max_stream_data.stream_id);
if (strm == NULL ||
(strm->flags &
(NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_STOP_SENDING)) ||
(*pfrc)->fr.max_stream_data.max_stream_data < strm->rx.max_offset) {
if (strm == NULL || !ngtcp2_strm_require_retransmit_max_stream_data(
strm, &(*pfrc)->fr.max_stream_data)) {
frc = *pfrc;
*pfrc = (*pfrc)->next;
ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem);
Expand All @@ -3497,8 +3505,8 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
case NGTCP2_FRAME_STREAM_DATA_BLOCKED:
strm = ngtcp2_conn_find_stream(
conn, (*pfrc)->fr.stream_data_blocked.stream_id);
if (strm == NULL || (strm->flags & NGTCP2_STRM_FLAG_SHUT_WR) ||
(*pfrc)->fr.stream_data_blocked.offset != strm->tx.max_offset) {
if (strm == NULL || !ngtcp2_strm_require_retransmit_stream_data_blocked(
strm, &(*pfrc)->fr.stream_data_blocked)) {
frc = *pfrc;
*pfrc = (*pfrc)->next;
ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem);
Expand Down Expand Up @@ -7145,7 +7153,7 @@ static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr) {
return rv;
}
}
} else if (fr->datacnt) {
} else if (fr->datacnt && !(strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING)) {
rv = ngtcp2_strm_recv_reordering(strm, fr->data[0].base, fr->data[0].len,
fr->offset);
if (rv != 0) {
Expand Down Expand Up @@ -7304,27 +7312,20 @@ static int conn_recv_reset_stream(ngtcp2_conn *conn,
}

/* Stream is reset before we create ngtcp2_strm object. */
conn->rx.offset += fr->final_size;
ngtcp2_conn_extend_max_offset(conn, fr->final_size);

rv = conn_call_stream_reset(conn, fr->stream_id, fr->final_size,
fr->app_error_code, NULL);
strm = ngtcp2_objalloc_strm_get(&conn->strm_objalloc);
if (strm == NULL) {
return NGTCP2_ERR_NOMEM;
}
rv = ngtcp2_conn_init_stream(conn, strm, fr->stream_id, NULL);
if (rv != 0) {
ngtcp2_objalloc_strm_release(&conn->strm_objalloc, strm);
return rv;
}

/* There will be no activity in this stream because we got
RESET_STREAM and don't write stream data any further. This
effectively allows another new stream for peer. */
if (bidi) {
handle_max_remote_streams_extension(&conn->remote.bidi.unsent_max_streams,
1);
} else {
handle_max_remote_streams_extension(&conn->remote.uni.unsent_max_streams,
1);
rv = conn_call_stream_open(conn, strm);
if (rv != 0) {
return rv;
}

return 0;
}

if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD)) {
Expand Down Expand Up @@ -7461,15 +7462,16 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
been acknowledged. */
if (!ngtcp2_strm_is_all_tx_data_fin_acked(strm) &&
!(strm->flags & NGTCP2_STRM_FLAG_RESET_STREAM)) {
strm->flags |= NGTCP2_STRM_FLAG_RESET_STREAM;

rv = conn_reset_stream(conn, strm, fr->app_error_code);
if (rv != 0) {
return rv;
}
}

strm->flags |= NGTCP2_STRM_FLAG_SHUT_WR |
NGTCP2_STRM_FLAG_STOP_SENDING_RECVED |
NGTCP2_STRM_FLAG_RESET_STREAM;
strm->flags |=
NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_STOP_SENDING_RECVED;

ngtcp2_strm_streamfrq_clear(strm);

Expand Down Expand Up @@ -12533,14 +12535,15 @@ static int conn_shutdown_stream_read(ngtcp2_conn *conn, ngtcp2_strm *strm,

/* Extend connection flow control window for the amount of data
which are not passed to application. */
if (!(strm->flags & (NGTCP2_STRM_FLAG_STOP_SENDING |
NGTCP2_STRM_FLAG_RESET_STREAM_RECVED))) {
if (!(strm->flags & NGTCP2_STRM_FLAG_RESET_STREAM_RECVED)) {
ngtcp2_conn_extend_max_offset(conn, strm->rx.last_offset -
ngtcp2_strm_rx_offset(strm));
}

strm->flags |= NGTCP2_STRM_FLAG_STOP_SENDING;

ngtcp2_strm_discard_reordered_data(strm);

return conn_stop_sending(conn, strm, app_error_code);
}

Expand Down
58 changes: 41 additions & 17 deletions deps/ngtcp2/ngtcp2/lib/ngtcp2_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ static uint8_t *write_varint_param(uint8_t *p, ngtcp2_transport_param_id id,
return ngtcp2_put_uvarint(p, value);
}

/*
* zero_paramlen returns the length of a single transport parameter
* which has zero length value in its parameter.
*/
static size_t zero_paramlen(ngtcp2_transport_param_id id) {
return ngtcp2_put_uvarintlen(id) + 1;
}

/*
* write_zero_param writes parameter |id| that has zero length value.
* It returns p + the number of bytes written.
*/
static uint8_t *write_zero_param(uint8_t *p, ngtcp2_transport_param_id id) {
p = ngtcp2_put_uvarint(p, id);
*p++ = 0;

return p;
}

/*
* cid_paramlen returns the length of a single transport parameter
* which has |cid| as value.
Expand Down Expand Up @@ -235,9 +254,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned(
params->ack_delay_exponent);
}
if (params->disable_active_migration) {
len +=
ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) +
ngtcp2_put_uvarintlen(0);
len += zero_paramlen(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
}
if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY,
Expand All @@ -258,8 +275,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned(
params->max_datagram_frame_size);
}
if (params->grease_quic_bit) {
len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT) +
ngtcp2_put_uvarintlen(0);
len += zero_paramlen(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
}
if (params->version_info_present) {
version_infolen =
Expand Down Expand Up @@ -377,8 +393,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned(
}

if (params->disable_active_migration) {
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
p = ngtcp2_put_uvarint(p, 0);
p = write_zero_param(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION);
}

if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
Expand All @@ -404,8 +419,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned(
}

if (params->grease_quic_bit) {
p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
p = ngtcp2_put_uvarint(p, 0);
p = write_zero_param(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT);
}

if (params->version_info_present) {
Expand Down Expand Up @@ -482,6 +496,22 @@ static int decode_varint_param(uint64_t *pdest, const uint8_t **pp,
return 0;
}

/*
* decode_zero_param decodes zero length value from the buffer pointed
* by |*pp| of length |end - *pp|. The length is encoded in varint
* form. If it decodes zero length value successfully, it increments
* |*pp| by 1, and returns 0. Otherwise it returns -1.
*/
static int decode_zero_param(const uint8_t **pp, const uint8_t *end) {
if (*pp == end || **pp != 0) {
return -1;
}

++*pp;

return 0;
}

/*
* decode_cid_param decodes length prefixed ngtcp2_cid from the buffer
* pointed by |*pp| of length |end - *pp|. The length is encoded in
Expand Down Expand Up @@ -701,10 +731,7 @@ int ngtcp2_transport_params_decode_versioned(int transport_params_version,
params->preferred_addr_present = 1;
break;
case NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION:
if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
if (valuelen != 0) {
if (decode_zero_param(&p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
params->disable_active_migration = 1;
Expand Down Expand Up @@ -751,10 +778,7 @@ int ngtcp2_transport_params_decode_versioned(int transport_params_version,
}
break;
case NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT:
if (decode_varint(&valuelen, &p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
if (valuelen != 0) {
if (decode_zero_param(&p, end) != 0) {
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
}
params->grease_quic_bit = 1;
Expand Down
Loading

0 comments on commit 3b29dff

Please sign in to comment.