1
#pragma once
2

            
3
#include <cstddef>
4
#include <memory>
5
#include <vector>
6

            
7
#include "absl/strings/string_view.h"
8
#include "absl/synchronization/mutex.h"
9
#include "grpcpp/channel.h"
10

            
11
namespace Envoy {
12
namespace Extensions {
13
namespace TransportSockets {
14
namespace Alts {
15

            
16
// Manages a pool of gRPC channels to the ALTS handshaker service.
17
class AltsChannelPool {
18
public:
19
  static std::unique_ptr<AltsChannelPool> create(absl::string_view handshaker_service_address);
20

            
21
  // Gets a channel to the ALTS handshaker service. The caller is responsible
22
  // for checking that the channel is non-null.
23
  std::shared_ptr<grpc::Channel> getChannel();
24

            
25
  std::size_t getChannelPoolSize() const;
26

            
27
private:
28
  explicit AltsChannelPool(const std::vector<std::shared_ptr<grpc::Channel>>& channel_pool);
29

            
30
  // Use round-robin to select channels from the pool.
31
  absl::Mutex mu_;
32
  std::size_t index_ ABSL_GUARDED_BY(mu_) = 0;
33
  std::vector<std::shared_ptr<grpc::Channel>> channel_pool_;
34
};
35

            
36
} // namespace Alts
37
} // namespace TransportSockets
38
} // namespace Extensions
39
} // namespace Envoy