hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
channel_factory.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_CHANNEL_FACTORY_HPP
7 #define IROHA_CHANNEL_FACTORY_HPP
8 
10 
11 #include <memory>
12 #include <set>
13 #include <string>
14 
15 #include <grpc++/grpc++.h>
16 
17 #include "common/result.hpp"
20 
21 namespace iroha {
22  namespace network {
23  namespace detail {
24  grpc::ChannelArguments makeChannelArguments(
25  const std::set<std::string> &services,
26  const GrpcChannelParams &params);
27 
28  grpc::ChannelArguments makeInterPeerChannelArguments(
29  const std::set<std::string> &services,
30  const GrpcChannelParams &params);
31  } // namespace detail
32 
39  template <typename Service>
40  grpc::ChannelArguments makeInterPeerChannelArguments(
41  const GrpcChannelParams &params) {
43  {Service::service_full_name()}, params);
44  }
45 
53  template <typename Service>
54  std::shared_ptr<grpc::Channel> createInsecureChannel(
56  std::optional<std::reference_wrapper<GrpcChannelParams const>>
57  maybe_params) {
58  return createInsecureChannel(
59  address, Service::service_full_name(), maybe_params);
60  }
61 
70  std::shared_ptr<grpc::Channel> createInsecureChannel(
72  const std::string &service_full_name,
73  std::optional<std::reference_wrapper<GrpcChannelParams const>>
74  maybe_params);
75 
83  template <typename Service>
84  std::unique_ptr<typename Service::StubInterface> createInsecureClient(
85  const std::string &address,
86  std::optional<std::reference_wrapper<GrpcChannelParams const>> params) {
87  return Service::NewStub(createInsecureChannel<Service>(address, params));
88  }
89 
98  template <typename Service>
99  std::unique_ptr<typename Service::StubInterface> createInsecureClient(
100  const std::string &ip,
101  size_t port,
102  std::optional<std::reference_wrapper<GrpcChannelParams const>>
103  maybe_params) {
104  return createInsecureClient<Service>(ip + ":" + std::to_string(port),
105  maybe_params);
106  }
107 
109  public:
112  std::optional<std::shared_ptr<const GrpcChannelParams>> maybe_params);
113 
114  ~ChannelFactory() override;
115 
117  getChannel(const std::string &service_full_name,
118  const shared_model::interface::Peer &peer) override;
119 
120  protected:
122  std::string>
123  getChannelCredentials(const shared_model::interface::Peer &) const;
124 
125  private:
127  std::unique_ptr<ChannelArgumentsProvider> args_;
128  };
129 
130  } // namespace network
131 } // namespace iroha
132 
133 #endif
std::shared_ptr< grpc::Channel > createInsecureChannel(const shared_model::interface::types::AddressType &address, std::optional< std::reference_wrapper< GrpcChannelParams const >> maybe_params)
Definition: channel_factory.hpp:54
std::string AddressType
Type of peer address.
Definition: types.hpp:50
Definition: peer.hpp:20
Definition: result_fwd.hpp:27
Definition: grpc_channel_params.hpp:16
grpc::ChannelArguments makeChannelArguments(const std::set< std::string > &services, const GrpcChannelParams &params)
Definition: channel_factory.cpp:30
Definition: block_query.hpp:15
Definition: channel_factory.hpp:108
Definition: channel_provider.hpp:24
std::unique_ptr< typename Service::StubInterface > createInsecureClient(const std::string &address, std::optional< std::reference_wrapper< GrpcChannelParams const >> params)
Definition: channel_factory.hpp:84
grpc::ChannelArguments makeInterPeerChannelArguments(const std::set< std::string > &services, const GrpcChannelParams &params)
Definition: channel_factory.cpp:25