LCOV - code coverage report
Current view: top level - source/extensions/upstreams/tcp/generic - config.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 3 31 9.7 %
Date: 2024-01-05 06:35:25 Functions: 1 4 25.0 %

          Line data    Source code
       1             : #include "source/extensions/upstreams/tcp/generic/config.h"
       2             : 
       3             : #include "envoy/stream_info/bool_accessor.h"
       4             : #include "envoy/stream_info/filter_state.h"
       5             : #include "envoy/upstream/cluster_manager.h"
       6             : 
       7             : #include "source/common/http/codec_client.h"
       8             : #include "source/common/stream_info/bool_accessor_impl.h"
       9             : #include "source/common/tcp_proxy/upstream.h"
      10             : 
      11             : namespace Envoy {
      12             : namespace Extensions {
      13             : namespace Upstreams {
      14             : namespace Tcp {
      15             : namespace Generic {
      16             : 
      17             : TcpProxy::GenericConnPoolPtr GenericConnPoolFactory::createGenericConnPool(
      18             :     Upstream::ThreadLocalCluster& thread_local_cluster,
      19             :     TcpProxy::TunnelingConfigHelperOptConstRef config, Upstream::LoadBalancerContext* context,
      20             :     Envoy::Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks,
      21           0 :     StreamInfo::StreamInfo& downstream_info) const {
      22           0 :   if (config.has_value() && !disableTunnelingByFilterState(downstream_info)) {
      23           0 :     Http::CodecType pool_type;
      24           0 :     if ((thread_local_cluster.info()->features() & Upstream::ClusterInfo::Features::HTTP2) != 0) {
      25           0 :       pool_type = Http::CodecType::HTTP2;
      26           0 :     } else if ((thread_local_cluster.info()->features() & Upstream::ClusterInfo::Features::HTTP3) !=
      27           0 :                0) {
      28           0 :       pool_type = Http::CodecType::HTTP3;
      29           0 :     } else {
      30           0 :       pool_type = Http::CodecType::HTTP1;
      31           0 :     }
      32           0 :     auto ret = std::make_unique<TcpProxy::HttpConnPool>(
      33           0 :         thread_local_cluster, context, *config, upstream_callbacks, pool_type, downstream_info);
      34           0 :     return (ret->valid() ? std::move(ret) : nullptr);
      35           0 :   }
      36           0 :   auto ret = std::make_unique<TcpProxy::TcpConnPool>(thread_local_cluster, context,
      37           0 :                                                      upstream_callbacks, downstream_info);
      38           0 :   return (ret->valid() ? std::move(ret) : nullptr);
      39           0 : }
      40             : 
      41             : bool GenericConnPoolFactory::disableTunnelingByFilterState(
      42           0 :     StreamInfo::StreamInfo& downstream_info) const {
      43           0 :   const StreamInfo::BoolAccessor* disable_tunneling =
      44           0 :       downstream_info.filterState()->getDataReadOnly<StreamInfo::BoolAccessor>(
      45           0 :           TcpProxy::DisableTunnelingFilterStateKey);
      46             : 
      47           0 :   return disable_tunneling != nullptr && disable_tunneling->value() == true;
      48           0 : }
      49             : 
      50             : REGISTER_FACTORY(GenericConnPoolFactory, TcpProxy::GenericConnPoolFactory);
      51             : 
      52             : class DisableTunnelingObjectFactory : public StreamInfo::FilterState::ObjectFactory {
      53             : public:
      54           2 :   std::string name() const override {
      55           2 :     return std::string(TcpProxy::DisableTunnelingFilterStateKey);
      56           2 :   }
      57             :   std::unique_ptr<StreamInfo::FilterState::Object>
      58           0 :   createFromBytes(absl::string_view data) const override {
      59           0 :     return std::make_unique<StreamInfo::BoolAccessorImpl>(data == "true");
      60           0 :   }
      61             : };
      62             : 
      63             : REGISTER_FACTORY(DisableTunnelingObjectFactory, StreamInfo::FilterState::ObjectFactory);
      64             : 
      65             : } // namespace Generic
      66             : } // namespace Tcp
      67             : } // namespace Upstreams
      68             : } // namespace Extensions
      69             : } // namespace Envoy

Generated by: LCOV version 1.15