From 25d3323c8a9f00fe4cf03269d52a96ab1b5421ec Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 20 Feb 2021 17:31:52 +0900 Subject: [PATCH] Support both h3 and h3-29 ALPN and their corresponding QUIC versions --- README.rst | 6 +++--- src/h2load.cc | 6 ++++-- src/h2load_quic.cc | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 90faa40d..0ecfb529 100644 --- a/README.rst +++ b/README.rst @@ -24,12 +24,12 @@ ngtcp2, nghttp3 and my patched OpenSSL. https://github.com/ngtcp2/ngtcp2#build-from-git describes how to build these three software. -To run h2load against HTTP/3 server, specify h3-29 ALPN with +To run h2load against HTTP/3 server, specify h3 or h3-29 ALPN with ``--npn-list`` option like so: .. code-block:: text - $ h2load --npn-list h3-29 https://127.0.0.1:4433 + $ h2load --npn-list h3 https://127.0.0.1:4433 You can use Dockerfile to skip the tedious build steps to manually pull and build dependencies. In order to build Docker image, do this: @@ -43,7 +43,7 @@ Run h2load: .. code-block:: text - $ docker run --rm -it --network=host nghttp2-quic /usr/local/bin/h2load --npn-list h3-29 https://127.0.0.1:4433 + $ docker run --rm -it --network=host nghttp2-quic /usr/local/bin/h2load --npn-list h3 https://127.0.0.1:4433 Development Status ------------------ diff --git a/src/h2load.cc b/src/h2load.cc index a51b2372..fca66a9e 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -138,7 +138,8 @@ bool Config::is_timing_based_mode() const { return (this->duration > 0); } bool Config::has_base_uri() const { return (!this->base_uri.empty()); } bool Config::rps_enabled() const { return this->rps > 0.0; } bool Config::is_quic() const { - return !npn_list.empty() && npn_list[0] == NGHTTP3_ALPN_H3; + return !npn_list.empty() && + (npn_list[0] == NGHTTP3_ALPN_H3 || npn_list[0] == "\x5h3-29"); } Config config; @@ -1042,7 +1043,8 @@ int Client::connection_made() { auto proto = StringRef{next_proto, next_proto_len}; if (config.is_quic()) { assert(session); - if (!util::streq(StringRef{&NGHTTP3_ALPN_H3[1]}, proto)) { + if (!util::streq(StringRef{&NGHTTP3_ALPN_H3[1]}, proto) && + !util::streq_l("h3-29", proto)) { return -1; } } else if (util::check_h2_is_selected(proto)) { diff --git a/src/h2load_quic.cc b/src/h2load_quic.cc index b52b8abc..31a576c8 100644 --- a/src/h2load_quic.cc +++ b/src/h2load_quic.cc @@ -370,9 +370,18 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen, {remote_addrlen, const_cast(remote_addr)}, }; - rv = ngtcp2_conn_client_new(&quic.conn, &dcid, &scid, &path, - NGTCP2_PROTO_VER_MIN, &callbacks, &settings, - ¶ms, nullptr, this); + assert(config->npn_list.size()); + + uint32_t quic_version; + + if (config->npn_list[0] == NGHTTP3_ALPN_H3) { + quic_version = NGTCP2_PROTO_VER_V1; + } else { + quic_version = NGTCP2_PROTO_VER_MIN; + } + + rv = ngtcp2_conn_client_new(&quic.conn, &dcid, &scid, &path, quic_version, + &callbacks, &settings, ¶ms, nullptr, this); if (rv != 0) { return -1; }