Skip to content

Commit fa74543

Browse files
committed
deps: update ngtcp2 to 1.15.1
1 parent 01aa635 commit fa74543

26 files changed

+1462
-138
lines changed

deps/ngtcp2/ngtcp2.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
'ngtcp2/lib/ngtcp2_objalloc.c',
2828
'ngtcp2/lib/ngtcp2_opl.c',
2929
'ngtcp2/lib/ngtcp2_path.c',
30+
'ngtcp2/lib/ngtcp2_pcg.c',
3031
'ngtcp2/lib/ngtcp2_pkt.c',
3132
'ngtcp2/lib/ngtcp2_pmtud.c',
3233
'ngtcp2/lib/ngtcp2_ppe.c',
3334
'ngtcp2/lib/ngtcp2_pq.c',
3435
'ngtcp2/lib/ngtcp2_pv.c',
3536
'ngtcp2/lib/ngtcp2_qlog.c',
3637
'ngtcp2/lib/ngtcp2_range.c',
38+
'ngtcp2/lib/ngtcp2_ratelim.c',
3739
'ngtcp2/lib/ngtcp2_ringbuf.c',
3840
'ngtcp2/lib/ngtcp2_rob.c',
3941
'ngtcp2/lib/ngtcp2_rst.c',

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

Lines changed: 117 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,8 @@ typedef enum ngtcp2_token_type {
17041704

17051705
#define NGTCP2_SETTINGS_V1 1
17061706
#define NGTCP2_SETTINGS_V2 2
1707-
#define NGTCP2_SETTINGS_VERSION NGTCP2_SETTINGS_V2
1707+
#define NGTCP2_SETTINGS_V3 3
1708+
#define NGTCP2_SETTINGS_VERSION NGTCP2_SETTINGS_V3
17081709

17091710
/**
17101711
* @struct
@@ -1917,6 +1918,23 @@ typedef struct ngtcp2_settings {
19171918
* field has been available since v1.4.0.
19181919
*/
19191920
size_t pmtud_probeslen;
1921+
/* The following fields have been added since NGTCP2_SETTINGS_V3. */
1922+
/**
1923+
* :member:`glitch_ratelim_burst` is the maximum number of tokens
1924+
* available to "glitch" rate limiter. "glitch" is a suspicious
1925+
* activity from a remote endpoint. If detected, certain amount of
1926+
* tokens are consumed. If no tokens are available to consume, the
1927+
* connection is closed. The rate of token generation is specified
1928+
* by :member:`glitch_ratelim_rate`. This field has been available
1929+
* since v1.15.0.
1930+
*/
1931+
uint64_t glitch_ratelim_burst;
1932+
/**
1933+
* :member:`glitch_ratelim_rate` is the number of tokens generated
1934+
* per second. See :member:`glitch_ratelim_burst` for "glitch" rate
1935+
* limiter. This field has been available since v1.15.0.
1936+
*/
1937+
uint64_t glitch_ratelim_rate;
19201938
} ngtcp2_settings;
19211939

19221940
/**
@@ -3000,9 +3018,8 @@ typedef int (*ngtcp2_begin_path_validation)(ngtcp2_conn *conn, uint32_t flags,
30003018
* an application the outcome of path validation. |flags| is zero or
30013019
* more of :macro:`NGTCP2_PATH_VALIDATION_FLAG_*
30023020
* <NGTCP2_PATH_VALIDATION_FLAG_NONE>`. |path| is the path that was
3003-
* validated. |old_path| is the path that is previously used before a
3004-
* local endpoint has migrated to |path| if |old_path| is not NULL.
3005-
* If |res| is
3021+
* validated. |fallback_path|, if not NULL, is the path that is used
3022+
* if the path validation failed. If |res| is
30063023
* :enum:`ngtcp2_path_validation_result.NGTCP2_PATH_VALIDATION_RESULT_SUCCESS`,
30073024
* the path validation succeeded. If |res| is
30083025
* :enum:`ngtcp2_path_validation_result.NGTCP2_PATH_VALIDATION_RESULT_FAILURE`,
@@ -3014,7 +3031,7 @@ typedef int (*ngtcp2_begin_path_validation)(ngtcp2_conn *conn, uint32_t flags,
30143031
*/
30153032
typedef int (*ngtcp2_path_validation)(ngtcp2_conn *conn, uint32_t flags,
30163033
const ngtcp2_path *path,
3017-
const ngtcp2_path *old_path,
3034+
const ngtcp2_path *fallback_path,
30183035
ngtcp2_path_validation_result res,
30193036
void *user_data);
30203037

