nghttpx: Utilize the latest ngtcp2 features
This commit is contained in:
parent
0566a5833b
commit
95601d3179
|
@ -507,7 +507,8 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr,
|
||||||
settings.cc_algo = NGTCP2_CC_ALGO_BBR;
|
settings.cc_algo = NGTCP2_CC_ALGO_BBR;
|
||||||
settings.max_window = http3conf.upstream.max_connection_window_size;
|
settings.max_window = http3conf.upstream.max_connection_window_size;
|
||||||
settings.max_stream_window = http3conf.upstream.max_window_size;
|
settings.max_stream_window = http3conf.upstream.max_window_size;
|
||||||
settings.max_udp_payload_size = SHRPX_MAX_UDP_PAYLOAD_SIZE;
|
settings.max_udp_payload_size = SHRPX_QUIC_MAX_UDP_PAYLOAD_SIZE;
|
||||||
|
settings.assume_symmetric_path = 1;
|
||||||
settings.rand_ctx.native_handle = &worker->get_randgen();
|
settings.rand_ctx.native_handle = &worker->get_randgen();
|
||||||
settings.token = ngtcp2_vec{const_cast<uint8_t *>(token), tokenlen};
|
settings.token = ngtcp2_vec{const_cast<uint8_t *>(token), tokenlen};
|
||||||
|
|
||||||
|
@ -581,9 +582,10 @@ int Http3Upstream::on_write() {
|
||||||
int Http3Upstream::write_streams() {
|
int Http3Upstream::write_streams() {
|
||||||
std::array<nghttp3_vec, 16> vec;
|
std::array<nghttp3_vec, 16> vec;
|
||||||
std::array<uint8_t, 64_k> buf;
|
std::array<uint8_t, 64_k> buf;
|
||||||
|
auto max_udp_payload_size = ngtcp2_conn_get_path_max_udp_payload_size(conn_);
|
||||||
size_t max_pktcnt =
|
size_t max_pktcnt =
|
||||||
std::min(static_cast<size_t>(64_k), ngtcp2_conn_get_send_quantum(conn_)) /
|
std::min(static_cast<size_t>(64_k), ngtcp2_conn_get_send_quantum(conn_)) /
|
||||||
SHRPX_MAX_UDP_PAYLOAD_SIZE;
|
max_udp_payload_size;
|
||||||
ngtcp2_pkt_info pi;
|
ngtcp2_pkt_info pi;
|
||||||
uint8_t *bufpos = buf.data();
|
uint8_t *bufpos = buf.data();
|
||||||
ngtcp2_path_storage ps, prev_ps;
|
ngtcp2_path_storage ps, prev_ps;
|
||||||
|
@ -620,8 +622,8 @@ int Http3Upstream::write_streams() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nwrite = ngtcp2_conn_writev_stream(
|
auto nwrite = ngtcp2_conn_writev_stream(
|
||||||
conn_, &ps.path, &pi, bufpos, SHRPX_MAX_UDP_PAYLOAD_SIZE, &ndatalen,
|
conn_, &ps.path, &pi, bufpos, max_udp_payload_size, &ndatalen, flags,
|
||||||
flags, stream_id, reinterpret_cast<const ngtcp2_vec *>(v), vcnt, ts);
|
stream_id, reinterpret_cast<const ngtcp2_vec *>(v), vcnt, ts);
|
||||||
if (nwrite < 0) {
|
if (nwrite < 0) {
|
||||||
switch (nwrite) {
|
switch (nwrite) {
|
||||||
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
|
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
|
||||||
|
@ -678,8 +680,7 @@ int Http3Upstream::write_streams() {
|
||||||
quic_send_packet(static_cast<UpstreamAddr *>(prev_ps.path.user_data),
|
quic_send_packet(static_cast<UpstreamAddr *>(prev_ps.path.user_data),
|
||||||
prev_ps.path.remote.addr, prev_ps.path.remote.addrlen,
|
prev_ps.path.remote.addr, prev_ps.path.remote.addrlen,
|
||||||
prev_ps.path.local.addr, prev_ps.path.local.addrlen,
|
prev_ps.path.local.addr, prev_ps.path.local.addrlen,
|
||||||
buf.data(), bufpos - buf.data(),
|
buf.data(), bufpos - buf.data(), max_udp_payload_size);
|
||||||
SHRPX_MAX_UDP_PAYLOAD_SIZE);
|
|
||||||
|
|
||||||
ngtcp2_conn_update_pkt_tx_time(conn_, ts);
|
ngtcp2_conn_update_pkt_tx_time(conn_, ts);
|
||||||
reset_idle_timer();
|
reset_idle_timer();
|
||||||
|
@ -700,12 +701,12 @@ int Http3Upstream::write_streams() {
|
||||||
prev_ps.path.remote.addr, prev_ps.path.remote.addrlen,
|
prev_ps.path.remote.addr, prev_ps.path.remote.addrlen,
|
||||||
prev_ps.path.local.addr, prev_ps.path.local.addrlen,
|
prev_ps.path.local.addr, prev_ps.path.local.addrlen,
|
||||||
buf.data(), bufpos - buf.data() - nwrite,
|
buf.data(), bufpos - buf.data() - nwrite,
|
||||||
SHRPX_MAX_UDP_PAYLOAD_SIZE);
|
max_udp_payload_size);
|
||||||
|
|
||||||
quic_send_packet(static_cast<UpstreamAddr *>(ps.path.user_data),
|
quic_send_packet(static_cast<UpstreamAddr *>(ps.path.user_data),
|
||||||
ps.path.remote.addr, ps.path.remote.addrlen,
|
ps.path.remote.addr, ps.path.remote.addrlen,
|
||||||
ps.path.local.addr, ps.path.local.addrlen,
|
ps.path.local.addr, ps.path.local.addrlen,
|
||||||
bufpos - nwrite, nwrite, SHRPX_MAX_UDP_PAYLOAD_SIZE);
|
bufpos - nwrite, nwrite, max_udp_payload_size);
|
||||||
|
|
||||||
ngtcp2_conn_update_pkt_tx_time(conn_, ts);
|
ngtcp2_conn_update_pkt_tx_time(conn_, ts);
|
||||||
reset_idle_timer();
|
reset_idle_timer();
|
||||||
|
@ -716,11 +717,11 @@ int Http3Upstream::write_streams() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++pktcnt == max_pktcnt ||
|
if (++pktcnt == max_pktcnt ||
|
||||||
static_cast<size_t>(nwrite) < SHRPX_MAX_UDP_PAYLOAD_SIZE) {
|
static_cast<size_t>(nwrite) < max_udp_payload_size) {
|
||||||
quic_send_packet(static_cast<UpstreamAddr *>(ps.path.user_data),
|
quic_send_packet(static_cast<UpstreamAddr *>(ps.path.user_data),
|
||||||
ps.path.remote.addr, ps.path.remote.addrlen,
|
ps.path.remote.addr, ps.path.remote.addrlen,
|
||||||
ps.path.local.addr, ps.path.local.addrlen, buf.data(),
|
ps.path.local.addr, ps.path.local.addrlen, buf.data(),
|
||||||
bufpos - buf.data(), SHRPX_MAX_UDP_PAYLOAD_SIZE);
|
bufpos - buf.data(), max_udp_payload_size);
|
||||||
|
|
||||||
ngtcp2_conn_update_pkt_tx_time(conn_, ts);
|
ngtcp2_conn_update_pkt_tx_time(conn_, ts);
|
||||||
reset_idle_timer();
|
reset_idle_timer();
|
||||||
|
@ -1241,7 +1242,7 @@ void Http3Upstream::on_handler_delete() {
|
||||||
!ngtcp2_conn_is_in_draining_period(conn_)) {
|
!ngtcp2_conn_is_in_draining_period(conn_)) {
|
||||||
ngtcp2_path_storage ps;
|
ngtcp2_path_storage ps;
|
||||||
ngtcp2_pkt_info pi;
|
ngtcp2_pkt_info pi;
|
||||||
std::array<uint8_t, SHRPX_MAX_UDP_PAYLOAD_SIZE> buf;
|
std::array<uint8_t, NGTCP2_DEFAULT_MAX_PKTLEN> buf;
|
||||||
|
|
||||||
ngtcp2_path_storage_zero(&ps);
|
ngtcp2_path_storage_zero(&ps);
|
||||||
|
|
||||||
|
@ -1529,7 +1530,7 @@ int Http3Upstream::handle_error() {
|
||||||
|
|
||||||
auto ts = quic_timestamp();
|
auto ts = quic_timestamp();
|
||||||
|
|
||||||
std::array<uint8_t, SHRPX_MAX_UDP_PAYLOAD_SIZE> buf;
|
std::array<uint8_t, NGTCP2_DEFAULT_MAX_PKTLEN> buf;
|
||||||
ngtcp2_ssize nwrite;
|
ngtcp2_ssize nwrite;
|
||||||
|
|
||||||
if (last_error_.type == quic::ErrorType::Transport) {
|
if (last_error_.type == quic::ErrorType::Transport) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct UpstreamAddr;
|
||||||
|
|
||||||
constexpr size_t SHRPX_QUIC_SCIDLEN = 20;
|
constexpr size_t SHRPX_QUIC_SCIDLEN = 20;
|
||||||
constexpr size_t SHRPX_QUIC_CID_PREFIXLEN = 8;
|
constexpr size_t SHRPX_QUIC_CID_PREFIXLEN = 8;
|
||||||
constexpr size_t SHRPX_MAX_UDP_PAYLOAD_SIZE = NGTCP2_MAX_PKTLEN_IPV4;
|
constexpr size_t SHRPX_QUIC_MAX_UDP_PAYLOAD_SIZE = 1472;
|
||||||
constexpr size_t SHRPX_QUIC_STATELESS_RESET_SECRETLEN = 32;
|
constexpr size_t SHRPX_QUIC_STATELESS_RESET_SECRETLEN = 32;
|
||||||
constexpr size_t SHRPX_QUIC_TOKEN_SECRETLEN = 32;
|
constexpr size_t SHRPX_QUIC_TOKEN_SECRETLEN = 32;
|
||||||
constexpr size_t SHRPX_QUIC_TOKEN_RAND_DATALEN = 16;
|
constexpr size_t SHRPX_QUIC_TOKEN_RAND_DATALEN = 16;
|
||||||
|
|
|
@ -315,7 +315,7 @@ int QUICConnectionHandler::send_retry(
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<uint8_t, SHRPX_MAX_UDP_PAYLOAD_SIZE> buf;
|
std::array<uint8_t, NGTCP2_DEFAULT_MAX_PKTLEN> buf;
|
||||||
|
|
||||||
auto nwrite =
|
auto nwrite =
|
||||||
ngtcp2_crypto_write_retry(buf.data(), buf.size(), version, &iscid,
|
ngtcp2_crypto_write_retry(buf.data(), buf.size(), version, &iscid,
|
||||||
|
@ -339,7 +339,7 @@ int QUICConnectionHandler::send_version_negotiation(
|
||||||
sv[0] = generate_reserved_version(remote_addr, version);
|
sv[0] = generate_reserved_version(remote_addr, version);
|
||||||
sv[1] = NGTCP2_PROTO_VER_V1;
|
sv[1] = NGTCP2_PROTO_VER_V1;
|
||||||
|
|
||||||
std::array<uint8_t, SHRPX_MAX_UDP_PAYLOAD_SIZE> buf;
|
std::array<uint8_t, NGTCP2_DEFAULT_MAX_PKTLEN> buf;
|
||||||
|
|
||||||
uint8_t rand_byte;
|
uint8_t rand_byte;
|
||||||
util::random_bytes(&rand_byte, &rand_byte + 1, worker_->get_randgen());
|
util::random_bytes(&rand_byte, &rand_byte + 1, worker_->get_randgen());
|
||||||
|
@ -384,7 +384,7 @@ int QUICConnectionHandler::send_stateless_reset(const UpstreamAddr *faddr,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<uint8_t, SHRPX_MAX_UDP_PAYLOAD_SIZE> buf;
|
std::array<uint8_t, NGTCP2_DEFAULT_MAX_PKTLEN> buf;
|
||||||
|
|
||||||
auto nwrite =
|
auto nwrite =
|
||||||
ngtcp2_pkt_write_stateless_reset(buf.data(), buf.size(), token.data(),
|
ngtcp2_pkt_write_stateless_reset(buf.data(), buf.size(), token.data(),
|
||||||
|
|
Loading…
Reference in New Issue