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 
28  std::unique_ptr<GrpcChannelParams> getDefaultChannelParams();
29 
30  grpc::ChannelArguments makeChannelArguments(
31  const std::set<std::string> &services, const GrpcChannelParams &params);
32 
39  template <typename Service>
40  grpc::ChannelArguments makeChannelArguments(
41  const GrpcChannelParams &params) {
42  return makeChannelArguments(Service::service_full_name(), params);
43  }
44 
52  template <typename Service>
53  std::unique_ptr<typename Service::StubInterface> createInsecureClient(
54  const std::string &address, const GrpcChannelParams &params) {
55  auto channel =
56  createInsecureChannel(address, Service::service_full_name(), params);
57  return Service::NewStub(std::move(channel));
58  }
59 
68  template <typename Service>
69  std::unique_ptr<typename Service::StubInterface> createInsecureClient(
70  const std::string &ip, size_t port, const GrpcChannelParams &params) {
71  return createInsecureClient<Service>(ip + ":" + std::to_string(port),
72  params);
73  }
74 
83  std::shared_ptr<grpc::Channel> createInsecureChannel(
85  const std::string &service_full_name,
86  const GrpcChannelParams &params);
87 
89  public:
91  ChannelFactory(std::shared_ptr<const GrpcChannelParams> params);
92 
93  ~ChannelFactory() override;
94 
95  iroha::expected::Result<std::shared_ptr<grpc::Channel>, std::string>
96  getChannel(const std::string &service_full_name,
97  const shared_model::interface::Peer &peer) override;
98 
99  protected:
100  virtual iroha::expected::Result<std::shared_ptr<grpc::ChannelCredentials>,
101  std::string>
103 
104  private:
106  std::unique_ptr<ChannelArgumentsProvider> args_;
107  };
108 
109  } // namespace network
110 } // namespace iroha
111 
112 #endif
std::unique_ptr< GrpcChannelParams > getDefaultChannelParams()
Definition: channel_factory.cpp:26
std::string AddressType
Type of peer address.
Definition: types.hpp:45
virtual iroha::expected::Result< std::shared_ptr< grpc::ChannelCredentials >, std::string > getChannelCredentials(const shared_model::interface::Peer &) const
Definition: channel_factory.cpp:142
Definition: peer.hpp:20
Definition: grpc_channel_params.hpp:17
iroha::expected::Result< std::shared_ptr< grpc::Channel >, std::string > getChannel(const std::string &service_full_name, const shared_model::interface::Peer &peer) override
Definition: channel_factory.cpp:132
grpc::ChannelArguments makeChannelArguments(const std::set< std::string > &services, const GrpcChannelParams &params)
Definition: channel_factory.cpp:44
std::unique_ptr< typename Service::StubInterface > createInsecureClient(const std::string &address, const GrpcChannelParams &params)
Definition: channel_factory.hpp:53
Definition: block_query.hpp:14
ChannelFactory(std::shared_ptr< const GrpcChannelParams > params)
Definition: channel_factory.cpp:127
Definition: channel_factory.hpp:88
Definition: channel_provider.hpp:24
std::shared_ptr< grpc::Channel > createInsecureChannel(const shared_model::interface::types::AddressType &address, const std::string &service_full_name, const GrpcChannelParams &params)
Definition: channel_factory.cpp:98