LCOV - code coverage report
Current view: top level - source/common/quic - quic_client_transport_socket_factory.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 3 36 8.3 %
Date: 2024-01-05 06:35:25 Functions: 1 6 16.7 %

          Line data    Source code
       1             : #include "source/common/quic/quic_client_transport_socket_factory.h"
       2             : 
       3             : #include <memory>
       4             : 
       5             : #include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.validate.h"
       6             : 
       7             : #include "source/common/quic/envoy_quic_proof_verifier.h"
       8             : #include "source/common/runtime/runtime_features.h"
       9             : #include "source/extensions/transport_sockets/tls/context_config_impl.h"
      10             : 
      11             : #include "quiche/quic/core/crypto/quic_client_session_cache.h"
      12             : 
      13             : namespace Envoy {
      14             : namespace Quic {
      15             : 
      16             : Network::UpstreamTransportSocketFactoryPtr
      17             : QuicClientTransportSocketConfigFactory::createTransportSocketFactory(
      18             :     const Protobuf::Message& config,
      19           0 :     Server::Configuration::TransportSocketFactoryContext& context) {
      20           0 :   auto quic_transport = MessageUtil::downcastAndValidate<
      21           0 :       const envoy::extensions::transport_sockets::quic::v3::QuicUpstreamTransport&>(
      22           0 :       config, context.messageValidationVisitor());
      23           0 :   auto client_config = std::make_unique<Extensions::TransportSockets::Tls::ClientContextConfigImpl>(
      24           0 :       quic_transport.upstream_tls_context(), context);
      25           0 :   auto factory =
      26           0 :       std::make_unique<QuicClientTransportSocketFactory>(std::move(client_config), context);
      27           0 :   factory->initialize();
      28           0 :   return factory;
      29           0 : }
      30             : 
      31             : QuicClientTransportSocketFactory::QuicClientTransportSocketFactory(
      32             :     Ssl::ClientContextConfigPtr config,
      33             :     Server::Configuration::TransportSocketFactoryContext& factory_context)
      34             :     : QuicTransportSocketFactoryBase(factory_context.statsScope(), "client"),
      35             :       fallback_factory_(std::make_unique<Extensions::TransportSockets::Tls::ClientSslSocketFactory>(
      36           0 :           std::move(config), factory_context.sslContextManager(), factory_context.statsScope())) {}
      37             : 
      38           0 : void QuicClientTransportSocketFactory::initialize() {
      39           0 :   if (!fallback_factory_->clientContextConfig()->alpnProtocols().empty()) {
      40           0 :     supported_alpns_ =
      41           0 :         absl::StrSplit(fallback_factory_->clientContextConfig()->alpnProtocols(), ',');
      42           0 :   }
      43           0 : }
      44             : 
      45          12 : ProtobufTypes::MessagePtr QuicClientTransportSocketConfigFactory::createEmptyConfigProto() {
      46          12 :   return std::make_unique<envoy::extensions::transport_sockets::quic::v3::QuicUpstreamTransport>();
      47          12 : }
      48             : 
      49           0 : std::shared_ptr<quic::QuicCryptoClientConfig> QuicClientTransportSocketFactory::getCryptoConfig() {
      50           0 :   Envoy::Ssl::ClientContextSharedPtr context = sslCtx();
      51             :   // If the secrets haven't been loaded, there is no crypto config.
      52           0 :   if (context == nullptr) {
      53           0 :     ENVOY_LOG(warn, "SDS hasn't finished updating Ssl context config yet.");
      54           0 :     stats_.upstream_context_secrets_not_ready_.inc();
      55           0 :     return nullptr;
      56           0 :   }
      57             : 
      58           0 :   if (client_context_ != context) {
      59             :     // If the context has been updated, update the crypto config.
      60           0 :     client_context_ = context;
      61           0 :     crypto_config_ = std::make_shared<quic::QuicCryptoClientConfig>(
      62           0 :         std::make_unique<Quic::EnvoyQuicProofVerifier>(std::move(context)),
      63           0 :         std::make_unique<quic::QuicClientSessionCache>());
      64           0 :   }
      65             :   // Return the latest crypto config.
      66           0 :   return crypto_config_;
      67           0 : }
      68             : 
      69             : REGISTER_FACTORY(QuicClientTransportSocketConfigFactory,
      70             :                  Server::Configuration::UpstreamTransportSocketConfigFactory);
      71             : 
      72             : } // namespace Quic
      73             : } // namespace Envoy

Generated by: LCOV version 1.15