Commit c4828dbd authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

h2load: Fix assertion failure with the latest ngtcp2

parent 0d16db2c
...@@ -1516,7 +1516,8 @@ int get_ev_loop_flags() { ...@@ -1516,7 +1516,8 @@ int get_ev_loop_flags() {
Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients,
size_t rate, size_t max_samples, Config *config) size_t rate, size_t max_samples, Config *config)
: stats(req_todo, nclients), : randgen(util::make_mt19937()),
stats(req_todo, nclients),
loop(ev_loop_new(get_ev_loop_flags())), loop(ev_loop_new(get_ev_loop_flags())),
ssl_ctx(ssl_ctx), ssl_ctx(ssl_ctx),
config(config), config(config),
......
...@@ -269,6 +269,7 @@ struct Sampling { ...@@ -269,6 +269,7 @@ struct Sampling {
struct Worker { struct Worker {
MemchunkPool mcpool; MemchunkPool mcpool;
std::mt19937 randgen;
Stats stats; Stats stats;
Sampling request_times_smp; Sampling request_times_smp;
Sampling client_smp; Sampling client_smp;
......
...@@ -36,15 +36,12 @@ ...@@ -36,15 +36,12 @@
#endif // HAVE_LIBNGTCP2_CRYPTO_BORINGSSL #endif // HAVE_LIBNGTCP2_CRYPTO_BORINGSSL
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/rand.h>
#include "h2load_http3_session.h" #include "h2load_http3_session.h"
namespace h2load { namespace h2load {
namespace {
auto randgen = util::make_mt19937();
} // namespace
namespace { namespace {
int handshake_completed(ngtcp2_conn *conn, void *user_data) { int handshake_completed(ngtcp2_conn *conn, void *user_data) {
auto c = static_cast<Client *>(user_data); auto c = static_cast<Client *>(user_data);
...@@ -202,13 +199,15 @@ int Client::quic_extend_max_local_streams() { ...@@ -202,13 +199,15 @@ int Client::quic_extend_max_local_streams() {
namespace { namespace {
int get_new_connection_id(ngtcp2_conn *conn, ngtcp2_cid *cid, uint8_t *token, int get_new_connection_id(ngtcp2_conn *conn, ngtcp2_cid *cid, uint8_t *token,
size_t cidlen, void *user_data) { size_t cidlen, void *user_data) {
auto dis = std::uniform_int_distribution<uint8_t>( if (RAND_bytes(cid->data, cidlen) != 1) {
0, std::numeric_limits<uint8_t>::max()); return NGTCP2_ERR_CALLBACK_FAILURE;
auto f = [&dis]() { return dis(randgen); }; }
std::generate_n(cid->data, cidlen, f);
cid->datalen = cidlen; cid->datalen = cidlen;
std::generate_n(token, NGTCP2_STATELESS_RESET_TOKENLEN, f);
if (RAND_bytes(token, NGTCP2_STATELESS_RESET_TOKENLEN) != 1) {
return NGTCP2_ERR_CALLBACK_FAILURE;
}
return 0; return 0;
} }
...@@ -227,11 +226,14 @@ void debug_log_printf(void *user_data, const char *fmt, ...) { ...@@ -227,11 +226,14 @@ void debug_log_printf(void *user_data, const char *fmt, ...) {
} // namespace } // namespace
namespace { namespace {
void generate_cid(ngtcp2_cid &dest) { int generate_cid(ngtcp2_cid &dest) {
auto dis = std::uniform_int_distribution<uint8_t>(
0, std::numeric_limits<uint8_t>::max());
dest.datalen = 8; dest.datalen = 8;
std::generate_n(dest.data, dest.datalen, [&dis]() { return dis(randgen); });
if (RAND_bytes(dest.data, dest.datalen) != 1) {
return -1;
}
return 0;
} }
} // namespace } // namespace
...@@ -370,6 +372,13 @@ void Client::quic_write_qlog(const void *data, size_t datalen) { ...@@ -370,6 +372,13 @@ void Client::quic_write_qlog(const void *data, size_t datalen) {
fwrite(data, 1, datalen, quic.qlog_file); fwrite(data, 1, datalen, quic.qlog_file);
} }
namespace {
void rand(uint8_t *dest, size_t destlen, const ngtcp2_rand_ctx *rand_ctx) {
util::random_bytes(dest, dest + destlen,
*static_cast<std::mt19937 *>(rand_ctx->native_handle));
}
} // namespace
int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen, int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
const sockaddr *remote_addr, socklen_t remote_addrlen) { const sockaddr *remote_addr, socklen_t remote_addrlen) {
int rv; int rv;
...@@ -400,7 +409,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen, ...@@ -400,7 +409,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
ngtcp2_crypto_recv_retry_cb, ngtcp2_crypto_recv_retry_cb,
h2load::extend_max_local_streams_bidi, h2load::extend_max_local_streams_bidi,
nullptr, // extend_max_local_streams_uni nullptr, // extend_max_local_streams_uni
nullptr, // rand h2load::rand,
get_new_connection_id, get_new_connection_id,
nullptr, // remove_connection_id nullptr, // remove_connection_id
ngtcp2_crypto_update_key_cb, ngtcp2_crypto_update_key_cb,
...@@ -418,13 +427,17 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen, ...@@ -418,13 +427,17 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
nullptr, // recv_datagram nullptr, // recv_datagram
nullptr, // ack_datagram nullptr, // ack_datagram
nullptr, // lost_datagram nullptr, // lost_datagram
nullptr, // get_path_challenge_data ngtcp2_crypto_get_path_challenge_data_cb,
h2load::stream_stop_sending, h2load::stream_stop_sending,
}; };
ngtcp2_cid scid, dcid; ngtcp2_cid scid, dcid;
generate_cid(scid); if (generate_cid(scid) != 0) {
generate_cid(dcid); return -1;
}
if (generate_cid(dcid) != 0) {
return -1;
}
auto config = worker->config; auto config = worker->config;
...@@ -434,6 +447,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen, ...@@ -434,6 +447,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
settings.log_printf = debug_log_printf; settings.log_printf = debug_log_printf;
} }
settings.initial_ts = timestamp(worker->loop); settings.initial_ts = timestamp(worker->loop);
settings.rand_ctx.native_handle = &worker->randgen;
if (!config->qlog_file_base.empty()) { if (!config->qlog_file_base.empty()) {
assert(quic.qlog_file == nullptr); assert(quic.qlog_file == nullptr);
auto path = config->qlog_file_base; auto path = config->qlog_file_base;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment