nghttpx: Use existing QUIC error object

This commit is contained in:
Tatsuhiro Tsujikawa 2021-08-16 17:05:48 +09:00
parent 3e79ea5c52
commit 9b69069fa3
7 changed files with 12 additions and 53 deletions

View File

@ -156,6 +156,7 @@ NGHTTPX_SRCS = \
shrpx_quic_listener.cc shrpx_quic_listener.h \ shrpx_quic_listener.cc shrpx_quic_listener.h \
shrpx_quic_connection_handler.cc shrpx_quic_connection_handler.h \ shrpx_quic_connection_handler.cc shrpx_quic_connection_handler.h \
shrpx_http3_upstream.cc shrpx_http3_upstream.h \ shrpx_http3_upstream.cc shrpx_http3_upstream.h \
quic.cc quic.h \
buffer.h memchunk.h template.h allocator.h \ buffer.h memchunk.h template.h allocator.h \
xsi_strerror.c xsi_strerror.h xsi_strerror.c xsi_strerror.h

View File

@ -43,6 +43,10 @@ Error err_transport(int liberr) {
ngtcp2_err_infer_quic_transport_error_code(liberr)}; ngtcp2_err_infer_quic_transport_error_code(liberr)};
} }
Error err_transport_idle_timeout() {
return {ErrorType::TransportIdleTimeout, 0};
}
Error err_transport_tls(int alert) { Error err_transport_tls(int alert) {
return {ErrorType::Transport, ngtcp2_err_infer_quic_transport_error_code( return {ErrorType::Transport, ngtcp2_err_infer_quic_transport_error_code(
NGTCP2_CRYPTO_ERROR | alert)}; NGTCP2_CRYPTO_ERROR | alert)};

View File

@ -34,6 +34,7 @@ namespace quic {
enum class ErrorType { enum class ErrorType {
Transport, Transport,
TransportVersionNegotiation, TransportVersionNegotiation,
TransportIdleTimeout,
Application, Application,
}; };
@ -46,6 +47,7 @@ struct Error {
}; };
Error err_transport(int liberr); Error err_transport(int liberr);
Error err_transport_idle_timeout();
Error err_transport_tls(int alert); Error err_transport_tls(int alert);
Error err_application(int liberr); Error err_application(int liberr);

View File

@ -39,10 +39,7 @@
namespace shrpx { namespace shrpx {
Http3Upstream::Http3Upstream(ClientHandler *handler) Http3Upstream::Http3Upstream(ClientHandler *handler)
: handler_{handler}, : handler_{handler}, conn_{nullptr}, tls_alert_{0} {}
conn_{nullptr},
last_error_{QUICErrorType::Transport, 0},
tls_alert_{0} {}
Http3Upstream::~Http3Upstream() { Http3Upstream::~Http3Upstream() {
if (conn_) { if (conn_) {
@ -139,7 +136,6 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr,
ngtcp2_crypto_decrypt_cb, ngtcp2_crypto_decrypt_cb,
ngtcp2_crypto_hp_mask_cb, ngtcp2_crypto_hp_mask_cb,
nullptr, // recv_stream_data nullptr, // recv_stream_data
nullptr, // acked_crypto_offset
nullptr, // acked_stream_data_offset nullptr, // acked_stream_data_offset
nullptr, // stream_open nullptr, // stream_open
nullptr, // stream_close nullptr, // stream_close
@ -343,13 +339,13 @@ int Http3Upstream::on_read(const UpstreamAddr *faddr,
// If rv indicates transport_parameters related error, we should // If rv indicates transport_parameters related error, we should
// send TRANSPORT_PARAMETER_ERROR even if last_error_.code is // send TRANSPORT_PARAMETER_ERROR even if last_error_.code is
// already set. This is because OpenSSL might set Alert. // already set. This is because OpenSSL might set Alert.
last_error_ = quic_err_transport(rv); last_error_ = quic::err_transport(rv);
break; break;
case NGTCP2_ERR_DROP_CONN: case NGTCP2_ERR_DROP_CONN:
return -1; return -1;
default: default:
if (!last_error_.code) { if (!last_error_.code) {
last_error_ = quic_err_transport(rv); last_error_ = quic::err_transport(rv);
} }
} }

View File

@ -30,7 +30,7 @@
#include <ngtcp2/ngtcp2.h> #include <ngtcp2/ngtcp2.h>
#include "shrpx_upstream.h" #include "shrpx_upstream.h"
#include "shrpx_quic.h" #include "quic.h"
#include "network.h" #include "network.h"
using namespace nghttp2; using namespace nghttp2;
@ -107,7 +107,7 @@ private:
ClientHandler *handler_; ClientHandler *handler_;
ngtcp2_cid initial_client_dcid_; ngtcp2_cid initial_client_dcid_;
ngtcp2_conn *conn_; ngtcp2_conn *conn_;
QUICError last_error_; quic::Error last_error_;
uint8_t tls_alert_; uint8_t tls_alert_;
}; };

View File

@ -46,28 +46,6 @@ using namespace nghttp2;
namespace shrpx { namespace shrpx {
QUICError quic_err_transport(int liberr) {
if (liberr == NGTCP2_ERR_RECV_VERSION_NEGOTIATION) {
return {QUICErrorType::TransportVersionNegotiation, 0};
}
return {QUICErrorType::Transport,
ngtcp2_err_infer_quic_transport_error_code(liberr)};
}
QUICError quic_err_idle_timeout() {
return {QUICErrorType::TransportIdleTimeout, 0};
}
QUICError quic_err_tls(int alert) {
return {QUICErrorType::Transport,
static_cast<uint64_t>(NGTCP2_CRYPTO_ERROR | alert)};
}
QUICError quic_err_app(int liberr) {
return {QUICErrorType::Application,
nghttp3_err_infer_quic_app_error_code(liberr)};
}
ngtcp2_tstamp quic_timestamp() { ngtcp2_tstamp quic_timestamp() {
return std::chrono::duration_cast<std::chrono::nanoseconds>( return std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now().time_since_epoch()) std::chrono::steady_clock::now().time_since_epoch())

View File

@ -38,28 +38,6 @@ struct UpstreamAddr;
constexpr size_t SHRPX_QUIC_SCIDLEN = 20; constexpr size_t SHRPX_QUIC_SCIDLEN = 20;
constexpr size_t SHRPX_MAX_UDP_PAYLOAD_SIZE = 1280; constexpr size_t SHRPX_MAX_UDP_PAYLOAD_SIZE = 1280;
enum class QUICErrorType {
Application,
Transport,
TransportVersionNegotiation,
TransportIdleTimeout,
};
struct QUICError {
QUICError(QUICErrorType type, uint64_t code) : type{type}, code{code} {}
QUICErrorType type;
uint64_t code;
};
QUICError quic_err_transport(int liberr);
QUICError quic_err_idle_timeout();
QUICError quic_err_tls(int alert);
QUICError quic_err_app(int liberr);
ngtcp2_tstamp quic_timestamp(); ngtcp2_tstamp quic_timestamp();
int create_quic_server_socket(UpstreamAddr &addr); int create_quic_server_socket(UpstreamAddr &addr);