mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
deps: update ngtcp2 to 1.26.0
PR-URL: https://github.com/nodejs/node/pull/67257 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
b6d6c6c38a
commit
e5cb867504
54 files changed
+1751
-1349
No files matched your search
+15
-2
@@ -411,6 +411,7 @@ static void crypto_buf_write(crypto_buf *cbuf, const uint8_t *data,
|
||||
|
||||
struct ngtcp2_crypto_ossl_ctx {
|
||||
SSL *ssl;
|
||||
ngtcp2_encryption_level rx_level;
|
||||
ngtcp2_encryption_level tx_level;
|
||||
crypto_buf *crypto_head, *crypto_read, *crypto_write;
|
||||
size_t crypto_head_released;
|
||||
@@ -425,6 +426,7 @@ int ngtcp2_crypto_ossl_ctx_new(ngtcp2_crypto_ossl_ctx **possl_ctx, SSL *ssl) {
|
||||
}
|
||||
|
||||
ossl_ctx->ssl = ssl;
|
||||
ossl_ctx->rx_level = NGTCP2_ENCRYPTION_LEVEL_INITIAL;
|
||||
ossl_ctx->tx_level = NGTCP2_ENCRYPTION_LEVEL_INITIAL;
|
||||
ossl_ctx->crypto_head = ossl_ctx->crypto_read = ossl_ctx->crypto_write = NULL;
|
||||
ossl_ctx->crypto_head_released = 0;
|
||||
@@ -962,7 +964,10 @@ int ngtcp2_crypto_read_write_crypto_data(
|
||||
SSL *ssl = ossl_ctx->ssl;
|
||||
int rv;
|
||||
int err;
|
||||
(void)encryption_level;
|
||||
|
||||
if (encryption_level != ossl_ctx->rx_level) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (crypto_ossl_ctx_write_crypto_data(ossl_ctx, data, datalen) != 0) {
|
||||
return -1;
|
||||
@@ -1128,7 +1133,10 @@ static int ossl_yield_secret(SSL *ssl, uint32_t ossl_level, int direction,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ossl_ctx->tx_level = level;
|
||||
/* CRYPTO data is never sent in 0-RTT packet. */
|
||||
if (level != NGTCP2_ENCRYPTION_LEVEL_0RTT) {
|
||||
ossl_ctx->tx_level = level;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1138,6 +1146,11 @@ static int ossl_yield_secret(SSL *ssl, uint32_t ossl_level, int direction,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This check is probably not needed, but just in case */
|
||||
if (level != NGTCP2_ENCRYPTION_LEVEL_0RTT) {
|
||||
ossl_ctx->rx_level = level;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -387,9 +387,11 @@ int ngtcp2_crypto_read_write_crypto_data(
|
||||
size_t i;
|
||||
int rv;
|
||||
|
||||
ptls_buffer_init(&sendbuf, (void *)"", 0);
|
||||
if (epoch != ptls_get_read_epoch(cptls->ptls)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(datalen == 0 || epoch == ptls_get_read_epoch(cptls->ptls));
|
||||
ptls_buffer_init(&sendbuf, (void *)"", 0);
|
||||
|
||||
rv = ptls_handle_message(cptls->ptls, &sendbuf, epoch_offsets, epoch, data,
|
||||
datalen, &cptls->handshake_properties);
|
||||
|
||||
Vendored
+32
-3
@@ -236,6 +236,35 @@ int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, uint32_t version,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* crypto_set_remote_transport_params retrieves remote QUIC transport
|
||||
* parameters from |tls| and sets it to |conn|. Some TLS backends set
|
||||
* them to |conn| from their own TLS extension callback instead, which
|
||||
* is never called if a remote endpoint omits the extension. This
|
||||
* function fails if they have not been set to |conn| after all.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
static int crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) {
|
||||
const ngtcp2_transport_params *params;
|
||||
|
||||
if (ngtcp2_crypto_set_remote_transport_params(conn, tls) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
params = ngtcp2_conn_get_remote_transport_params2(conn);
|
||||
|
||||
/* Client might have the remembered 0-RTT transport parameters, but
|
||||
they never include initial_scid which is mandatory in the ones
|
||||
received from a remote endpoint. */
|
||||
if (!params || !params->initial_scid_present) {
|
||||
ngtcp2_conn_set_tls_error(conn, NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
uint8_t *iv, uint8_t *hp_key,
|
||||
ngtcp2_encryption_level level,
|
||||
@@ -282,7 +311,7 @@ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
if (ngtcp2_conn_is_server2(conn) &&
|
||||
!ngtcp2_conn_get_negotiated_version2(conn)) {
|
||||
rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
|
||||
rv = crypto_set_remote_transport_params(conn, tls);
|
||||
if (rv != 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -340,7 +369,7 @@ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
break;
|
||||
case NGTCP2_ENCRYPTION_LEVEL_1RTT:
|
||||
if (!ngtcp2_conn_is_server2(conn)) {
|
||||
rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
|
||||
rv = crypto_set_remote_transport_params(conn, tls);
|
||||
if (rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -443,7 +472,7 @@ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
|
||||
case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
|
||||
if (ngtcp2_conn_is_server2(conn) &&
|
||||
!ngtcp2_conn_get_negotiated_version2(conn)) {
|
||||
rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
|
||||
rv = crypto_set_remote_transport_params(conn, tls);
|
||||
if (rv != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1721,7 +1721,8 @@ std::expected<void, Error> Client::make_stream_early() {
|
||||
void Client::on_extend_max_streams() {
|
||||
int64_t stream_id;
|
||||
|
||||
if ((config.delay_stream && !handshake_confirmed_) ||
|
||||
if (config.requests.empty() ||
|
||||
(config.delay_stream && !handshake_confirmed_) ||
|
||||
ev_is_active(&delay_stream_timer_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,10 @@ ProtoCodec::on_stream_close(int64_t stream_id,
|
||||
return {};
|
||||
}
|
||||
|
||||
if (auto stream = client_->find_stream(stream_id); stream) {
|
||||
sendq_.erase(stream);
|
||||
}
|
||||
|
||||
if (!config.quiet) {
|
||||
std::println(stderr,
|
||||
"HTTP stream {:#x} closed with error codes (RX:{}, TX:{})",
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public:
|
||||
std::expected<void, Error> extend_max_stream_data(int64_t stream_id,
|
||||
uint64_t max_data);
|
||||
|
||||
void early_data_rejected() {}
|
||||
void early_data_rejected() { sendq_.clear(); }
|
||||
|
||||
std::expected<void, Error>
|
||||
on_stream_close(int64_t stream_id, std::optional<uint64_t> rx_app_error_code,
|
||||
|
||||
+46
-4
@@ -31,6 +31,8 @@
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
@@ -216,6 +218,11 @@ Stream::open_file(const std::filesystem::path &path) {
|
||||
close(fd);
|
||||
} else {
|
||||
fe.fd = fd;
|
||||
// A file larger than the address space cannot be mapped.
|
||||
if (std::cmp_greater(st.st_size, std::numeric_limits<size_t>::max())) {
|
||||
close(fd);
|
||||
return std::unexpected{Error::INTEGER_OVERFLOW};
|
||||
}
|
||||
fe.len = static_cast<size_t>(st.st_size);
|
||||
if (fe.len) {
|
||||
fe.map = mmap(nullptr, fe.len, PROT_READ, MAP_SHARED, fd, 0);
|
||||
@@ -321,9 +328,7 @@ void timeoutcb(struct ev_loop *loop, ev_timer *w, int revents) {
|
||||
}
|
||||
|
||||
if (auto rv = h->handle_expiry(); !rv) {
|
||||
if (rv.error() == Error::CLOSE_WAIT) {
|
||||
ev_timer_stop(loop, w);
|
||||
} else {
|
||||
if (rv.error() != Error::CLOSE_WAIT) {
|
||||
s->remove(h);
|
||||
}
|
||||
|
||||
@@ -773,6 +778,7 @@ Handler::init(const Endpoint &ep, const Address &local_addr,
|
||||
settings.handshake_timeout = config.handshake_timeout;
|
||||
settings.no_pmtud = config.no_pmtud;
|
||||
settings.ack_thresh = config.ack_thresh;
|
||||
settings.write_stream_data_thresh = config.write_stream_data_thresh;
|
||||
if (config.max_udp_payload_size) {
|
||||
settings.max_tx_udp_payload_size = config.max_udp_payload_size;
|
||||
settings.no_tx_udp_payload_size_shaping = 1;
|
||||
@@ -1705,7 +1711,9 @@ void Server::on_read(const Endpoint &ep) {
|
||||
stderr,
|
||||
"Received packet: local={} remote={} if={} ecn={:#x} {} bytes",
|
||||
util::straddr(*local_addr), util::straddr(remote_addr),
|
||||
if_indextoname(local_addr->ifindex, ifname.data()), pi.ecn, datalen);
|
||||
if_indextoname(local_addr->ifindex, ifname.data()) ? ifname.data()
|
||||
: "(unknown)",
|
||||
pi.ecn, datalen);
|
||||
}
|
||||
|
||||
// Packets less than 21 bytes never be a valid QUIC packet.
|
||||
@@ -1735,6 +1743,11 @@ void Server::read_pkt(const Endpoint &ep, const Address &local_addr,
|
||||
NGTCP2_SV_SCIDLEN);
|
||||
rv) {
|
||||
case 0:
|
||||
if ((data[0] & 0x80U) && vc.version == 0) {
|
||||
// Version Negotiation packet was received.
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_ERR_VERSION_NEGOTIATION:
|
||||
(void)send_version_negotiation(vc.version, {vc.scid, vc.scidlen},
|
||||
@@ -2658,6 +2671,15 @@ Options:
|
||||
to send per an event loop in a single connection. It
|
||||
defaults to 0, which means it is not limited by the
|
||||
configuration.
|
||||
--write-stream-data-thresh=<SIZE>
|
||||
The threshold for the length of STREAM frame payload
|
||||
that the local endpoint sends. If there is data more
|
||||
than this value to send, and the flow control does not
|
||||
allow sending more than this length, the data is not
|
||||
sent, waiting for the window update from the remote
|
||||
endpoint.
|
||||
Default: )"
|
||||
<< config.write_stream_data_thresh << R"(
|
||||
-h, --help Display this help and exit.
|
||||
|
||||
---
|
||||
@@ -2732,6 +2754,7 @@ int main(int argc, char **argv) {
|
||||
{"no-gso", no_argument, &flag, 35},
|
||||
{"show-stat", no_argument, &flag, 36},
|
||||
{"gso-burst", required_argument, &flag, 37},
|
||||
{"write-stream-data-thresh", required_argument, &flag, 38},
|
||||
{},
|
||||
};
|
||||
|
||||
@@ -3163,6 +3186,25 @@ int main(int argc, char **argv) {
|
||||
|
||||
break;
|
||||
}
|
||||
case 38: {
|
||||
// --write-stream-data-thresh
|
||||
auto n = util::parse_uint_iec(optarg);
|
||||
if (!n) {
|
||||
std::println(stderr, "write-stream-data-thresh: invalid argument");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (auto max = std::numeric_limits<size_t>::max(); *n > max) {
|
||||
std::println(
|
||||
stderr,
|
||||
"write-stream-data-thresh: must be less than or equal to {}", max);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
config.write_stream_data_thresh = static_cast<size_t>(*n);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Vendored
+1
-1
@@ -68,7 +68,7 @@ enum FileEntryFlag {
|
||||
};
|
||||
|
||||
struct FileEntry {
|
||||
uint64_t len{};
|
||||
size_t len{};
|
||||
void *map{};
|
||||
int fd{};
|
||||
uint8_t flags{};
|
||||
|
||||
+3
@@ -169,6 +169,9 @@ struct Config {
|
||||
// gso_burst is the number of packets to aggregate in GSO. 0 means
|
||||
// it is not limited by the configuration.
|
||||
size_t gso_burst{};
|
||||
// write_stream_data_thresh is the threshold for the length of
|
||||
// STREAM frame payload that the local endpoint sends.
|
||||
size_t write_stream_data_thresh{255};
|
||||
};
|
||||
|
||||
struct HTTPHeader {
|
||||
|
||||
+2
-2
@@ -130,8 +130,8 @@ void test_sim_unistream(void) {
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_true(svapp.is_all_bytes_sent());
|
||||
assert_uint64(link.compute_expected_goodput(link.delay * 2), <=,
|
||||
svapp.compute_goodput());
|
||||
assert_lte(link.compute_expected_goodput(link.delay * 2),
|
||||
svapp.compute_goodput());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -62,7 +62,7 @@ void test_siphash(void) {
|
||||
std::array<uint8_t, 15> input;
|
||||
std::iota(std::ranges::begin(input), std::ranges::end(input), 0);
|
||||
|
||||
assert_uint64(0xA129CA6149BE45E5ULL, ==, siphash24(key, input));
|
||||
assert_eq(0xA129CA6149BE45E5ULL, siphash24(key, input));
|
||||
}
|
||||
|
||||
void test_siphash_vector(void) {
|
||||
@@ -91,7 +91,7 @@ void test_siphash_vector(void) {
|
||||
expect = byteswap(expect);
|
||||
}
|
||||
|
||||
assert_uint64(expect, ==, h);
|
||||
assert_eq(expect, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@
|
||||
|
||||
#define MUNIT_ENABLE_ASSERT_ALIASES
|
||||
|
||||
#include "munit.h"
|
||||
#include "munitxx.h"
|
||||
|
||||
namespace ngtcp2 {
|
||||
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ class ClientRun:
|
||||
def assert_verify_cert_handshake(self):
|
||||
c_hs, s_hs = self.norm_exp(
|
||||
"ServerHello:EncryptedExtensions:CertificateRequest:(Compressed)?Certificate:CertificateVerify:Finished",
|
||||
"ClientHello:Certificate:CertificateVerify:Finished")
|
||||
"ClientHello:(Compressed)?Certificate:CertificateVerify:Finished")
|
||||
self._assert_hs(c_hs, s_hs)
|
||||
|
||||
|
||||
|
||||
+26
-1
@@ -842,6 +842,31 @@ class Certificate(HSRecord):
|
||||
f'{ind} certificate_list: \n' + '\n'.join(
|
||||
[self._enxtry_text(e, indent+4) for e in self._cert_entries])
|
||||
|
||||
class CompressedCertificate(HSRecord):
|
||||
|
||||
def __init__(self, hsid: int, name: str, data):
|
||||
super().__init__(hsid=hsid, name=name, data=data)
|
||||
d = data
|
||||
d, algorithm = _get_field(d, 2)
|
||||
self._algorithm = int.from_bytes(bytearray(algorithm), byteorder='big')
|
||||
d, uncompressed_length = _get_field(d, 3)
|
||||
self._uncompressed_length = int.from_bytes(bytearray(uncompressed_length), byteorder='big')
|
||||
d, self._compressed_certificate_message = _get_len_field(d, 3)
|
||||
assert len(d) == 0
|
||||
|
||||
def to_json(self):
|
||||
jdata = super().to_json()
|
||||
jdata['algorithm'] = self._algorithm
|
||||
jdata['uncompressed_length'] = self._uncompressed_length
|
||||
jdata['compressed_certificate_message'] = binascii.hexlify(self._compressed_certificate_message).decode()
|
||||
return jdata
|
||||
|
||||
def to_text(self, indent: int = 0):
|
||||
ind = ' ' * (indent + 2)
|
||||
return super().to_text(indent=indent) + '\n'\
|
||||
f'{ind} algorithm: {self._algorithm}\n'\
|
||||
f'{ind} uncompressed_length: {self._uncompressed_length}\n'\
|
||||
f'{ind} compressed_certificate_message: {binascii.hexlify(self._compressed_certificate_message).decode()}'
|
||||
|
||||
class SessionTicket(HSRecord):
|
||||
|
||||
@@ -901,7 +926,7 @@ class HandShake:
|
||||
(20, 'Finished', HSRecord),
|
||||
(22, 'CertificateStatus', HSRecord),
|
||||
(24, 'KeyUpdate', HSRecord),
|
||||
(25, 'CompressedCertificate', HSRecord),
|
||||
(25, 'CompressedCertificate', CompressedCertificate),
|
||||
]
|
||||
RT_NAME_BY_ID = {}
|
||||
RT_CLS_BY_ID = {}
|
||||
|
||||
+7
-3
@@ -49,9 +49,13 @@ class TestClientCert:
|
||||
creqs = [r for r in cr.handshake if r.hsid == 13] # CertificateRequest
|
||||
assert len(creqs) == 1
|
||||
creq = creqs[0].to_json()
|
||||
certs = [r for r in cr.server.handshake if r.hsid == 11] # Certificate
|
||||
certs = [r for r in cr.server.handshake if r.hsid == 11 or r.hsid == 25] # Certificate or CompressedCertificate
|
||||
assert len(certs) == 1
|
||||
crec = certs[0].to_json()
|
||||
assert len(crec['certificate_list']) == 1
|
||||
assert creq['context'] == crec['context']
|
||||
if 'certificate_list' in crec:
|
||||
cert_list = crec['certificate_list']
|
||||
assert len(cert_list) == 1
|
||||
assert creq['context'] == crec['context']
|
||||
else:
|
||||
assert 'compressed_certificate_message' in crec
|
||||
# TODO: check that GET indeed gave a response
|
||||
@@ -36,7 +36,8 @@
|
||||
extern Config config;
|
||||
|
||||
namespace {
|
||||
int save_ticket_cb(ptls_save_ticket_t *self, ptls_t *ptls, ptls_iovec_t input) {
|
||||
int save_ticket_cb(ptls_save_ticket_t *self, ptls_t *ptls, ptls_iovec_t input,
|
||||
const ptls_save_ticket_properties_t *ticket_prop) {
|
||||
auto conn_ref =
|
||||
static_cast<ngtcp2_crypto_conn_ref *>(*ptls_get_data_ptr(ptls));
|
||||
auto c = static_cast<ClientBase *>(conn_ref->user_data);
|
||||
|
||||
+138
-353
@@ -92,323 +92,112 @@ std::expected<void, Error> generate_secure_random(std::span<uint8_t> data) {
|
||||
} // namespace util
|
||||
|
||||
void test_util_format_durationf() {
|
||||
assert_stdstring_equal("0ns", util::format_durationf(0));
|
||||
assert_stdstring_equal("999ns", util::format_durationf(999));
|
||||
assert_stdstring_equal("1.00us", util::format_durationf(1000));
|
||||
assert_stdstring_equal("1.00us", util::format_durationf(1004));
|
||||
assert_stdstring_equal("1.00us", util::format_durationf(1005));
|
||||
assert_stdstring_equal("1.02us", util::format_durationf(1015));
|
||||
assert_stdstring_equal("2.00us", util::format_durationf(1999));
|
||||
assert_stdstring_equal("1.00ms", util::format_durationf(999999));
|
||||
assert_stdstring_equal("3.50ms", util::format_durationf(3500111));
|
||||
assert_stdstring_equal("9999.99s", util::format_durationf(9999990000000ULL));
|
||||
assert_eq("0ns", util::format_durationf(0));
|
||||
assert_eq("999ns", util::format_durationf(999));
|
||||
assert_eq("1.00us", util::format_durationf(1000));
|
||||
assert_eq("1.00us", util::format_durationf(1004));
|
||||
assert_eq("1.00us", util::format_durationf(1005));
|
||||
assert_eq("1.02us", util::format_durationf(1015));
|
||||
assert_eq("2.00us", util::format_durationf(1999));
|
||||
assert_eq("1.00ms", util::format_durationf(999999));
|
||||
assert_eq("3.50ms", util::format_durationf(3500111));
|
||||
assert_eq("9999.99s", util::format_durationf(9999990000000ULL));
|
||||
}
|
||||
|
||||
void test_util_format_uint() {
|
||||
assert_stdstring_equal("0"s, util::format_uint(0U));
|
||||
assert_stdstring_equal("18446744073709551615"s,
|
||||
util::format_uint(18446744073709551615ULL));
|
||||
assert_eq("0", util::format_uint(0U));
|
||||
assert_eq("18446744073709551615", util::format_uint(18446744073709551615ULL));
|
||||
}
|
||||
|
||||
void test_util_format_uint_iec() {
|
||||
assert_stdstring_equal("0"s, util::format_uint_iec(0U));
|
||||
assert_stdstring_equal("1023"s, util::format_uint_iec((1U << 10) - 1));
|
||||
assert_stdstring_equal("1K"s, util::format_uint_iec(1U << 10));
|
||||
assert_stdstring_equal("1M"s, util::format_uint_iec(1U << 20));
|
||||
assert_stdstring_equal("1G"s, util::format_uint_iec(1U << 30));
|
||||
assert_stdstring_equal(
|
||||
"18446744073709551615"s,
|
||||
util::format_uint_iec(std::numeric_limits<uint64_t>::max()));
|
||||
assert_stdstring_equal("1025K"s,
|
||||
util::format_uint_iec((1U << 20) + (1U << 10)));
|
||||
assert_eq("0", util::format_uint_iec(0U));
|
||||
assert_eq("1023", util::format_uint_iec((1U << 10) - 1));
|
||||
assert_eq("1K", util::format_uint_iec(1U << 10));
|
||||
assert_eq("1M", util::format_uint_iec(1U << 20));
|
||||
assert_eq("1G", util::format_uint_iec(1U << 30));
|
||||
assert_eq("18446744073709551615"s,
|
||||
util::format_uint_iec(std::numeric_limits<uint64_t>::max()));
|
||||
assert_eq("1025K", util::format_uint_iec((1U << 20) + (1U << 10)));
|
||||
}
|
||||
|
||||
void test_util_format_duration() {
|
||||
assert_stdstring_equal("0ns", util::format_duration(0));
|
||||
assert_stdstring_equal("999ns", util::format_duration(999));
|
||||
assert_stdstring_equal("1us", util::format_duration(1000));
|
||||
assert_stdstring_equal("1ms", util::format_duration(1000000));
|
||||
assert_stdstring_equal("1s", util::format_duration(1000000000));
|
||||
assert_stdstring_equal("1m", util::format_duration(60000000000ULL));
|
||||
assert_stdstring_equal("1h", util::format_duration(3600000000000ULL));
|
||||
assert_stdstring_equal(
|
||||
"18446744073709551615ns",
|
||||
util::format_duration(std::numeric_limits<uint64_t>::max()));
|
||||
assert_stdstring_equal("61s", util::format_duration(61000000000ULL));
|
||||
assert_eq("0ns", util::format_duration(0));
|
||||
assert_eq("999ns", util::format_duration(999));
|
||||
assert_eq("1us", util::format_duration(1000));
|
||||
assert_eq("1ms", util::format_duration(1000000));
|
||||
assert_eq("1s", util::format_duration(1000000000));
|
||||
assert_eq("1m", util::format_duration(60000000000ULL));
|
||||
assert_eq("1h", util::format_duration(3600000000000ULL));
|
||||
assert_eq("18446744073709551615ns",
|
||||
util::format_duration(std::numeric_limits<uint64_t>::max()));
|
||||
assert_eq("61s", util::format_duration(61000000000ULL));
|
||||
}
|
||||
|
||||
void test_util_parse_uint() {
|
||||
{
|
||||
auto res = util::parse_uint("0");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(0, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint("1");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(1, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint("18446744073709551615");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(18446744073709551615ULL, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint("18446744073709551616");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint("a");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint("1a");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint("");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
assert_ok_eq(0, util::parse_uint("0"));
|
||||
assert_ok_eq(1, util::parse_uint("1"));
|
||||
assert_ok_eq(18446744073709551615ULL,
|
||||
util::parse_uint("18446744073709551615"));
|
||||
assert_err(Error::INTEGER_OVERFLOW, util::parse_uint("18446744073709551616"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint("a"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint("1a"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint(""));
|
||||
}
|
||||
|
||||
void test_util_parse_uint_iec() {
|
||||
{
|
||||
auto res = util::parse_uint_iec("0");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(0, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("1023");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(1023, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("1K");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(1 << 10, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("1M");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(1 << 20, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("1G");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(1 << 30, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("11G");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64((1ULL << 30) * 11, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("18446744073709551616");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("1x");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("1Gx");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("G");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_uint_iec("");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
assert_ok_eq(0, util::parse_uint_iec("0"));
|
||||
assert_ok_eq(1023, util::parse_uint_iec("1023"));
|
||||
assert_ok_eq(1 << 10, util::parse_uint_iec("1K"));
|
||||
assert_ok_eq(1 << 20, util::parse_uint_iec("1M"));
|
||||
assert_ok_eq(1 << 30, util::parse_uint_iec("1G"));
|
||||
assert_ok_eq((1ULL << 30) * 11, util::parse_uint_iec("11G"));
|
||||
assert_err(Error::INTEGER_OVERFLOW,
|
||||
util::parse_uint_iec("18446744073709551616"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint_iec("1x"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint_iec("1Gx"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint_iec("G"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_uint_iec(""));
|
||||
}
|
||||
|
||||
void test_util_parse_duration() {
|
||||
{
|
||||
auto res = util::parse_duration("0");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(0, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(NGTCP2_SECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("0ns");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(0, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1ns");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(1, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1us");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(NGTCP2_MICROSECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1ms");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(NGTCP2_MILLISECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1s");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(NGTCP2_SECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1m");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(60 * NGTCP2_SECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1h");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(3600 * NGTCP2_SECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("2h");
|
||||
assert_true(res.has_value());
|
||||
assert_uint64(2 * 3600 * NGTCP2_SECONDS, ==, *res);
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("18446744073709551616");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1x");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1mx");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("1mxy");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("s");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("ms");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
{
|
||||
auto res = util::parse_duration("");
|
||||
assert_false(res.has_value());
|
||||
}
|
||||
assert_ok_eq(0, util::parse_duration("0"));
|
||||
assert_ok_eq(NGTCP2_SECONDS, util::parse_duration("1"));
|
||||
assert_ok_eq(0, util::parse_duration("0ns"));
|
||||
assert_ok_eq(1, util::parse_duration("1ns"));
|
||||
assert_ok_eq(NGTCP2_MICROSECONDS, util::parse_duration("1us"));
|
||||
assert_ok_eq(NGTCP2_MILLISECONDS, util::parse_duration("1ms"));
|
||||
assert_ok_eq(NGTCP2_SECONDS, util::parse_duration("1s"));
|
||||
assert_ok_eq(60 * NGTCP2_SECONDS, util::parse_duration("1m"));
|
||||
assert_ok_eq(3600 * NGTCP2_SECONDS, util::parse_duration("1h"));
|
||||
assert_ok_eq(2 * 3600 * NGTCP2_SECONDS, util::parse_duration("2h"));
|
||||
assert_err(Error::INTEGER_OVERFLOW,
|
||||
util::parse_duration("18446744073709551616"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_duration("1x"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_duration("1mx"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_duration("1mxy"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_duration("s"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_duration("ms"));
|
||||
assert_err(Error::INVALID_ARGUMENT, util::parse_duration(""));
|
||||
}
|
||||
|
||||
void test_util_normalize_path() {
|
||||
{
|
||||
auto rv = util::normalize_path("/");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("//");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/foo");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/foo/bar/");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo/bar/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/foo/abc/../bar/");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo/bar/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/../foo/abc/../bar/");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo/bar/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/./foo/././abc///.././bar/./");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo/bar/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/foo/.");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/foo/./bar");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/foo/bar", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/foo/./../bar");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/bar", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/../../bar");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/bar", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path(std::string(1024, '/'));
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path(std::string(1025, '/'));
|
||||
|
||||
assert_false(rv);
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/..");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/", rv.value());
|
||||
}
|
||||
|
||||
{
|
||||
auto rv = util::normalize_path("/../../index.html");
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_stdstring_equal("/index.html", rv.value());
|
||||
}
|
||||
assert_ok_eq("/", util::normalize_path("/"));
|
||||
assert_ok_eq("/", util::normalize_path("//"));
|
||||
assert_ok_eq("/foo", util::normalize_path("/foo"));
|
||||
assert_ok_eq("/foo/bar/", util::normalize_path("/foo/bar/"));
|
||||
assert_ok_eq("/foo/bar/", util::normalize_path("/foo/abc/../bar/"));
|
||||
assert_ok_eq("/foo/bar/", util::normalize_path("/../foo/abc/../bar/"));
|
||||
assert_ok_eq("/foo/bar/",
|
||||
util::normalize_path("/./foo/././abc///.././bar/./"));
|
||||
assert_ok_eq("/foo/", util::normalize_path("/foo/."));
|
||||
assert_ok_eq("/foo/bar", util::normalize_path("/foo/./bar"));
|
||||
assert_ok_eq("/bar", util::normalize_path("/foo/./../bar"));
|
||||
assert_ok_eq("/bar", util::normalize_path("/../../bar"));
|
||||
assert_ok_eq("/", util::normalize_path(std::string(1024, '/')));
|
||||
assert_err(Error::INVALID_ARGUMENT,
|
||||
util::normalize_path(std::string(1025, '/')));
|
||||
assert_ok_eq("/", util::normalize_path("/.."));
|
||||
assert_ok_eq("/index.html", util::normalize_path("/../../index.html"));
|
||||
}
|
||||
|
||||
void test_util_hexdump() {
|
||||
@@ -522,15 +311,14 @@ void test_util_hexdump() {
|
||||
munit_log(MUNIT_LOG_INFO, t.title);
|
||||
|
||||
auto f = tmpfile();
|
||||
auto rv = util::hexdump(f, std::span{t.data});
|
||||
|
||||
assert_true(rv.has_value());
|
||||
assert_ok(util::hexdump(f, std::span{t.data}));
|
||||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
auto nread = fread(buf, 1, sizeof(buf), f);
|
||||
buf[nread] = '\0';
|
||||
|
||||
assert_stdsv_equal(t.dump, buf);
|
||||
assert_eq(t.dump, buf);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
@@ -539,58 +327,39 @@ void test_util_hexdump() {
|
||||
void test_util_format_hex() {
|
||||
auto a = std::to_array<uint8_t>({0xDE, 0xAD, 0xBE, 0xEF});
|
||||
|
||||
assert_stdstring_equal("deadbeef"s, util::format_hex(a));
|
||||
assert_stdstring_equal("deadbeef"s, util::format_hex(0xDEADBEEF));
|
||||
assert_stdstring_equal("beef"s, util::format_hex(a.data() + 2, 2));
|
||||
assert_eq("deadbeef", util::format_hex(a));
|
||||
assert_eq("deadbeef", util::format_hex(0xDEADBEEF));
|
||||
assert_eq("beef", util::format_hex(a.data() + 2, 2));
|
||||
|
||||
std::array<char, 64> buf;
|
||||
auto b = std::ranges::begin(buf);
|
||||
|
||||
assert_stdsv_equal(
|
||||
"00"sv, (std::string_view{std::ranges::begin(buf),
|
||||
util::format_hex(static_cast<uint8_t>(0U),
|
||||
std::ranges::begin(buf))}));
|
||||
assert_stdsv_equal(
|
||||
"ec"sv, (std::string_view{std::ranges::begin(buf),
|
||||
util::format_hex(static_cast<uint8_t>(0xECU),
|
||||
std::ranges::begin(buf))}));
|
||||
assert_stdsv_equal(
|
||||
"00000000"sv,
|
||||
(std::string_view{std::ranges::begin(buf),
|
||||
util::format_hex(0U, std::ranges::begin(buf))}));
|
||||
assert_stdsv_equal(
|
||||
"0000ab01"sv,
|
||||
(std::string_view{std::ranges::begin(buf),
|
||||
util::format_hex(0xAB01U, std::ranges::begin(buf))}));
|
||||
assert_stdsv_equal(
|
||||
"deadbeefbaadf00d"sv,
|
||||
(std::string_view{
|
||||
std::ranges::begin(buf),
|
||||
util::format_hex(0xDEADBEEFBAADF00DU, std::ranges::begin(buf))}));
|
||||
assert_stdsv_equal(
|
||||
"ffffffffffffffff"sv,
|
||||
(std::string_view{std::ranges::begin(buf),
|
||||
util::format_hex(std::numeric_limits<uint64_t>::max(),
|
||||
std::ranges::begin(buf))}));
|
||||
assert_eq("00",
|
||||
std::string_view(b, util::format_hex(static_cast<uint8_t>(0U), b)));
|
||||
assert_eq("ec", std::string_view(
|
||||
b, util::format_hex(static_cast<uint8_t>(0xECU), b)));
|
||||
assert_eq("00000000", std::string_view(b, util::format_hex(0U, b)));
|
||||
assert_eq("0000ab01", std::string_view(b, util::format_hex(0xAB01U, b)));
|
||||
assert_eq("deadbeefbaadf00d",
|
||||
std::string_view(b, util::format_hex(0xDEADBEEFBAADF00DU, b)));
|
||||
assert_eq("ffffffffffffffff",
|
||||
std::string_view(
|
||||
b, util::format_hex(std::numeric_limits<uint64_t>::max(), b)));
|
||||
|
||||
std::vector<char> char_vec;
|
||||
util::format_hex(a, std::back_inserter(char_vec));
|
||||
|
||||
assert_stdsv_equal("deadbeef"sv,
|
||||
(std::string_view{std::ranges::begin(char_vec),
|
||||
std::ranges::end(char_vec)}));
|
||||
assert_eq("deadbeef", as_string_view(char_vec));
|
||||
|
||||
std::vector<uint8_t> uint8_vec;
|
||||
util::format_hex(a, std::back_inserter(uint8_vec));
|
||||
|
||||
assert_stdsv_equal(
|
||||
"deadbeef"sv,
|
||||
(std::string_view{reinterpret_cast<const char *>(uint8_vec.data()),
|
||||
uint8_vec.size()}));
|
||||
assert_eq("deadbeef", as_string_view(uint8_vec));
|
||||
}
|
||||
|
||||
void test_util_decode_hex() {
|
||||
assert_stdstring_equal("\xDE\xAD\xBE\xEF"s, util::decode_hex("deadbeef"sv));
|
||||
assert_stdstring_equal(""s, util::decode_hex(""sv));
|
||||
assert_eq("\xDE\xAD\xBE\xEF", util::decode_hex("deadbeef"sv));
|
||||
assert_eq("", util::decode_hex(""sv));
|
||||
}
|
||||
|
||||
void test_util_is_hex_string() {
|
||||
@@ -607,25 +376,41 @@ void test_util_is_hex_string() {
|
||||
}
|
||||
|
||||
void test_util_split_str() {
|
||||
assert_true((std::vector{"alpha"sv, "bravo"sv, "charlie"sv} ==
|
||||
(util::split_str("alpha,bravo,charlie"sv) |
|
||||
std::ranges::to<std::vector>())));
|
||||
assert_true((std::vector{"alpha"sv, "bravo"sv, "charlie"sv} ==
|
||||
(util::split_str("alpha bravo charlie"sv, ' ') |
|
||||
std::ranges::to<std::vector>())));
|
||||
assert_true((std::vector<std::string_view>{} ==
|
||||
(util::split_str(""sv, ' ') | std::ranges::to<std::vector>())));
|
||||
assert_true((std::vector{""sv, ""sv} ==
|
||||
(util::split_str(","sv) | std::ranges::to<std::vector>())));
|
||||
assert_true(
|
||||
(std::vector{""sv, "alpha"sv, ""sv, ""sv, "bravo"sv, "charlie"sv, ""sv,
|
||||
""sv} == (util::split_str(" alpha bravo charlie "sv, ' ') |
|
||||
std::ranges::to<std::vector>())));
|
||||
assert_eq((std::vector{
|
||||
"alpha"sv,
|
||||
"bravo"sv,
|
||||
"charlie"sv,
|
||||
}),
|
||||
util::split_str("alpha,bravo,charlie"sv) |
|
||||
std::ranges::to<std::vector>());
|
||||
assert_eq((std::vector{
|
||||
"alpha"sv,
|
||||
"bravo"sv,
|
||||
"charlie"sv,
|
||||
}),
|
||||
util::split_str("alpha bravo charlie"sv, ' ') |
|
||||
std::ranges::to<std::vector>());
|
||||
assert_eq((std::vector<std::string_view>{}),
|
||||
util::split_str(""sv, ' ') | std::ranges::to<std::vector>());
|
||||
assert_eq((std::vector{""sv, ""sv}),
|
||||
util::split_str(","sv) | std::ranges::to<std::vector>());
|
||||
assert_eq((std::vector{
|
||||
""sv,
|
||||
"alpha"sv,
|
||||
""sv,
|
||||
""sv,
|
||||
"bravo"sv,
|
||||
"charlie"sv,
|
||||
""sv,
|
||||
""sv,
|
||||
}),
|
||||
util::split_str(" alpha bravo charlie "sv, ' ') |
|
||||
std::ranges::to<std::vector>());
|
||||
}
|
||||
|
||||
void test_util_format_app_error_code() {
|
||||
assert_stdstring_equal("(no error)", util::format_app_error_code({}));
|
||||
assert_stdstring_equal("0xfe01", util::format_app_error_code(0xfe01));
|
||||
assert_eq("(no error)", util::format_app_error_code({}));
|
||||
assert_eq("0xfe01", util::format_app_error_code(0xfe01));
|
||||
}
|
||||
|
||||
} // namespace ngtcp2
|
||||
+106
-17
@@ -1861,7 +1861,8 @@ typedef enum ngtcp2_token_type {
|
||||
#define NGTCP2_SETTINGS_V2 2
|
||||
#define NGTCP2_SETTINGS_V3 3
|
||||
#define NGTCP2_SETTINGS_V4 4
|
||||
#define NGTCP2_SETTINGS_VERSION NGTCP2_SETTINGS_V4
|
||||
#define NGTCP2_SETTINGS_V5 5
|
||||
#define NGTCP2_SETTINGS_VERSION NGTCP2_SETTINGS_V5
|
||||
|
||||
/**
|
||||
* @struct
|
||||
@@ -1913,7 +1914,7 @@ typedef struct ngtcp2_settings {
|
||||
* :member:`token_type` field.
|
||||
*
|
||||
* Client sets this field if it intends to send token in its Initial
|
||||
* packet.
|
||||
* packet. A token longer than 512 bytes is ignored.
|
||||
*
|
||||
* `ngtcp2_conn_server_new` and `ngtcp2_conn_client_new` make a copy
|
||||
* of token.
|
||||
@@ -2087,11 +2088,12 @@ typedef struct ngtcp2_settings {
|
||||
/* The following fields have been added since NGTCP2_SETTINGS_V3. */
|
||||
/**
|
||||
* :member:`glitch_ratelim_burst` is the maximum number of tokens
|
||||
* available to "glitch" rate limiter. "glitch" is a suspicious
|
||||
* activity from a remote endpoint. If detected, certain amount of
|
||||
* tokens are consumed. If no tokens are available to consume, the
|
||||
* connection is closed. The rate of token generation is specified
|
||||
* by :member:`glitch_ratelim_rate`.
|
||||
* available to "glitch" rate limiter. It is clamped to UINT64_MAX
|
||||
* / NGTCP2_SECONDS. "glitch" is a suspicious activity from a
|
||||
* remote endpoint. If detected, certain amount of tokens are
|
||||
* consumed. If no tokens are available to consume, the connection
|
||||
* is closed. The rate of token generation is specified by
|
||||
* :member:`glitch_ratelim_rate`.
|
||||
*
|
||||
* .. version-added:: 1.15.0
|
||||
*/
|
||||
@@ -2116,6 +2118,29 @@ typedef struct ngtcp2_settings {
|
||||
* .. version-added:: 1.23.0
|
||||
*/
|
||||
ngtcp2_log_write log_write;
|
||||
/* The following fields have been added since NGTCP2_SETTINGS_V5. */
|
||||
/**
|
||||
* :member:`write_stream_data_thresh` is the threshold for the
|
||||
* length of STREAM frame payload that the local endpoint sends. If
|
||||
* there is data more than this value to send, and the flow control
|
||||
* does not allow sending more than this length, the data is not
|
||||
* sent, waiting for the window update from the remote endpoint.
|
||||
* This effectively means that flow control credit less than or
|
||||
* equal to :member:`write_stream_data_thresh` is considered 0. It
|
||||
* implies that the connection to the remote endpoint that only
|
||||
* grants less than or equal to :member:`write_stream_data_thresh`
|
||||
* stalls. But normally the endpoint offers far more flow control
|
||||
* credits. Those that only gives small credit are most likely
|
||||
* badly configured or manipulated by an attacker, and no need to be
|
||||
* supported. If nonzero value is set to this field, the
|
||||
* application should use
|
||||
* `ngtcp2_conn_get_max_data_left_write_thresh` instead of
|
||||
* `ngtcp2_conn_get_max_data_left`, so that the streams are not
|
||||
* blocked by the connection-level flow control.
|
||||
*
|
||||
* .. version-added:: 1.26.0
|
||||
*/
|
||||
size_t write_stream_data_thresh;
|
||||
} ngtcp2_settings;
|
||||
|
||||
/**
|
||||
@@ -3324,6 +3349,10 @@ typedef enum ngtcp2_connection_id_status_type {
|
||||
* :type:`ngtcp2_connection_id_status` is a callback function which is
|
||||
* called when the status of Destination Connection ID changes.
|
||||
*
|
||||
* This callback function is not called before handshake completes.
|
||||
* When handshake completes, it is called for Destination Connection
|
||||
* ID in use at that time.
|
||||
*
|
||||
* |token| is the associated stateless reset token, and it is ``NULL``
|
||||
* if no token is present.
|
||||
*
|
||||
@@ -3500,6 +3529,8 @@ typedef int (*ngtcp2_stream_stop_sending)(ngtcp2_conn *conn, int64_t stream_id,
|
||||
* The callback function must return 0 if it succeeds. Returning
|
||||
* :macro:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return
|
||||
* immediately.
|
||||
*
|
||||
* .. version-added:: 1.24.0
|
||||
*/
|
||||
typedef int (*ngtcp2_recv_stop_sending)(ngtcp2_conn *conn, int64_t stream_id,
|
||||
uint64_t app_error_code,
|
||||
@@ -3596,6 +3627,10 @@ typedef int (*ngtcp2_get_new_connection_id2)(
|
||||
* :type:`ngtcp2_connection_id_status2` is a callback function which
|
||||
* is called when the status of Destination Connection ID changes.
|
||||
*
|
||||
* This callback function is not called before handshake completes.
|
||||
* When handshake completes, it is called for Destination Connection
|
||||
* ID in use at that time.
|
||||
*
|
||||
* |token| is the associated stateless reset token, and it is ``NULL``
|
||||
* if no token is present.
|
||||
*
|
||||
@@ -3719,12 +3754,29 @@ typedef int (*ngtcp2_stream_close2)(ngtcp2_conn *conn, uint32_t flags,
|
||||
uint64_t tx_app_error_code, void *user_data,
|
||||
void *stream_user_data);
|
||||
|
||||
/**
|
||||
* @functypedef
|
||||
*
|
||||
* :type:`ngtcp2_extend_max_data` is a callback function which is
|
||||
* invoked when max session data is extended. |max_data| is a
|
||||
* cumulative number of bytes an endpoint can send on this session.
|
||||
*
|
||||
* The callback function must return 0 if it succeeds. Returning
|
||||
* :macro:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return
|
||||
* immediately.
|
||||
*
|
||||
* .. version-added:: 1.26.0
|
||||
*/
|
||||
typedef int (*ngtcp2_extend_max_data)(ngtcp2_conn *conn, uint64_t max_data,
|
||||
void *user_data);
|
||||
|
||||
#define NGTCP2_CALLBACKS_V1 1
|
||||
#define NGTCP2_CALLBACKS_V2 2
|
||||
#define NGTCP2_CALLBACKS_V3 3
|
||||
#define NGTCP2_CALLBACKS_V4 4
|
||||
#define NGTCP2_CALLBACKS_V5 5
|
||||
#define NGTCP2_CALLBACKS_VERSION NGTCP2_CALLBACKS_V5
|
||||
#define NGTCP2_CALLBACKS_V6 6
|
||||
#define NGTCP2_CALLBACKS_VERSION NGTCP2_CALLBACKS_V6
|
||||
|
||||
/**
|
||||
* @struct
|
||||
@@ -4086,6 +4138,16 @@ typedef struct ngtcp2_callbacks {
|
||||
* .. version-added:: 1.25.0
|
||||
*/
|
||||
ngtcp2_stream_close2 stream_close2;
|
||||
/* The following fields have been added since
|
||||
NGTCP2_CALLBACKS_V6. */
|
||||
/**
|
||||
* :member:`extend_max_data` is callback function which is invoked
|
||||
* when the maximum offset of session data that a local endpoint can
|
||||
* send is increased. This callback function is optional.
|
||||
*
|
||||
* .. version-added:: 1.26.0
|
||||
*/
|
||||
ngtcp2_extend_max_data extend_max_data;
|
||||
} ngtcp2_callbacks;
|
||||
|
||||
/**
|
||||
@@ -4532,6 +4594,8 @@ NGTCP2_EXTERN int ngtcp2_conn_install_0rtt_key(
|
||||
*
|
||||
* :macro:`NGTCP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
* :macro:`NGTCP2_ERR_INVALID_STATE`
|
||||
* `ngtcp2_conn_install_rx_key` has already been called.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_conn_install_rx_key(
|
||||
ngtcp2_conn *conn, const uint8_t *secret, size_t secretlen,
|
||||
@@ -4563,6 +4627,8 @@ NGTCP2_EXTERN int ngtcp2_conn_install_rx_key(
|
||||
*
|
||||
* :macro:`NGTCP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
* :macro:`NGTCP2_ERR_INVALID_STATE`
|
||||
* `ngtcp2_conn_install_tx_key` has already been called.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_conn_install_tx_key(
|
||||
ngtcp2_conn *conn, const uint8_t *secret, size_t secretlen,
|
||||
@@ -4578,8 +4644,12 @@ NGTCP2_EXTERN int ngtcp2_conn_install_tx_key(
|
||||
* negative error codes:
|
||||
*
|
||||
* :macro:`NGTCP2_ERR_INVALID_STATE`
|
||||
* The previous key update has not been confirmed yet; or key
|
||||
* update is too frequent; or new keys are not available yet.
|
||||
* The handshake has not been confirmed yet; or the connection is
|
||||
* in the closing or draining period; or the previous key update
|
||||
* has not been confirmed yet; or key update is too frequent; or
|
||||
* new keys are not available yet; or no packet encrypted with the
|
||||
* current key has been acknowledged since the previous key
|
||||
* update.
|
||||
*/
|
||||
NGTCP2_EXTERN int ngtcp2_conn_initiate_key_update(ngtcp2_conn *conn,
|
||||
ngtcp2_tstamp ts);
|
||||
@@ -5894,8 +5964,8 @@ ngtcp2_conn_get_negotiated_version2(const ngtcp2_conn *conn);
|
||||
*
|
||||
* `ngtcp2_conn_tls_early_data_rejected` tells |conn| that early data
|
||||
* was rejected by a server during TLS handshake, or client decided
|
||||
* not to attempt early data for some reason. |conn| discards the
|
||||
* following connection states:
|
||||
* not to attempt early data for some reason. Only client can call
|
||||
* this function. |conn| discards the following connection states:
|
||||
*
|
||||
* - Any opened streams.
|
||||
* - Stream identifier allocations.
|
||||
@@ -6175,9 +6245,27 @@ NGTCP2_EXTERN uint64_t ngtcp2_conn_get_max_data_left(ngtcp2_conn *conn);
|
||||
* connection-level flow control.
|
||||
*
|
||||
* .. version-added:: 1.23.0
|
||||
*
|
||||
* .. seealso::
|
||||
* `ngtcp2_conn_get_max_data_left_write_thresh`
|
||||
*/
|
||||
NGTCP2_EXTERN uint64_t ngtcp2_conn_get_max_data_left2(const ngtcp2_conn *conn);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_conn_get_max_data_left_write_thresh` returns the number of
|
||||
* bytes that this local endpoint can send in this connection without
|
||||
* violating connection-level flow control. If the remaining credit
|
||||
* is less than or equal to
|
||||
* :member:`ngtcp2_settings.write_stream_data_thresh`, this function
|
||||
* returns 0.
|
||||
*
|
||||
* .. version-added:: 1.26.0
|
||||
*/
|
||||
NGTCP2_EXTERN uint64_t
|
||||
ngtcp2_conn_get_max_data_left_write_thresh(const ngtcp2_conn *conn);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
@@ -6879,7 +6967,8 @@ NGTCP2_EXTERN size_t ngtcp2_conn_get_send_quantum(ngtcp2_conn *conn);
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_conn_get_send_quantum2` returns the maximum number of bytes
|
||||
* that can be sent in one go without packet spacing.
|
||||
* that can be sent in one go without packet spacing. It is at least
|
||||
* `ngtcp2_conn_get_path_max_tx_udp_payload_size2` bytes.
|
||||
*
|
||||
* .. version-added:: 1.23.0
|
||||
*/
|
||||
@@ -7109,8 +7198,8 @@ NGTCP2_EXTERN void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps);
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_settings_default` initializes |settings| with the default
|
||||
* values. First this function fills |settings| with 0, and set the
|
||||
* default value to the following fields:
|
||||
* values. First this function fills |settings| with 0, and sets the
|
||||
* default values to the following fields:
|
||||
*
|
||||
* * :member:`cc_algo <ngtcp2_settings.cc_algo>` =
|
||||
* :enum:`ngtcp2_cc_algo.NGTCP2_CC_ALGO_CUBIC`
|
||||
@@ -7133,8 +7222,8 @@ NGTCP2_EXTERN void ngtcp2_settings_default_versioned(int settings_version,
|
||||
* @function
|
||||
*
|
||||
* `ngtcp2_transport_params_default` initializes |params| with the
|
||||
* default values. First this function fills |params| with 0, and set
|
||||
* the default value to the following fields:
|
||||
* default values. First this function fills |params| with 0, and
|
||||
* sets the default values to the following fields:
|
||||
*
|
||||
* * :member:`max_udp_payload_size
|
||||
* <ngtcp2_transport_params.max_udp_payload_size>` =
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@
|
||||
*
|
||||
* Version number of the ngtcp2 library release.
|
||||
*/
|
||||
#define NGTCP2_VERSION "1.25.0"
|
||||
#define NGTCP2_VERSION "1.26.0"
|
||||
|
||||
/**
|
||||
* @macro
|
||||
@@ -46,6 +46,6 @@
|
||||
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
|
||||
* becomes 0x010203.
|
||||
*/
|
||||
#define NGTCP2_VERSION_NUM 0x011900
|
||||
#define NGTCP2_VERSION_NUM 0x011a00
|
||||
|
||||
#endif /* !defined(NGTCP2_VERSION_H) */
|
||||
+3
-1
@@ -65,8 +65,10 @@ int ngtcp2_balloc_get(ngtcp2_balloc *balloc, void **pbuf, size_t n) {
|
||||
assert(n <= balloc->blklen);
|
||||
|
||||
if (ngtcp2_buf_left(&balloc->buf) < n) {
|
||||
// 0xF: the 16-byte alignment below needs up to 15 bytes when malloc
|
||||
// returns only 4-byte aligned memory (for example on ESP-IDF heap)!
|
||||
p = ngtcp2_mem_malloc(balloc->mem,
|
||||
sizeof(ngtcp2_memblock_hd) + 0x8U + balloc->blklen);
|
||||
sizeof(ngtcp2_memblock_hd) + 0xFU + balloc->blklen);
|
||||
if (p == NULL) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
+3
@@ -63,6 +63,9 @@ size_t ngtcp2_callbackslen_version(int callbacks_version) {
|
||||
switch (callbacks_version) {
|
||||
case NGTCP2_CALLBACKS_VERSION:
|
||||
return sizeof(callbacks);
|
||||
case NGTCP2_CALLBACKS_V5:
|
||||
return offsetof(ngtcp2_callbacks, stream_close2) +
|
||||
sizeof(callbacks.stream_close2);
|
||||
case NGTCP2_CALLBACKS_V4:
|
||||
return offsetof(ngtcp2_callbacks, recv_stop_sending) +
|
||||
sizeof(callbacks.recv_stop_sending);
|
||||
|
||||
Vendored
+34
-5
@@ -40,6 +40,9 @@ uint64_t ngtcp2_cc_compute_initcwnd(size_t max_udp_payload_size) {
|
||||
return ngtcp2_min(10 * max_udp_payload_size, n);
|
||||
}
|
||||
|
||||
/* NGTCP2_CC_SLOW_START_PACING_GAIN_H is the pacing rate for slow
|
||||
start phase. */
|
||||
#define NGTCP2_CC_SLOW_START_PACING_GAIN_H 200
|
||||
/* 1.25 is the under-utilization avoidance factor described in
|
||||
https://datatracker.ietf.org/doc/html/rfc9002#section-7.7 */
|
||||
#define NGTCP2_CC_PACING_GAIN_H 125
|
||||
@@ -47,22 +50,30 @@ uint64_t ngtcp2_cc_compute_initcwnd(size_t max_udp_payload_size) {
|
||||
static void init_pacing_rate(ngtcp2_conn_stat *cstat) {
|
||||
assert(cstat->cwnd);
|
||||
|
||||
cstat->pacing_interval_m = ngtcp2_max((NGTCP2_MILLISECONDS << 10) * 100 /
|
||||
NGTCP2_CC_PACING_GAIN_H / cstat->cwnd,
|
||||
1);
|
||||
cstat->pacing_interval_m =
|
||||
ngtcp2_max((NGTCP2_MILLISECONDS << 10) * 100 /
|
||||
NGTCP2_CC_SLOW_START_PACING_GAIN_H / cstat->cwnd,
|
||||
1);
|
||||
cstat->send_quantum = 10 * cstat->max_tx_udp_payload_size;
|
||||
}
|
||||
|
||||
static void set_pacing_rate(ngtcp2_conn_stat *cstat) {
|
||||
size_t send_quantum = 64 * 1024;
|
||||
uint64_t pacing_gain_h;
|
||||
|
||||
assert(cstat->cwnd);
|
||||
|
||||
if (cstat->cwnd < cstat->ssthresh) {
|
||||
pacing_gain_h = NGTCP2_CC_SLOW_START_PACING_GAIN_H;
|
||||
} else {
|
||||
pacing_gain_h = NGTCP2_CC_PACING_GAIN_H;
|
||||
}
|
||||
|
||||
cstat->pacing_interval_m =
|
||||
((cstat->first_rtt_sample_ts == UINT64_MAX ? NGTCP2_MILLISECONDS
|
||||
: cstat->smoothed_rtt)
|
||||
<< 10) *
|
||||
100 / NGTCP2_CC_PACING_GAIN_H / cstat->cwnd;
|
||||
100 / pacing_gain_h / cstat->cwnd;
|
||||
|
||||
cstat->pacing_interval_m = ngtcp2_max(cstat->pacing_interval_m, 1);
|
||||
|
||||
@@ -232,6 +243,7 @@ void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cubic, ngtcp2_log *log,
|
||||
.congestion_event = ngtcp2_cc_cubic_cc_congestion_event,
|
||||
.on_spurious_congestion = ngtcp2_cc_cubic_cc_on_spurious_congestion,
|
||||
.on_persistent_congestion = ngtcp2_cc_cubic_cc_on_persistent_congestion,
|
||||
.on_pkt_lost_confirmed = ngtcp2_cc_cubic_cc_on_pkt_lost_confirmed,
|
||||
.reset = ngtcp2_cc_cubic_cc_reset,
|
||||
},
|
||||
.rst = rst,
|
||||
@@ -375,6 +387,8 @@ void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
cstat->ssthresh = cstat->cwnd;
|
||||
cubic->current.cwnd_prior = cstat->cwnd;
|
||||
cubic->current.w_est = cstat->cwnd;
|
||||
|
||||
set_pacing_rate(cstat);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -444,7 +458,7 @@ void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
if (cubic->current.w_est > w_cubic) {
|
||||
cstat->cwnd = cubic->current.w_est;
|
||||
} else {
|
||||
bytes_acked = (target - cstat->cwnd) * cstat->max_tx_udp_payload_size;
|
||||
bytes_acked = (target - cstat->cwnd) * ack->bytes_delivered;
|
||||
m = (bytes_acked + cubic->current.pending_bytes_acked) / cstat->cwnd;
|
||||
|
||||
cubic->current.pending_bytes_acked += bytes_acked;
|
||||
@@ -567,6 +581,21 @@ void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *cc,
|
||||
set_pacing_rate(cstat);
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_lost_confirmed(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
(void)cstat;
|
||||
(void)ts;
|
||||
|
||||
/* The loss is real. Discard the snapshot so that a spurious
|
||||
congestion detected later does not restore the state from before
|
||||
this loss. */
|
||||
cubic_vars_reset(&cubic->undo.v);
|
||||
cubic->undo.cwnd = 0;
|
||||
cubic->undo.ssthresh = 0;
|
||||
}
|
||||
|
||||
void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
|
||||
|
||||
Vendored
+23
@@ -170,6 +170,19 @@ typedef void (*ngtcp2_cc_on_persistent_congestion)(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
/**
|
||||
* @functypedef
|
||||
*
|
||||
* :type:`ngtcp2_cc_on_pkt_lost_confirmed` is a callback function
|
||||
* which is called when a packet which was declared lost is removed
|
||||
* from the retransmission buffer without being acknowledged. The
|
||||
* congestion event that the packet belongs to is no longer considered
|
||||
* to be spurious.
|
||||
*/
|
||||
typedef void (*ngtcp2_cc_on_pkt_lost_confirmed)(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
/**
|
||||
* @functypedef
|
||||
*
|
||||
@@ -235,6 +248,12 @@ typedef struct ngtcp2_cc {
|
||||
* is called when persistent congestion is established.
|
||||
*/
|
||||
ngtcp2_cc_on_persistent_congestion on_persistent_congestion;
|
||||
/**
|
||||
* :member:`on_pkt_lost_confirmed` is a callback function which is
|
||||
* called when a lost packet is removed from the retransmission
|
||||
* buffer without being acknowledged.
|
||||
*/
|
||||
ngtcp2_cc_on_pkt_lost_confirmed on_pkt_lost_confirmed;
|
||||
/**
|
||||
* :member:`on_ack_recv` is a callback function which is called when
|
||||
* an acknowledgement is received.
|
||||
@@ -349,6 +368,10 @@ void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_cubic_cc_on_pkt_lost_confirmed(ngtcp2_cc *cc,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
|
||||
Vendored
+2
-14
@@ -92,6 +92,7 @@ void ngtcp2_dcid_init(ngtcp2_dcid *dcid, uint64_t seq, const ngtcp2_cid *cid,
|
||||
dcid->bytes_sent = 0;
|
||||
dcid->bytes_recv = 0;
|
||||
dcid->max_udp_payload_size = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
|
||||
dcid->scid_seq = 0;
|
||||
}
|
||||
|
||||
void ngtcp2_dcid_set_token(ngtcp2_dcid *dcid,
|
||||
@@ -117,6 +118,7 @@ void ngtcp2_dcid_copy(ngtcp2_dcid *dest, const ngtcp2_dcid *src) {
|
||||
dest->bytes_sent = src->bytes_sent;
|
||||
dest->bytes_recv = src->bytes_recv;
|
||||
dest->max_udp_payload_size = src->max_udp_payload_size;
|
||||
dest->scid_seq = src->scid_seq;
|
||||
}
|
||||
|
||||
void ngtcp2_dcid_copy_cid_token(ngtcp2_dcid *dest, const ngtcp2_dcid *src) {
|
||||
@@ -131,20 +133,6 @@ void ngtcp2_dcid_copy_cid_token(ngtcp2_dcid *dest, const ngtcp2_dcid *src) {
|
||||
}
|
||||
}
|
||||
|
||||
int ngtcp2_dcid_verify_uniqueness(const ngtcp2_dcid *dcid, uint64_t seq,
|
||||
const ngtcp2_cid *cid,
|
||||
const ngtcp2_stateless_reset_token *token) {
|
||||
if (dcid->seq == seq) {
|
||||
return ngtcp2_cid_eq(&dcid->cid, cid) &&
|
||||
(dcid->flags & NGTCP2_DCID_FLAG_TOKEN_PRESENT) &&
|
||||
ngtcp2_stateless_reset_token_eq(&dcid->token, token)
|
||||
? 0
|
||||
: NGTCP2_ERR_PROTO;
|
||||
}
|
||||
|
||||
return !ngtcp2_cid_eq(&dcid->cid, cid) ? 0 : NGTCP2_ERR_PROTO;
|
||||
}
|
||||
|
||||
int ngtcp2_dcid_verify_stateless_reset_token(
|
||||
const ngtcp2_dcid *dcid, const ngtcp2_path *path,
|
||||
const ngtcp2_stateless_reset_token *token) {
|
||||
|
||||
Vendored
+4
-8
@@ -88,6 +88,10 @@ typedef struct ngtcp2_dcid {
|
||||
/* max_udp_payload_size is the maximum size of UDP datagram payload
|
||||
that is allowed to be sent to this path. */
|
||||
size_t max_udp_payload_size;
|
||||
/* scid_seq is the sequence number of the Source Connection ID that
|
||||
a remote endpoint put in the Destination Connection ID field of
|
||||
the latest packet received on an associated path. */
|
||||
uint64_t scid_seq;
|
||||
/* flags is bitwise OR of zero or more of NGTCP2_DCID_FLAG_*. */
|
||||
uint8_t flags;
|
||||
/* token is a stateless reset token received along with this
|
||||
@@ -156,14 +160,6 @@ void ngtcp2_dcid_copy(ngtcp2_dcid *dest, const ngtcp2_dcid *src);
|
||||
*/
|
||||
void ngtcp2_dcid_copy_cid_token(ngtcp2_dcid *dest, const ngtcp2_dcid *src);
|
||||
|
||||
/*
|
||||
* ngtcp2_dcid_verify_uniqueness verifies uniqueness of (|seq|, |cid|,
|
||||
* |token|) tuple against |dcid|.
|
||||
*/
|
||||
int ngtcp2_dcid_verify_uniqueness(const ngtcp2_dcid *dcid, uint64_t seq,
|
||||
const ngtcp2_cid *cid,
|
||||
const ngtcp2_stateless_reset_token *token);
|
||||
|
||||
/*
|
||||
* ngtcp2_dcid_verify_stateless_reset_token verifies stateless reset
|
||||
* token |token| received on |path| against the one included in
|
||||
|
||||
Vendored
+880
-557
File diff suppressed because it is too large.
Load diff
Vendored
+76
-52
@@ -93,6 +93,10 @@ typedef enum {
|
||||
value, it is truncated. */
|
||||
#define NGTCP2_CCERR_MAX_REASONLEN 1024
|
||||
|
||||
/* NGTCP2_MAX_TOKENLEN is the maximum length of token given in
|
||||
ngtcp2_settings.token that client sends in its Initial packet. */
|
||||
#define NGTCP2_MAX_TOKENLEN 512
|
||||
|
||||
/* NGTCP2_WRITE_PKT_FLAG_NONE indicates that no flag is set. */
|
||||
#define NGTCP2_WRITE_PKT_FLAG_NONE 0x00U
|
||||
/* NGTCP2_WRITE_PKT_FLAG_REQUIRE_PADDING indicates that packet other
|
||||
@@ -164,9 +168,9 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
|
||||
supports Greasing QUIC Bit extension. */
|
||||
#define NGTCP2_CONN_FLAG_CLEAR_FIXED_BIT 0x0400U
|
||||
/* NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED is set when key update is
|
||||
not confirmed by the local endpoint. That is, it has not received
|
||||
ACK frame which acknowledges packet which is encrypted with new
|
||||
key. */
|
||||
not confirmed by the local endpoint. That is, it has received
|
||||
neither ACK frame which acknowledges packet which is encrypted with
|
||||
new key, nor packet which is encrypted with new key. */
|
||||
#define NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED 0x0800U
|
||||
/* NGTCP2_CONN_FLAG_PPE_PENDING is set when
|
||||
NGTCP2_WRITE_STREAM_FLAG_MORE is used and the intermediate state of
|
||||
@@ -193,6 +197,9 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
|
||||
Initial CRYPTO frame into pieces as a countermeasure against Deep
|
||||
Packet Inspection. */
|
||||
#define NGTCP2_CONN_FLAG_CRUMBLE_INITIAL_CRYPTO 0x40000U
|
||||
/* NGTCP2_CONN_FLAG_CLIENT_INITIAL_CALLED is set when
|
||||
ngtcp2_callbacks.client_initial has been called successfully. */
|
||||
#define NGTCP2_CONN_FLAG_CLIENT_INITIAL_CALLED 0x80000U
|
||||
|
||||
typedef struct ngtcp2_pktns {
|
||||
struct {
|
||||
@@ -391,6 +398,24 @@ struct ngtcp2_conn {
|
||||
sent. */
|
||||
ngtcp2_tstamp last_max_data_ts;
|
||||
|
||||
struct {
|
||||
/* max_streams is the maximum number of bidirectional streams which
|
||||
the local endpoint can open. */
|
||||
uint64_t max_streams;
|
||||
/* next_stream_id is the bidirectional stream ID which the local
|
||||
endpoint opens next. */
|
||||
int64_t next_stream_id;
|
||||
} bidi;
|
||||
|
||||
struct {
|
||||
/* max_streams is the maximum number of unidirectional streams
|
||||
which the local endpoint can open. */
|
||||
uint64_t max_streams;
|
||||
/* next_stream_id is the unidirectional stream ID which the
|
||||
local endpoint opens next. */
|
||||
int64_t next_stream_id;
|
||||
} uni;
|
||||
|
||||
struct {
|
||||
/* validation_start_ts is the timestamp when ECN validation is
|
||||
started. It is UINT64_MAX if it has not started yet. */
|
||||
@@ -441,10 +466,28 @@ struct ngtcp2_conn {
|
||||
ngtcp2_ccerr ccerr;
|
||||
|
||||
struct {
|
||||
/* pkt_num is the lowest incoming packet number of the packet
|
||||
that server verified preferred address usage of client. */
|
||||
int64_t pkt_num;
|
||||
} preferred_addr;
|
||||
/* unsent_max_streams is the maximum number of streams of peer
|
||||
initiated bidirectional stream which the local endpoint can
|
||||
accept. This limit is not yet notified to the remote
|
||||
endpoint. */
|
||||
uint64_t unsent_max_streams;
|
||||
/* max_streams is the maximum number of streams of peer
|
||||
initiated bidirectional stream which the local endpoint can
|
||||
accept. */
|
||||
uint64_t max_streams;
|
||||
} bidi;
|
||||
|
||||
struct {
|
||||
/* unsent_max_streams is the maximum number of streams of peer
|
||||
initiated unidirectional stream which the local endpoint can
|
||||
accept. This limit is not yet notified to the remote
|
||||
endpoint. */
|
||||
uint64_t unsent_max_streams;
|
||||
/* max_streams is the maximum number of streams of peer
|
||||
initiated unidirectional stream which the local endpoint can
|
||||
accept. */
|
||||
uint64_t max_streams;
|
||||
} uni;
|
||||
} rx;
|
||||
|
||||
struct {
|
||||
@@ -467,23 +510,6 @@ struct ngtcp2_conn {
|
||||
/* transport_params is the local transport parameters. It is used
|
||||
for Short packet only. */
|
||||
ngtcp2_transport_params transport_params;
|
||||
struct {
|
||||
/* max_streams is the maximum number of bidirectional streams which
|
||||
the local endpoint can open. */
|
||||
uint64_t max_streams;
|
||||
/* next_stream_id is the bidirectional stream ID which the local
|
||||
endpoint opens next. */
|
||||
int64_t next_stream_id;
|
||||
} bidi;
|
||||
|
||||
struct {
|
||||
/* max_streams is the maximum number of unidirectional streams
|
||||
which the local endpoint can open. */
|
||||
uint64_t max_streams;
|
||||
/* next_stream_id is the unidirectional stream ID which the
|
||||
local endpoint opens next. */
|
||||
int64_t next_stream_id;
|
||||
} uni;
|
||||
} local;
|
||||
|
||||
struct {
|
||||
@@ -494,33 +520,18 @@ struct ngtcp2_conn {
|
||||
during handshake. It is copied to transport_params when 1RTT
|
||||
key is available. */
|
||||
ngtcp2_transport_params *pending_transport_params;
|
||||
struct {
|
||||
ngtcp2_idtr idtr;
|
||||
/* unsent_max_streams is the maximum number of streams of peer
|
||||
initiated bidirectional stream which the local endpoint can
|
||||
accept. This limit is not yet notified to the remote
|
||||
endpoint. */
|
||||
uint64_t unsent_max_streams;
|
||||
/* max_streams is the maximum number of streams of peer
|
||||
initiated bidirectional stream which the local endpoint can
|
||||
accept. */
|
||||
uint64_t max_streams;
|
||||
} bidi;
|
||||
|
||||
struct {
|
||||
ngtcp2_idtr idtr;
|
||||
/* unsent_max_streams is the maximum number of streams of peer
|
||||
initiated unidirectional stream which the local endpoint can
|
||||
accept. This limit is not yet notified to the remote
|
||||
endpoint. */
|
||||
uint64_t unsent_max_streams;
|
||||
/* max_streams is the maximum number of streams of peer
|
||||
initiated unidirectional stream which the local endpoint can
|
||||
accept. */
|
||||
uint64_t max_streams;
|
||||
} uni;
|
||||
} remote;
|
||||
|
||||
struct {
|
||||
/* idtr tracks the stream ID usage. */
|
||||
ngtcp2_idtr idtr;
|
||||
} bidi;
|
||||
|
||||
struct {
|
||||
/* idtr tracks the stream ID usage. */
|
||||
ngtcp2_idtr idtr;
|
||||
} uni;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
/* new_tx_ckm is a new sender 1RTT key which has not been
|
||||
@@ -786,18 +797,19 @@ int ngtcp2_conn_detect_lost_pkt(ngtcp2_conn *conn, ngtcp2_pktns *pktns,
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_tx_strmq_top returns the ngtcp2_strm which sits on the
|
||||
* top of queue. tx_strmq must not be empty.
|
||||
* top of queue. |conn|->tx.strmq must not be empty.
|
||||
*/
|
||||
ngtcp2_strm *ngtcp2_conn_tx_strmq_top(ngtcp2_conn *conn);
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_tx_strmq_pop pops the ngtcp2_strm from the queue.
|
||||
* tx_strmq must not be empty.
|
||||
* |conn|->tx.strmq must not be empty.
|
||||
*/
|
||||
void ngtcp2_conn_tx_strmq_pop(ngtcp2_conn *conn);
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_tx_strmq_push pushes |strm| into tx_strmq.
|
||||
* ngtcp2_conn_tx_strmq_push pushes |strm| into |conn|->tx.strmq.
|
||||
* |strm|->cycle must be set before calling this function.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
@@ -807,6 +819,18 @@ void ngtcp2_conn_tx_strmq_pop(ngtcp2_conn *conn);
|
||||
*/
|
||||
int ngtcp2_conn_tx_strmq_push(ngtcp2_conn *conn, ngtcp2_strm *strm);
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_tx_strmq_push_if_not pushes |strm| into
|
||||
* |conn|->tx.strmq if |strm| is not pushed yet.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int ngtcp2_conn_tx_strmq_push_if_not(ngtcp2_conn *conn, ngtcp2_strm *strm);
|
||||
|
||||
/*
|
||||
* ngtcp2_conn_internal_expiry returns the minimum expiry time among
|
||||
* all timers in |conn|.
|
||||
|
||||
+3
-1
@@ -54,7 +54,9 @@ typedef struct ngtcp2_crypto_km {
|
||||
/* pkt_num is a packet number of a packet which uses this keying
|
||||
material. For encryption key, it is the lowest packet number of
|
||||
a packet. For decryption key, it is the lowest packet number of
|
||||
a packet which can be decrypted with this keying material. */
|
||||
a packet which can be decrypted with this keying material, or
|
||||
INT64_MAX if the local endpoint initiated key update, and no
|
||||
packet has been decrypted with this keying material yet. */
|
||||
int64_t pkt_num;
|
||||
/* use_count is the number of encryption applied with this key. */
|
||||
uint64_t use_count;
|
||||
|
||||
+7
-14
@@ -174,39 +174,32 @@ int ngtcp2_dcidtr_verify_stateless_reset(
|
||||
return NGTCP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
static int verify_token_uniqueness(const ngtcp2_ringbuf *rb, int *pfound,
|
||||
uint64_t seq, const ngtcp2_cid *cid,
|
||||
const ngtcp2_stateless_reset_token *token) {
|
||||
static int verify_cid_uniqueness(const ngtcp2_ringbuf *rb,
|
||||
const ngtcp2_cid *cid) {
|
||||
const ngtcp2_dcid *dcid;
|
||||
size_t i, len = ngtcp2_ringbuf_len(rb);
|
||||
int rv;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
dcid = ngtcp2_ringbuf_get(rb, i);
|
||||
rv = ngtcp2_dcid_verify_uniqueness(dcid, seq, cid, token);
|
||||
if (rv != 0) {
|
||||
return NGTCP2_ERR_PROTO;
|
||||
}
|
||||
|
||||
if (ngtcp2_cid_eq(&dcid->cid, cid)) {
|
||||
*pfound = 1;
|
||||
return NGTCP2_ERR_PROTO;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ngtcp2_dcidtr_verify_token_uniqueness(
|
||||
const ngtcp2_dcidtr *dtr, int *pfound, uint64_t seq, const ngtcp2_cid *cid,
|
||||
const ngtcp2_stateless_reset_token *token) {
|
||||
int ngtcp2_dcidtr_verify_cid_uniqueness(const ngtcp2_dcidtr *dtr,
|
||||
const ngtcp2_cid *cid) {
|
||||
int rv;
|
||||
|
||||
rv = verify_token_uniqueness(&dtr->bound.rb, pfound, seq, cid, token);
|
||||
rv = verify_cid_uniqueness(&dtr->bound.rb, cid);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return verify_token_uniqueness(&dtr->unused.rb, pfound, seq, cid, token);
|
||||
return verify_cid_uniqueness(&dtr->unused.rb, cid);
|
||||
}
|
||||
|
||||
static void remove_dcid_at(ngtcp2_ringbuf *rb, size_t at) {
|
||||
|
||||
+5
-18
@@ -159,30 +159,17 @@ int ngtcp2_dcidtr_verify_stateless_reset(
|
||||
const ngtcp2_stateless_reset_token *token);
|
||||
|
||||
/*
|
||||
* ngtcp2_dcidtr_verify_token_uniqueness verifies that the uniqueness
|
||||
* of the combination of |seq|, |cid|, and |token| against the exiting
|
||||
* Destination Connection IDs. That is:
|
||||
*
|
||||
* - If they do not share the same seq, then their Connection IDs must
|
||||
* be different.
|
||||
*
|
||||
* - If they share the same seq, then their Connection IDs and tokens
|
||||
* must be the same.
|
||||
*
|
||||
* If this function succeeds, and there is Destination Connection ID
|
||||
* which shares |seq|, |cid|, and |token|, |*pfound| is set to
|
||||
* nonzero.
|
||||
* ngtcp2_dcidtr_verify_cid_uniqueness verifies that |dtr| does not
|
||||
* contain |cid|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGTCP2_ERR_PROTO
|
||||
* The given combination of values does not satisfy the above
|
||||
* conditions.
|
||||
* |dtr| contains |cid|.
|
||||
*/
|
||||
int ngtcp2_dcidtr_verify_token_uniqueness(
|
||||
const ngtcp2_dcidtr *dtr, int *pfound, uint64_t seq, const ngtcp2_cid *cid,
|
||||
const ngtcp2_stateless_reset_token *token);
|
||||
int ngtcp2_dcidtr_verify_cid_uniqueness(const ngtcp2_dcidtr *dtr,
|
||||
const ngtcp2_cid *cid);
|
||||
|
||||
/*
|
||||
* ngtcp2_dcidtr_retire_inactive_dcid_prior_to retires inactive
|
||||
|
||||
Vendored
+3
-2
@@ -284,7 +284,7 @@ static void log_fr_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const char *dir) {
|
||||
ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM, NGTCP2_LOG_PKT(dir, hd),
|
||||
" DATA_BLOCKED(0x", hex(fr->type),
|
||||
") offset=", fr->offset);
|
||||
") max_data=", fr->max_data);
|
||||
}
|
||||
|
||||
static void log_fr_stream_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
@@ -292,7 +292,8 @@ static void log_fr_stream_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
const char *dir) {
|
||||
ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM, NGTCP2_LOG_PKT(dir, hd),
|
||||
" STREAM_DATA_BLOCKED(0x", hex(fr->type), ") id=0x",
|
||||
hex(fr->stream_id), " offset=", fr->offset);
|
||||
hex(fr->stream_id),
|
||||
" max_stream_data=", fr->max_stream_data);
|
||||
}
|
||||
|
||||
static void log_fr_streams_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
|
||||
|
||||
Vendored
+36
-57
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ngtcp2_conv.h"
|
||||
#include "ngtcp2_macro.h"
|
||||
|
||||
#define NGTCP2_INITIAL_HASHBITS 4
|
||||
|
||||
@@ -74,18 +75,19 @@ int ngtcp2_map_each(const ngtcp2_map *map, int (*func)(void *data, void *ptr),
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Hasher from
|
||||
https://github.com/rust-lang/rustc-hash/blob/dc5c33f1283de2da64d8d7a06401d91aded03ad4/src/lib.rs
|
||||
to maximize the output's sensitivity to all input bits. */
|
||||
#define NGTCP2_MAP_HASHER 0xF1357AEA2E62A9C5ULL
|
||||
/* 64-bit Fibonacci hashing constant, Golden Ratio constant, to get
|
||||
the high bits with the good distribution. */
|
||||
#define NGTCP2_MAP_FIBO 0x9E3779B97F4A7C15ULL
|
||||
/* 64-bit finalizer (fmix64) from MurmurHash3 to maximize the output's
|
||||
sensitivity to all input bits. */
|
||||
#define NGTCP2_MAP_HASHER1 0xFF51AFD7ED558CCDULL
|
||||
#define NGTCP2_MAP_HASHER2 0xC4CEB9FE1A85EC53ULL
|
||||
|
||||
static size_t map_index(const ngtcp2_map *map, ngtcp2_map_key_type key) {
|
||||
key += map->seed;
|
||||
key *= NGTCP2_MAP_HASHER;
|
||||
return (size_t)((key * NGTCP2_MAP_FIBO) >> (64 - map->hashbits));
|
||||
key ^= map->seed;
|
||||
key ^= key >> 33;
|
||||
key *= NGTCP2_MAP_HASHER1;
|
||||
key ^= key >> 33;
|
||||
key *= NGTCP2_MAP_HASHER2;
|
||||
key ^= key >> 33;
|
||||
return (size_t)(key >> (64 - map->hashbits));
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
@@ -107,17 +109,17 @@ void ngtcp2_map_print_distance(const ngtcp2_map *map) {
|
||||
}
|
||||
|
||||
idx = map_index(map, map->keys[i]);
|
||||
fprintf(stderr, "@%zu key=%" PRIu64 " base=%zu distance=%u\n", i,
|
||||
fprintf(stderr, "@%zu key=%" PRIu64 " base=%zu distance=%zu\n", i,
|
||||
map->keys[i], idx, map->psl[i] - 1);
|
||||
}
|
||||
}
|
||||
#endif /* !defined(WIN32) */
|
||||
|
||||
static void map_set_entry(ngtcp2_map *map, size_t idx, ngtcp2_map_key_type key,
|
||||
void *data, size_t psl) {
|
||||
size_t psl, void *data) {
|
||||
map->keys[idx] = key;
|
||||
map->psl[idx] = psl;
|
||||
map->data[idx] = data;
|
||||
map->psl[idx] = (uint8_t)psl;
|
||||
}
|
||||
|
||||
#define NGTCP2_SWAP(TYPE, A, B) \
|
||||
@@ -129,15 +131,15 @@ static void map_set_entry(ngtcp2_map *map, size_t idx, ngtcp2_map_key_type key,
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* map_insert inserts |key| and |data| to |map|, and returns the index
|
||||
* where the pair is stored if it succeeds. Otherwise, it returns one
|
||||
* of the following negative error codes:
|
||||
* map_insert inserts |key| and |data| to |map|.
|
||||
*
|
||||
* It returns 0 if it succeeds, or one of the following negative error
|
||||
* codes:
|
||||
*
|
||||
* NGTCP2_ERR_INVALID_ARGUMENT
|
||||
* The another data associated to |key| is already present.
|
||||
*/
|
||||
static ngtcp2_ssize map_insert(ngtcp2_map *map, ngtcp2_map_key_type key,
|
||||
void *data) {
|
||||
static int map_insert(ngtcp2_map *map, ngtcp2_map_key_type key, void *data) {
|
||||
size_t idx = map_index(map, key);
|
||||
size_t mask = ((size_t)1 << map->hashbits) - 1;
|
||||
size_t psl = 1;
|
||||
@@ -147,16 +149,16 @@ static ngtcp2_ssize map_insert(ngtcp2_map *map, ngtcp2_map_key_type key,
|
||||
kpsl = map->psl[idx];
|
||||
|
||||
if (kpsl == 0) {
|
||||
map_set_entry(map, idx, key, data, psl);
|
||||
map_set_entry(map, idx, key, psl, data);
|
||||
++map->size;
|
||||
|
||||
return (ngtcp2_ssize)idx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (psl > kpsl) {
|
||||
NGTCP2_SWAP(ngtcp2_map_key_type, &key, &map->keys[idx]);
|
||||
NGTCP2_SWAP(size_t, &psl, &map->psl[idx]);
|
||||
NGTCP2_SWAP(void *, &data, &map->data[idx]);
|
||||
NGTCP2_SWAP(uint8_t, &psl, &map->psl[idx]);
|
||||
} else if (map->keys[idx] == key) {
|
||||
/* This check ensures that no duplicate keys are inserted. But
|
||||
it is just a waste after first swap or if this function is
|
||||
@@ -178,14 +180,14 @@ static ngtcp2_ssize map_insert(ngtcp2_map *map, ngtcp2_map_key_type key,
|
||||
static int map_resize(ngtcp2_map *map, size_t new_hashbits) {
|
||||
size_t i;
|
||||
size_t tablelen;
|
||||
ngtcp2_ssize idx;
|
||||
ngtcp2_map new_map = {
|
||||
.mem = map->mem,
|
||||
.seed = map->seed,
|
||||
.hashbits = new_hashbits,
|
||||
};
|
||||
void *buf;
|
||||
(void)idx;
|
||||
int rv;
|
||||
(void)rv;
|
||||
|
||||
if (new_hashbits > NGTCP2_MAP_MAX_HASHBITS) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
@@ -194,16 +196,16 @@ static int map_resize(ngtcp2_map *map, size_t new_hashbits) {
|
||||
tablelen = (size_t)1 << new_hashbits;
|
||||
|
||||
buf = ngtcp2_mem_calloc(map->mem, tablelen,
|
||||
sizeof(ngtcp2_map_key_type) + sizeof(void *) +
|
||||
sizeof(uint8_t));
|
||||
if (buf == NULL) {
|
||||
sizeof(ngtcp2_map_key_type) + sizeof(size_t) +
|
||||
sizeof(void *));
|
||||
if (!buf) {
|
||||
return NGTCP2_ERR_NOMEM;
|
||||
}
|
||||
|
||||
new_map.keys = buf;
|
||||
new_map.data =
|
||||
(void *)((uint8_t *)new_map.keys + tablelen * sizeof(ngtcp2_map_key_type));
|
||||
new_map.psl = (uint8_t *)new_map.data + tablelen * sizeof(void *);
|
||||
new_map.psl = (size_t *)(void *)((uint8_t *)new_map.keys +
|
||||
tablelen * sizeof(ngtcp2_map_key_type));
|
||||
new_map.data = (void *)((uint8_t *)new_map.psl + tablelen * sizeof(size_t));
|
||||
|
||||
if (map->size) {
|
||||
tablelen = (size_t)1 << map->hashbits;
|
||||
@@ -213,31 +215,26 @@ static int map_resize(ngtcp2_map *map, size_t new_hashbits) {
|
||||
continue;
|
||||
}
|
||||
|
||||
idx = map_insert(&new_map, map->keys[i], map->data[i]);
|
||||
rv = map_insert(&new_map, map->keys[i], map->data[i]);
|
||||
|
||||
/* map_insert must not fail because all keys are unique during
|
||||
resize. */
|
||||
assert(idx >= 0);
|
||||
assert(0 == rv);
|
||||
}
|
||||
}
|
||||
|
||||
ngtcp2_mem_free(map->mem, map->keys);
|
||||
map->keys = new_map.keys;
|
||||
map->data = new_map.data;
|
||||
map->psl = new_map.psl;
|
||||
map->data = new_map.data;
|
||||
map->hashbits = new_hashbits;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* NGTCP2_MAX_PSL_RESIZE_THRESH is the maximum psl threshold. If
|
||||
reached, resize the table. */
|
||||
#define NGTCP2_MAX_PSL_RESIZE_THRESH 128
|
||||
|
||||
int ngtcp2_map_insert(ngtcp2_map *map, ngtcp2_map_key_type key, void *data) {
|
||||
int rv;
|
||||
size_t tablelen;
|
||||
ngtcp2_ssize idx;
|
||||
|
||||
assert(data);
|
||||
|
||||
@@ -254,27 +251,9 @@ int ngtcp2_map_insert(ngtcp2_map *map, ngtcp2_map_key_type key, void *data) {
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
idx = map_insert(map, key, data);
|
||||
if (idx < 0) {
|
||||
return (int)idx;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
idx = map_insert(map, key, data);
|
||||
if (idx < 0) {
|
||||
return (int)idx;
|
||||
}
|
||||
|
||||
/* Resize if psl reaches really large value which is almost
|
||||
improbable, but just in case. */
|
||||
if (map->psl[idx] - 1 < NGTCP2_MAX_PSL_RESIZE_THRESH) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return map_resize(map, map->hashbits + 1);
|
||||
return map_insert(map, key, data);
|
||||
}
|
||||
|
||||
void *ngtcp2_map_find(const ngtcp2_map *map, ngtcp2_map_key_type key) {
|
||||
@@ -332,7 +311,7 @@ int ngtcp2_map_remove(ngtcp2_map *map, ngtcp2_map_key_type key) {
|
||||
break;
|
||||
}
|
||||
|
||||
map_set_entry(map, dest, map->keys[idx], map->data[idx], kpsl - 1);
|
||||
map_set_entry(map, dest, map->keys[idx], kpsl - 1, map->data[idx]);
|
||||
|
||||
dest = idx;
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -40,11 +40,11 @@ typedef uint64_t ngtcp2_map_key_type;
|
||||
|
||||
typedef struct ngtcp2_map {
|
||||
ngtcp2_map_key_type *keys;
|
||||
void **data;
|
||||
/* psl is the Probe Sequence Length. 0 has special meaning that the
|
||||
element is not stored at i-th position if psl[i] == 0. Because
|
||||
of this, the actual psl value is psl[i] - 1 if psl[i] > 0. */
|
||||
uint8_t *psl;
|
||||
size_t *psl;
|
||||
void **data;
|
||||
const ngtcp2_mem *mem;
|
||||
uint64_t seed;
|
||||
size_t size;
|
||||
|
||||
Vendored
+11
-22
@@ -70,7 +70,9 @@ int ngtcp2_pkt_decode_version_cid(ngtcp2_version_cid *dest, const uint8_t *data,
|
||||
size_t dcidlen, scidlen;
|
||||
int supported_version;
|
||||
|
||||
assert(datalen);
|
||||
if (datalen == 0) {
|
||||
return NGTCP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (data[0] & NGTCP2_HEADER_FORM_BIT) {
|
||||
/* 1 byte (Header Form, Fixed Bit, Long Packet Type, Type-Specific bits)
|
||||
@@ -307,7 +309,7 @@ ngtcp2_ssize ngtcp2_pkt_decode_hd_long(ngtcp2_pkt_hd *dest, const uint8_t *pkt,
|
||||
|
||||
ngtcp2_get_uvarint(&vi, p);
|
||||
#if SIZE_MAX < UINT64_MAX
|
||||
if (vi > SIZE_MAX) {
|
||||
if (vi > SIZE_MAX / 2) {
|
||||
return NGTCP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
#endif /* SIZE_MAX < UINT64_MAX */
|
||||
@@ -1087,7 +1089,7 @@ ngtcp2_ssize ngtcp2_pkt_decode_data_blocked_frame(ngtcp2_data_blocked *dest,
|
||||
}
|
||||
|
||||
dest->type = NGTCP2_FRAME_DATA_BLOCKED;
|
||||
p = ngtcp2_get_uvarint(&dest->offset, p);
|
||||
p = ngtcp2_get_uvarint(&dest->max_data, p);
|
||||
|
||||
assert((size_t)(p - payload) == len);
|
||||
|
||||
@@ -1126,7 +1128,7 @@ ngtcp2_ssize ngtcp2_pkt_decode_stream_data_blocked_frame(
|
||||
|
||||
dest->type = NGTCP2_FRAME_STREAM_DATA_BLOCKED;
|
||||
p = ngtcp2_get_varint(&dest->stream_id, p);
|
||||
p = ngtcp2_get_uvarint(&dest->offset, p);
|
||||
p = ngtcp2_get_uvarint(&dest->max_stream_data, p);
|
||||
|
||||
assert((size_t)(p - payload) == len);
|
||||
|
||||
@@ -1820,7 +1822,7 @@ ngtcp2_ssize ngtcp2_pkt_encode_ping_frame(uint8_t *out, size_t outlen,
|
||||
ngtcp2_ssize
|
||||
ngtcp2_pkt_encode_data_blocked_frame(uint8_t *out, size_t outlen,
|
||||
const ngtcp2_data_blocked *fr) {
|
||||
size_t len = 1 + ngtcp2_put_uvarintlen(fr->offset);
|
||||
size_t len = 1 + ngtcp2_put_uvarintlen(fr->max_data);
|
||||
uint8_t *p;
|
||||
|
||||
if (outlen < len) {
|
||||
@@ -1830,7 +1832,7 @@ ngtcp2_pkt_encode_data_blocked_frame(uint8_t *out, size_t outlen,
|
||||
p = out;
|
||||
|
||||
*p++ = NGTCP2_FRAME_DATA_BLOCKED;
|
||||
p = ngtcp2_put_uvarint(p, fr->offset);
|
||||
p = ngtcp2_put_uvarint(p, fr->max_data);
|
||||
|
||||
assert((size_t)(p - out) == len);
|
||||
|
||||
@@ -1840,7 +1842,7 @@ ngtcp2_pkt_encode_data_blocked_frame(uint8_t *out, size_t outlen,
|
||||
ngtcp2_ssize ngtcp2_pkt_encode_stream_data_blocked_frame(
|
||||
uint8_t *out, size_t outlen, const ngtcp2_stream_data_blocked *fr) {
|
||||
size_t len = 1 + ngtcp2_put_uvarintlen((uint64_t)fr->stream_id) +
|
||||
ngtcp2_put_uvarintlen(fr->offset);
|
||||
ngtcp2_put_uvarintlen(fr->max_stream_data);
|
||||
uint8_t *p;
|
||||
|
||||
if (outlen < len) {
|
||||
@@ -1851,7 +1853,7 @@ ngtcp2_ssize ngtcp2_pkt_encode_stream_data_blocked_frame(
|
||||
|
||||
*p++ = NGTCP2_FRAME_STREAM_DATA_BLOCKED;
|
||||
p = ngtcp2_put_uvarint(p, (uint64_t)fr->stream_id);
|
||||
p = ngtcp2_put_uvarint(p, fr->offset);
|
||||
p = ngtcp2_put_uvarint(p, fr->max_stream_data);
|
||||
|
||||
assert((size_t)(p - out) == len);
|
||||
|
||||
@@ -2193,8 +2195,7 @@ int64_t ngtcp2_pkt_adjust_pkt_num(int64_t max_pkt_num, int64_t pkt_num,
|
||||
uint64_t mask = win - 1;
|
||||
uint64_t cand = (expected & ~mask) | (uint64_t)pkt_num;
|
||||
|
||||
if (cand + hwin <= expected) {
|
||||
assert(cand <= NGTCP2_MAX_VARINT - win);
|
||||
if (cand + hwin <= expected && cand <= NGTCP2_MAX_VARINT - win) {
|
||||
return (int64_t)(cand + win);
|
||||
}
|
||||
|
||||
@@ -2439,11 +2440,6 @@ size_t ngtcp2_pkt_stream_max_datalen(int64_t stream_id, uint64_t offset,
|
||||
|
||||
left -= n;
|
||||
|
||||
if (left > 8 + 1073741823 && len > 1073741823) {
|
||||
len = ngtcp2_min(len, 4611686018427387903UL);
|
||||
return (size_t)ngtcp2_min(len, (uint64_t)(left - 8));
|
||||
}
|
||||
|
||||
if (left > 4 + 16383 && len > 16383) {
|
||||
len = ngtcp2_min(len, 1073741823);
|
||||
return (size_t)ngtcp2_min(len, (uint64_t)(left - 4));
|
||||
@@ -2469,13 +2465,6 @@ size_t ngtcp2_pkt_crypto_max_datalen(uint64_t offset, size_t len, size_t left) {
|
||||
|
||||
left -= n;
|
||||
|
||||
if (left > 8 + 1073741823 && len > 1073741823) {
|
||||
#if SIZE_MAX == UINT64_MAX
|
||||
len = ngtcp2_min(len, 4611686018427387903UL);
|
||||
#endif /* SIZE_MAX == UINT64_MAX */
|
||||
return ngtcp2_min(len, left - 8);
|
||||
}
|
||||
|
||||
if (left > 4 + 16383 && len > 16383) {
|
||||
len = ngtcp2_min(len, 1073741823);
|
||||
return ngtcp2_min(len, left - 4);
|
||||
|
||||
Vendored
+2
-2
@@ -281,13 +281,13 @@ typedef struct ngtcp2_ping {
|
||||
|
||||
typedef struct ngtcp2_data_blocked {
|
||||
uint64_t type;
|
||||
uint64_t offset;
|
||||
uint64_t max_data;
|
||||
} ngtcp2_data_blocked;
|
||||
|
||||
typedef struct ngtcp2_stream_data_blocked {
|
||||
uint64_t type;
|
||||
int64_t stream_id;
|
||||
uint64_t offset;
|
||||
uint64_t max_stream_data;
|
||||
} ngtcp2_stream_data_blocked;
|
||||
|
||||
typedef struct ngtcp2_streams_blocked {
|
||||
|
||||
Vendored
+6
-1
@@ -86,7 +86,12 @@ int ngtcp2_ppe_encode_hd(ngtcp2_ppe *ppe, const ngtcp2_pkt_hd *hd) {
|
||||
|
||||
buf->last += rv;
|
||||
|
||||
if (ngtcp2_buf_cap(buf) < ppe_sample_offset(ppe) + NGTCP2_HP_SAMPLELEN) {
|
||||
/* The space for header protection sample only guarantees 4 -
|
||||
hd->pkt_numlen bytes of payload, which is 0 if packet number is
|
||||
encoded in 4 bytes. A packet must contain at least one frame, so
|
||||
make sure that at least 1 byte of payload can be written. */
|
||||
if (ngtcp2_buf_cap(buf) < ppe_sample_offset(ppe) + NGTCP2_HP_SAMPLELEN ||
|
||||
ngtcp2_ppe_left(ppe) == 0) {
|
||||
return NGTCP2_ERR_NOBUF;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-1
@@ -70,7 +70,8 @@ void ngtcp2_ppe_init(ngtcp2_ppe *ppe, uint8_t *out, size_t outlen,
|
||||
size_t dgram_offset, ngtcp2_crypto_cc *cc);
|
||||
|
||||
/*
|
||||
* ngtcp2_ppe_encode_hd encodes |hd|.
|
||||
* ngtcp2_ppe_encode_hd encodes |hd|. If it succeeds, it is
|
||||
* guaranteed that at least 1 byte of payload can be written.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
|
||||
Vendored
+16
-3
@@ -117,7 +117,12 @@ int ngtcp2_pv_validate(ngtcp2_pv *pv, uint8_t *pflags,
|
||||
void ngtcp2_pv_handle_entry_expiry(ngtcp2_pv *pv, ngtcp2_tstamp ts) {
|
||||
ngtcp2_pv_entry *ent;
|
||||
|
||||
if (ngtcp2_ringbuf_len(&pv->ents.rb) == 0) {
|
||||
/* Do not start new round until at least one PATH_CHALLENGE is sent
|
||||
in the current round. It might not be sent (e.g., server is
|
||||
blocked by anti-amplification limit), and the last entry remains
|
||||
expired. */
|
||||
if (ngtcp2_ringbuf_len(&pv->ents.rb) == 0 ||
|
||||
pv->probe_pkt_left == NGTCP2_PV_NUM_PROBE_PKT) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,13 +163,21 @@ int ngtcp2_pv_validation_timed_out(ngtcp2_pv *pv, ngtcp2_tstamp ts) {
|
||||
ngtcp2_tstamp ngtcp2_pv_next_expiry(ngtcp2_pv *pv) {
|
||||
ngtcp2_pv_entry *ent;
|
||||
|
||||
if ((pv->flags & NGTCP2_PV_FLAG_CANCEL_TIMER) ||
|
||||
ngtcp2_ringbuf_len(&pv->ents.rb) == 0) {
|
||||
if (ngtcp2_ringbuf_len(&pv->ents.rb) == 0) {
|
||||
return UINT64_MAX;
|
||||
}
|
||||
|
||||
ent = ngtcp2_ringbuf_get(&pv->ents.rb, ngtcp2_ringbuf_len(&pv->ents.rb) - 1);
|
||||
|
||||
if (pv->flags & NGTCP2_PV_FLAG_CANCEL_TIMER) {
|
||||
/* The timer of the last entry has expired, but a new
|
||||
PATH_CHALLENGE might never be sent (e.g., server is blocked by
|
||||
anti-amplification limit), which leaves no timer armed. Keep
|
||||
the timer for the timeout of path validation armed, which is
|
||||
the value ngtcp2_pv_validation_timed_out compares with. */
|
||||
return ngtcp2_max(pv->started_ts + pv->timeout, ent->expiry);
|
||||
}
|
||||
|
||||
return ent->expiry;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+15
-4
@@ -69,19 +69,24 @@ void ngtcp2_pv_entry_init(ngtcp2_pv_entry *pvent,
|
||||
/* NGTCP2_PV_FLAG_DONT_CARE indicates that the outcome of path
|
||||
validation should be ignored entirely. */
|
||||
#define NGTCP2_PV_FLAG_DONT_CARE 0x01U
|
||||
/* NGTCP2_PV_FLAG_CANCEL_TIMER indicates that the expiry timer is
|
||||
cancelled. */
|
||||
/* NGTCP2_PV_FLAG_CANCEL_TIMER indicates that the expiry timer of the
|
||||
last ngtcp2_pv_entry is cancelled. The timer for the timeout of
|
||||
path validation itself is still armed. */
|
||||
#define NGTCP2_PV_FLAG_CANCEL_TIMER 0x02U
|
||||
/* NGTCP2_PV_FLAG_FALLBACK_PRESENT indicates that a fallback
|
||||
Destination Connection ID and PTO are available in ngtcp2_pv. If
|
||||
path validation fails, then fallback to them. If path validation
|
||||
succeeds, the fallback Destination Connection ID is retired if it
|
||||
is not zero length, and does not equal to the current Destination
|
||||
Connection ID. */
|
||||
Connection ID, and NGTCP2_PV_FLAG_DONT_RETIRE_FALLBACK is not
|
||||
set. */
|
||||
#define NGTCP2_PV_FLAG_FALLBACK_PRESENT 0x04U
|
||||
/* NGTCP2_PV_FLAG_PREFERRED_ADDR indicates that client is migrating to
|
||||
server's preferred address. This flag is only used by client. */
|
||||
#define NGTCP2_PV_FLAG_PREFERRED_ADDR 0x10U
|
||||
/* NGTCP2_PV_FLAG_DONT_RETIRE_FALLBACK prevents the fallback
|
||||
Destination Connection ID from being retired. */
|
||||
#define NGTCP2_PV_FLAG_DONT_RETIRE_FALLBACK 0x20U
|
||||
|
||||
typedef struct ngtcp2_pv ngtcp2_pv;
|
||||
|
||||
@@ -170,6 +175,9 @@ int ngtcp2_pv_validate(ngtcp2_pv *pv, uint8_t *pflags,
|
||||
|
||||
/*
|
||||
* ngtcp2_pv_handle_entry_expiry checks expiry of existing entries.
|
||||
* If the last entry has expired, it starts new round. Calling this
|
||||
* function again has no effect until new entry is added by
|
||||
* ngtcp2_pv_add_entry.
|
||||
*/
|
||||
void ngtcp2_pv_handle_entry_expiry(ngtcp2_pv *pv, ngtcp2_tstamp ts);
|
||||
|
||||
@@ -191,7 +199,10 @@ int ngtcp2_pv_validation_timed_out(ngtcp2_pv *pv, ngtcp2_tstamp ts);
|
||||
ngtcp2_tstamp ngtcp2_pv_next_expiry(ngtcp2_pv *pv);
|
||||
|
||||
/*
|
||||
* ngtcp2_pv_cancel_expired_timer cancels the expired timer.
|
||||
* ngtcp2_pv_cancel_expired_timer cancels the expired timer. It does
|
||||
* not cancel the timer for the timeout of path validation. The
|
||||
* caller must check it with ngtcp2_pv_validation_timed_out before
|
||||
* calling this function.
|
||||
*/
|
||||
void ngtcp2_pv_cancel_expired_timer(ngtcp2_pv *pv, ngtcp2_tstamp ts);
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -488,7 +488,7 @@ static uint8_t *write_data_blocked_frame(uint8_t *p,
|
||||
#define NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD 57
|
||||
|
||||
p = write_verbatim(p, "{\"frame_type\":\"data_blocked\",");
|
||||
p = write_pair_number(p, "limit", fr->offset);
|
||||
p = write_pair_number(p, "limit", fr->max_data);
|
||||
*p++ = '}';
|
||||
|
||||
return p;
|
||||
@@ -505,7 +505,7 @@ write_stream_data_blocked_frame(uint8_t *p,
|
||||
p = write_verbatim(p, "{\"frame_type\":\"stream_data_blocked\",");
|
||||
p = write_pair_number(p, "stream_id", (uint64_t)fr->stream_id);
|
||||
*p++ = ',';
|
||||
p = write_pair_number(p, "limit", fr->offset);
|
||||
p = write_pair_number(p, "limit", fr->max_stream_data);
|
||||
*p++ = '}';
|
||||
|
||||
return p;
|
||||
|
||||
+9
-10
@@ -31,6 +31,8 @@
|
||||
|
||||
void ngtcp2_ratelim_init(ngtcp2_ratelim *rlim, uint64_t burst, uint64_t rate,
|
||||
ngtcp2_tstamp ts) {
|
||||
burst = ngtcp2_min(burst, NGTCP2_RATELIM_MAX_BURST);
|
||||
|
||||
*rlim = (ngtcp2_ratelim){
|
||||
.burst = burst,
|
||||
.rate = rate,
|
||||
@@ -52,19 +54,16 @@ static void ratelim_update(ngtcp2_ratelim *rlim, ngtcp2_tstamp ts) {
|
||||
d = ts - rlim->ts;
|
||||
rlim->ts = ts;
|
||||
|
||||
if (rlim->rate > (UINT64_MAX - rlim->carry) / d) {
|
||||
gain = UINT64_MAX;
|
||||
} else {
|
||||
if (rlim->rate <= (UINT64_MAX - rlim->carry) / d) {
|
||||
gain = rlim->rate * d + rlim->carry;
|
||||
}
|
||||
gps = gain / NGTCP2_SECONDS;
|
||||
|
||||
gps = gain / NGTCP2_SECONDS;
|
||||
if (gps < rlim->burst && rlim->tokens < rlim->burst - gps) {
|
||||
rlim->tokens += gps;
|
||||
rlim->carry = gain % NGTCP2_SECONDS;
|
||||
|
||||
if (gps < rlim->burst && rlim->tokens < rlim->burst - gps) {
|
||||
rlim->tokens += gps;
|
||||
rlim->carry = gain % NGTCP2_SECONDS;
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rlim->tokens = rlim->burst;
|
||||
|
||||
+5
-2
@@ -32,6 +32,9 @@
|
||||
|
||||
#include <ngtcp2/ngtcp2.h>
|
||||
|
||||
/* NGTCP2_RATELIM_MAX_BURST is the maximum value of the burst. */
|
||||
#define NGTCP2_RATELIM_MAX_BURST (UINT64_MAX / NGTCP2_SECONDS)
|
||||
|
||||
typedef struct ngtcp2_ratelim {
|
||||
/* burst is the maximum number of tokens. */
|
||||
uint64_t burst;
|
||||
@@ -47,8 +50,8 @@ typedef struct ngtcp2_ratelim {
|
||||
ngtcp2_tstamp ts;
|
||||
} ngtcp2_ratelim;
|
||||
|
||||
/* ngtcp2_ratelim_init initializes |rlim| with the given
|
||||
parameters. */
|
||||
/* ngtcp2_ratelim_init initializes |rlim| with the given parameters.
|
||||
|burst| is clamped to NGTCP2_RATELIM_MAX_BURST. */
|
||||
void ngtcp2_ratelim_init(ngtcp2_ratelim *rlim, uint64_t burst, uint64_t rate,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
|
||||
Vendored
+4
-36
@@ -62,7 +62,6 @@ int ngtcp2_rob_init(ngtcp2_rob *rob, size_t chunk, const ngtcp2_mem *mem) {
|
||||
|
||||
rob->chunk = chunk;
|
||||
rob->mem = mem;
|
||||
rob->discard_data = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -96,10 +95,6 @@ static int rob_write_data(ngtcp2_rob *rob, uint64_t offset, const uint8_t *data,
|
||||
const ngtcp2_range *r;
|
||||
uint64_t chunk_offset;
|
||||
|
||||
if (rob->discard_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (it = ngtcp2_ksl_lower_bound_search(&rob->dataksl, &range,
|
||||
ngtcp2_ksl_range_exclusive_search);
|
||||
len; ngtcp2_ksl_it_next(&it)) {
|
||||
@@ -235,10 +230,6 @@ void ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset) {
|
||||
ngtcp2_ksl_remove_hint(&rob->gapksl, &it, &it, &g);
|
||||
}
|
||||
|
||||
if (rob->discard_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
it = ngtcp2_ksl_begin(&rob->dataksl);
|
||||
|
||||
for (; !ngtcp2_ksl_it_end(&it);) {
|
||||
@@ -254,8 +245,8 @@ void ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset) {
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
uint64_t offset) {
|
||||
size_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
uint64_t offset) {
|
||||
const ngtcp2_range *g;
|
||||
const ngtcp2_range *r;
|
||||
uint8_t *d;
|
||||
@@ -272,12 +263,6 @@ uint64_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rob->discard_data) {
|
||||
*pdest = NULL;
|
||||
|
||||
return g->begin - offset;
|
||||
}
|
||||
|
||||
it = ngtcp2_ksl_begin(&rob->dataksl);
|
||||
r = ngtcp2_ksl_it_key(&it);
|
||||
d = ngtcp2_ksl_it_get(&it);
|
||||
@@ -288,18 +273,14 @@ uint64_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
|
||||
*pdest = d + (offset - r->begin);
|
||||
|
||||
return ngtcp2_min(g->begin, r->end) - offset;
|
||||
return (size_t)(ngtcp2_min(g->begin, r->end) - offset);
|
||||
}
|
||||
|
||||
void ngtcp2_rob_pop(ngtcp2_rob *rob, uint64_t offset, uint64_t len) {
|
||||
void ngtcp2_rob_pop(ngtcp2_rob *rob, uint64_t offset, size_t len) {
|
||||
ngtcp2_ksl_it it;
|
||||
ngtcp2_range r;
|
||||
uint8_t *d;
|
||||
|
||||
if (rob->discard_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
it = ngtcp2_ksl_begin(&rob->dataksl);
|
||||
r = *(const ngtcp2_range *)ngtcp2_ksl_it_key(&it);
|
||||
d = ngtcp2_ksl_it_get(&it);
|
||||
@@ -330,16 +311,3 @@ uint64_t ngtcp2_rob_first_gap_offset(const ngtcp2_rob *rob) {
|
||||
int ngtcp2_rob_data_buffered(const ngtcp2_rob *rob) {
|
||||
return ngtcp2_ksl_len(&rob->dataksl) != 0;
|
||||
}
|
||||
|
||||
void ngtcp2_rob_discard_data(ngtcp2_rob *rob) {
|
||||
ngtcp2_ksl_it it;
|
||||
|
||||
rob->discard_data = 1;
|
||||
|
||||
for (it = ngtcp2_ksl_begin(&rob->dataksl); !ngtcp2_ksl_it_end(&it);
|
||||
ngtcp2_ksl_it_next(&it)) {
|
||||
rob_data_del(ngtcp2_ksl_it_get(&it), rob->mem);
|
||||
}
|
||||
|
||||
ngtcp2_ksl_clear(&rob->dataksl);
|
||||
}
|
||||
Vendored
+3
-20
@@ -50,9 +50,6 @@ typedef struct ngtcp2_rob {
|
||||
const ngtcp2_mem *mem;
|
||||
/* chunk is the size of each buffer in data field */
|
||||
size_t chunk;
|
||||
/* discard_data, if nonzero, stops buffering data. If it is
|
||||
nonzero, ngtcp2_ksl_empty(&dataksl) always returns nonzero. */
|
||||
int discard_data;
|
||||
} ngtcp2_rob;
|
||||
|
||||
/*
|
||||
@@ -76,10 +73,6 @@ void ngtcp2_rob_free(ngtcp2_rob *rob);
|
||||
* ngtcp2_rob_push adds new data pointed by |data| of length |datalen|
|
||||
* at the stream offset |offset|.
|
||||
*
|
||||
* If ngtcp2_rob_discard_data is called, this function does not buffer
|
||||
* data. The return value is the number of bytes that would be
|
||||
* buffered if ngtcp2_rob_discard_data has not been called.
|
||||
*
|
||||
* This function returns the number of data newly buffered if it
|
||||
* succeeds, or one of the following negative error codes:
|
||||
*
|
||||
@@ -102,11 +95,9 @@ void ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset);
|
||||
* valid length of available data. If no data is available, it
|
||||
* returns 0. This function only returns the data before the first
|
||||
* gap. It returns 0 even if data is available after the first gap.
|
||||
* If ngtcp2_rob_discard_data has been called, NULL is assigned to
|
||||
* |*pdest| if this function returns nonzero.
|
||||
*/
|
||||
uint64_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
uint64_t offset);
|
||||
size_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
uint64_t offset);
|
||||
|
||||
/*
|
||||
* ngtcp2_rob_pop clears data at stream offset |offset| of length
|
||||
@@ -118,10 +109,8 @@ uint64_t ngtcp2_rob_data_at(const ngtcp2_rob *rob, const uint8_t **pdest,
|
||||
*
|
||||
* Caller should call this function from offset 0 in non-decreasing
|
||||
* order.
|
||||
*
|
||||
* ngtcp2_rob_pop is noop if ngtcp2_rob_discard_data has been called.
|
||||
*/
|
||||
void ngtcp2_rob_pop(ngtcp2_rob *rob, uint64_t offset, uint64_t len);
|
||||
void ngtcp2_rob_pop(ngtcp2_rob *rob, uint64_t offset, size_t len);
|
||||
|
||||
/*
|
||||
* ngtcp2_rob_first_gap_offset returns the offset to the first gap.
|
||||
@@ -134,10 +123,4 @@ uint64_t ngtcp2_rob_first_gap_offset(const ngtcp2_rob *rob);
|
||||
*/
|
||||
int ngtcp2_rob_data_buffered(const ngtcp2_rob *rob);
|
||||
|
||||
/*
|
||||
* ngtcp2_rob_discard_data discards the buffered data, and stops
|
||||
* buffering data any further.
|
||||
*/
|
||||
void ngtcp2_rob_discard_data(ngtcp2_rob *rob);
|
||||
|
||||
#endif /* !defined(NGTCP2_ROB_H) */
|
||||
Vendored
+123
-60
@@ -106,6 +106,7 @@ void ngtcp2_rtb_init(ngtcp2_rtb *rtb, ngtcp2_rst *rst, ngtcp2_cc *cc,
|
||||
rtb->cc_bytes_in_flight = 0;
|
||||
rtb->num_lost_pkts = 0;
|
||||
rtb->num_lost_ignore_pkts = 0;
|
||||
rtb->pto_reclaim_pkt_num = -1;
|
||||
}
|
||||
|
||||
void ngtcp2_rtb_free(ngtcp2_rtb *rtb) {
|
||||
@@ -247,7 +248,8 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
fr->stream.offset + ngtcp2_vec_len(fr->stream.data, fr->stream.datacnt);
|
||||
range = ngtcp2_range_intersect(&range, &gap);
|
||||
|
||||
if (ngtcp2_range_len(&range) == 0 && !fr->stream.fin &&
|
||||
if (ngtcp2_range_len(&range) == 0 &&
|
||||
(!fr->stream.fin || (strm->flags & NGTCP2_STRM_FLAG_FIN_ACKED)) &&
|
||||
/* 0 length STREAM frame with offset == 0 must be
|
||||
retransmitted if no non-empty data are sent to this
|
||||
stream, fin flag is not set, and no data in this stream
|
||||
@@ -286,13 +288,9 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!ngtcp2_strm_is_tx_queued(strm)) {
|
||||
strm->cycle = ngtcp2_conn_tx_strmq_first_cycle(conn);
|
||||
|
||||
rv = ngtcp2_conn_tx_strmq_push(conn, strm);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
rv = ngtcp2_conn_tx_strmq_push_if_not(conn, strm);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
++num_reclaimed;
|
||||
@@ -348,6 +346,7 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
|
||||
rv = ngtcp2_bind_frame_chains(frc, nfrc, rtb->mem);
|
||||
if (rv != 0) {
|
||||
ngtcp2_frame_chain_objalloc_del(nfrc, rtb->frc_objalloc, rtb->mem);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -374,6 +373,18 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_MAX_STREAMS_BIDI:
|
||||
if (fr->max_streams.max_streams < conn->rx.bidi.max_streams) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_MAX_STREAMS_UNI:
|
||||
if (fr->max_streams.max_streams < conn->rx.uni.max_streams) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_MAX_STREAM_DATA:
|
||||
strm = ngtcp2_conn_find_stream(conn, fr->max_stream_data.stream_id);
|
||||
@@ -382,6 +393,12 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_MAX_DATA:
|
||||
if (fr->max_data.max_data < conn->rx.max_offset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_STREAM_DATA_BLOCKED:
|
||||
strm = ngtcp2_conn_find_stream(conn, fr->stream_data_blocked.stream_id);
|
||||
@@ -390,6 +407,12 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
case NGTCP2_FRAME_DATA_BLOCKED:
|
||||
if (fr->data_blocked.max_data != conn->tx.max_offset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -402,6 +425,7 @@ static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, uint8_t flags,
|
||||
|
||||
rv = ngtcp2_bind_frame_chains(frc, nfrc, rtb->mem);
|
||||
if (rv != 0) {
|
||||
ngtcp2_frame_chain_objalloc_del(nfrc, rtb->frc_objalloc, rtb->mem);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -481,30 +505,31 @@ static int rtb_on_pkt_lost(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
}
|
||||
}
|
||||
|
||||
/* DATAGRAM frame is not reclaimed on PTO, so its loss must be
|
||||
notified even if the packet has already been reclaimed on
|
||||
PTO. */
|
||||
if (conn->callbacks.lost_datagram &&
|
||||
(ent->flags & NGTCP2_RTB_ENTRY_FLAG_DATAGRAM)) {
|
||||
rv = conn_process_lost_datagram(conn, ent);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PTO_RECLAIMED) {
|
||||
ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC, "pkn=", ent->hd.pkt_num,
|
||||
" has already been reclaimed on PTO");
|
||||
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED));
|
||||
assert(UINT64_MAX == ent->lost_ts);
|
||||
} else {
|
||||
if (conn->callbacks.lost_datagram &&
|
||||
(ent->flags & NGTCP2_RTB_ENTRY_FLAG_DATAGRAM)) {
|
||||
rv = conn_process_lost_datagram(conn, ent);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
} else if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_RETRANSMITTABLE) {
|
||||
assert(ent->frc);
|
||||
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED));
|
||||
assert(UINT64_MAX == ent->lost_ts);
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_RETRANSMITTABLE) {
|
||||
assert(ent->frc);
|
||||
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED));
|
||||
assert(UINT64_MAX == ent->lost_ts);
|
||||
|
||||
reclaimed =
|
||||
rtb_reclaim_frame(rtb, NGTCP2_RECLAIM_FLAG_ON_LOSS, conn, pktns, ent);
|
||||
if (reclaimed < 0) {
|
||||
return (int)reclaimed;
|
||||
}
|
||||
reclaimed =
|
||||
rtb_reclaim_frame(rtb, NGTCP2_RECLAIM_FLAG_ON_LOSS, conn, pktns, ent);
|
||||
if (reclaimed < 0) {
|
||||
return (int)reclaimed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,7 +823,7 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
size_t i;
|
||||
int rv;
|
||||
ngtcp2_ksl_it it;
|
||||
size_t num_acked = 0;
|
||||
size_t num_acked = 0, num_cc_acked = 0;
|
||||
int64_t pkt_num;
|
||||
ngtcp2_cc *cc = rtb->cc;
|
||||
ngtcp2_rtb_entry *acked_ent = NULL;
|
||||
@@ -855,7 +880,10 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
|
||||
ent = ngtcp2_ksl_it_get(&it);
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_SKIP) {
|
||||
/* A packet cannot acknowledge a packet which was sent after it
|
||||
had been received. This could happen with a buffered
|
||||
packet. */
|
||||
if ((ent->flags & NGTCP2_RTB_ENTRY_FLAG_SKIP) || pkt_ts < ent->ts) {
|
||||
rv = NGTCP2_ERR_PROTO;
|
||||
goto fail;
|
||||
}
|
||||
@@ -888,7 +916,7 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
|
||||
ent = ngtcp2_ksl_it_get(&it);
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_SKIP) {
|
||||
if ((ent->flags & NGTCP2_RTB_ENTRY_FLAG_SKIP) || pkt_ts < ent->ts) {
|
||||
rv = NGTCP2_ERR_PROTO;
|
||||
goto fail;
|
||||
}
|
||||
@@ -928,9 +956,11 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
|
||||
rtb_on_pkt_acked(rtb, ent, cstat, pktns, ts);
|
||||
|
||||
++num_acked;
|
||||
++num_cc_acked;
|
||||
}
|
||||
|
||||
++num_acked;
|
||||
|
||||
acked_ent = ent->next;
|
||||
ngtcp2_rtb_entry_objalloc_del(ent, rtb->rtb_entry_objalloc,
|
||||
rtb->frc_objalloc, rtb->mem);
|
||||
@@ -940,6 +970,7 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
for (ent = acked_ent; ent; ent = acked_ent) {
|
||||
rtb_on_pkt_acked(rtb, ent, cstat, pktns, ts);
|
||||
acked_ent = ent->next;
|
||||
++num_cc_acked;
|
||||
++num_acked;
|
||||
ngtcp2_rtb_entry_objalloc_del(ent, rtb->rtb_entry_objalloc,
|
||||
rtb->frc_objalloc, rtb->mem);
|
||||
@@ -951,9 +982,11 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
rtb->cc->on_spurious_congestion(cc, cstat, ts);
|
||||
}
|
||||
|
||||
if (num_acked) {
|
||||
if (num_cc_acked) {
|
||||
ngtcp2_rst_on_ack_recv(rtb->rst, cstat);
|
||||
}
|
||||
|
||||
if (num_acked) {
|
||||
if (conn) {
|
||||
rv = rtb_detect_lost_pkt(rtb, &cc_ack, conn, pktns, cstat, ts);
|
||||
if (rv != 0) {
|
||||
@@ -1189,7 +1222,7 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_cc_ack *cc_ack,
|
||||
}
|
||||
}
|
||||
|
||||
ngtcp2_rtb_remove_excessive_lost_pkt(rtb, (size_t)pkt_thres);
|
||||
ngtcp2_rtb_remove_excessive_lost_pkt(rtb, (size_t)pkt_thres, cstat, ts);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1205,7 +1238,34 @@ int ngtcp2_rtb_detect_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
conn, pktns, cstat, ts);
|
||||
}
|
||||
|
||||
void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n) {
|
||||
/*
|
||||
* rtb_on_lost_pkt_removed is called when a lost packet |ent| is
|
||||
* removed from |rtb| without being acknowledged. It tells the
|
||||
* congestion controller that the loss is not spurious.
|
||||
*/
|
||||
static void rtb_on_lost_pkt_removed(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
|
||||
ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts) {
|
||||
ngtcp2_cc *cc = rtb->cc;
|
||||
|
||||
assert(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED);
|
||||
|
||||
--rtb->num_lost_pkts;
|
||||
|
||||
if (ent->flags &
|
||||
(NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE | NGTCP2_RTB_ENTRY_FLAG_SKIP)) {
|
||||
--rtb->num_lost_ignore_pkts;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (cc->on_pkt_lost_confirmed) {
|
||||
cc->on_pkt_lost_confirmed(cc, cstat, ts);
|
||||
}
|
||||
}
|
||||
|
||||
void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_ksl_it it = ngtcp2_ksl_end(&rtb->ents);
|
||||
ngtcp2_rtb_entry *ent;
|
||||
int rv;
|
||||
@@ -1221,12 +1281,7 @@ void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n) {
|
||||
ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"removing stale lost pkn=", ent->hd.pkt_num);
|
||||
|
||||
--rtb->num_lost_pkts;
|
||||
|
||||
if (ent->flags &
|
||||
(NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE | NGTCP2_RTB_ENTRY_FLAG_SKIP)) {
|
||||
--rtb->num_lost_ignore_pkts;
|
||||
}
|
||||
rtb_on_lost_pkt_removed(rtb, ent, cstat, ts);
|
||||
|
||||
rv = ngtcp2_ksl_remove_hint(&rtb->ents, &it, &it, &ent->hd.pkt_num);
|
||||
assert(0 == rv);
|
||||
@@ -1237,6 +1292,7 @@ void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n) {
|
||||
|
||||
void ngtcp2_rtb_remove_expired_lost_pkt(ngtcp2_rtb *rtb,
|
||||
ngtcp2_duration timeout,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts) {
|
||||
ngtcp2_ksl_it it;
|
||||
ngtcp2_rtb_entry *ent;
|
||||
@@ -1264,12 +1320,7 @@ void ngtcp2_rtb_remove_expired_lost_pkt(ngtcp2_rtb *rtb,
|
||||
ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
|
||||
"removing stale lost pkn=", ent->hd.pkt_num);
|
||||
|
||||
--rtb->num_lost_pkts;
|
||||
|
||||
if (ent->flags &
|
||||
(NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE | NGTCP2_RTB_ENTRY_FLAG_SKIP)) {
|
||||
--rtb->num_lost_ignore_pkts;
|
||||
}
|
||||
rtb_on_lost_pkt_removed(rtb, ent, cstat, ts);
|
||||
|
||||
rv = ngtcp2_ksl_remove_hint(&rtb->ents, &it, &it, &ent->hd.pkt_num);
|
||||
assert(0 == rv);
|
||||
@@ -1320,18 +1371,26 @@ static int rtb_reclaim_frame_on_retry(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
break;
|
||||
}
|
||||
|
||||
/* 0 length STREAM frame with offset == 0 must be retransmitted
|
||||
only if no non-empty data are sent to this stream, and fin
|
||||
flag is not set. Otherwise, it shares the offset with the
|
||||
first non-empty (or fin ) STREAM frame, and
|
||||
ngtcp2_strm_streamfrq_push fails. */
|
||||
if (sfr->offset == 0 && sfr->datacnt == 0 && !sfr->fin &&
|
||||
(strm->tx.offset || (strm->flags & NGTCP2_STRM_FLAG_SHUT_WR))) {
|
||||
ngtcp2_frame_chain_objalloc_del(frc, rtb->frc_objalloc, rtb->mem);
|
||||
break;
|
||||
}
|
||||
|
||||
rv = ngtcp2_strm_streamfrq_push(strm, frc);
|
||||
if (rv != 0) {
|
||||
ngtcp2_frame_chain_objalloc_del(frc, rtb->frc_objalloc, rtb->mem);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!ngtcp2_strm_is_tx_queued(strm)) {
|
||||
strm->cycle = ngtcp2_conn_tx_strmq_first_cycle(conn);
|
||||
rv = ngtcp2_conn_tx_strmq_push(conn, strm);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
rv = ngtcp2_conn_tx_strmq_push_if_not(conn, strm);
|
||||
if (rv != 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1400,11 +1459,6 @@ int ngtcp2_rtb_reclaim_on_retry(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
}
|
||||
}
|
||||
|
||||
/* We never send PING only probe packet because we should have
|
||||
CRYPTO data or just nothing. If we have nothing, then we do
|
||||
not send probe packet. */
|
||||
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_PROBE));
|
||||
|
||||
/* We never get ACK before Retry packet. */
|
||||
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED));
|
||||
assert(0 == rtb->num_lost_pkts);
|
||||
@@ -1486,11 +1540,13 @@ ngtcp2_ssize ngtcp2_rtb_reclaim_on_pto(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
ngtcp2_ssize reclaimed;
|
||||
size_t atmost = num_pkts;
|
||||
|
||||
it = ngtcp2_ksl_end(&rtb->ents);
|
||||
it = ngtcp2_ksl_lower_bound(&rtb->ents, &rtb->pto_reclaim_pkt_num);
|
||||
for (; !ngtcp2_ksl_it_begin(&it) && num_pkts;) {
|
||||
ngtcp2_ksl_it_prev(&it);
|
||||
ent = ngtcp2_ksl_it_get(&it);
|
||||
|
||||
rtb->pto_reclaim_pkt_num = ent->hd.pkt_num;
|
||||
|
||||
if ((ent->flags & (NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED |
|
||||
NGTCP2_RTB_ENTRY_FLAG_PTO_RECLAIMED)) ||
|
||||
!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_RETRANSMITTABLE)) {
|
||||
@@ -1512,15 +1568,22 @@ ngtcp2_ssize ngtcp2_rtb_reclaim_on_pto(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
assert(rtb->num_retransmittable);
|
||||
--rtb->num_retransmittable;
|
||||
|
||||
/* If nothing is reclaimed, no packet is sent on behalf of ent.
|
||||
Keep ent PTO eliciting so that loss detection timer stays armed,
|
||||
and PING is sent as a probe. Otherwise, if ent and the packets
|
||||
reclaimed earlier are lost, nothing removes them from bytes in
|
||||
flight. */
|
||||
if (reclaimed == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PTO_ELICITING) {
|
||||
ent->flags &= (uint16_t)~NGTCP2_RTB_ENTRY_FLAG_PTO_ELICITING;
|
||||
assert(rtb->num_pto_eliciting);
|
||||
--rtb->num_pto_eliciting;
|
||||
}
|
||||
|
||||
if (reclaimed) {
|
||||
--num_pkts;
|
||||
}
|
||||
--num_pkts;
|
||||
}
|
||||
|
||||
return (ngtcp2_ssize)(atmost - num_pkts);
|
||||
|
||||
Vendored
+12
-1
@@ -195,6 +195,11 @@ typedef struct ngtcp2_rtb {
|
||||
excluded from lost byte count. If only those packets are lost,
|
||||
congestion event is not triggered. */
|
||||
size_t num_lost_ignore_pkts;
|
||||
/* pto_reclaim_pkt_num is the largest packet number among the
|
||||
entries that ngtcp2_rtb_reclaim_on_pto has visited, or -1 if it
|
||||
has not visited any entry yet. The entries up to this packet
|
||||
number have been reclaimed, or never will be. */
|
||||
int64_t pto_reclaim_pkt_num;
|
||||
} ngtcp2_rtb;
|
||||
|
||||
/*
|
||||
@@ -243,6 +248,9 @@ ngtcp2_ksl_it ngtcp2_rtb_head(const ngtcp2_rtb *rtb);
|
||||
* User callback failed
|
||||
* NGTCP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
* NGTCP2_ERR_PROTO
|
||||
* |fr| acknowledges a skipped packet number, or a packet that was
|
||||
* sent after |pkt_ts|.
|
||||
*/
|
||||
ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
|
||||
ngtcp2_conn_stat *cstat, ngtcp2_conn *conn,
|
||||
@@ -264,6 +272,7 @@ int ngtcp2_rtb_detect_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_conn *conn,
|
||||
*/
|
||||
void ngtcp2_rtb_remove_expired_lost_pkt(ngtcp2_rtb *rtb,
|
||||
ngtcp2_duration timeout,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
/*
|
||||
@@ -302,7 +311,9 @@ void ngtcp2_rtb_reset_cc_state(ngtcp2_rtb *rtb, int64_t cc_pkt_num);
|
||||
* ngtcp2_rtb_remove_excessive_lost_pkt ensures that the number of
|
||||
* lost packets is at most |n|.
|
||||
*/
|
||||
void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n);
|
||||
void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n,
|
||||
ngtcp2_conn_stat *cstat,
|
||||
ngtcp2_tstamp ts);
|
||||
|
||||
/*
|
||||
* ngtcp2_rtb_reclaim_on_pto reclaims up to |num_pkts| packets which
|
||||
|
||||
+3
@@ -37,6 +37,7 @@ void ngtcp2_settings_default_versioned(int settings_version,
|
||||
|
||||
switch (settings_version) {
|
||||
case NGTCP2_SETTINGS_VERSION:
|
||||
case NGTCP2_SETTINGS_V4:
|
||||
case NGTCP2_SETTINGS_V3:
|
||||
settings->glitch_ratelim_burst = NGTCP2_DEFAULT_GLITCH_RATELIM_BURST;
|
||||
settings->glitch_ratelim_rate = NGTCP2_DEFAULT_GLITCH_RATELIM_RATE;
|
||||
@@ -87,6 +88,8 @@ size_t ngtcp2_settingslen_version(int settings_version) {
|
||||
switch (settings_version) {
|
||||
case NGTCP2_SETTINGS_VERSION:
|
||||
return sizeof(settings);
|
||||
case NGTCP2_SETTINGS_V4:
|
||||
return offsetof(ngtcp2_settings, log_write) + sizeof(settings.log_write);
|
||||
case NGTCP2_SETTINGS_V3:
|
||||
return offsetof(ngtcp2_settings, glitch_ratelim_rate) +
|
||||
sizeof(settings.glitch_ratelim_rate);
|
||||
|
||||
Vendored
+20
-27
@@ -115,9 +115,21 @@ uint64_t ngtcp2_strm_rx_offset(const ngtcp2_strm *strm) {
|
||||
}
|
||||
|
||||
/* strm_rob_heavily_fragmented returns nonzero if the number of gaps
|
||||
in |rob| exceeds the limit. */
|
||||
static int strm_rob_heavily_fragmented(const ngtcp2_rob *rob) {
|
||||
return ngtcp2_ksl_len(&rob->gapksl) >= 4000;
|
||||
in strm->rx.rob exceeds the limit. A gap costs memory no matter
|
||||
how small it is, while flow control only charges the remote
|
||||
endpoint for the offset range that the reorder buffer covers.
|
||||
Therefore, beyond a fixed allowance, each gap must be backed by
|
||||
NGTCP2_MIN_STREAM_DATALEN bytes of that range. */
|
||||
static int strm_rob_heavily_fragmented(const ngtcp2_strm *strm) {
|
||||
size_t ngap = ngtcp2_ksl_len(&strm->rx.rob->gapksl);
|
||||
uint64_t rx_offset = ngtcp2_rob_first_gap_offset(strm->rx.rob);
|
||||
uint64_t span;
|
||||
|
||||
assert(strm->rx.last_offset >= rx_offset);
|
||||
|
||||
span = strm->rx.last_offset - rx_offset;
|
||||
|
||||
return ngap >= 4000 || ngap > 128 + span / NGTCP2_MIN_STREAM_DATALEN;
|
||||
}
|
||||
|
||||
ngtcp2_ssize ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
@@ -134,10 +146,6 @@ ngtcp2_ssize ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
if (strm->rx.cont_offset) {
|
||||
ngtcp2_rob_remove_prefix(strm->rx.rob, strm->rx.cont_offset);
|
||||
}
|
||||
|
||||
if (strm->flags & NGTCP2_STRM_FLAG_NO_REORDERED_DATA_BUFFERING) {
|
||||
ngtcp2_rob_discard_data(strm->rx.rob);
|
||||
}
|
||||
}
|
||||
|
||||
nwrite = ngtcp2_rob_push(strm->rx.rob, offset, data, datalen);
|
||||
@@ -145,7 +153,7 @@ ngtcp2_ssize ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data,
|
||||
return nwrite;
|
||||
}
|
||||
|
||||
if (strm_rob_heavily_fragmented(strm->rx.rob)) {
|
||||
if (strm_rob_heavily_fragmented(strm)) {
|
||||
return NGTCP2_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -734,13 +742,12 @@ int ngtcp2_strm_require_retransmit_max_stream_data(
|
||||
|
||||
int ngtcp2_strm_require_retransmit_stream_data_blocked(
|
||||
const ngtcp2_strm *strm, const ngtcp2_stream_data_blocked *fr) {
|
||||
return fr->offset == strm->tx.max_offset &&
|
||||
return fr->max_stream_data == strm->tx.max_offset &&
|
||||
!(strm->flags & NGTCP2_STRM_FLAG_SHUT_WR);
|
||||
}
|
||||
|
||||
uint64_t ngtcp2_strm_discard_ordered_data(ngtcp2_strm *strm,
|
||||
uint64_t rx_offset) {
|
||||
uint64_t datalen;
|
||||
size_t ngtcp2_strm_discard_ordered_data(ngtcp2_strm *strm, uint64_t rx_offset) {
|
||||
size_t datalen;
|
||||
const uint8_t *data;
|
||||
uint64_t orig_rx_offset = rx_offset;
|
||||
|
||||
@@ -759,19 +766,5 @@ uint64_t ngtcp2_strm_discard_ordered_data(ngtcp2_strm *strm,
|
||||
rx_offset += datalen;
|
||||
}
|
||||
|
||||
return rx_offset - orig_rx_offset;
|
||||
}
|
||||
|
||||
void ngtcp2_strm_stop_buffering_reordered_data(ngtcp2_strm *strm) {
|
||||
if (strm->flags & NGTCP2_STRM_FLAG_NO_REORDERED_DATA_BUFFERING) {
|
||||
return;
|
||||
}
|
||||
|
||||
strm->flags |= NGTCP2_STRM_FLAG_NO_REORDERED_DATA_BUFFERING;
|
||||
|
||||
if (!strm->rx.rob) {
|
||||
return;
|
||||
}
|
||||
|
||||
ngtcp2_rob_discard_data(strm->rx.rob);
|
||||
return (size_t)(rx_offset - orig_rx_offset);
|
||||
}
|
||||
Vendored
+13
-21
@@ -89,9 +89,6 @@ typedef struct ngtcp2_frame_chain ngtcp2_frame_chain;
|
||||
/* NGTCP2_STRM_FLAG_ANY_SENT indicates that any STREAM frame,
|
||||
including empty one, has been sent. */
|
||||
#define NGTCP2_STRM_FLAG_ANY_SENT 0x1000U
|
||||
/* NGTCP2_STRM_FLAG_NO_REORDERED_DATA_BUFFERING is set when
|
||||
ngtcp2_strm_stop_buffering_reordered_data is called. */
|
||||
#define NGTCP2_STRM_FLAG_NO_REORDERED_DATA_BUFFERING 0x2000U
|
||||
/* NGTCP2_STRM_FLAG_RX_APP_ERROR_CODE_SET is set when
|
||||
ngtcp2_strm.rx.app_error_code is set. */
|
||||
#define NGTCP2_STRM_FLAG_RX_APP_ERROR_CODE_SET 0x4000U
|
||||
@@ -101,6 +98,14 @@ typedef struct ngtcp2_frame_chain ngtcp2_frame_chain;
|
||||
/* NGTCP2_STRM_FLAG_TX_STOP_SENDING_APP_ERROR_CODE_SET is set when
|
||||
ngtcp2_strm.tx.stop_sending_app_error_code is set. */
|
||||
#define NGTCP2_STRM_FLAG_TX_STOP_SENDING_APP_ERROR_CODE_SET 0x10000U
|
||||
/* NGTCP2_STRM_FLAG_SEND_STREAM_DATA_BLOCKED is set when
|
||||
STREAM_DATA_BLOCKED and/or DATA_BLOCKED frame should be sent. */
|
||||
#define NGTCP2_STRM_FLAG_SEND_STREAM_DATA_BLOCKED 0x20000U
|
||||
/* NGTCP2_STRM_FLAG_RX_FIN_DELIVERED is set when all stream data up to
|
||||
the final offset have been passed to an application via
|
||||
ngtcp2_callbacks.recv_stream_data with
|
||||
NGTCP2_STREAM_DATA_FLAG_FIN. */
|
||||
#define NGTCP2_STRM_FLAG_RX_FIN_DELIVERED 0x40000U
|
||||
|
||||
typedef struct ngtcp2_strm ngtcp2_strm;
|
||||
|
||||
@@ -234,10 +239,6 @@ uint64_t ngtcp2_strm_rx_offset(const ngtcp2_strm *strm);
|
||||
/*
|
||||
* ngtcp2_strm_recv_reordering handles reordered data.
|
||||
*
|
||||
* If ngtcp2_strm_stop_buffering_reordered_data has been called, this
|
||||
* function only records the range of the reordered data. The actual
|
||||
* data is not buffered.
|
||||
*
|
||||
* It returns the number of bytes newly buffered if it succeeds, or
|
||||
* one of the following negative error codes:
|
||||
*
|
||||
@@ -382,19 +383,10 @@ int ngtcp2_strm_require_retransmit_max_stream_data(
|
||||
int ngtcp2_strm_require_retransmit_stream_data_blocked(
|
||||
const ngtcp2_strm *strm, const ngtcp2_stream_data_blocked *fr);
|
||||
|
||||
/*
|
||||
* ngtcp2_strm_discard_ordered_data discards the ordered data starting
|
||||
* at |rx_offset|. It stops when it finds a gap, which means that a
|
||||
* portion of the data has not been received yet. It returns the size
|
||||
* of the buffered bytes discarded.
|
||||
*/
|
||||
uint64_t ngtcp2_strm_discard_ordered_data(ngtcp2_strm *strm,
|
||||
uint64_t rx_offset);
|
||||
|
||||
/*
|
||||
* ngtcp2_strm_stop_buffering_reordered_data discards the buffered
|
||||
* reordered data, and stops buffering data any further.
|
||||
*/
|
||||
void ngtcp2_strm_stop_buffering_reordered_data(ngtcp2_strm *strm);
|
||||
/* ngtcp2_strm_discard_ordered_data discards the ordered data starting
|
||||
at |rx_offset|. It stops when it finds a gap, which means that a
|
||||
portion of the data has not been received yet. It returns the size
|
||||
of the buffered bytes discarded. */
|
||||
size_t ngtcp2_strm_discard_ordered_data(ngtcp2_strm *strm, uint64_t rx_offset);
|
||||
|
||||
#endif /* !defined(NGTCP2_STRM_H) */
|
||||
+7
-2
@@ -586,10 +586,15 @@ int ngtcp2_transport_params_decode_versioned(int transport_params_version,
|
||||
if (decode_varint_param(¶ms->max_idle_timeout, &p, end) != 0) {
|
||||
return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM;
|
||||
}
|
||||
/* Because we multiply the value by NGTCP2_MILLISECONDS, the
|
||||
maximum max_idle_timeout is 18446744073709ms ~= 213504 days.
|
||||
If it is larger than that, it is truncated. */
|
||||
if (params->max_idle_timeout > UINT64_MAX / NGTCP2_MILLISECONDS) {
|
||||
params->max_idle_timeout = UINT64_MAX;
|
||||
params->max_idle_timeout =
|
||||
UINT64_MAX / NGTCP2_MILLISECONDS * NGTCP2_MILLISECONDS;
|
||||
} else {
|
||||
params->max_idle_timeout *= NGTCP2_MILLISECONDS;
|
||||
}
|
||||
params->max_idle_timeout *= NGTCP2_MILLISECONDS;
|
||||
break;
|
||||
case NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE:
|
||||
if (decode_varint_param(¶ms->max_udp_payload_size, &p, end) != 0) {
|
||||
|
||||
+3
-3
@@ -43,10 +43,10 @@
|
||||
#ifdef _MSC_VER
|
||||
__declspec(noreturn)
|
||||
#endif /* defined(_MSC_VER) */
|
||||
void ngtcp2_unreachable_fail(const char *file, int line, const char *func)
|
||||
void ngtcp2_unreachable_fail(const char *file, int line, const char *func)
|
||||
#ifndef _MSC_VER
|
||||
__attribute__((noreturn))
|
||||
__attribute__((noreturn))
|
||||
#endif /* !defined(_MSC_VER) */
|
||||
;
|
||||
;
|
||||
|
||||
#endif /* !defined(NGTCP2_UNREACHABLE_H) */
|
||||
Vendored
+2
-1
@@ -134,6 +134,8 @@ size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src,
|
||||
a = &dst[0];
|
||||
b = &src[0];
|
||||
|
||||
++*pdstcnt;
|
||||
|
||||
if (left < b->len) {
|
||||
a->len = left;
|
||||
a->base = b->base;
|
||||
@@ -144,7 +146,6 @@ size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src,
|
||||
}
|
||||
|
||||
*a = *b;
|
||||
++*pdstcnt;
|
||||
left -= b->len;
|
||||
i = 1;
|
||||
}
|
||||
|
||||
+9
-2
@@ -1705,6 +1705,9 @@ struct Session::Impl final : public MemoryRetainer {
|
||||
on_receive_stream_stop_sending,
|
||||
#ifdef NGTCP2_CALLBACKS_V5
|
||||
nullptr, // stream_close2
|
||||
#endif
|
||||
#ifdef NGTCP2_CALLBACKS_V6
|
||||
nullptr, // extend_max_data
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1757,6 +1760,9 @@ struct Session::Impl final : public MemoryRetainer {
|
||||
on_receive_stream_stop_sending,
|
||||
#ifdef NGTCP2_CALLBACKS_V5
|
||||
nullptr, // stream_close2
|
||||
#endif
|
||||
#ifdef NGTCP2_CALLBACKS_V6
|
||||
nullptr, // extend_max_data
|
||||
#endif
|
||||
};
|
||||
};
|
||||
@@ -3707,8 +3713,9 @@ void Session::OnTimeout() {
|
||||
// on a freed object.
|
||||
BaseObjectPtr<Session> ref(this);
|
||||
HandleScope scope(env()->isolate());
|
||||
int ret;
|
||||
{
|
||||
int ret = 0;
|
||||
// Once we're draining, we don't want ngtcp to handle expired timeouts
|
||||
if (!is_in_draining_period()) {
|
||||
NgTcp2CallbackScope callback_scope(this);
|
||||
ret = ngtcp2_conn_handle_expiry(*this, uv_hrtime());
|
||||
}
|
||||
|
||||
@@ -21,11 +21,18 @@ const serverDone = Promise.withResolvers();
|
||||
|
||||
const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
// The client destroys its first stream with an error, which resets it.
|
||||
if (stream.id === 0n) {
|
||||
await assert.rejects(stream.closed, {
|
||||
code: 'ERR_QUIC_APPLICATION_ERROR',
|
||||
});
|
||||
return;
|
||||
}
|
||||
stream.writer.endSync();
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
serverDone.resolve();
|
||||
});
|
||||
}, 2);
|
||||
}));
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address);
|
||||
|
||||
Reference in new issue
Block a user