hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
network_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_NETWORK_IMPL_HPP
7 #define IROHA_NETWORK_IMPL_HPP
8 
9 #include "consensus/yac/transport/yac_network_interface.hpp" // for YacNetwork
10 #include "yac.grpc.pb.h"
11 
12 #include <memory>
13 #include <mutex>
14 #include <unordered_map>
15 
20 #include "logger/logger_fwd.hpp"
22 
23 namespace iroha {
24  namespace consensus {
25  namespace yac {
26 
31  class NetworkImpl : public YacNetwork, public proto::Yac::Service {
32  public:
33  explicit NetworkImpl(
35  async_call,
36  std::function<std::unique_ptr<proto::Yac::StubInterface>(
37  const shared_model::interface::Peer &)> client_creator,
38  logger::LoggerPtr log);
39 
40  void subscribe(
41  std::shared_ptr<YacNetworkNotifications> handler) override;
42 
44  const std::vector<VoteMessage> &state) override;
45 
52  ::grpc::ServerContext *context,
53  const ::iroha::consensus::yac::proto::State *request,
54  ::google::protobuf::Empty *response) override;
55 
56  void stop() override;
57 
58  private:
64  void createPeerConnection(const shared_model::interface::Peer &peer);
65 
70  std::unique_ptr<proto::Yac::StubInterface>>
71  peers_;
72 
76  std::weak_ptr<YacNetworkNotifications> handler_;
77 
81  std::shared_ptr<network::AsyncGrpcClient<google::protobuf::Empty>>
82  async_call_;
83 
87  std::function<std::unique_ptr<proto::Yac::StubInterface>(
89  client_creator_;
90 
91  std::mutex stop_mutex_;
92  bool stop_requested_{false};
93 
94  logger::LoggerPtr log_;
95  };
96 
97  } // namespace yac
98  } // namespace consensus
99 } // namespace iroha
100 
101 #endif // IROHA_NETWORK_IMPL_HPP
Definition: yac_network_interface.hpp:35
std::string AddressType
Type of peer address.
Definition: types.hpp:50
Definition: peer.hpp:20
void stop() override
Prevent any new outgoing network activity. Be passive.
Definition: network_impl.cpp:38
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: block_query.hpp:15
Definition: network_impl.hpp:31
void sendState(const shared_model::interface::Peer &to, const std::vector< VoteMessage > &state) override
Definition: network_impl.cpp:43
void subscribe(std::shared_ptr< YacNetworkNotifications > handler) override
Definition: network_impl.cpp:33
NetworkImpl(std::shared_ptr< network::AsyncGrpcClient< google::protobuf::Empty >> async_call, std::function< std::unique_ptr< proto::Yac::StubInterface >(const shared_model::interface::Peer &)> client_creator, logger::LoggerPtr log)
Definition: network_impl.cpp:23
Definition: async_grpc_client.hpp:25
Status
Definition: status.hpp:12
grpc::Status SendState(::grpc::ServerContext *context, const ::iroha::consensus::yac::proto::State *request, ::google::protobuf::Empty *response) override
Definition: network_impl.cpp:67