@@ -5598,6 +5615,77 @@ NGTCP2_EXTERN size_t ngtcp2_conn_get_send_quantum(ngtcp2_conn *conn);
55985615
NGTCP2_EXTERN size_t ngtcp2_conn_get_stream_loss_count(ngtcp2_conn *conn,
55995616
int64_t stream_id);
56005617

5618+
/**
5619+
* @functypedef
5620+
*
5621+
* :type:`ngtcp2_write_pkt` is a callback function to write a single
5622+
* packet in the buffer pointed by |dest| of length |destlen|. The
5623+
* implementation should use `ngtcp2_conn_write_pkt`,
5624+
* `ngtcp2_conn_writev_stream`, `ngtcp2_conn_writev_datagram`, or
5625+
* their variants to write the packet. |path|, |pi|, |dest|,
5626+
* |destlen|, and |ts| should be directly passed to those functions.
5627+
* If the callback succeeds, it should return the number of bytes
5628+
* written to the buffer. In general, this callback function should
5629+
* return the value that the above mentioned functions returned except
5630+
* for the following error codes:
5631+
*
5632+
* - :macro:`NGTCP2_ERR_STREAM_DATA_BLOCKED`
5633+
* - :macro:`NGTCP2_ERR_STREAM_SHUT_WR`
5634+
* - :macro:`NGTCP2_ERR_STREAM_NOT_FOUND`
5635+
*
5636+
* Those error codes should be handled by an application. If any
5637+
* error occurred outside those functions, return
5638+
* :macro:`NGTCP2_ERR_CALLBACK_FAILURE`. If no packet is produced,
5639+
* return 0.
5640+
*
5641+
* Because GSO requires that the aggregated packets have the same
5642+
* length, :macro:`NGTCP2_WRITE_STREAM_FLAG_PADDING` (or
5643+
* :macro:`NGTCP2_WRITE_DATAGRAM_FLAG_PADDING` if
5644+
* `ngtcp2_conn_writev_datagram` is used) is recommended.
5645+
*
5646+
* This callback function has been available since v1.15.0.
5647+
*/
5648+
typedef ngtcp2_ssize (*ngtcp2_write_pkt)(ngtcp2_conn *conn, ngtcp2_path *path,
5649+
ngtcp2_pkt_info *pi, uint8_t *dest,
5650+
size_t destlen, ngtcp2_tstamp ts,
5651+
void *user_data);
5652+
5653+
/**
5654+
* @function
5655+
*
5656+
* `ngtcp2_conn_write_aggregate_pkt` is a helper function to write
5657+
* multiple packets in the provided buffer, which is suitable to be
5658+
* sent at once in GSO. This function returns the number of bytes
5659+
* written to the buffer pointed by |buf| of length |buflen|.
5660+
* |buflen| must be at least
5661+
* `ngtcp2_conn_get_path_max_tx_udp_payload_size(conn)
5662+
* <ngtcp2_conn_get_path_max_tx_udp_payload_size>` bytes long. It is
5663+
* recommended to pass the buffer at least
5664+
* `ngtcp2_conn_get_max_tx_udp_payload_size(conn)
5665+
* <ngtcp2_conn_get_max_tx_udp_payload_size>` bytes in order to send a
5666+
* PMTUD packet. This function only writes multiple packets if the
5667+
* first packet is `ngtcp2_conn_get_path_max_tx_udp_payload_size(conn)
5668+
* <ngtcp2_conn_get_path_max_tx_udp_payload_size>` bytes long. The
5669+
* application can adjust the length of the buffer to limit the number
5670+
* of packets to aggregate. If this function returns positive
5671+
* integer, all packets share the same :type:`ngtcp2_path` and
5672+
* :type:`ngtcp2_pkt_info` values, and they are assigned to the
5673+
* objects pointed by |path| and |pi| respectively. The length of all
5674+
* packets other than the last packet is assigned to |*pgsolen|. The
5675+
* length of last packet is equal to or less than |*pgsolen|.
5676+
* |write_pkt| must write a single packet. After all packets are
5677+
* written, this function calls `ngtcp2_conn_update_pkt_tx_time`.
5678+
*
5679+
* This function returns the number of bytes written to the buffer, or
5680+
* a negative error code returned by |write_pkt|.
5681+
*
5682+
* This function has been available since v1.15.0.
5683+
*/
5684+
NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_aggregate_pkt_versioned(
5685+
ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version,
5686+
ngtcp2_pkt_info *pi, uint8_t *buf, size_t buflen, size_t *pgsolen,
5687+
ngtcp2_write_pkt write_pkt, ngtcp2_tstamp ts);
5688+
56015689
/**
56025690
* @function
56035691
*
@@ -5680,15 +5768,19 @@ NGTCP2_EXTERN void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps);
56805768
* values. First this function fills |settings| with 0, and set the
56815769
* default value to the following fields:
56825770
*
5683-
* * :type:`cc_algo <ngtcp2_settings.cc_algo>` =
5771+
* * :member:`cc_algo <ngtcp2_settings.cc_algo>` =
56845772
* :enum:`ngtcp2_cc_algo.NGTCP2_CC_ALGO_CUBIC`
5685-
* * :type:`initial_rtt <ngtcp2_settings.initial_rtt>` =
5773+
* * :member:`initial_rtt <ngtcp2_settings.initial_rtt>` =
56865774
* :macro:`NGTCP2_DEFAULT_INITIAL_RTT`
5687-
* * :type:`ack_thresh <ngtcp2_settings.ack_thresh>` = 2
5688-
* * :type:`max_tx_udp_payload_size
5775+
* * :member:`ack_thresh <ngtcp2_settings.ack_thresh>` = 2
5776+
* * :member:`max_tx_udp_payload_size
56895777
* <ngtcp2_settings.max_tx_udp_payload_size>` = 1452
5690-
* * :type:`handshake_timeout <ngtcp2_settings.handshake_timeout>` =
5778+
* * :member:`handshake_timeout <ngtcp2_settings.handshake_timeout>` =
56915779
* ``UINT64_MAX``
5780+
* * :member:`glitch_ratelim_burst
5781+
* <ngtcp2_settings.glitch_ratelim_burst>` = 1000
5782+
* * :member:`glitch_ratelim_rate
5783+
* <ngtcp2_settings.glitch_ratelim_rate>` = 33
56925784
*/
56935785
NGTCP2_EXTERN void ngtcp2_settings_default_versioned(int settings_version,
56945786
ngtcp2_settings *settings);
@@ -5700,15 +5792,15 @@ NGTCP2_EXTERN void ngtcp2_settings_default_versioned(int settings_version,
57005792
* default values. First this function fills |params| with 0, and set
57015793
* the default value to the following fields:
57025794
*
5703-
* * :type:`max_udp_payload_size
5795+
* * :member:`max_udp_payload_size
57045796
* <ngtcp2_transport_params.max_udp_payload_size>` =
57055797
* :macro:`NGTCP2_DEFAULT_MAX_RECV_UDP_PAYLOAD_SIZE`
5706-
* * :type:`ack_delay_exponent
5798+
* * :member:`ack_delay_exponent
57075799
* <ngtcp2_transport_params.ack_delay_exponent>` =
57085800
* :macro:`NGTCP2_DEFAULT_ACK_DELAY_EXPONENT`
5709-
* * :type:`max_ack_delay <ngtcp2_transport_params.max_ack_delay>` =
5801+
* * :member:`max_ack_delay <ngtcp2_transport_params.max_ack_delay>` =
57105802
* :macro:`NGTCP2_DEFAULT_MAX_ACK_DELAY`
5711-
* * :type:`active_connection_id_limit
5803+
* * :member:`active_connection_id_limit
57125804
* <ngtcp2_transport_params.active_connection_id_limit>` =
57135805
* :macro:`NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT`
57145806
*/
@@ -5980,6 +6072,17 @@ NGTCP2_EXTERN uint32_t ngtcp2_select_version(const uint32_t *preferred_versions,
59806072
#define ngtcp2_conn_get_conn_info(CONN, CINFO) \
59816073
ngtcp2_conn_get_conn_info_versioned((CONN), NGTCP2_CONN_INFO_VERSION, (CINFO))
59826074

6075+
/*
6076+
* `ngtcp2_conn_write_aggregate_pkt` is a wrapper around
6077+
* `ngtcp2_conn_write_aggregate_pkt_versioned` to set the correct
6078+
* struct version.
6079+
*/
6080+
#define ngtcp2_conn_write_aggregate_pkt(CONN, PATH, PI, BUF, BUFLEN, PGSOLEN, \
6081+
WRITE_PKT, TS) \
6082+
ngtcp2_conn_write_aggregate_pkt_versioned( \
6083+
(CONN), (PATH), NGTCP2_PKT_INFO_VERSION, (PI), (BUF), (BUFLEN), (PGSOLEN), \
6084+
(WRITE_PKT), (TS))
6085+
59836086
/*
59846087
* `ngtcp2_settings_default` is a wrapper around
59856088
* `ngtcp2_settings_default_versioned` to set the correct struct

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

Lines changed: 2 additions & 2 deletions
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.14.0"
39+
#define NGTCP2_VERSION "1.15.1"
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 0x010e00
49+
#define NGTCP2_VERSION_NUM 0x010f01
5050

5151
#endif /* !defined(NGTCP2_VERSION_H) */

deps/ngtcp2/ngtcp2/lib/ngtcp2_acktr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ void ngtcp2_acktr_recv_ack(ngtcp2_acktr *acktr, const ngtcp2_ack *fr) {
316316
}
317317

318318
void ngtcp2_acktr_commit_ack(ngtcp2_acktr *acktr) {
319-
acktr->flags &= (uint16_t) ~(NGTCP2_ACKTR_FLAG_ACTIVE_ACK |
320-
NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK |
321-
NGTCP2_ACKTR_FLAG_CANCEL_TIMER);
319+
acktr->flags &=
320+
(uint16_t)~(NGTCP2_ACKTR_FLAG_ACTIVE_ACK | NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK |
321+
NGTCP2_ACKTR_FLAG_CANCEL_TIMER);
322322
acktr->first_unacked_ts = UINT64_MAX;
323323
acktr->rx_npkt = 0;
324324
}

deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "ngtcp2_rcvry.h"
3434
#include "ngtcp2_rst.h"
3535
#include "ngtcp2_conn_stat.h"
36+
#include "ngtcp2_pcg.h"
3637

3738
#define NGTCP2_BBR_MAX_BW_FILTERLEN 2
3839

@@ -906,15 +907,9 @@ static int bbr_is_time_to_probe_bw(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
906907
}
907908

908909
static void bbr_pick_probe_wait(ngtcp2_cc_bbr *bbr) {
909-
uint8_t rand;
910-
911-
bbr->rand(&rand, 1, &bbr->rand_ctx);
912-
913-
bbr->rounds_since_bw_probe = (uint64_t)(rand / 128);
914-
915-
bbr->rand(&rand, 1, &bbr->rand_ctx);
916-
917-
bbr->bw_probe_wait = 2 * NGTCP2_SECONDS + NGTCP2_SECONDS * rand / 255;
910+
bbr->rounds_since_bw_probe = ngtcp2_pcg32_rand_n(bbr->pcg, 2);
911+
bbr->bw_probe_wait =
912+
2 * NGTCP2_SECONDS + ngtcp2_pcg32_rand_n(bbr->pcg, NGTCP2_SECONDS + 1);
918913
}
919914

920915
static int bbr_is_reno_coexistence_probe_time(ngtcp2_cc_bbr *bbr,
@@ -1388,8 +1383,7 @@ static void bbr_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
13881383

13891384
void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
13901385
ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
1391-
ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
1392-
const ngtcp2_rand_ctx *rand_ctx) {
1386+
ngtcp2_tstamp initial_ts, ngtcp2_pcg32 *pcg) {
13931387
*bbr = (ngtcp2_cc_bbr){
13941388
.cc =
13951389
{
@@ -1403,8 +1397,7 @@ void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
14031397
.reset = bbr_cc_reset,
14041398
},
14051399
.rst = rst,
1406-
.rand = rand,
1407-
.rand_ctx = *rand_ctx,
1400+
.pcg = pcg,
14081401
.initial_cwnd = cstat->cwnd,
14091402
};
14101403

deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "ngtcp2_window_filter.h"
3636

3737
typedef struct ngtcp2_rst ngtcp2_rst;
38+
typedef struct ngtcp2_pcg32 ngtcp2_pcg32;
3839

3940
typedef enum ngtcp2_bbr_state {
4041
NGTCP2_BBR_STATE_STARTUP,
@@ -62,8 +63,7 @@ typedef struct ngtcp2_cc_bbr {
6263

6364
uint64_t initial_cwnd;
6465
ngtcp2_rst *rst;
65-
ngtcp2_rand rand;
66-
ngtcp2_rand_ctx rand_ctx;
66+
ngtcp2_pcg32 *pcg;
6767

6868
/* max_bw_filter for tracking the maximum recent delivery rate
6969
samples for estimating max_bw. */
@@ -136,7 +136,6 @@ typedef struct ngtcp2_cc_bbr {
136136

137137
void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
138138
ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
139-
ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
140-
const ngtcp2_rand_ctx *rand_ctx);
139+
ngtcp2_tstamp initial_ts, ngtcp2_pcg32 *pcg);
141140

142141
#endif /* !defined(NGTCP2_BBR_H) */

deps/ngtcp2/ngtcp2/lib/ngtcp2_buf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ size_t ngtcp2_buf_cap(const ngtcp2_buf *buf) {
3636
return (size_t)(buf->end - buf->begin);
3737
}
3838

39+
void ngtcp2_buf_trunc(ngtcp2_buf *buf, size_t len) {
40+
if (ngtcp2_buf_len(buf) > len) {
41+
buf->last = buf->pos + len;
42+
}
43+
}
44+
3945
int ngtcp2_buf_chain_new(ngtcp2_buf_chain **pbufchain, size_t len,
4046
const ngtcp2_mem *mem) {
4147
*pbufchain = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_buf_chain) + len);

deps/ngtcp2/ngtcp2/lib/ngtcp2_buf.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,21 @@ static inline size_t ngtcp2_buf_left(const ngtcp2_buf *buf) {
7070
* ngtcp2_buf_len returns the number of bytes left to read. In other
7171
* words, it returns buf->last - buf->pos.
7272
*/
73-
static inline size_t ngtcp2_buf_len(const ngtcp2_buf *buf) {
74-
return (size_t)(buf->last - buf->pos);
75-
}
73+
#define ngtcp2_buf_len(BUF) (size_t)((BUF)->last - (BUF)->pos)
7674

7775
/*
7876
* ngtcp2_buf_cap returns the capacity of the buffer. In other words,
7977
* it returns buf->end - buf->begin.
8078
*/
8179
size_t ngtcp2_buf_cap(const ngtcp2_buf *buf);
8280

81+
/*
82+
* ngtcp2_buf_trunc truncates the number of bytes to read to at most
83+
* |len|. In other words, it sets buf->last = buf->pos + len if
84+
* ngtcp2_buf_len(buf) > len.
85+
*/
86+
void ngtcp2_buf_trunc(ngtcp2_buf *buf, size_t len);
87+
8388
/*
8489
* ngtcp2_buf_chain is a linked list of ngtcp2_buf.
8590
*/

0 commit comments

Comments
 (0)