From 9b789342400c403e96a5b830bff999b11bb62d4e Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Mon, 25 Oct 2021 12:38:25 -0400 Subject: [PATCH] quic: applying config options upstream Signed-off-by: Alyssa Wilk --- source/common/http/http3/conn_pool.cc | 7 +------ source/common/quic/active_quic_listener.cc | 6 +----- source/common/quic/envoy_quic_utils.cc | 8 ++++++++ source/common/quic/envoy_quic_utils.h | 4 ++++ test/common/quic/envoy_quic_utils_test.cc | 21 +++++++++++++++++++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/source/common/http/http3/conn_pool.cc b/source/common/http/http3/conn_pool.cc index fbc3e4503607..d4b063de64df 100644 --- a/source/common/http/http3/conn_pool.cc +++ b/source/common/http/http3/conn_pool.cc @@ -32,15 +32,10 @@ ActiveClient::ActiveClient(Envoy::Http::HttpConnPoolImplBase& parent, void Http3ConnPoolImpl::setQuicConfigFromClusterConfig(const Upstream::ClusterInfo& cluster, quic::QuicConfig& quic_config) { - // TODO(alyssawilk) use and test other defaults. + Quic::convertQuicConfig(cluster.http3Options().quic_protocol_options(), quic_config); quic::QuicTime::Delta crypto_timeout = quic::QuicTime::Delta::FromMilliseconds(cluster.connectTimeout().count()); quic_config.set_max_time_before_crypto_handshake(crypto_timeout); - int32_t max_streams = getMaxStreams(cluster); - quic_config.SetMaxBidirectionalStreamsToSend(max_streams); - quic_config.SetMaxUnidirectionalStreamsToSend(max_streams); - Quic::configQuicInitialFlowControlWindow(cluster.http3Options().quic_protocol_options(), - quic_config); } Http3ConnPoolImpl::Http3ConnPoolImpl( diff --git a/source/common/quic/active_quic_listener.cc b/source/common/quic/active_quic_listener.cc index 7e3d761deded..5aa56cada9b6 100644 --- a/source/common/quic/active_quic_listener.cc +++ b/source/common/quic/active_quic_listener.cc @@ -254,11 +254,7 @@ ActiveQuicListenerFactory::ActiveQuicListenerFactory( : 20000; quic_config_.set_max_time_before_crypto_handshake( quic::QuicTime::Delta::FromMilliseconds(max_time_before_crypto_handshake_ms)); - int32_t max_streams = - PROTOBUF_GET_WRAPPED_OR_DEFAULT(config.quic_protocol_options(), max_concurrent_streams, 100); - quic_config_.SetMaxBidirectionalStreamsToSend(max_streams); - quic_config_.SetMaxUnidirectionalStreamsToSend(max_streams); - configQuicInitialFlowControlWindow(config.quic_protocol_options(), quic_config_); + convertQuicConfig(config.quic_protocol_options(), quic_config_); // Initialize crypto stream factory. envoy::config::core::v3::TypedExtensionConfig crypto_stream_config; diff --git a/source/common/quic/envoy_quic_utils.cc b/source/common/quic/envoy_quic_utils.cc index b49fefff5785..433d379580da 100644 --- a/source/common/quic/envoy_quic_utils.cc +++ b/source/common/quic/envoy_quic_utils.cc @@ -237,6 +237,14 @@ createServerConnectionSocket(Network::IoHandle& io_handle, return connection_socket; } +void convertQuicConfig(const envoy::config::core::v3::QuicProtocolOptions& config, + quic::QuicConfig& quic_config) { + int32_t max_streams = PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, max_concurrent_streams, 100); + quic_config.SetMaxBidirectionalStreamsToSend(max_streams); + quic_config.SetMaxUnidirectionalStreamsToSend(max_streams); + configQuicInitialFlowControlWindow(config, quic_config); +} + void configQuicInitialFlowControlWindow(const envoy::config::core::v3::QuicProtocolOptions& config, quic::QuicConfig& quic_config) { size_t stream_flow_control_window_to_send = PROTOBUF_GET_WRAPPED_OR_DEFAULT( diff --git a/source/common/quic/envoy_quic_utils.h b/source/common/quic/envoy_quic_utils.h index 67ffd0dcf70c..ccef576914f9 100644 --- a/source/common/quic/envoy_quic_utils.h +++ b/source/common/quic/envoy_quic_utils.h @@ -178,6 +178,10 @@ createServerConnectionSocket(Network::IoHandle& io_handle, const quic::QuicSocketAddress& peer_address, const std::string& hostname, absl::string_view alpn); +// Alter QuicConfig based on all the options in the supplied config. +void convertQuicConfig(const envoy::config::core::v3::QuicProtocolOptions& config, + quic::QuicConfig& quic_config); + // Set initial flow control windows in quic_config according to the given Envoy config. void configQuicInitialFlowControlWindow(const envoy::config::core::v3::QuicProtocolOptions& config, quic::QuicConfig& quic_config); diff --git a/test/common/quic/envoy_quic_utils_test.cc b/test/common/quic/envoy_quic_utils_test.cc index d8d290975f08..99794c49700d 100644 --- a/test/common/quic/envoy_quic_utils_test.cc +++ b/test/common/quic/envoy_quic_utils_test.cc @@ -171,5 +171,26 @@ TEST(EnvoyQuicUtilsTest, deduceSignatureAlgorithmFromNullPublicKey) { EXPECT_EQ("Invalid leaf cert, bad public key", error); } +TEST(EnvoyQuicUtilsTest, ConvertQuicConfig) { + envoy::config::core::v3::QuicProtocolOptions config; + quic::QuicConfig quic_config; + + // Test defaults. + convertQuicConfig(config, quic_config); + EXPECT_EQ(100, quic_config.GetMaxBidirectionalStreamsToSend()); + EXPECT_EQ(100, quic_config.GetMaxUnidirectionalStreamsToSend()); + EXPECT_EQ(16777216, quic_config.GetInitialMaxStreamDataBytesIncomingBidirectionalToSend()); + EXPECT_EQ(25165824, quic_config.GetInitialSessionFlowControlWindowToSend()); + + // Test converting values. + config.mutable_max_concurrent_streams()->set_value(2); + config.mutable_initial_stream_window_size()->set_value(3); + config.mutable_initial_connection_window_size()->set_value(50); + convertQuicConfig(config, quic_config); + EXPECT_EQ(2, quic_config.GetMaxBidirectionalStreamsToSend()); + EXPECT_EQ(2, quic_config.GetMaxUnidirectionalStreamsToSend()); + EXPECT_EQ(3, quic_config.GetInitialMaxStreamDataBytesIncomingBidirectionalToSend()); +} + } // namespace Quic } // namespace Envoy