From e57d6658593a663245a61909b831f057371b66df Mon Sep 17 00:00:00 2001 From: alyssawilk Date: Wed, 16 Feb 2022 12:02:26 -0500 Subject: [PATCH] quic: using real runtime, not runtime singleton (#19983) Risk Level: low Testing: existing tests Docs Changes: n/a Release Notes: n/a part of #19847 Signed-off-by: Alyssa Wilk --- envoy/network/connection_handler.h | 6 ++-- source/common/quic/active_quic_listener.cc | 36 ++++++++++--------- source/common/quic/active_quic_listener.h | 14 ++++---- .../server/active_raw_udp_listener_config.cc | 2 +- .../server/active_raw_udp_listener_config.h | 5 +-- source/server/connection_handler_impl.cc | 4 +-- test/common/quic/active_quic_listener_test.cc | 3 +- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/envoy/network/connection_handler.h b/envoy/network/connection_handler.h index 0769b38af759..1b5ff8820015 100644 --- a/envoy/network/connection_handler.h +++ b/envoy/network/connection_handler.h @@ -216,6 +216,7 @@ class ActiveUdpListenerFactory { /** * Creates an ActiveUdpListener object and a corresponding UdpListener * according to given config. + * @param runtime the runtime for this server. * @param worker_index The index of the worker this listener is being created on. * @param parent is the owner of the created ActiveListener objects. * @param dispatcher is used to create actual UDP listener. @@ -224,8 +225,9 @@ class ActiveUdpListenerFactory { * @return the ActiveUdpListener created. */ virtual ConnectionHandler::ActiveUdpListenerPtr - createActiveUdpListener(uint32_t worker_index, UdpConnectionHandler& parent, - Event::Dispatcher& dispatcher, Network::ListenerConfig& config) PURE; + createActiveUdpListener(Runtime::Loader& runtime, uint32_t worker_index, + UdpConnectionHandler& parent, Event::Dispatcher& dispatcher, + Network::ListenerConfig& config) PURE; /** * @return true if the UDP passing through listener doesn't form stateful connections. diff --git a/source/common/quic/active_quic_listener.cc b/source/common/quic/active_quic_listener.cc index 7449bde7e2ef..92d7c723ce5d 100644 --- a/source/common/quic/active_quic_listener.cc +++ b/source/common/quic/active_quic_listener.cc @@ -24,25 +24,26 @@ namespace Quic { bool ActiveQuicListenerFactory::disable_kernel_bpf_packet_routing_for_test_ = false; ActiveQuicListener::ActiveQuicListener( - uint32_t worker_index, uint32_t concurrency, Event::Dispatcher& dispatcher, - Network::UdpConnectionHandler& parent, Network::ListenerConfig& listener_config, - const quic::QuicConfig& quic_config, bool kernel_worker_routing, - const envoy::config::core::v3::RuntimeFeatureFlag& enabled, QuicStatNames& quic_stat_names, - uint32_t packets_received_to_connection_count_ratio, + Runtime::Loader& runtime, uint32_t worker_index, uint32_t concurrency, + Event::Dispatcher& dispatcher, Network::UdpConnectionHandler& parent, + Network::ListenerConfig& listener_config, const quic::QuicConfig& quic_config, + bool kernel_worker_routing, const envoy::config::core::v3::RuntimeFeatureFlag& enabled, + QuicStatNames& quic_stat_names, uint32_t packets_received_to_connection_count_ratio, EnvoyQuicCryptoServerStreamFactoryInterface& crypto_server_stream_factory, EnvoyQuicProofSourceFactoryInterface& proof_source_factory) - : ActiveQuicListener(worker_index, concurrency, dispatcher, parent, + : ActiveQuicListener(runtime, worker_index, concurrency, dispatcher, parent, listener_config.listenSocketFactory().getListenSocket(worker_index), listener_config, quic_config, kernel_worker_routing, enabled, quic_stat_names, packets_received_to_connection_count_ratio, crypto_server_stream_factory, proof_source_factory) {} ActiveQuicListener::ActiveQuicListener( - uint32_t worker_index, uint32_t concurrency, Event::Dispatcher& dispatcher, - Network::UdpConnectionHandler& parent, Network::SocketSharedPtr listen_socket, - Network::ListenerConfig& listener_config, const quic::QuicConfig& quic_config, - bool kernel_worker_routing, const envoy::config::core::v3::RuntimeFeatureFlag& enabled, - QuicStatNames& quic_stat_names, uint32_t packets_to_read_to_connection_count_ratio, + Runtime::Loader& runtime, uint32_t worker_index, uint32_t concurrency, + Event::Dispatcher& dispatcher, Network::UdpConnectionHandler& parent, + Network::SocketSharedPtr listen_socket, Network::ListenerConfig& listener_config, + const quic::QuicConfig& quic_config, bool kernel_worker_routing, + const envoy::config::core::v3::RuntimeFeatureFlag& enabled, QuicStatNames& quic_stat_names, + uint32_t packets_to_read_to_connection_count_ratio, EnvoyQuicCryptoServerStreamFactoryInterface& crypto_server_stream_factory, EnvoyQuicProofSourceFactoryInterface& proof_source_factory) : Server::ActiveUdpListenerBase( @@ -59,7 +60,7 @@ ActiveQuicListener::ActiveQuicListener( ASSERT(!GetQuicFlag(FLAGS_quic_header_size_limit_includes_overhead)); if (Runtime::LoaderSingleton::getExisting()) { - enabled_.emplace(Runtime::FeatureFlag(enabled, Runtime::LoaderSingleton::get())); + enabled_.emplace(Runtime::FeatureFlag(enabled, runtime)); } quic::QuicRandom* const random = quic::QuicRandom::GetInstance(); @@ -339,13 +340,14 @@ ActiveQuicListenerFactory::ActiveQuicListenerFactory( } Network::ConnectionHandler::ActiveUdpListenerPtr ActiveQuicListenerFactory::createActiveUdpListener( - uint32_t worker_index, Network::UdpConnectionHandler& parent, Event::Dispatcher& disptacher, - Network::ListenerConfig& config) { + Runtime::Loader& runtime, uint32_t worker_index, Network::UdpConnectionHandler& parent, + Event::Dispatcher& disptacher, Network::ListenerConfig& config) { ASSERT(crypto_server_stream_factory_.has_value()); return std::make_unique( - worker_index, concurrency_, disptacher, parent, config, quic_config_, kernel_worker_routing_, - enabled_, quic_stat_names_, packets_to_read_to_connection_count_ratio_, - crypto_server_stream_factory_.value(), proof_source_factory_.value()); + runtime, worker_index, concurrency_, disptacher, parent, config, quic_config_, + kernel_worker_routing_, enabled_, quic_stat_names_, + packets_to_read_to_connection_count_ratio_, crypto_server_stream_factory_.value(), + proof_source_factory_.value()); } } // namespace Quic diff --git a/source/common/quic/active_quic_listener.h b/source/common/quic/active_quic_listener.h index eca1f28c0caa..6feda1abc7c2 100644 --- a/source/common/quic/active_quic_listener.h +++ b/source/common/quic/active_quic_listener.h @@ -28,8 +28,8 @@ class ActiveQuicListener : public Envoy::Server::ActiveUdpListenerBase, // TODO(bencebeky): Tune this value. static const size_t kNumSessionsToCreatePerLoop = 16; - ActiveQuicListener(uint32_t worker_index, uint32_t concurrency, Event::Dispatcher& dispatcher, - Network::UdpConnectionHandler& parent, + ActiveQuicListener(Runtime::Loader& runtime, uint32_t worker_index, uint32_t concurrency, + Event::Dispatcher& dispatcher, Network::UdpConnectionHandler& parent, Network::ListenerConfig& listener_config, const quic::QuicConfig& quic_config, bool kernel_worker_routing, const envoy::config::core::v3::RuntimeFeatureFlag& enabled, @@ -38,8 +38,9 @@ class ActiveQuicListener : public Envoy::Server::ActiveUdpListenerBase, EnvoyQuicCryptoServerStreamFactoryInterface& crypto_server_stream_factory, EnvoyQuicProofSourceFactoryInterface& proof_source_factory); - ActiveQuicListener(uint32_t worker_index, uint32_t concurrency, Event::Dispatcher& dispatcher, - Network::UdpConnectionHandler& parent, Network::SocketSharedPtr listen_socket, + ActiveQuicListener(Runtime::Loader& runtime, uint32_t worker_index, uint32_t concurrency, + Event::Dispatcher& dispatcher, Network::UdpConnectionHandler& parent, + Network::SocketSharedPtr listen_socket, Network::ListenerConfig& listener_config, const quic::QuicConfig& quic_config, bool kernel_worker_routing, const envoy::config::core::v3::RuntimeFeatureFlag& enabled, @@ -106,8 +107,9 @@ class ActiveQuicListenerFactory : public Network::ActiveUdpListenerFactory, // Network::ActiveUdpListenerFactory. Network::ConnectionHandler::ActiveUdpListenerPtr - createActiveUdpListener(uint32_t worker_index, Network::UdpConnectionHandler& parent, - Event::Dispatcher& disptacher, Network::ListenerConfig& config) override; + createActiveUdpListener(Runtime::Loader& runtime, uint32_t worker_index, + Network::UdpConnectionHandler& parent, Event::Dispatcher& disptacher, + Network::ListenerConfig& config) override; bool isTransportConnectionless() const override { return false; } const Network::Socket::OptionsSharedPtr& socketOptions() const override { return options_; } diff --git a/source/server/active_raw_udp_listener_config.cc b/source/server/active_raw_udp_listener_config.cc index 86de0c3053b0..e149dadf0071 100644 --- a/source/server/active_raw_udp_listener_config.cc +++ b/source/server/active_raw_udp_listener_config.cc @@ -13,7 +13,7 @@ ActiveRawUdpListenerFactory::ActiveRawUdpListenerFactory(uint32_t concurrency) : concurrency_(concurrency) {} Network::ConnectionHandler::ActiveUdpListenerPtr -ActiveRawUdpListenerFactory::createActiveUdpListener(uint32_t worker_index, +ActiveRawUdpListenerFactory::createActiveUdpListener(Runtime::Loader&, uint32_t worker_index, Network::UdpConnectionHandler& parent, Event::Dispatcher& dispatcher, Network::ListenerConfig& config) { diff --git a/source/server/active_raw_udp_listener_config.h b/source/server/active_raw_udp_listener_config.h index 7b9bcf890acf..4b79d9ed6d4f 100644 --- a/source/server/active_raw_udp_listener_config.h +++ b/source/server/active_raw_udp_listener_config.h @@ -10,8 +10,9 @@ class ActiveRawUdpListenerFactory : public Network::ActiveUdpListenerFactory { ActiveRawUdpListenerFactory(uint32_t concurrency); Network::ConnectionHandler::ActiveUdpListenerPtr - createActiveUdpListener(uint32_t worker_index, Network::UdpConnectionHandler& parent, - Event::Dispatcher& disptacher, Network::ListenerConfig& config) override; + createActiveUdpListener(Runtime::Loader&, uint32_t worker_index, + Network::UdpConnectionHandler& parent, Event::Dispatcher& disptacher, + Network::ListenerConfig& config) override; bool isTransportConnectionless() const override { return true; } const Network::Socket::OptionsSharedPtr& socketOptions() const override { return options_; } diff --git a/source/server/connection_handler_impl.cc b/source/server/connection_handler_impl.cc index d5af15820c6b..4aeafd42cfe7 100644 --- a/source/server/connection_handler_impl.cc +++ b/source/server/connection_handler_impl.cc @@ -71,8 +71,8 @@ void ConnectionHandlerImpl::addListener(absl::optional overridden_list ASSERT(config.udpListenerConfig().has_value(), "UDP listener factory is not initialized."); ASSERT(worker_index_.has_value()); ConnectionHandler::ActiveUdpListenerPtr udp_listener = - config.udpListenerConfig()->listenerFactory().createActiveUdpListener(*worker_index_, *this, - dispatcher_, config); + config.udpListenerConfig()->listenerFactory().createActiveUdpListener( + runtime, *worker_index_, *this, dispatcher_, config); details->typed_listener_ = *udp_listener; details->listener_ = std::move(udp_listener); } diff --git a/test/common/quic/active_quic_listener_test.cc b/test/common/quic/active_quic_listener_test.cc index 8bbcb25eae33..6242cd77f389 100644 --- a/test/common/quic/active_quic_listener_test.cc +++ b/test/common/quic/active_quic_listener_test.cc @@ -120,7 +120,8 @@ class ActiveQuicListenerTest : public testing::TestWithParam(listener_factory_->createActiveUdpListener( - 0, connection_handler_, *dispatcher_, listener_config_)); + Runtime::LoaderSingleton::get(), 0, connection_handler_, *dispatcher_, + listener_config_)); quic_dispatcher_ = ActiveQuicListenerPeer::quicDispatcher(*quic_listener_); quic::QuicCryptoServerConfig& crypto_config = ActiveQuicListenerPeer::cryptoConfig(*quic_listener_);