From 49b8c56fde2d4f790a641345a345e25d63ae7e34 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 16 Aug 2021 17:05:48 +0900 Subject: [PATCH] nghttpx: Use existing QUIC error object --- src/Makefile.am | 1 + src/quic.cc | 4 ++++ src/quic.h | 2 ++ src/shrpx_http3_upstream.cc | 10 +++------- src/shrpx_http3_upstream.h | 4 ++-- src/shrpx_quic.cc | 22 ---------------------- src/shrpx_quic.h | 22 ---------------------- 7 files changed, 12 insertions(+), 53 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e7ed9db1..344cc7cf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -157,6 +157,7 @@ NGHTTPX_SRCS = \ shrpx_quic_listener.cc shrpx_quic_listener.h \ shrpx_quic_connection_handler.cc shrpx_quic_connection_handler.h \ shrpx_http3_upstream.cc shrpx_http3_upstream.h \ + quic.cc quic.h \ buffer.h memchunk.h template.h allocator.h \ xsi_strerror.c xsi_strerror.h diff --git a/src/quic.cc b/src/quic.cc index 1abad98a..1c68a5be 100644 --- a/src/quic.cc +++ b/src/quic.cc @@ -43,6 +43,10 @@ Error err_transport(int liberr) { ngtcp2_err_infer_quic_transport_error_code(liberr)}; } +Error err_transport_idle_timeout() { + return {ErrorType::TransportIdleTimeout, 0}; +} + Error err_transport_tls(int alert) { return {ErrorType::Transport, ngtcp2_err_infer_quic_transport_error_code( NGTCP2_CRYPTO_ERROR | alert)}; diff --git a/src/quic.h b/src/quic.h index 1bb3096f..d72ae1fe 100644 --- a/src/quic.h +++ b/src/quic.h @@ -34,6 +34,7 @@ namespace quic { enum class ErrorType { Transport, TransportVersionNegotiation, + TransportIdleTimeout, Application, }; @@ -46,6 +47,7 @@ struct Error { }; Error err_transport(int liberr); +Error err_transport_idle_timeout(); Error err_transport_tls(int alert); Error err_application(int liberr); diff --git a/src/shrpx_http3_upstream.cc b/src/shrpx_http3_upstream.cc index 34e7e0cb..83b957bd 100644 --- a/src/shrpx_http3_upstream.cc +++ b/src/shrpx_http3_upstream.cc @@ -39,10 +39,7 @@ namespace shrpx { Http3Upstream::Http3Upstream(ClientHandler *handler) - : handler_{handler}, - conn_{nullptr}, - last_error_{QUICErrorType::Transport, 0}, - tls_alert_{0} {} + : handler_{handler}, conn_{nullptr}, tls_alert_{0} {} Http3Upstream::~Http3Upstream() { if (conn_) { @@ -139,7 +136,6 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, ngtcp2_crypto_decrypt_cb, ngtcp2_crypto_hp_mask_cb, nullptr, // recv_stream_data - nullptr, // acked_crypto_offset nullptr, // acked_stream_data_offset nullptr, // stream_open nullptr, // stream_close @@ -343,13 +339,13 @@ int Http3Upstream::on_read(const UpstreamAddr *faddr, // If rv indicates transport_parameters related error, we should // send TRANSPORT_PARAMETER_ERROR even if last_error_.code is // already set. This is because OpenSSL might set Alert. - last_error_ = quic_err_transport(rv); + last_error_ = quic::err_transport(rv); break; case NGTCP2_ERR_DROP_CONN: return -1; default: if (!last_error_.code) { - last_error_ = quic_err_transport(rv); + last_error_ = quic::err_transport(rv); } } diff --git a/src/shrpx_http3_upstream.h b/src/shrpx_http3_upstream.h index 486f680a..f41f6597 100644 --- a/src/shrpx_http3_upstream.h +++ b/src/shrpx_http3_upstream.h @@ -30,7 +30,7 @@ #include #include "shrpx_upstream.h" -#include "shrpx_quic.h" +#include "quic.h" #include "network.h" using namespace nghttp2; @@ -107,7 +107,7 @@ private: ClientHandler *handler_; ngtcp2_cid initial_client_dcid_; ngtcp2_conn *conn_; - QUICError last_error_; + quic::Error last_error_; uint8_t tls_alert_; }; diff --git a/src/shrpx_quic.cc b/src/shrpx_quic.cc index 708886c0..cd989f9f 100644 --- a/src/shrpx_quic.cc +++ b/src/shrpx_quic.cc @@ -46,28 +46,6 @@ using namespace nghttp2; 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(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() { return std::chrono::duration_cast( std::chrono::steady_clock::now().time_since_epoch()) diff --git a/src/shrpx_quic.h b/src/shrpx_quic.h index 8350adc7..cf405e61 100644 --- a/src/shrpx_quic.h +++ b/src/shrpx_quic.h @@ -38,28 +38,6 @@ struct UpstreamAddr; constexpr size_t SHRPX_QUIC_SCIDLEN = 20; 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(); int create_quic_server_socket(UpstreamAddr &addr);