summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-11-01 15:48:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-11-01 15:48:56 +0000
commite61435024b4ace528a3481ade4545125a48be03c (patch)
tree7f9505c8d51d5e74b5f7b1ee66cbe5d266bd70fa
parentAdding debian version 1.53.0-1. (diff)
downloadnghttp2-e61435024b4ace528a3481ade4545125a48be03c.tar.xz
nghttp2-e61435024b4ace528a3481ade4545125a48be03c.zip
Merging upstream version 1.54.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--.github/workflows/build.yml10
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.rst18
-rw-r--r--configure.ac8
-rw-r--r--doc/h2load.12
-rw-r--r--doc/nghttp.12
-rw-r--r--doc/nghttpd.12
-rw-r--r--doc/nghttpx.12
-rw-r--r--docker/Dockerfile8
-rwxr-xr-xmakerelease.sh5
-rw-r--r--src/HttpServer.cc20
-rw-r--r--src/HttpServer.h5
-rw-r--r--src/h2load.cc36
-rw-r--r--src/h2load.h7
-rw-r--r--src/h2load_http3_session.cc12
-rw-r--r--src/h2load_http3_session.h1
-rw-r--r--src/h2load_quic.cc56
-rw-r--r--src/nghttp.cc3
-rw-r--r--src/shrpx.cc23
-rw-r--r--src/shrpx_connect_blocker.cc4
-rw-r--r--src/shrpx_connection.cc26
-rw-r--r--src/shrpx_connection.h6
-rw-r--r--src/shrpx_connection_handler.h4
-rw-r--r--src/shrpx_dns_tracker.cc17
-rw-r--r--src/shrpx_dns_tracker.h3
-rw-r--r--src/shrpx_http2_session.cc10
-rw-r--r--src/shrpx_http3_upstream.cc28
-rw-r--r--src/shrpx_http_downstream_connection.cc14
-rw-r--r--src/shrpx_live_check.cc10
-rw-r--r--src/shrpx_memcached_connection.cc10
-rw-r--r--src/shrpx_tls.cc16
-rw-r--r--src/shrpx_tls.h4
-rw-r--r--src/shrpx_worker.cc54
-rw-r--r--src/util.h11
34 files changed, 251 insertions, 188 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index cd2e4ce..c8eab90 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -5,12 +5,12 @@ on: [push, pull_request]
permissions: read-all
env:
- LIBBPF_VERSION: v1.1.0
- OPENSSL1_VERSION: 1_1_1t+quic
+ LIBBPF_VERSION: v1.2.0
+ OPENSSL1_VERSION: 1_1_1u+quic
OPENSSL3_VERSION: 3.1.0+quic
- BORINGSSL_VERSION: b0b1f9dfc583c96d5f91b7f8cdb7efabcf22793b
- NGHTTP3_VERSION: v0.11.0
- NGTCP2_VERSION: v0.15.0
+ BORINGSSL_VERSION: b0341041b03ea71d8371a9692aedae263fc06ee9
+ NGHTTP3_VERSION: v0.12.0
+ NGTCP2_VERSION: v0.16.0
jobs:
build-cache:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1827c7e..288957f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@
cmake_minimum_required(VERSION 3.0)
# XXX using 1.8.90 instead of 1.9.0-DEV
-project(nghttp2 VERSION 1.53.0)
+project(nghttp2 VERSION 1.54.0)
# See versioning rule:
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
diff --git a/README.rst b/README.rst
index 76291f0..5215be3 100644
--- a/README.rst
+++ b/README.rst
@@ -127,11 +127,11 @@ To enable the experimental HTTP/3 support for h2load and nghttpx, the
following libraries are required:
* `OpenSSL with QUIC support
- <https://github.com/quictls/openssl/tree/OpenSSL_1_1_1t+quic>`_; or
+ <https://github.com/quictls/openssl/tree/OpenSSL_1_1_1u+quic>`_; or
`BoringSSL <https://boringssl.googlesource.com/boringssl/>`_ (commit
- b0b1f9dfc583c96d5f91b7f8cdb7efabcf22793b)
-* `ngtcp2 <https://github.com/ngtcp2/ngtcp2>`_ >= 0.15.0
-* `nghttp3 <https://github.com/ngtcp2/nghttp3>`_ >= 0.9.0
+ b0341041b03ea71d8371a9692aedae263fc06ee9)
+* `ngtcp2 <https://github.com/ngtcp2/ngtcp2>`_ 0.16.x
+* `nghttp3 <https://github.com/ngtcp2/nghttp3>`_ 0.12.x
Use ``--enable-http3`` configure option to enable HTTP/3 feature for
h2load and nghttpx.
@@ -146,7 +146,7 @@ Use ``--with-libbpf`` configure option to build eBPF program.
libelf-dev is needed to build libbpf.
For Ubuntu 20.04, you can build libbpf from `the source code
-<https://github.com/libbpf/libbpf/releases/tag/v1.1.0>`_. nghttpx
+<https://github.com/libbpf/libbpf/releases/tag/v1.2.0>`_. nghttpx
requires eBPF program for reloading its configuration and hot swapping
its executable.
@@ -343,7 +343,7 @@ Build custom OpenSSL:
.. code-block:: text
- $ git clone --depth 1 -b OpenSSL_1_1_1t+quic https://github.com/quictls/openssl
+ $ git clone --depth 1 -b OpenSSL_1_1_1u+quic https://github.com/quictls/openssl
$ cd openssl
$ ./config --prefix=$PWD/build --openssldir=/etc/ssl
$ make -j$(nproc)
@@ -354,7 +354,7 @@ Build nghttp3:
.. code-block:: text
- $ git clone --depth 1 -b v0.11.0 https://github.com/ngtcp2/nghttp3
+ $ git clone --depth 1 -b v0.12.0 https://github.com/ngtcp2/nghttp3
$ cd nghttp3
$ autoreconf -i
$ ./configure --prefix=$PWD/build --enable-lib-only
@@ -366,7 +366,7 @@ Build ngtcp2:
.. code-block:: text
- $ git clone --depth 1 -b v0.15.0 https://github.com/ngtcp2/ngtcp2
+ $ git clone --depth 1 -b v0.16.0 https://github.com/ngtcp2/ngtcp2
$ cd ngtcp2
$ autoreconf -i
$ ./configure --prefix=$PWD/build --enable-lib-only \
@@ -380,7 +380,7 @@ from source:
.. code-block:: text
- $ git clone --depth 1 -b v1.1.0 https://github.com/libbpf/libbpf
+ $ git clone --depth 1 -b v1.2.0 https://github.com/libbpf/libbpf
$ cd libbpf
$ PREFIX=$PWD/build make -C src install
$ cd ..
diff --git a/configure.ac b/configure.ac
index dd8194f..c913a02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,7 @@ dnl Do not change user variables!
dnl https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
AC_PREREQ(2.61)
-AC_INIT([nghttp2], [1.53.0], [t-tujikawa@users.sourceforge.net])
+AC_INIT([nghttp2], [1.54.0], [t-tujikawa@users.sourceforge.net])
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
@@ -504,7 +504,7 @@ fi
# ngtcp2 (for src)
have_libngtcp2=no
if test "x${request_libngtcp2}" != "xno"; then
- PKG_CHECK_MODULES([LIBNGTCP2], [libngtcp2 >= 0.15.0], [have_libngtcp2=yes],
+ PKG_CHECK_MODULES([LIBNGTCP2], [libngtcp2 >= 0.16.0], [have_libngtcp2=yes],
[have_libngtcp2=no])
if test "x${have_libngtcp2}" = "xno"; then
AC_MSG_NOTICE($LIBNGTCP2_PKG_ERRORS)
@@ -521,7 +521,7 @@ have_libngtcp2_crypto_openssl=no
if test "x${have_ssl_is_quic}" = "xyes" &&
test "x${request_libngtcp2}" != "xno"; then
PKG_CHECK_MODULES([LIBNGTCP2_CRYPTO_OPENSSL],
- [libngtcp2_crypto_openssl >= 0.15.0],
+ [libngtcp2_crypto_openssl >= 0.16.0],
[have_libngtcp2_crypto_openssl=yes],
[have_libngtcp2_crypto_openssl=no])
if test "x${have_libngtcp2_crypto_openssl}" = "xno"; then
@@ -563,7 +563,7 @@ fi
# nghttp3 (for src)
have_libnghttp3=no
if test "x${request_libnghttp3}" != "xno"; then
- PKG_CHECK_MODULES([LIBNGHTTP3], [libnghttp3 >= 0.9.0], [have_libnghttp3=yes],
+ PKG_CHECK_MODULES([LIBNGHTTP3], [libnghttp3 >= 0.12.0], [have_libnghttp3=yes],
[have_libnghttp3=no])
if test "x${have_libnghttp3}" = "xno"; then
AC_MSG_NOTICE($LIBNGHTTP3_PKG_ERRORS)
diff --git a/doc/h2load.1 b/doc/h2load.1
index fc8ac94..41fb0d1 100644
--- a/doc/h2load.1
+++ b/doc/h2load.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "H2LOAD" "1" "May 10, 2023" "1.53.0" "nghttp2"
+.TH "H2LOAD" "1" "Jun 07, 2023" "1.54.0" "nghttp2"
.SH NAME
h2load \- HTTP/2 benchmarking tool
.SH SYNOPSIS
diff --git a/doc/nghttp.1 b/doc/nghttp.1
index c233af5..c315aef 100644
--- a/doc/nghttp.1
+++ b/doc/nghttp.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "NGHTTP" "1" "May 10, 2023" "1.53.0" "nghttp2"
+.TH "NGHTTP" "1" "Jun 07, 2023" "1.54.0" "nghttp2"
.SH NAME
nghttp \- HTTP/2 client
.SH SYNOPSIS
diff --git a/doc/nghttpd.1 b/doc/nghttpd.1
index 2f0bda0..e67dbb8 100644
--- a/doc/nghttpd.1
+++ b/doc/nghttpd.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "NGHTTPD" "1" "May 10, 2023" "1.53.0" "nghttp2"
+.TH "NGHTTPD" "1" "Jun 07, 2023" "1.54.0" "nghttp2"
.SH NAME
nghttpd \- HTTP/2 server
.SH SYNOPSIS
diff --git a/doc/nghttpx.1 b/doc/nghttpx.1
index e5650ef..52cf9dd 100644
--- a/doc/nghttpx.1
+++ b/doc/nghttpx.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "NGHTTPX" "1" "May 10, 2023" "1.53.0" "nghttp2"
+.TH "NGHTTPX" "1" "Jun 07, 2023" "1.54.0" "nghttp2"
.SH NAME
nghttpx \- HTTP/2 proxy
.SH SYNOPSIS
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 62791a1..9cb49bb 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -7,7 +7,7 @@ RUN apt-get update && \
zlib1g-dev libev-dev libjemalloc-dev ruby-dev libc-ares-dev bison \
libelf-dev
-RUN git clone --depth 1 -b OpenSSL_1_1_1t+quic https://github.com/quictls/openssl && \
+RUN git clone --depth 1 -b OpenSSL_1_1_1u+quic https://github.com/quictls/openssl && \
cd openssl && \
./config --openssldir=/etc/ssl && \
make -j$(nproc) && \
@@ -15,7 +15,7 @@ RUN git clone --depth 1 -b OpenSSL_1_1_1t+quic https://github.com/quictls/openss
cd .. && \
rm -rf openssl
-RUN git clone --depth 1 -b v0.11.0 https://github.com/ngtcp2/nghttp3 && \
+RUN git clone --depth 1 -b v0.12.0 https://github.com/ngtcp2/nghttp3 && \
cd nghttp3 && \
autoreconf -i && \
./configure --enable-lib-only && \
@@ -24,7 +24,7 @@ RUN git clone --depth 1 -b v0.11.0 https://github.com/ngtcp2/nghttp3 && \
cd .. && \
rm -rf nghttp3
-RUN git clone --depth 1 -b v0.15.0 https://github.com/ngtcp2/ngtcp2 && \
+RUN git clone --depth 1 -b v0.16.0 https://github.com/ngtcp2/ngtcp2 && \
cd ngtcp2 && \
autoreconf -i && \
./configure --enable-lib-only \
@@ -36,7 +36,7 @@ RUN git clone --depth 1 -b v0.15.0 https://github.com/ngtcp2/ngtcp2 && \
cd .. && \
rm -rf ngtcp2
-RUN git clone --depth 1 -b v1.1.0 https://github.com/libbpf/libbpf && \
+RUN git clone --depth 1 -b v1.2.0 https://github.com/libbpf/libbpf && \
cd libbpf && \
PREFIX=/usr/local make -C src install && \
cd .. && \
diff --git a/makerelease.sh b/makerelease.sh
index d43a1f6..b65e08f 100755
--- a/makerelease.sh
+++ b/makerelease.sh
@@ -12,9 +12,12 @@ autoreconf -i
./configure --with-mruby && \
make dist-bzip2 && make dist-gzip && make dist-xz || echo "error"
+rm -f checksums.txt
+
VERSION=`echo -n $TAG | sed -E 's|^v([0-9]+\.[0-9]+\.[0-9]+)(-DEV)?$|\1|'`
for f in nghttp2-$VERSION.tar.bz2 nghttp2-$VERSION.tar.gz nghttp2-$VERSION.tar.xz; do
- sha256sum $f > $f.asc
+ sha256sum $f >> checksums.txt
+ gpg --armor --detach-sign $f
done
make distclean
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index afc9e2e..dac18a8 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -72,6 +72,8 @@
# define O_BINARY (0)
#endif // O_BINARY
+using namespace std::chrono_literals;
+
namespace nghttp2 {
namespace {
@@ -194,7 +196,7 @@ void release_fd_cb(struct ev_loop *loop, ev_timer *w, int revents);
} // namespace
namespace {
-constexpr ev_tstamp FILE_ENTRY_MAX_AGE = 10.;
+constexpr auto FILE_ENTRY_MAX_AGE = 10s;
} // namespace
namespace {
@@ -202,13 +204,15 @@ constexpr size_t FILE_ENTRY_EVICT_THRES = 2048;
} // namespace
namespace {
-bool need_validation_file_entry(const FileEntry *ent, ev_tstamp now) {
+bool need_validation_file_entry(
+ const FileEntry *ent, const std::chrono::steady_clock::time_point &now) {
return ent->last_valid + FILE_ENTRY_MAX_AGE < now;
}
} // namespace
namespace {
-bool validate_file_entry(FileEntry *ent, ev_tstamp now) {
+bool validate_file_entry(FileEntry *ent,
+ const std::chrono::steady_clock::time_point &now) {
struct stat stbuf;
int rv;
@@ -335,7 +339,7 @@ public:
return nullptr;
}
- auto now = ev_now(loop_);
+ auto now = std::chrono::steady_clock::now();
for (auto it = range.first; it != range.second;) {
auto &ent = (*it).second;
@@ -1197,7 +1201,7 @@ bool prepare_upload_temp_store(Stream *stream, Http2Handler *hd) {
// now. We will update it when we get whole request body.
auto path = std::string("echo:") + tempfn;
stream->file_ent =
- sessions->cache_fd(path, FileEntry(path, 0, 0, fd, nullptr, 0, true));
+ sessions->cache_fd(path, FileEntry(path, 0, 0, fd, nullptr, {}, true));
stream->echo_upload = true;
return true;
}
@@ -1368,7 +1372,7 @@ void prepare_response(Stream *stream, Http2Handler *hd,
file_ent = sessions->cache_fd(
file_path, FileEntry(file_path, buf.st_size, buf.st_mtime, file,
- content_type, ev_now(sessions->get_loop())));
+ content_type, std::chrono::steady_clock::now()));
}
stream->file_ent = file_ent;
@@ -1891,7 +1895,7 @@ class ListenEventHandler {
public:
ListenEventHandler(Sessions *sessions, int fd,
std::shared_ptr<AcceptHandler> acceptor)
- : acceptor_(acceptor), sessions_(sessions), fd_(fd) {
+ : acceptor_(std::move(acceptor)), sessions_(sessions), fd_(fd) {
ev_io_init(&w_, acceptcb, fd, EV_READ);
w_.data = this;
ev_io_start(sessions_->get_loop(), &w_);
@@ -1969,7 +1973,7 @@ FileEntry make_status_body(int status, uint16_t port) {
assert(0);
}
- return FileEntry(util::utos(status), nwrite, 0, fd, nullptr, 0);
+ return FileEntry(util::utos(status), nwrite, 0, fd, nullptr, {});
}
} // namespace
diff --git a/src/HttpServer.h b/src/HttpServer.h
index cde3479..f825b83 100644
--- a/src/HttpServer.h
+++ b/src/HttpServer.h
@@ -92,7 +92,8 @@ class Http2Handler;
struct FileEntry {
FileEntry(std::string path, int64_t length, int64_t mtime, int fd,
- const std::string *content_type, ev_tstamp last_valid,
+ const std::string *content_type,
+ const std::chrono::steady_clock::time_point &last_valid,
bool stale = false)
: path(std::move(path)),
length(length),
@@ -108,7 +109,7 @@ struct FileEntry {
std::multimap<std::string, std::unique_ptr<FileEntry>>::iterator it;
int64_t length;
int64_t mtime;
- ev_tstamp last_valid;
+ std::chrono::steady_clock::time_point last_valid;
const std::string *content_type;
FileEntry *dlnext, *dlprev;
int fd;
diff --git a/src/h2load.cc b/src/h2load.cc
index 44dff0e..d4c3c69 100644
--- a/src/h2load.cc
+++ b/src/h2load.cc
@@ -344,11 +344,13 @@ void rps_cb(struct ev_loop *loop, ev_timer *w, int revents) {
return;
}
- auto now = ev_now(loop);
+ auto now = std::chrono::steady_clock::now();
auto d = now - client->rps_duration_started;
- auto n = static_cast<size_t>(round(d * config.rps));
+ auto n = static_cast<size_t>(
+ round(std::chrono::duration<double>(d).count() * config.rps));
client->rps_req_pending += n;
- client->rps_duration_started = now - d + static_cast<double>(n) / config.rps;
+ client->rps_duration_started +=
+ util::duration_from(static_cast<double>(n) / config.rps);
if (client->rps_req_pending == 0) {
return;
@@ -425,10 +427,10 @@ void client_request_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
return;
}
- ev_tstamp duration =
+ auto duration =
config.timings[client->reqidx] - config.timings[client->reqidx - 1];
- while (duration < 1e-9) {
+ while (duration < std::chrono::duration<double>(1e-9)) {
if (client->submit_request() != 0) {
ev_timer_stop(client->worker->loop, w);
client->process_request_failure();
@@ -443,7 +445,7 @@ void client_request_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
config.timings[client->reqidx] - config.timings[client->reqidx - 1];
}
- client->request_timeout_watcher.repeat = duration;
+ client->request_timeout_watcher.repeat = util::ev_tstamp_from(duration);
ev_timer_again(client->worker->loop, &client->request_timeout_watcher);
}
} // namespace
@@ -470,7 +472,6 @@ Client::Client(uint32_t id, Worker *worker, size_t req_todo)
local_addr{},
new_connection_requested(false),
final(false),
- rps_duration_started(0),
rps_req_pending(0),
rps_req_inflight(0) {
if (req_todo == 0) { // this means infinite number of requests are to be made
@@ -1178,7 +1179,7 @@ int Client::connection_made() {
if (config.rps_enabled()) {
rps_watcher.repeat = std::max(0.01, 1. / config.rps);
ev_timer_again(worker->loop, &rps_watcher);
- rps_duration_started = ev_now(worker->loop);
+ rps_duration_started = std::chrono::steady_clock::now();
}
if (config.rps_enabled()) {
@@ -1202,9 +1203,9 @@ int Client::connection_made() {
}
} else {
- ev_tstamp duration = config.timings[reqidx];
+ auto duration = config.timings[reqidx];
- while (duration < 1e-9) {
+ while (duration < std::chrono::duration<double>(1e-9)) {
if (submit_request() != 0) {
process_request_failure();
break;
@@ -1217,10 +1218,10 @@ int Client::connection_made() {
}
}
- if (duration >= 1e-9) {
+ if (duration >= std::chrono::duration<double>(1e-9)) {
// double check since we may have break due to reqidx wraps
// around back to 0
- request_timeout_watcher.repeat = duration;
+ request_timeout_watcher.repeat = util::ev_tstamp_from(duration);
ev_timer_again(worker->loop, &request_timeout_watcher);
}
}
@@ -1971,9 +1972,10 @@ std::vector<std::string> read_uri_from_file(std::istream &infile) {
} // namespace
namespace {
-void read_script_from_file(std::istream &infile,
- std::vector<ev_tstamp> &timings,
- std::vector<std::string> &uris) {
+void read_script_from_file(
+ std::istream &infile,
+ std::vector<std::chrono::steady_clock::duration> &timings,
+ std::vector<std::string> &uris) {
std::string script_line;
int line_count = 0;
while (std::getline(infile, script_line)) {
@@ -2006,7 +2008,9 @@ void read_script_from_file(std::istream &infile,
exit(EXIT_FAILURE);
}
- timings.push_back(v / 1000.0);
+ timings.emplace_back(
+ std::chrono::duration_cast<std::chrono::steady_clock::duration>(
+ std::chrono::duration<double, std::milli>(v)));
uris.push_back(script_line.substr(pos + 1, script_line.size()));
}
}
diff --git a/src/h2load.h b/src/h2load.h
index 874cc4d..d848fdf 100644
--- a/src/h2load.h
+++ b/src/h2load.h
@@ -73,7 +73,7 @@ struct Worker;
struct Config {
std::vector<std::vector<nghttp2_nv>> nva;
std::vector<std::string> h1reqs;
- std::vector<ev_tstamp> timings;
+ std::vector<std::chrono::steady_clock::duration> timings;
nghttp2::Headers custom_headers;
std::string scheme;
std::string host;
@@ -396,7 +396,7 @@ struct Client {
ev_timer rps_watcher;
// The timestamp that starts the period which contributes to the
// next request generation.
- ev_tstamp rps_duration_started;
+ std::chrono::steady_clock::time_point rps_duration_started;
// The number of requests allowed by rps, but limited by stream
// concurrency.
size_t rps_req_pending;
@@ -494,8 +494,9 @@ struct Client {
int quic_stream_reset(int64_t stream_id, uint64_t app_error_code);
int quic_stream_stop_sending(int64_t stream_id, uint64_t app_error_code);
int quic_extend_max_local_streams();
+ int quic_extend_max_stream_data(int64_t stream_id);
- int quic_write_client_handshake(ngtcp2_crypto_level level,
+ int quic_write_client_handshake(ngtcp2_encryption_level level,
const uint8_t *data, size_t datalen);
int quic_pkt_timeout();
void quic_restart_pkt_timer();
diff --git a/src/h2load_http3_session.cc b/src/h2load_http3_session.cc
index 4d16ab0..f4779be 100644
--- a/src/h2load_http3_session.cc
+++ b/src/h2load_http3_session.cc
@@ -224,7 +224,7 @@ int stop_sending(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code,
} // namespace
int Http3Session::stop_sending(int64_t stream_id, uint64_t app_error_code) {
- auto rv = ngtcp2_conn_shutdown_stream_read(client_->quic.conn, stream_id,
+ auto rv = ngtcp2_conn_shutdown_stream_read(client_->quic.conn, 0, stream_id,
app_error_code);
if (rv != 0) {
std::cerr << "ngtcp2_conn_shutdown_stream_read: " << ngtcp2_strerror(rv)
@@ -246,7 +246,7 @@ int reset_stream(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code,
} // namespace
int Http3Session::reset_stream(int64_t stream_id, uint64_t app_error_code) {
- auto rv = ngtcp2_conn_shutdown_stream_write(client_->quic.conn, stream_id,
+ auto rv = ngtcp2_conn_shutdown_stream_write(client_->quic.conn, 0, stream_id,
app_error_code);
if (rv != 0) {
std::cerr << "ngtcp2_conn_shutdown_stream_write: " << ngtcp2_strerror(rv)
@@ -420,6 +420,14 @@ void Http3Session::block_stream(int64_t stream_id) {
nghttp3_conn_block_stream(conn_, stream_id);
}
+int Http3Session::unblock_stream(int64_t stream_id) {
+ if (nghttp3_conn_unblock_stream(conn_, stream_id) != 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
void Http3Session::shutdown_stream_write(int64_t stream_id) {
nghttp3_conn_shutdown_stream_write(conn_, stream_id);
}
diff --git a/src/h2load_http3_session.h b/src/h2load_http3_session.h
index 9c3f43f..89c7ca0 100644
--- a/src/h2load_http3_session.h
+++ b/src/h2load_http3_session.h
@@ -64,6 +64,7 @@ public:
ssize_t write_stream(int64_t &stream_id, int &fin, nghttp3_vec *vec,
size_t veccnt);
void block_stream(int64_t stream_id);
+ int unblock_stream(int64_t stream_id);
void shutdown_stream_write(int64_t stream_id);
int add_write_offset(int64_t stream_id, size_t ndatalen);
int add_ack_offset(int64_t stream_id, size_t datalen);
diff --git a/src/h2load_quic.cc b/src/h2load_quic.cc
index 83be0ee..a58a642 100644
--- a/src/h2load_quic.cc
+++ b/src/h2load_quic.cc
@@ -197,6 +197,28 @@ int Client::quic_extend_max_local_streams() {
}
namespace {
+int extend_max_stream_data(ngtcp2_conn *conn, int64_t stream_id,
+ uint64_t max_data, void *user_data,
+ void *stream_user_data) {
+ auto c = static_cast<Client *>(user_data);
+
+ if (c->quic_extend_max_stream_data(stream_id) != 0) {
+ return NGTCP2_ERR_CALLBACK_FAILURE;
+ }
+
+ return 0;
+}
+} // namespace
+
+int Client::quic_extend_max_stream_data(int64_t stream_id) {
+ auto s = static_cast<Http3Session *>(session.get());
+ if (s->unblock_stream(stream_id) != 0) {
+ return -1;
+ }
+ return 0;
+}
+
+namespace {
int get_new_connection_id(ngtcp2_conn *conn, ngtcp2_cid *cid, uint8_t *token,
size_t cidlen, void *user_data) {
if (RAND_bytes(cid->data, cidlen) != 1) {
@@ -238,8 +260,10 @@ int generate_cid(ngtcp2_cid &dest) {
} // namespace
namespace {
-ngtcp2_tstamp timestamp(struct ev_loop *loop) {
- return ev_now(loop) * NGTCP2_SECONDS;
+ngtcp2_tstamp quic_timestamp() {
+ return std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::steady_clock::now().time_since_epoch())
+ .count();
}
} // namespace
@@ -265,8 +289,9 @@ void rand(uint8_t *dest, size_t destlen, const ngtcp2_rand_ctx *rand_ctx) {
} // namespace
namespace {
-int recv_rx_key(ngtcp2_conn *conn, ngtcp2_crypto_level level, void *user_data) {
- if (level != NGTCP2_CRYPTO_LEVEL_APPLICATION) {
+int recv_rx_key(ngtcp2_conn *conn, ngtcp2_encryption_level level,
+ void *user_data) {
+ if (level != NGTCP2_ENCRYPTION_LEVEL_1RTT) {
return 0;
}
@@ -338,7 +363,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
h2load::stream_reset,
nullptr, // extend_max_remote_streams_bidi
nullptr, // extend_max_remote_streams_uni
- nullptr, // extend_max_stream_data
+ h2load::extend_max_stream_data,
nullptr, // dcid_status
nullptr, // handshake_confirmed
nullptr, // recv_new_token
@@ -369,7 +394,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
if (config->verbose) {
settings.log_printf = debug_log_printf;
}
- settings.initial_ts = timestamp(worker->loop);
+ settings.initial_ts = quic_timestamp();
settings.rand_ctx.native_handle = &worker->randgen;
if (!config->qlog_file_base.empty()) {
assert(quic.qlog_file == nullptr);
@@ -384,7 +409,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
std::cerr << "Failed to open a qlog file: " << path << std::endl;
return -1;
}
- settings.qlog.write = qlog_write_cb;
+ settings.qlog_write = qlog_write_cb;
}
if (config->max_udp_payload_size) {
settings.max_tx_udp_payload_size = config->max_udp_payload_size;
@@ -453,7 +478,7 @@ void Client::quic_close_connection() {
auto nwrite = ngtcp2_conn_write_connection_close(
quic.conn, &ps.path, nullptr, buf.data(), buf.size(), &quic.last_error,
- timestamp(worker->loop));
+ quic_timestamp());
if (nwrite <= 0) {
return;
@@ -463,7 +488,7 @@ void Client::quic_close_connection() {
ps.path.remote.addrlen, buf.data(), nwrite, 0);
}
-int Client::quic_write_client_handshake(ngtcp2_crypto_level level,
+int Client::quic_write_client_handshake(ngtcp2_encryption_level level,
const uint8_t *data, size_t datalen) {
int rv;
@@ -492,7 +517,7 @@ void quic_pkt_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
int Client::quic_pkt_timeout() {
int rv;
- auto now = timestamp(worker->loop);
+ auto now = quic_timestamp();
rv = ngtcp2_conn_handle_expiry(quic.conn, now);
if (rv != 0) {
@@ -505,7 +530,7 @@ int Client::quic_pkt_timeout() {
void Client::quic_restart_pkt_timer() {
auto expiry = ngtcp2_conn_get_expiry(quic.conn);
- auto now = timestamp(worker->loop);
+ auto now = quic_timestamp();
auto t = expiry > now ? static_cast<ev_tstamp>(expiry - now) / NGTCP2_SECONDS
: 1e-9;
quic.pkt_timer.repeat = t;
@@ -520,6 +545,8 @@ int Client::read_quic() {
size_t pktcnt = 0;
ngtcp2_pkt_info pi{};
+ auto ts = quic_timestamp();
+
for (;;) {
auto nread =
recvfrom(fd, buf.data(), buf.size(), MSG_DONTWAIT, &su.sa, &addrlen);
@@ -542,8 +569,7 @@ int Client::read_quic() {
},
};
- rv = ngtcp2_conn_read_pkt(quic.conn, &path, &pi, buf.data(), nread,
- timestamp(worker->loop));
+ rv = ngtcp2_conn_read_pkt(quic.conn, &path, &pi, buf.data(), nread, ts);
if (rv != 0) {
std::cerr << "ngtcp2_conn_read_pkt: " << ngtcp2_strerror(rv) << std::endl;
@@ -605,6 +631,7 @@ int Client::write_quic() {
ngtcp2_path_storage_zero(&ps);
auto s = static_cast<Http3Session *>(session.get());
+ auto ts = quic_timestamp();
for (;;) {
int64_t stream_id = -1;
@@ -629,8 +656,7 @@ int Client::write_quic() {
auto nwrite = ngtcp2_conn_writev_stream(
quic.conn, &ps.path, nullptr, bufpos, max_udp_payload_size, &ndatalen,
- flags, stream_id, reinterpret_cast<const ngtcp2_vec *>(v), vcnt,
- timestamp(worker->loop));
+ flags, stream_id, reinterpret_cast<const ngtcp2_vec *>(v), vcnt, ts);
if (nwrite < 0) {
switch (nwrite) {
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
diff --git a/src/nghttp.cc b/src/nghttp.cc
index 61f8212..d4576f3 100644
--- a/src/nghttp.cc
+++ b/src/nghttp.cc
@@ -451,10 +451,9 @@ constexpr llhttp_settings_t htp_hooks = {
namespace {
int submit_request(HttpClient *client, const Headers &headers, Request *req) {
- auto path = req->make_reqpath();
auto scheme = util::get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA);
auto build_headers = Headers{{":method", req->data_prd ? "POST" : "GET"},
- {":path", path},
+ {":path", req->make_reqpath()},
{":scheme", scheme.str()},
{":authority", client->hostport},
{"accept", "*/*"},
diff --git a/src/shrpx.cc b/src/shrpx.cc
index b94e24f..7a410de 100644
--- a/src/shrpx.cc
+++ b/src/shrpx.cc
@@ -210,8 +210,7 @@ struct WorkerProcess {
)
: loop(loop),
worker_pid(worker_pid),
- ipc_fd(ipc_fd),
- termination_deadline(0.)
+ ipc_fd(ipc_fd)
#ifdef ENABLE_HTTP3
,
quic_ipc_fd(quic_ipc_fd),
@@ -243,7 +242,7 @@ struct WorkerProcess {
struct ev_loop *loop;
pid_t worker_pid;
int ipc_fd;
- ev_tstamp termination_deadline;
+ std::chrono::steady_clock::time_point termination_deadline;
#ifdef ENABLE_HTTP3
int quic_ipc_fd;
std::vector<std::array<uint8_t, SHRPX_QUIC_CID_PREFIXLEN>> cid_prefixes;
@@ -265,21 +264,22 @@ ev_timer worker_process_grace_period_timer;
namespace {
void worker_process_grace_period_timercb(struct ev_loop *loop, ev_timer *w,
int revents) {
- auto now = ev_now(loop);
- ev_tstamp next_repeat = 0.;
+ auto now = std::chrono::steady_clock::now();
+ auto next_repeat = std::chrono::steady_clock::duration::zero();
for (auto it = std::begin(worker_processes);
it != std::end(worker_processes);) {
auto &wp = *it;
- if (!(wp->termination_deadline > 0.)) {
+ if (wp->termination_deadline.time_since_epoch().count() == 0) {
++it;
continue;
}
auto d = wp->termination_deadline - now;
- if (d > 0) {
- if (!(next_repeat > 0.) || d < next_repeat) {
+ if (d.count() > 0) {
+ if (next_repeat == std::chrono::steady_clock::duration::zero() ||
+ d < next_repeat) {
next_repeat = d;
}
@@ -294,8 +294,8 @@ void worker_process_grace_period_timercb(struct ev_loop *loop, ev_timer *w,
it = worker_processes.erase(it);
}
- if (next_repeat > 0.) {
- w->repeat = next_repeat;
+ if (next_repeat.count() > 0) {
+ w->repeat = util::ev_tstamp_from(next_repeat);
ev_timer_again(loop, w);
return;
@@ -315,7 +315,8 @@ void worker_process_set_termination_deadline(WorkerProcess *wp,
}
wp->termination_deadline =
- ev_now(loop) + config->worker_process_grace_shutdown_period;
+ std::chrono::steady_clock::now() +
+ util::duration_from(config->worker_process_grace_shutdown_period);
if (!ev_is_active(&worker_process_grace_period_timer)) {
worker_process_grace_period_timer.repeat =
diff --git a/src/shrpx_connect_blocker.cc b/src/shrpx_connect_blocker.cc
index e272d07..ff767b0 100644
--- a/src/shrpx_connect_blocker.cc
+++ b/src/shrpx_connect_blocker.cc
@@ -43,8 +43,8 @@ ConnectBlocker::ConnectBlocker(std::mt19937 &gen, struct ev_loop *loop,
std::function<void()> block_func,
std::function<void()> unblock_func)
: gen_(gen),
- block_func_(block_func),
- unblock_func_(unblock_func),
+ block_func_(std::move(block_func)),
+ unblock_func_(std::move(unblock_func)),
loop_(loop),
fail_count_(0),
offline_(false) {
diff --git a/src/shrpx_connection.cc b/src/shrpx_connection.cc
index 9869e5f..f0a9dc1 100644
--- a/src/shrpx_connection.cc
+++ b/src/shrpx_connection.cc
@@ -41,6 +41,7 @@
#include "ssl_compat.h"
using namespace nghttp2;
+using namespace std::chrono_literals;
namespace shrpx {
@@ -72,9 +73,8 @@ Connection::Connection(struct ev_loop *loop, int fd, SSL *ssl,
data(data),
fd(fd),
tls_dyn_rec_warmup_threshold(tls_dyn_rec_warmup_threshold),
- tls_dyn_rec_idle_timeout(tls_dyn_rec_idle_timeout),
+ tls_dyn_rec_idle_timeout(util::duration_from(tls_dyn_rec_idle_timeout)),
proto(proto),
- last_read(0.),
read_timeout(read_timeout) {
ev_io_init(&wev, writecb, fd, EV_WRITE);
@@ -89,9 +89,6 @@ Connection::Connection(struct ev_loop *loop, int fd, SSL *ssl,
wt.data = this;
rt.data = this;
- // set 0. to double field explicitly just in case
- tls.last_write_idle = 0.;
-
if (ssl) {
set_ssl(ssl);
}
@@ -124,7 +121,7 @@ void Connection::disconnect() {
tls.wbuf.reset();
tls.rbuf.reset();
- tls.last_write_idle = 0.;
+ tls.last_write_idle = {};
tls.warmup_writelen = 0;
tls.last_writelen = 0;
tls.last_readlen = 0;
@@ -881,9 +878,9 @@ size_t Connection::get_tls_write_limit() {
return std::numeric_limits<ssize_t>::max();
}
- auto t = ev_now(loop);
+ auto t = std::chrono::steady_clock::now();
- if (tls.last_write_idle >= 0. &&
+ if (tls.last_write_idle.time_since_epoch().count() >= 0 &&
t - tls.last_write_idle > tls_dyn_rec_idle_timeout) {
// Time out, use small record size
tls.warmup_writelen = 0;
@@ -904,8 +901,8 @@ void Connection::update_tls_warmup_writelen(size_t n) {
}
void Connection::start_tls_write_idle() {
- if (tls.last_write_idle < 0.) {
- tls.last_write_idle = ev_now(loop);
+ if (tls.last_write_idle.time_since_epoch().count() < 0) {
+ tls.last_write_idle = std::chrono::steady_clock::now();
}
}
@@ -927,7 +924,7 @@ ssize_t Connection::write_tls(const void *data, size_t len) {
tls.last_writelen = 0;
}
- tls.last_write_idle = -1.;
+ tls.last_write_idle = std::chrono::steady_clock::time_point(-1s);
auto &tlsconf = get_config()->tls;
auto via_bio =
@@ -1285,17 +1282,18 @@ void Connection::again_rt(ev_tstamp t) {
read_timeout = t;
rt.repeat = t;
ev_timer_again(loop, &rt);
- last_read = ev_now(loop);
+ last_read = std::chrono::steady_clock::now();
}
void Connection::again_rt() {
rt.repeat = read_timeout;
ev_timer_again(loop, &rt);
- last_read = ev_now(loop);
+ last_read = std::chrono::steady_clock::now();
}
bool Connection::expired_rt() {
- auto delta = read_timeout - (ev_now(loop) - last_read);
+ auto delta = read_timeout - util::ev_tstamp_from(
+ std::chrono::steady_clock::now() - last_read);
if (delta < 1e-9) {
return true;
}
diff --git a/src/shrpx_connection.h b/src/shrpx_connection.h
index 22934df..3a45848 100644
--- a/src/shrpx_connection.h
+++ b/src/shrpx_connection.h
@@ -66,7 +66,7 @@ struct TLSConnection {
SSL_SESSION *cached_session;
MemcachedRequest *cached_session_lookup_req;
tls::TLSSessionCache *client_session_cache;
- ev_tstamp last_write_idle;
+ std::chrono::steady_clock::time_point last_write_idle;
size_t warmup_writelen;
// length passed to SSL_write and SSL_read last time. This is
// required since these functions require the exact same parameters
@@ -178,14 +178,14 @@ struct Connection {
void *data;
int fd;
size_t tls_dyn_rec_warmup_threshold;
- ev_tstamp tls_dyn_rec_idle_timeout;
+ std::chrono::steady_clock::duration tls_dyn_rec_idle_timeout;
// Application protocol used over the connection. This field is not
// used in this object at the moment. The rest of the program may
// use this value when it is useful.
Proto proto;
// The point of time when last read is observed. Note: since we use
// |rt| as idle timer, the activity is not limited to read.
- ev_tstamp last_read;
+ std::chrono::steady_clock::time_point last_read;
// Timeout for read timer |rt|.
ev_tstamp read_timeout;
};
diff --git a/src/shrpx_connection_handler.h b/src/shrpx_connection_handler.h
index e89b6d5..f3748ab 100644
--- a/src/shrpx_connection_handler.h
+++ b/src/shrpx_connection_handler.h
@@ -107,8 +107,8 @@ struct SerialEvent {
# ifdef HAVE_LIBBPF
struct BPFRef {
bpf_object *obj;
- int reuseport_array;
- int cid_prefix_map;
+ bpf_map *reuseport_array;
+ bpf_map *cid_prefix_map;
};
# endif // HAVE_LIBBPF
diff --git a/src/shrpx_dns_tracker.cc b/src/shrpx_dns_tracker.cc
index dcc79e5..57387ce 100644
--- a/src/shrpx_dns_tracker.cc
+++ b/src/shrpx_dns_tracker.cc
@@ -71,7 +71,8 @@ ResolverEntry DNSTracker::make_entry(std::unique_ptr<DualDNSResolver> resolv,
switch (status) {
case DNSResolverStatus::ERROR:
case DNSResolverStatus::OK:
- ent.expiry = ev_now(loop_) + dnsconf.timeout.cache;
+ ent.expiry = std::chrono::steady_clock::now() +
+ util::duration_from(dnsconf.timeout.cache);
break;
default:
break;
@@ -92,7 +93,8 @@ void DNSTracker::update_entry(ResolverEntry &ent,
switch (status) {
case DNSResolverStatus::ERROR:
case DNSResolverStatus::OK:
- ent.expiry = ev_now(loop_) + dnsconf.timeout.cache;
+ ent.expiry = std::chrono::steady_clock::now() +
+ util::duration_from(dnsconf.timeout.cache);
break;
default:
break;
@@ -175,7 +177,8 @@ DNSResolverStatus DNSTracker::resolve(Address *result, DNSQuery *dnsq) {
auto &ent = (*it).second;
- if (ent.status != DNSResolverStatus::RUNNING && ent.expiry < ev_now(loop_)) {
+ if (ent.status != DNSResolverStatus::RUNNING &&
+ ent.expiry < std::chrono::steady_clock::now()) {
if (LOG_ENABLED(INFO)) {
LOG(INFO) << "DNS entry found for " << dnsq->host
<< ", but it has been expired";
@@ -252,9 +255,8 @@ DNSResolverStatus DNSTracker::resolve(Address *result, DNSQuery *dnsq) {
}
void DNSTracker::add_to_qlist(ResolverEntry &ent, DNSQuery *dnsq) {
- auto loop = loop_;
ent.resolv->set_complete_cb(
- [&ent, loop](DNSResolverStatus status, const Address *result) {
+ [&ent](DNSResolverStatus status, const Address *result) {
auto &qlist = ent.qlist;
while (!qlist.empty()) {
auto head = qlist.head;
@@ -269,7 +271,8 @@ void DNSTracker::add_to_qlist(ResolverEntry &ent, DNSQuery *dnsq) {
ent.resolv.reset();
ent.status = status;
- ent.expiry = ev_now(loop) + dnsconf.timeout.cache;
+ ent.expiry = std::chrono::steady_clock::now() +
+ util::duration_from(dnsconf.timeout.cache);
if (ent.status == DNSResolverStatus::OK) {
ent.result = *result;
}
@@ -306,7 +309,7 @@ void DNSTracker::gc() {
LOG(INFO) << "Starting removing expired DNS cache entries";
}
- auto now = ev_now(loop_);
+ auto now = std::chrono::steady_clock::now();
for (auto it = std::begin(ents_); it != std::end(ents_);) {
auto &ent = (*it).second;
if (ent.expiry >= now) {
diff --git a/src/shrpx_dns_tracker.h b/src/shrpx_dns_tracker.h
index 87b9f96..c7caac0 100644
--- a/src/shrpx_dns_tracker.h
+++ b/src/shrpx_dns_tracker.h
@@ -28,6 +28,7 @@
#include "shrpx.h"
#include <map>
+#include <chrono>
#include "shrpx_dual_dns_resolver.h"
@@ -70,7 +71,7 @@ struct ResolverEntry {
// result and its expiry time
Address result;
// time point when cached result expires.
- ev_tstamp expiry;
+ std::chrono::steady_clock::time_point expiry;
};
class DNSTracker {
diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc
index f0e9bf0..1700994 100644
--- a/src/shrpx_http2_session.cc
+++ b/src/shrpx_http2_session.cc
@@ -2018,7 +2018,7 @@ int Http2Session::connected() {
}
int Http2Session::read_clear() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<uint8_t, 16_k> buf;
@@ -2040,7 +2040,7 @@ int Http2Session::read_clear() {
}
int Http2Session::write_clear() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<struct iovec, MAX_WR_IOVCNT> iov;
@@ -2081,7 +2081,7 @@ int Http2Session::write_clear() {
}
int Http2Session::tls_handshake() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
ERR_clear_error();
@@ -2120,7 +2120,7 @@ int Http2Session::tls_handshake() {
}
int Http2Session::read_tls() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<uint8_t, 16_k> buf;
@@ -2144,7 +2144,7 @@ int Http2Session::read_tls() {
}
int Http2Session::write_tls() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
ERR_clear_error();
diff --git a/src/shrpx_http3_upstream.cc b/src/shrpx_http3_upstream.cc
index 4895d6e..b01d630 100644
--- a/src/shrpx_http3_upstream.cc
+++ b/src/shrpx_http3_upstream.cc
@@ -532,8 +532,9 @@ int Http3Upstream::send_new_token(const ngtcp2_addr *remote_addr) {
}
namespace {
-int recv_tx_key(ngtcp2_conn *conn, ngtcp2_crypto_level level, void *user_data) {
- if (level != NGTCP2_CRYPTO_LEVEL_APPLICATION) {
+int recv_tx_key(ngtcp2_conn *conn, ngtcp2_encryption_level level,
+ void *user_data) {
+ if (level != NGTCP2_ENCRYPTION_LEVEL_1RTT) {
return 0;
}
@@ -623,8 +624,7 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr,
auto fd = open_qlog_file(quicconf.upstream.qlog.dir, scid);
if (fd != -1) {
qlog_fd_ = fd;
- settings.qlog.odcid = initial_hd.dcid;
- settings.qlog.write = shrpx::qlog_write;
+ settings.qlog_write = shrpx::qlog_write;
}
}
@@ -1511,8 +1511,8 @@ void Http3Upstream::on_handler_delete() {
}
// If this is not idle close, send CONNECTION_CLOSE.
- if (!ngtcp2_conn_is_in_closing_period(conn_) &&
- !ngtcp2_conn_is_in_draining_period(conn_)) {
+ if (!ngtcp2_conn_in_closing_period(conn_) &&
+ !ngtcp2_conn_in_draining_period(conn_)) {
ngtcp2_path_storage ps;
ngtcp2_pkt_info pi;
conn_close_.resize(SHRPX_QUIC_CONN_CLOSE_PKTLEN);
@@ -1926,8 +1926,8 @@ void Http3Upstream::signal_write_upstream_addr(const UpstreamAddr *faddr) {
}
int Http3Upstream::handle_error() {
- if (ngtcp2_conn_is_in_closing_period(conn_) ||
- ngtcp2_conn_is_in_draining_period(conn_)) {
+ if (ngtcp2_conn_in_closing_period(conn_) ||
+ ngtcp2_conn_in_draining_period(conn_)) {
return -1;
}
@@ -2546,7 +2546,8 @@ int http_stop_sending(nghttp3_conn *conn, int64_t stream_id,
int Http3Upstream::http_stop_sending(int64_t stream_id,
uint64_t app_error_code) {
- auto rv = ngtcp2_conn_shutdown_stream_read(conn_, stream_id, app_error_code);
+ auto rv =
+ ngtcp2_conn_shutdown_stream_read(conn_, 0, stream_id, app_error_code);
if (ngtcp2_err_is_fatal(rv)) {
ULOG(ERROR, this) << "ngtcp2_conn_shutdown_stream_read: "
<< ngtcp2_strerror(rv);
@@ -2572,7 +2573,8 @@ int http_reset_stream(nghttp3_conn *conn, int64_t stream_id,
int Http3Upstream::http_reset_stream(int64_t stream_id,
uint64_t app_error_code) {
- auto rv = ngtcp2_conn_shutdown_stream_write(conn_, stream_id, app_error_code);
+ auto rv =
+ ngtcp2_conn_shutdown_stream_write(conn_, 0, stream_id, app_error_code);
if (ngtcp2_err_is_fatal(rv)) {
ULOG(ERROR, this) << "ngtcp2_conn_shutdown_stream_write: "
<< ngtcp2_strerror(rv);
@@ -2725,7 +2727,7 @@ int Http3Upstream::shutdown_stream(Downstream *downstream,
<< " with app_error_code=" << app_error_code;
}
- auto rv = ngtcp2_conn_shutdown_stream(conn_, stream_id, app_error_code);
+ auto rv = ngtcp2_conn_shutdown_stream(conn_, 0, stream_id, app_error_code);
if (rv != 0) {
ULOG(FATAL, this) << "ngtcp2_conn_shutdown_stream() failed: "
<< ngtcp2_strerror(rv);
@@ -2737,8 +2739,8 @@ int Http3Upstream::shutdown_stream(Downstream *downstream,
int Http3Upstream::shutdown_stream_read(int64_t stream_id,
uint64_t app_error_code) {
- auto rv =
- ngtcp2_conn_shutdown_stream_read(conn_, stream_id, NGHTTP3_H3_NO_ERROR);
+ auto rv = ngtcp2_conn_shutdown_stream_read(conn_, 0, stream_id,
+ NGHTTP3_H3_NO_ERROR);
if (ngtcp2_err_is_fatal(rv)) {
ULOG(FATAL, this) << "ngtcp2_conn_shutdown_stream_read: "
<< ngtcp2_strerror(rv);
diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc
index 96ce4b2..e464471 100644
--- a/src/shrpx_http_downstream_connection.cc
+++ b/src/shrpx_http_downstream_connection.cc
@@ -450,7 +450,7 @@ int HttpDownstreamConnection::initiate_connection() {
ev_set_cb(&conn_.rt, timeoutcb);
if (conn_.read_timeout < group_->shared_addr->timeout.read) {
conn_.read_timeout = group_->shared_addr->timeout.read;
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
} else {
conn_.again_rt(group_->shared_addr->timeout.read);
}
@@ -875,7 +875,7 @@ void HttpDownstreamConnection::detach_downstream(Downstream *downstream) {
ev_set_cb(&conn_.rt, idle_timeoutcb);
if (conn_.read_timeout < downstreamconf.timeout.idle_read) {
conn_.read_timeout = downstreamconf.timeout.idle_read;
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
} else {
conn_.again_rt(downstreamconf.timeout.idle_read);
}
@@ -1231,7 +1231,7 @@ int HttpDownstreamConnection::write_first() {
}
int HttpDownstreamConnection::read_clear() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<uint8_t, 16_k> buf;
int rv;
@@ -1270,7 +1270,7 @@ int HttpDownstreamConnection::read_clear() {
}
int HttpDownstreamConnection::write_clear() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
auto upstream = downstream_->get_upstream();
auto input = downstream_->get_request_buf();
@@ -1318,7 +1318,7 @@ int HttpDownstreamConnection::write_clear() {
int HttpDownstreamConnection::tls_handshake() {
ERR_clear_error();
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
auto rv = conn_.tls_handshake();
if (rv == SHRPX_ERR_INPROGRESS) {
@@ -1360,7 +1360,7 @@ int HttpDownstreamConnection::tls_handshake() {
}
int HttpDownstreamConnection::read_tls() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
ERR_clear_error();
@@ -1401,7 +1401,7 @@ int HttpDownstreamConnection::read_tls() {
}
int HttpDownstreamConnection::write_tls() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
ERR_clear_error();
diff --git a/src/shrpx_live_check.cc b/src/shrpx_live_check.cc
index a81e992..5d1057c 100644
--- a/src/shrpx_live_check.cc
+++ b/src/shrpx_live_check.cc
@@ -377,7 +377,7 @@ int LiveCheck::connected() {
}
int LiveCheck::tls_handshake() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
ERR_clear_error();
@@ -446,7 +446,7 @@ int LiveCheck::tls_handshake() {
}
int LiveCheck::read_tls() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<uint8_t, 4_k> buf;
@@ -470,7 +470,7 @@ int LiveCheck::read_tls() {
}
int LiveCheck::write_tls() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
ERR_clear_error();
@@ -519,7 +519,7 @@ int LiveCheck::write_tls() {
}
int LiveCheck::read_clear() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<uint8_t, 4_k> buf;
@@ -541,7 +541,7 @@ int LiveCheck::read_clear() {
}
int LiveCheck::write_clear() {
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
struct iovec iov;
diff --git a/src/shrpx_memcached_connection.cc b/src/shrpx_memcached_connection.cc
index 8d33d82..f72cb11 100644
--- a/src/shrpx_memcached_connection.cc
+++ b/src/shrpx_memcached_connection.cc
@@ -259,7 +259,7 @@ int MemcachedConnection::on_read() { return do_read_(*this); }
int MemcachedConnection::tls_handshake() {
ERR_clear_error();
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
auto rv = conn_.tls_handshake();
if (rv == SHRPX_ERR_INPROGRESS) {
@@ -301,7 +301,7 @@ int MemcachedConnection::write_tls() {
return 0;
}
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<struct iovec, MAX_WR_IOVCNT> iov;
std::array<uint8_t, 16_k> buf;
@@ -340,7 +340,7 @@ int MemcachedConnection::read_tls() {
return 0;
}
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
for (;;) {
auto nread = conn_.read_tls(recvbuf_.last, recvbuf_.wleft());
@@ -368,7 +368,7 @@ int MemcachedConnection::write_clear() {
return 0;
}
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
std::array<struct iovec, MAX_WR_IOVCNT> iov;
@@ -396,7 +396,7 @@ int MemcachedConnection::read_clear() {
return 0;
}
- conn_.last_read = ev_now(conn_.loop);
+ conn_.last_read = std::chrono::steady_clock::now();
for (;;) {
auto nread = conn_.read_clear(recvbuf_.last, recvbuf_.wleft());
diff --git a/src/shrpx_tls.cc b/src/shrpx_tls.cc
index 4134e04..43930d1 100644
--- a/src/shrpx_tls.cc
+++ b/src/shrpx_tls.cc
@@ -90,6 +90,7 @@
#include "timegm.h"
using namespace nghttp2;
+using namespace std::chrono_literals;
namespace shrpx {
@@ -383,7 +384,7 @@ int tls_session_client_new_cb(SSL *ssl, SSL_SESSION *session) {
}
try_cache_tls_session(conn->tls.client_session_cache, session,
- ev_now(conn->loop));
+ std::chrono::steady_clock::now());
return 0;
}
@@ -2427,8 +2428,8 @@ std::vector<uint8_t> serialize_ssl_session(SSL_SESSION *session) {
} // namespace
void try_cache_tls_session(TLSSessionCache *cache, SSL_SESSION *session,
- ev_tstamp t) {
- if (cache->last_updated + 1_min > t) {
+ const std::chrono::steady_clock::time_point &t) {
+ if (cache->last_updated + 1min > t) {
if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Client session cache entry is still fresh.";
}
@@ -2437,7 +2438,7 @@ void try_cache_tls_session(TLSSessionCache *cache, SSL_SESSION *session,
if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Update client cache entry "
- << "timestamp = " << t;
+ << "timestamp = " << t.time_since_epoch().count();
}
cache->session_data = serialize_ssl_session(session);
@@ -2598,13 +2599,6 @@ StringRef get_x509_issuer_name(BlockAllocator &balloc, X509 *x) {
return get_x509_name(balloc, X509_get_issuer_name(x));
}
-#ifdef WORDS_BIGENDIAN
-# define bswap64(N) (N)
-#else /* !WORDS_BIGENDIAN */
-# define bswap64(N) \
- ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
-#endif /* !WORDS_BIGENDIAN */
-
StringRef get_x509_serial(BlockAllocator &balloc, X509 *x) {
auto sn = X509_get_serialNumber(x);
auto bn = BN_new();
diff --git a/src/shrpx_tls.h b/src/shrpx_tls.h
index 25c2424..00265d5 100644
--- a/src/shrpx_tls.h
+++ b/src/shrpx_tls.h
@@ -58,7 +58,7 @@ struct TLSSessionCache {
// i2d_SSL_SESSION(3SSL).
std::vector<uint8_t> session_data;
// The last time stamp when this cache entry is created or updated.
- ev_tstamp last_updated;
+ std::chrono::steady_clock::time_point last_updated;
};
// This struct stores the additional information per SSL_CTX. This is
@@ -283,7 +283,7 @@ bool tls_hostname_match(const StringRef &pattern, const StringRef &hostname);
// Depending on the existing cache's time stamp, |session| might not
// be cached.
void try_cache_tls_session(TLSSessionCache *cache, SSL_SESSION *session,
- ev_tstamp t);
+ const std::chrono::steady_clock::time_point &t);
// Returns cached session associated |addr|. If no cache entry is
// found associated to |addr|, nullptr will be returned.
diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc
index d7bddda..4756322 100644
--- a/src/shrpx_worker.cc
+++ b/src/shrpx_worker.cc
@@ -919,8 +919,9 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
rv = bpf_object__load(obj);
if (rv != 0) {
+ auto error = errno;
LOG(FATAL) << "Failed to load bpf object file: "
- << xsi_strerror(-rv, errbuf.data(), errbuf.size());
+ << xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
return -1;
}
@@ -938,9 +939,9 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
ref.obj = obj;
- auto reuseport_array =
+ ref.reuseport_array =
bpf_object__find_map_by_name(obj, "reuseport_array");
- if (!reuseport_array) {
+ if (!ref.reuseport_array) {
auto error = errno;
LOG(FATAL) << "Failed to get reuseport_array: "
<< xsi_strerror(error, errbuf.data(), errbuf.size());
@@ -948,10 +949,8 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
return -1;
}
- ref.reuseport_array = bpf_map__fd(reuseport_array);
-
- auto cid_prefix_map = bpf_object__find_map_by_name(obj, "cid_prefix_map");
- if (!cid_prefix_map) {
+ ref.cid_prefix_map = bpf_object__find_map_by_name(obj, "cid_prefix_map");
+ if (!ref.cid_prefix_map) {
auto error = errno;
LOG(FATAL) << "Failed to get cid_prefix_map: "
<< xsi_strerror(error, errbuf.data(), errbuf.size());
@@ -959,8 +958,6 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
return -1;
}
- ref.cid_prefix_map = bpf_map__fd(cid_prefix_map);
-
auto sk_info = bpf_object__find_map_by_name(obj, "sk_info");
if (!sk_info) {
auto error = errno;
@@ -973,11 +970,12 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
constexpr uint32_t zero = 0;
uint64_t num_socks = config->num_worker;
- rv =
- bpf_map_update_elem(bpf_map__fd(sk_info), &zero, &num_socks, BPF_ANY);
+ rv = bpf_map__update_elem(sk_info, &zero, sizeof(zero), &num_socks,
+ sizeof(num_socks), BPF_ANY);
if (rv != 0) {
+ auto error = errno;
LOG(FATAL) << "Failed to update sk_info: "
- << xsi_strerror(-rv, errbuf.data(), errbuf.size());
+ << xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
return -1;
}
@@ -988,20 +986,25 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
auto &qkms = conn_handler_->get_quic_keying_materials();
auto &qkm = qkms->keying_materials.front();
- rv = bpf_map_update_elem(bpf_map__fd(sk_info), &key_high_idx,
- qkm.cid_encryption_key.data(), BPF_ANY);
+ rv = bpf_map__update_elem(sk_info, &key_high_idx, sizeof(key_high_idx),
+ qkm.cid_encryption_key.data(),
+ qkm.cid_encryption_key.size() / 2, BPF_ANY);
if (rv != 0) {
+ auto error = errno;
LOG(FATAL) << "Failed to update key_high_idx sk_info: "
- << xsi_strerror(-rv, errbuf.data(), errbuf.size());
+ << xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
return -1;
}
- rv = bpf_map_update_elem(bpf_map__fd(sk_info), &key_low_idx,
- qkm.cid_encryption_key.data() + 8, BPF_ANY);
+ rv = bpf_map__update_elem(sk_info, &key_low_idx, sizeof(key_low_idx),
+ qkm.cid_encryption_key.data() +
+ qkm.cid_encryption_key.size() / 2,
+ qkm.cid_encryption_key.size() / 2, BPF_ANY);
if (rv != 0) {
+ auto error = errno;
LOG(FATAL) << "Failed to update key_low_idx sk_info: "
- << xsi_strerror(-rv, errbuf.data(), errbuf.size());
+ << xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
return -1;
}
@@ -1021,20 +1024,23 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
const auto &ref = quic_bpf_refs[faddr.index];
auto sk_index = compute_sk_index();
- rv =
- bpf_map_update_elem(ref.reuseport_array, &sk_index, &fd, BPF_NOEXIST);
+ rv = bpf_map__update_elem(ref.reuseport_array, &sk_index,
+ sizeof(sk_index), &fd, sizeof(fd), BPF_NOEXIST);
if (rv != 0) {
+ auto error = errno;
LOG(FATAL) << "Failed to update reuseport_array: "
- << xsi_strerror(-rv, errbuf.data(), errbuf.size());
+ << xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
return -1;
}
- rv = bpf_map_update_elem(ref.cid_prefix_map, cid_prefix_.data(),
- &sk_index, BPF_NOEXIST);
+ rv = bpf_map__update_elem(ref.cid_prefix_map, cid_prefix_.data(),
+ cid_prefix_.size(), &sk_index, sizeof(sk_index),
+ BPF_NOEXIST);
if (rv != 0) {
+ auto error = errno;
LOG(FATAL) << "Failed to update cid_prefix_map: "
- << xsi_strerror(-rv, errbuf.data(), errbuf.size());
+ << xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
return -1;
}
diff --git a/src/util.h b/src/util.h
index 9c4de21..6b45922 100644
--- a/src/util.h
+++ b/src/util.h
@@ -47,6 +47,8 @@
#include <map>
#include <random>
+#include <ev.h>
+
#include "url-parser/url_parser.h"
#include "template.h"
@@ -695,6 +697,15 @@ template <typename Clock, typename Rep> Rep clock_precision() {
return duration.count();
}
+template <typename Duration = std::chrono::steady_clock::duration>
+Duration duration_from(ev_tstamp d) {
+ return std::chrono::duration_cast<Duration>(std::chrono::duration<double>(d));
+}
+
+template <typename Duration> ev_tstamp ev_tstamp_from(const Duration &d) {
+ return std::chrono::duration<double>(d).count();
+}
+
int make_socket_closeonexec(int fd);
int make_socket_nonblocking(int fd);
int make_socket_nodelay(int fd);