LCOV - code coverage report
Current view: top level - source/extensions/transport_sockets/alts - alts_channel_pool.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 22 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 4 0.0 %

          Line data    Source code
       1             : #include "source/extensions/transport_sockets/alts/alts_channel_pool.h"
       2             : 
       3             : #include <algorithm>
       4             : #include <memory>
       5             : #include <string>
       6             : #include <utility>
       7             : #include <vector>
       8             : 
       9             : #include "absl/memory/memory.h"
      10             : #include "absl/strings/string_view.h"
      11             : #include "absl/synchronization/mutex.h"
      12             : #include "grpcpp/channel.h"
      13             : #include "grpcpp/create_channel.h"
      14             : #include "grpcpp/security/credentials.h"
      15             : 
      16             : namespace Envoy {
      17             : namespace Extensions {
      18             : namespace TransportSockets {
      19             : namespace Alts {
      20             : 
      21             : // TODO(matthewstevenson88): Extend this to be configurable through API.
      22             : constexpr std::size_t ChannelPoolSize = 10;
      23             : 
      24             : std::unique_ptr<AltsChannelPool>
      25           0 : AltsChannelPool::create(absl::string_view handshaker_service_address) {
      26           0 :   std::vector<std::shared_ptr<grpc::Channel>> channel_pool;
      27           0 :   channel_pool.reserve(ChannelPoolSize);
      28           0 :   grpc::ChannelArguments channel_args;
      29           0 :   channel_args.SetInt(GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL, 1);
      30           0 :   for (std::size_t i = 0; i < ChannelPoolSize; ++i) {
      31           0 :     channel_pool.push_back(grpc::CreateCustomChannel(
      32           0 :         std::string(handshaker_service_address), grpc::InsecureChannelCredentials(), channel_args));
      33           0 :   }
      34           0 :   return absl::WrapUnique(new AltsChannelPool(std::move(channel_pool)));
      35           0 : }
      36             : 
      37             : AltsChannelPool::AltsChannelPool(const std::vector<std::shared_ptr<grpc::Channel>>& channel_pool)
      38           0 :     : channel_pool_(channel_pool) {}
      39             : 
      40             : // TODO(matthewstevenson88): Add logic to limit number of outstanding channels.
      41           0 : std::shared_ptr<grpc::Channel> AltsChannelPool::getChannel() {
      42           0 :   std::shared_ptr<grpc::Channel> channel;
      43           0 :   {
      44           0 :     absl::MutexLock lock(&mu_);
      45           0 :     channel = channel_pool_[index_];
      46           0 :     index_ = (index_ + 1) % channel_pool_.size();
      47           0 :   }
      48           0 :   return channel;
      49           0 : }
      50             : 
      51           0 : std::size_t AltsChannelPool::getChannelPoolSize() const { return channel_pool_.size(); }
      52             : 
      53             : } // namespace Alts
      54             : } // namespace TransportSockets
      55             : } // namespace Extensions
      56             : } // namespace Envoy

Generated by: LCOV version 1.15