draft-28
This commit is contained in:
parent
39e6588fd5
commit
0b98685c41
|
@ -136,7 +136,7 @@ bool Config::is_timing_based_mode() const { return (this->duration > 0); }
|
||||||
bool Config::has_base_uri() const { return (!this->base_uri.empty()); }
|
bool Config::has_base_uri() const { return (!this->base_uri.empty()); }
|
||||||
bool Config::rps_enabled() const { return this->rps > 0.0; }
|
bool Config::rps_enabled() const { return this->rps > 0.0; }
|
||||||
bool Config::is_quic() const {
|
bool Config::is_quic() const {
|
||||||
return !npn_list.empty() && npn_list[0] == NGTCP2_ALPN_H3;
|
return !npn_list.empty() && npn_list[0] == NGHTTP3_ALPN_H3;
|
||||||
}
|
}
|
||||||
Config config;
|
Config config;
|
||||||
|
|
||||||
|
@ -1038,7 +1038,7 @@ int Client::connection_made() {
|
||||||
auto proto = StringRef{next_proto, next_proto_len};
|
auto proto = StringRef{next_proto, next_proto_len};
|
||||||
if (config.is_quic()) {
|
if (config.is_quic()) {
|
||||||
assert(session);
|
assert(session);
|
||||||
if (!util::streq(StringRef{&NGTCP2_ALPN_H3[1]}, proto)) {
|
if (!util::streq(StringRef{&NGHTTP3_ALPN_H3[1]}, proto)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (util::check_h2_is_selected(proto)) {
|
} else if (util::check_h2_is_selected(proto)) {
|
||||||
|
|
|
@ -454,7 +454,6 @@ struct Client {
|
||||||
int write_udp(const sockaddr *addr, socklen_t addrlen, const uint8_t *data,
|
int write_udp(const sockaddr *addr, socklen_t addrlen, const uint8_t *data,
|
||||||
size_t datalen);
|
size_t datalen);
|
||||||
void quic_close_connection();
|
void quic_close_connection();
|
||||||
int quic_setup_initial_crypto();
|
|
||||||
|
|
||||||
int quic_recv_crypto_data(ngtcp2_crypto_level crypto_level,
|
int quic_recv_crypto_data(ngtcp2_crypto_level crypto_level,
|
||||||
const uint8_t *data, size_t datalen);
|
const uint8_t *data, size_t datalen);
|
||||||
|
|
|
@ -36,18 +36,6 @@ namespace {
|
||||||
auto randgen = util::make_mt19937();
|
auto randgen = util::make_mt19937();
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
|
||||||
int client_initial(ngtcp2_conn *conn, void *user_data) {
|
|
||||||
auto c = static_cast<Client *>(user_data);
|
|
||||||
|
|
||||||
if (c->quic_recv_crypto_data(NGTCP2_CRYPTO_LEVEL_INITIAL, nullptr, 0) != 0) {
|
|
||||||
return NGTCP2_ERR_CALLBACK_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int recv_crypto_data(ngtcp2_conn *conn, ngtcp2_crypto_level crypto_level,
|
int recv_crypto_data(ngtcp2_conn *conn, ngtcp2_crypto_level crypto_level,
|
||||||
uint64_t offset, const uint8_t *data, size_t datalen,
|
uint64_t offset, const uint8_t *data, size_t datalen,
|
||||||
|
@ -82,21 +70,6 @@ int handshake_completed(ngtcp2_conn *conn, void *user_data) {
|
||||||
|
|
||||||
int Client::quic_handshake_completed() { return connection_made(); }
|
int Client::quic_handshake_completed() { return connection_made(); }
|
||||||
|
|
||||||
namespace {
|
|
||||||
int recv_retry(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd,
|
|
||||||
const ngtcp2_pkt_retry *retry, void *user_data) {
|
|
||||||
// Re-generate handshake secrets here because connection ID might
|
|
||||||
// change.
|
|
||||||
auto c = static_cast<Client *>(user_data);
|
|
||||||
|
|
||||||
if (c->quic_setup_initial_crypto() != 0) {
|
|
||||||
return NGTCP2_ERR_CALLBACK_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int recv_stream_data(ngtcp2_conn *conn, int64_t stream_id, int fin,
|
int recv_stream_data(ngtcp2_conn *conn, int64_t stream_id, int fin,
|
||||||
uint64_t offset, const uint8_t *data, size_t datalen,
|
uint64_t offset, const uint8_t *data, size_t datalen,
|
||||||
|
@ -346,7 +319,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto callbacks = ngtcp2_conn_callbacks{
|
auto callbacks = ngtcp2_conn_callbacks{
|
||||||
h2load::client_initial,
|
ngtcp2_crypto_client_initial_cb,
|
||||||
nullptr, // recv_client_initial
|
nullptr, // recv_client_initial
|
||||||
h2load::recv_crypto_data,
|
h2load::recv_crypto_data,
|
||||||
h2load::handshake_completed,
|
h2load::handshake_completed,
|
||||||
|
@ -360,7 +333,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
|
||||||
nullptr, // stream_open
|
nullptr, // stream_open
|
||||||
h2load::stream_close,
|
h2load::stream_close,
|
||||||
nullptr, // recv_stateless_reset
|
nullptr, // recv_stateless_reset
|
||||||
h2load::recv_retry,
|
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
|
nullptr, // rand
|
||||||
|
@ -394,6 +367,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
|
||||||
params.initial_max_streams_bidi = 0;
|
params.initial_max_streams_bidi = 0;
|
||||||
params.initial_max_streams_uni = 100;
|
params.initial_max_streams_uni = 100;
|
||||||
params.max_idle_timeout = 30 * NGTCP2_SECONDS;
|
params.max_idle_timeout = 30 * NGTCP2_SECONDS;
|
||||||
|
params.max_udp_payload_size = quic.max_pktlen;
|
||||||
|
|
||||||
auto path = ngtcp2_path{
|
auto path = ngtcp2_path{
|
||||||
{local_addrlen,
|
{local_addrlen,
|
||||||
|
@ -408,28 +382,7 @@ int Client::quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<uint8_t, 64> buf;
|
ngtcp2_conn_set_tls(quic.conn, ssl);
|
||||||
|
|
||||||
auto nwrite = ngtcp2_encode_transport_params(
|
|
||||||
buf.data(), buf.size(), NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO,
|
|
||||||
¶ms);
|
|
||||||
if (nwrite < 0) {
|
|
||||||
std::cerr << "ngtcp2_encode_transport_params: " << ngtcp2_strerror(nwrite)
|
|
||||||
<< std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SSL_set_quic_transport_params(ssl, buf.data(), nwrite) != 1) {
|
|
||||||
std::cerr << "SSL_set_quic_transport_params failed" << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = quic_setup_initial_crypto();
|
|
||||||
if (rv != 0) {
|
|
||||||
ngtcp2_conn_del(quic.conn);
|
|
||||||
quic.conn = nullptr;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -471,24 +424,9 @@ void Client::quic_close_connection() {
|
||||||
ps.path.remote.addrlen, buf.data(), nwrite);
|
ps.path.remote.addrlen, buf.data(), nwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Client::quic_setup_initial_crypto() {
|
|
||||||
auto dcid = ngtcp2_conn_get_dcid(quic.conn);
|
|
||||||
|
|
||||||
if (ngtcp2_crypto_derive_and_install_initial_key(
|
|
||||||
quic.conn, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
|
||||||
nullptr, nullptr, nullptr, dcid) != 0) {
|
|
||||||
std::cerr << "ngtcp2_crypto_derive_and_install_initial_key() failed"
|
|
||||||
<< std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Client::quic_on_key(ngtcp2_crypto_level level, const uint8_t *rx_secret,
|
int Client::quic_on_key(ngtcp2_crypto_level level, const uint8_t *rx_secret,
|
||||||
const uint8_t *tx_secret, size_t secretlen) {
|
const uint8_t *tx_secret, size_t secretlen) {
|
||||||
if (level != NGTCP2_CRYPTO_LEVEL_EARLY &&
|
if (ngtcp2_crypto_derive_and_install_rx_key(quic.conn, ssl, nullptr, nullptr,
|
||||||
ngtcp2_crypto_derive_and_install_rx_key(quic.conn, ssl, nullptr, nullptr,
|
|
||||||
nullptr, level, rx_secret,
|
nullptr, level, rx_secret,
|
||||||
secretlen) != 0) {
|
secretlen) != 0) {
|
||||||
std::cerr << "ngtcp2_crypto_derive_and_install_rx_key() failed"
|
std::cerr << "ngtcp2_crypto_derive_and_install_rx_key() failed"
|
||||||
|
|
Loading…
Reference in New Issue