Line data Source code
1 : #include "source/common/quic/client_connection_factory_impl.h" 2 : 3 : namespace Envoy { 4 : namespace Quic { 5 : 6 : PersistentQuicInfoImpl::PersistentQuicInfoImpl(Event::Dispatcher& dispatcher, uint32_t buffer_limit) 7 : : conn_helper_(dispatcher), alarm_factory_(dispatcher, *conn_helper_.GetClock()), 8 0 : buffer_limit_(buffer_limit) { 9 0 : quiche::FlagRegistry::getInstance(); 10 0 : } 11 : 12 : std::unique_ptr<PersistentQuicInfoImpl> 13 : createPersistentQuicInfoForCluster(Event::Dispatcher& dispatcher, 14 0 : const Upstream::ClusterInfo& cluster) { 15 0 : auto quic_info = std::make_unique<Quic::PersistentQuicInfoImpl>( 16 0 : dispatcher, cluster.perConnectionBufferLimitBytes()); 17 0 : Quic::convertQuicConfig(cluster.http3Options().quic_protocol_options(), quic_info->quic_config_); 18 0 : quic::QuicTime::Delta crypto_timeout = 19 0 : quic::QuicTime::Delta::FromMilliseconds(cluster.connectTimeout().count()); 20 : 21 0 : quic_info->quic_config_.set_max_time_before_crypto_handshake(crypto_timeout); 22 0 : if (quic_info->quic_config_.max_time_before_crypto_handshake() < 23 0 : quic_info->quic_config_.max_idle_time_before_crypto_handshake()) { 24 0 : quic_info->quic_config_.set_max_idle_time_before_crypto_handshake(crypto_timeout); 25 0 : } 26 0 : return quic_info; 27 0 : } 28 : 29 : std::unique_ptr<Network::ClientConnection> createQuicNetworkConnection( 30 : Http::PersistentQuicInfo& info, std::shared_ptr<quic::QuicCryptoClientConfig> crypto_config, 31 : const quic::QuicServerId& server_id, Event::Dispatcher& dispatcher, 32 : Network::Address::InstanceConstSharedPtr server_addr, 33 : Network::Address::InstanceConstSharedPtr local_addr, QuicStatNames& quic_stat_names, 34 : OptRef<Http::HttpServerPropertiesCache> rtt_cache, Stats::Scope& scope, 35 : const Network::ConnectionSocket::OptionsSharedPtr& options, 36 : const Network::TransportSocketOptionsConstSharedPtr& transport_socket_options, 37 : quic::ConnectionIdGeneratorInterface& generator, 38 0 : Network::UpstreamTransportSocketFactory& transport_socket_factory) { 39 : // TODO: Quic should take into account the set_local_interface_name_on_upstream_connections config 40 : // and call maybeSetInterfaceName based on that upon acquiring a local socket. 41 : // Similar to what is done in ClientConnectionImpl::onConnected(). 42 0 : ASSERT(crypto_config != nullptr); 43 0 : PersistentQuicInfoImpl* info_impl = reinterpret_cast<PersistentQuicInfoImpl*>(&info); 44 0 : quic::ParsedQuicVersionVector quic_versions = quic::CurrentSupportedHttp3Versions(); 45 0 : ASSERT(!quic_versions.empty()); 46 0 : auto connection = std::make_unique<EnvoyQuicClientConnection>( 47 0 : quic::QuicUtils::CreateRandomConnectionId(), server_addr, info_impl->conn_helper_, 48 0 : info_impl->alarm_factory_, quic_versions, local_addr, dispatcher, options, generator); 49 : 50 : // TODO (danzh) move this temporary config and initial RTT configuration to h3 pool. 51 0 : quic::QuicConfig config = info_impl->quic_config_; 52 : // Update config with latest srtt, if available. 53 0 : if (rtt_cache.has_value()) { 54 0 : Http::HttpServerPropertiesCache::Origin origin("https", server_id.host(), server_id.port()); 55 0 : std::chrono::microseconds rtt = rtt_cache.value().get().getSrtt(origin); 56 0 : if (rtt.count() != 0) { 57 0 : config.SetInitialRoundTripTimeUsToSend(rtt.count()); 58 0 : } 59 0 : } 60 : 61 : // QUICHE client session always use the 1st version to start handshake. 62 0 : return std::make_unique<EnvoyQuicClientSession>( 63 0 : config, quic_versions, std::move(connection), server_id, std::move(crypto_config), dispatcher, 64 0 : info_impl->buffer_limit_, info_impl->crypto_stream_factory_, quic_stat_names, rtt_cache, 65 0 : scope, transport_socket_options, transport_socket_factory); 66 0 : } 67 : 68 : } // namespace Quic 69 : } // namespace Envoy