Skip to content

Commit 8f63f6f

Browse files
nodejs-github-bottargos
authored andcommitted
deps: update ngtcp2 to 1.2.0
PR-URL: #51584 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5fe493d commit 8f63f6f

14 files changed

+91
-74
lines changed

deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/ngtcp2.h

+17
Original file line numberDiff line numberDiff line change
@@ -4269,6 +4269,9 @@ NGTCP2_EXTERN int ngtcp2_conn_open_uni_stream(ngtcp2_conn *conn,
42694269
*
42704270
* |flags| is currently unused, and should be set to 0.
42714271
*
4272+
* This function returns 0 if a stream denoted by |stream_id| is not
4273+
* found.
4274+
*
42724275
* This function returns 0 if it succeeds, or one of the following
42734276
* negative error codes:
42744277
*
@@ -4291,6 +4294,9 @@ NGTCP2_EXTERN int ngtcp2_conn_shutdown_stream(ngtcp2_conn *conn, uint32_t flags,
42914294
*
42924295
* |flags| is currently unused, and should be set to 0.
42934296
*
4297+
* This function returns 0 if a stream denoted by |stream_id| is not
4298+
* found.
4299+
*
42944300
* This function returns 0 if it succeeds, or one of the following
42954301
* negative error codes:
42964302
*
@@ -4315,6 +4321,9 @@ NGTCP2_EXTERN int ngtcp2_conn_shutdown_stream_write(ngtcp2_conn *conn,
43154321
*
43164322
* |flags| is currently unused, and should be set to 0.
43174323
*
4324+
* This function returns 0 if a stream denoted by |stream_id| is not
4325+
* found.
4326+
*
43184327
* This function returns 0 if it succeeds, or one of the following
43194328
* negative error codes:
43204329
*
@@ -4675,6 +4684,9 @@ NGTCP2_EXTERN int ngtcp2_conn_in_draining_period(ngtcp2_conn *conn);
46754684
* specifies the stream ID. This function only extends stream-level
46764685
* flow control window.
46774686
*
4687+
* This function returns 0 if a stream denoted by |stream_id| is not
4688+
* found.
4689+
*
46784690
* This function returns 0 if it succeeds, or one of the following
46794691
* negative error codes:
46804692
*
@@ -5340,6 +5352,11 @@ NGTCP2_EXTERN void ngtcp2_ccerr_set_application_error(ngtcp2_ccerr *ccerr,
53405352
* CONNECTION_CLOSE (type 0x1d) frame. Otherwise, it does not produce
53415353
* any data, and returns 0.
53425354
*
5355+
* |destlen| could be shorten by some factors (e.g., server side
5356+
* amplification limit). This function returns
5357+
* :macro:`NGTCP2_ERR_NOBUF` if the resulting buffer is too small even
5358+
* if the given buffer has enough space.
5359+
*
53435360
* This function must not be called from inside the callback
53445361
* functions.
53455362
*

deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*
3737
* Version number of the ngtcp2 library release.
3838
*/
39-
#define NGTCP2_VERSION "1.1.0"
39+
#define NGTCP2_VERSION "1.2.0"
4040

4141
/**
4242
* @macro
@@ -46,6 +46,6 @@
4646
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
4747
* becomes 0x010203.
4848
*/
49-
#define NGTCP2_VERSION_NUM 0x010100
49+
#define NGTCP2_VERSION_NUM 0x010200
5050

5151
#endif /* VERSION_H */

deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "ngtcp2_mem.h"
3737
#include "ngtcp2_rcvry.h"
3838
#include "ngtcp2_conn_stat.h"
39+
#include "ngtcp2_unreachable.h"
3940

4041
/* NGTCP2_CC_DELIVERY_RATE_SEC_FILTERLEN is the window length of
4142
delivery rate filter driven by ACK clocking. */
@@ -247,6 +248,8 @@ uint64_t ngtcp2_cbrt(uint64_t n) {
247248
# if defined(_WIN64)
248249
if (_BitScanReverse64(&index, n)) {
249250
d = 61 - index;
251+
} else {
252+
ngtcp2_unreachable();
250253
}
251254
# else /* !defined(_WIN64) */
252255
if (_BitScanReverse(&index, (unsigned int)(n >> 32))) {

deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c

+23-51
Original file line numberDiff line numberDiff line change
@@ -5329,7 +5329,6 @@ static int conn_recv_ack(ngtcp2_conn *conn, ngtcp2_pktns *pktns, ngtcp2_ack *fr,
53295329
num_acked = ngtcp2_rtb_recv_ack(&pktns->rtb, fr, &conn->cstat, conn, pktns,
53305330
pkt_ts, ts);
53315331
if (num_acked < 0) {
5332-
/* TODO assert this */
53335332
assert(ngtcp2_err_is_fatal((int)num_acked));
53345333
return (int)num_acked;
53355334
}
@@ -5790,9 +5789,8 @@ static int conn_recv_path_response(ngtcp2_conn *conn, ngtcp2_path_response *fr,
57905789
}
57915790

57925791
if (!(pv->flags & NGTCP2_PV_FLAG_DONT_CARE)) {
5793-
if (!(pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE)) {
5792+
if (pv->dcid.seq != conn->dcid.current.seq) {
57945793
assert(!conn->server);
5795-
assert(pv->dcid.seq != conn->dcid.current.seq);
57965794
assert(conn->dcid.current.cid.datalen);
57975795

57985796
rv = conn_retire_dcid(conn, &conn->dcid.current, ts);
@@ -5871,25 +5869,6 @@ static int conn_recv_path_response(ngtcp2_conn *conn, ngtcp2_path_response *fr,
58715869
return conn_stop_pv(conn, ts);
58725870
}
58735871

5874-
/*
5875-
* pkt_num_bits returns the number of bits available when packet
5876-
* number is encoded in |pkt_numlen| bytes.
5877-
*/
5878-
static size_t pkt_num_bits(size_t pkt_numlen) {
5879-
switch (pkt_numlen) {
5880-
case 1:
5881-
return 8;
5882-
case 2:
5883-
return 16;
5884-
case 3:
5885-
return 24;
5886-
case 4:
5887-
return 32;
5888-
default:
5889-
ngtcp2_unreachable();
5890-
}
5891-
}
5892-
58935872
/*
58945873
* pktns_pkt_num_is_duplicate returns nonzero if |pkt_num| is
58955874
* duplicated packet number.
@@ -6020,9 +5999,7 @@ static int conn_verify_fixed_bit(ngtcp2_conn *conn, ngtcp2_pkt_hd *hd) {
60205999
case NGTCP2_PKT_INITIAL:
60216000
case NGTCP2_PKT_0RTT:
60226001
case NGTCP2_PKT_HANDSHAKE:
6023-
/* TODO we cannot determine whether a token comes from NEW_TOKEN
6024-
frame or Retry packet. RFC 9287 requires that a token from
6025-
NEW_TOKEN. */
6002+
/* RFC 9287 requires that a token from NEW_TOKEN. */
60266003
if (!(conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) &&
60276004
(conn->local.settings.token_type != NGTCP2_TOKEN_TYPE_NEW_TOKEN ||
60286005
!conn->local.settings.tokenlen)) {
@@ -6145,7 +6122,8 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
61456122
return NGTCP2_ERR_DISCARD_PKT;
61466123
}
61476124

6148-
if (hd.type == NGTCP2_PKT_VERSION_NEGOTIATION) {
6125+
switch (hd.type) {
6126+
case NGTCP2_PKT_VERSION_NEGOTIATION:
61496127
hdpktlen = (size_t)nread;
61506128

61516129
ngtcp2_log_rx_pkt_hd(&conn->log, &hd);
@@ -6181,7 +6159,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
61816159
return NGTCP2_ERR_DISCARD_PKT;
61826160
}
61836161
return NGTCP2_ERR_RECV_VERSION_NEGOTIATION;
6184-
} else if (hd.type == NGTCP2_PKT_RETRY) {
6162+
case NGTCP2_PKT_RETRY:
61856163
hdpktlen = (size_t)nread;
61866164

61876165
ngtcp2_log_rx_pkt_hd(&conn->log, &hd);
@@ -6402,10 +6380,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
64026380

64036381
break;
64046382
default:
6405-
/* unknown packet type */
6406-
ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
6407-
"packet was ignored because of unknown packet type");
6408-
return (ngtcp2_ssize)pktlen;
6383+
ngtcp2_unreachable();
64096384
}
64106385

64116386
hp_mask = conn->callbacks.hp_mask;
@@ -6438,7 +6413,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
64386413
payloadlen = hd.len - hd.pkt_numlen;
64396414

64406415
hd.pkt_num = ngtcp2_pkt_adjust_pkt_num(pktns->rx.max_pkt_num, hd.pkt_num,
6441-
pkt_num_bits(hd.pkt_numlen));
6416+
hd.pkt_numlen);
64426417
if (hd.pkt_num > NGTCP2_MAX_PKT_NUM) {
64436418
ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
64446419
"pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num);
@@ -6624,14 +6599,8 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
66246599

66256600
pktns_increase_ecn_counts(pktns, pi);
66266601

6627-
/* TODO Initial and Handshake are always acknowledged without
6628-
delay. */
6629-
if (require_ack &&
6630-
(++pktns->acktr.rx_npkt >= conn->local.settings.ack_thresh ||
6631-
(pi->ecn & NGTCP2_ECN_MASK) == NGTCP2_ECN_CE)) {
6632-
ngtcp2_acktr_immediate_ack(&pktns->acktr);
6633-
}
6634-
6602+
/* Initial and Handshake are always acknowledged without delay. No
6603+
need to call ngtcp2_acktr_immediate_ack(). */
66356604
rv = ngtcp2_conn_sched_ack(conn, &pktns->acktr, hd.pkt_num, require_ack,
66366605
pkt_ts);
66376606
if (rv != 0) {
@@ -7057,7 +7026,7 @@ static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr) {
70577026
if (strm == NULL) {
70587027
return NGTCP2_ERR_NOMEM;
70597028
}
7060-
/* TODO Perhaps, call new_stream callback? */
7029+
70617030
rv = ngtcp2_conn_init_stream(conn, strm, fr->stream_id, NULL);
70627031
if (rv != 0) {
70637032
ngtcp2_objalloc_strm_release(&conn->strm_objalloc, strm);
@@ -7464,7 +7433,7 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74647433
return 0;
74657434
}
74667435

7467-
/* Frame is received reset before we create ngtcp2_strm
7436+
/* STOP_SENDING frame is received before we create ngtcp2_strm
74687437
object. */
74697438
strm = ngtcp2_objalloc_strm_get(&conn->strm_objalloc);
74707439
if (strm == NULL) {
@@ -7482,6 +7451,10 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74827451
}
74837452
}
74847453

7454+
if (strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING_RECVED) {
7455+
return 0;
7456+
}
7457+
74857458
ngtcp2_strm_set_app_error_code(strm, fr->app_error_code);
74867459

74877460
/* No RESET_STREAM is required if we have sent FIN and all data have
@@ -7494,7 +7467,9 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74947467
}
74957468
}
74967469

7497-
strm->flags |= NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_RESET_STREAM;
7470+
strm->flags |= NGTCP2_STRM_FLAG_SHUT_WR |
7471+
NGTCP2_STRM_FLAG_STOP_SENDING_RECVED |
7472+
NGTCP2_STRM_FLAG_RESET_STREAM;
74987473

74997474
ngtcp2_strm_streamfrq_clear(strm);
75007475

@@ -8751,12 +8726,8 @@ conn_recv_delayed_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_pkt_info *pi,
87518726

87528727
pktns_increase_ecn_counts(pktns, pi);
87538728

8754-
if (require_ack &&
8755-
(++pktns->acktr.rx_npkt >= conn->local.settings.ack_thresh ||
8756-
(pi->ecn & NGTCP2_ECN_MASK) == NGTCP2_ECN_CE)) {
8757-
ngtcp2_acktr_immediate_ack(&pktns->acktr);
8758-
}
8759-
8729+
/* Initial and Handshake are always acknowledged without delay. No
8730+
need to call ngtcp2_acktr_immediate_ack(). */
87608731
rv = ngtcp2_conn_sched_ack(conn, &pktns->acktr, hd->pkt_num, require_ack,
87618732
pkt_ts);
87628733
if (rv != 0) {
@@ -9020,7 +8991,7 @@ static ngtcp2_ssize conn_recv_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
90208991
payloadlen = pktlen - hdpktlen;
90218992

90228993
hd.pkt_num = ngtcp2_pkt_adjust_pkt_num(pktns->rx.max_pkt_num, hd.pkt_num,
9023-
pkt_num_bits(hd.pkt_numlen));
8994+
hd.pkt_numlen);
90248995
if (hd.pkt_num > NGTCP2_MAX_PKT_NUM) {
90258996
ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
90268997
"pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num);
@@ -12551,7 +12522,8 @@ static int conn_shutdown_stream_read(ngtcp2_conn *conn, ngtcp2_strm *strm,
1255112522
uint64_t app_error_code) {
1255212523
ngtcp2_strm_set_app_error_code(strm, app_error_code);
1255312524

12554-
if (strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING) {
12525+
if (strm->flags &
12526+
(NGTCP2_STRM_FLAG_STOP_SENDING | NGTCP2_STRM_FLAG_RESET_STREAM_RECVED)) {
1255512527
return 0;
1255612528
}
1255712529
if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) &&

deps/ngtcp2/ngtcp2/lib/ngtcp2_log.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
6868
* Source Connection ID in hex string.
6969
*
7070
* <EVENT>:
71-
* Event. pkt=packet, frm=frame, ldc=loss-detection, cry=crypto,
72-
* con=connection(catch all)
71+
* Event. See ngtcp2_log_event.
7372
*
7473
* # Frame event
7574
*

deps/ngtcp2/ngtcp2/lib/ngtcp2_net.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
#if defined(WIN32)
8888
/* Windows requires ws2_32 library for ntonl family functions. We
8989
define inline functions for those function so that we don't have
90-
dependeny on that lib. */
90+
dependency on that lib. */
9191

9292
# ifdef _MSC_VER
9393
# define STIN static __inline

deps/ngtcp2/ngtcp2/lib/ngtcp2_pkt.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ ngtcp2_ssize ngtcp2_pkt_decode_stream_frame(ngtcp2_stream *dest,
558558
uint8_t type;
559559
size_t len = 1 + 1;
560560
const uint8_t *p;
561-
size_t datalen;
561+
size_t datalen = 0;
562562
size_t ndatalen = 0;
563563
size_t n;
564564
uint64_t vi;
@@ -2139,9 +2139,9 @@ int ngtcp2_pkt_decode_retry(ngtcp2_pkt_retry *dest, const uint8_t *payload,
21392139
}
21402140

21412141
int64_t ngtcp2_pkt_adjust_pkt_num(int64_t max_pkt_num, int64_t pkt_num,
2142-
size_t n) {
2142+
size_t pkt_numlen) {
21432143
int64_t expected = max_pkt_num + 1;
2144-
int64_t win = (int64_t)1 << n;
2144+
int64_t win = (int64_t)1 << (pkt_numlen * 8);
21452145
int64_t hwin = win / 2;
21462146
int64_t mask = win - 1;
21472147
int64_t cand = (expected & ~mask) | pkt_num;

deps/ngtcp2/ngtcp2/lib/ngtcp2_pkt.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,12 @@ ngtcp2_ssize ngtcp2_pkt_encode_datagram_frame(uint8_t *out, size_t outlen,
11201120

11211121
/*
11221122
* ngtcp2_pkt_adjust_pkt_num find the full 64 bits packet number for
1123-
* |pkt_num|, which is expected to be least significant |n| bits. The
1123+
* |pkt_num|, which is encoded in |pkt_numlen| bytes. The
11241124
* |max_pkt_num| is the highest successfully authenticated packet
11251125
* number.
11261126
*/
11271127
int64_t ngtcp2_pkt_adjust_pkt_num(int64_t max_pkt_num, int64_t pkt_num,
1128-
size_t n);
1128+
size_t pkt_numlen);
11291129

11301130
/*
11311131
* ngtcp2_pkt_validate_ack checks that ack is malformed or not.

deps/ngtcp2/ngtcp2/lib/ngtcp2_ppe.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void ngtcp2_ppe_init(ngtcp2_ppe *ppe, uint8_t *out, size_t outlen,
3939
ppe->pkt_num_offset = 0;
4040
ppe->pkt_numlen = 0;
4141
ppe->pkt_num = 0;
42-
ppe->sample_offset = 0;
4342
ppe->cc = cc;
4443
}
4544

@@ -69,8 +68,6 @@ int ngtcp2_ppe_encode_hd(ngtcp2_ppe *ppe, const ngtcp2_pkt_hd *hd) {
6968
return (int)rv;
7069
}
7170

72-
ppe->sample_offset = ppe->pkt_num_offset + 4;
73-
7471
buf->last += rv;
7572

7673
ppe->pkt_numlen = hd->pkt_numlen;
@@ -101,6 +98,14 @@ int ngtcp2_ppe_encode_frame(ngtcp2_ppe *ppe, ngtcp2_frame *fr) {
10198
return 0;
10299
}
103100

101+
/*
102+
* ppe_sample_offset returns the offset to sample for packet number
103+
* encryption.
104+
*/
105+
static size_t ppe_sample_offset(ngtcp2_ppe *ppe) {
106+
return ppe->pkt_num_offset + 4;
107+
}
108+
104109
ngtcp2_ssize ngtcp2_ppe_final(ngtcp2_ppe *ppe, const uint8_t **ppkt) {
105110
ngtcp2_buf *buf = &ppe->buf;
106111
ngtcp2_crypto_cc *cc = ppe->cc;
@@ -132,9 +137,10 @@ ngtcp2_ssize ngtcp2_ppe_final(ngtcp2_ppe *ppe, const uint8_t **ppkt) {
132137
buf->last = payload + payloadlen + cc->aead.max_overhead;
133138

134139
/* TODO Check that we have enough space to get sample */
135-
assert(ppe->sample_offset + NGTCP2_HP_SAMPLELEN <= ngtcp2_buf_len(buf));
140+
assert(ppe_sample_offset(ppe) + NGTCP2_HP_SAMPLELEN <= ngtcp2_buf_len(buf));
136141

137-
rv = cc->hp_mask(mask, &cc->hp, &cc->hp_ctx, buf->begin + ppe->sample_offset);
142+
rv = cc->hp_mask(mask, &cc->hp, &cc->hp_ctx,
143+
buf->begin + ppe_sample_offset(ppe));
138144
if (rv != 0) {
139145
return NGTCP2_ERR_CALLBACK_FAILURE;
140146
}
@@ -197,7 +203,7 @@ size_t ngtcp2_ppe_padding_hp_sample(ngtcp2_ppe *ppe) {
197203
assert(cc->aead.max_overhead);
198204

199205
max_samplelen =
200-
ngtcp2_buf_len(buf) + cc->aead.max_overhead - ppe->sample_offset;
206+
ngtcp2_buf_len(buf) + cc->aead.max_overhead - ppe_sample_offset(ppe);
201207
if (max_samplelen < NGTCP2_HP_SAMPLELEN) {
202208
len = NGTCP2_HP_SAMPLELEN - max_samplelen;
203209
assert(ngtcp2_ppe_left(ppe) >= len);

deps/ngtcp2/ngtcp2/lib/ngtcp2_ppe.h

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ typedef struct ngtcp2_ppe {
5050
/* pkt_numlen is the number of bytes used to encode a packet
5151
number */
5252
size_t pkt_numlen;
53-
/* sample_offset is the offset to sample for packet number
54-
encryption. */
55-
size_t sample_offset;
5653
/* pkt_num is the packet number written in buf. */
5754
int64_t pkt_num;
5855
/* nonce is the buffer to store nonce. It should be equal or longer

0 commit comments

Comments
 (0)