Kagome
Polkadot Runtime Engine in C++17
protocol_factory.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_NETWORK_PROTOCOLFACTORY
7 #define KAGOME_NETWORK_PROTOCOLFACTORY
8 
10 #include "consensus/babe/babe.hpp"
22 
23 #include <libp2p/basic/scheduler.hpp>
24 
25 namespace kagome::network {
26 
27  class ProtocolFactory final {
28  public:
30  libp2p::Host &host,
31  const application::AppConfiguration &app_config,
32  const application::ChainSpec &chain_spec,
33  const OwnPeerInfo &own_info,
34  std::shared_ptr<boost::asio::io_context> io_context,
35  std::shared_ptr<crypto::Hasher> hasher,
36  std::shared_ptr<StreamEngine> stream_engine,
37  std::shared_ptr<primitives::events::ExtrinsicSubscriptionEngine>
38  extrinsic_events_engine,
39  std::shared_ptr<subscription::ExtrinsicEventKeyRepository>
40  ext_event_key_repo,
41  std::shared_ptr<ReputationRepository> reputation_repository,
42  std::shared_ptr<libp2p::basic::Scheduler> scheduler);
43 
45  const std::shared_ptr<blockchain::BlockTree> &block_tree) {
46  block_tree_ = block_tree;
47  }
48 
49  void setBabe(const std::shared_ptr<consensus::babe::Babe> &babe) {
50  babe_ = babe;
51  }
52 
54  const std::shared_ptr<consensus::grandpa::GrandpaObserver>
55  &grandpa_observer) {
56  grandpa_observer_ = grandpa_observer;
57  }
58 
60  const std::shared_ptr<ExtrinsicObserver> &extrinsic_observer) {
61  extrinsic_observer_ = extrinsic_observer;
62  }
63 
65  std::shared_ptr<CollationObserver> const &collation_observer) {
66  collation_observer_ = collation_observer;
67  }
68 
70  const std::shared_ptr<StateProtocolObserver> &state_observer) {
71  state_observer_ = state_observer;
72  }
73 
75  std::shared_ptr<ReqCollationObserver> const &req_collation_observer) {
76  req_collation_observer_ = req_collation_observer;
77  }
78 
80  const std::shared_ptr<SyncProtocolObserver> &sync_observer) {
81  sync_observer_ = sync_observer;
82  }
83 
84  void setPeerManager(const std::shared_ptr<PeerManager> &peer_manager) {
85  peer_manager_ = peer_manager;
86  }
87 
88  std::shared_ptr<BlockAnnounceProtocol> makeBlockAnnounceProtocol() const;
89 
90  std::shared_ptr<GrandpaProtocol> makeGrandpaProtocol() const;
91 
92  std::shared_ptr<PropagateTransactionsProtocol>
94 
95  std::shared_ptr<StateProtocol> makeStateProtocol() const;
96  std::shared_ptr<SyncProtocol> makeSyncProtocol() const;
97 
98  std::shared_ptr<CollationProtocol> makeCollationProtocol() const;
99  std::shared_ptr<ReqCollationProtocol> makeReqCollationProtocol() const;
100 
101  private:
106  std::shared_ptr<boost::asio::io_context> io_context_;
107  std::shared_ptr<crypto::Hasher> hasher_;
108  std::shared_ptr<StreamEngine> stream_engine_;
109  std::shared_ptr<primitives::events::ExtrinsicSubscriptionEngine>
111  std::shared_ptr<subscription::ExtrinsicEventKeyRepository>
113  std::shared_ptr<ReputationRepository> reputation_repository_;
114  std::shared_ptr<libp2p::basic::Scheduler> scheduler_;
115 
116  std::weak_ptr<blockchain::BlockTree> block_tree_;
117  std::weak_ptr<consensus::babe::Babe> babe_;
118  std::weak_ptr<consensus::grandpa::GrandpaObserver> grandpa_observer_;
119  std::weak_ptr<ExtrinsicObserver> extrinsic_observer_;
120  std::weak_ptr<StateProtocolObserver> state_observer_;
121  std::weak_ptr<SyncProtocolObserver> sync_observer_;
122  std::weak_ptr<PeerManager> peer_manager_;
123  std::weak_ptr<CollationObserver> collation_observer_;
124  std::weak_ptr<ReqCollationObserver> req_collation_observer_;
125  };
126 
127 } // namespace kagome::network
128 
129 #endif // KAGOME_NETWORK_PROTOCOLFACTORY
std::shared_ptr< GrandpaProtocol > makeGrandpaProtocol() const
std::weak_ptr< consensus::grandpa::GrandpaObserver > grandpa_observer_
std::shared_ptr< CollationProtocol > makeCollationProtocol() const
std::shared_ptr< StateProtocol > makeStateProtocol() const
std::weak_ptr< StateProtocolObserver > state_observer_
std::weak_ptr< consensus::babe::Babe > babe_
std::weak_ptr< ReqCollationObserver > req_collation_observer_
std::shared_ptr< ReqCollationProtocol > makeReqCollationProtocol() const
void setPeerManager(const std::shared_ptr< PeerManager > &peer_manager)
std::weak_ptr< ExtrinsicObserver > extrinsic_observer_
void setGrandpaObserver(const std::shared_ptr< consensus::grandpa::GrandpaObserver > &grandpa_observer)
void setCollactionObserver(std::shared_ptr< CollationObserver > const &collation_observer)
void setExtrinsicObserver(const std::shared_ptr< ExtrinsicObserver > &extrinsic_observer)
ProtocolFactory(libp2p::Host &host, const application::AppConfiguration &app_config, const application::ChainSpec &chain_spec, const OwnPeerInfo &own_info, std::shared_ptr< boost::asio::io_context > io_context, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< StreamEngine > stream_engine, std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine > extrinsic_events_engine, std::shared_ptr< subscription::ExtrinsicEventKeyRepository > ext_event_key_repo, std::shared_ptr< ReputationRepository > reputation_repository, std::shared_ptr< libp2p::basic::Scheduler > scheduler)
std::weak_ptr< PeerManager > peer_manager_
std::shared_ptr< StreamEngine > stream_engine_
void setSyncObserver(const std::shared_ptr< SyncProtocolObserver > &sync_observer)
std::weak_ptr< blockchain::BlockTree > block_tree_
std::shared_ptr< SyncProtocol > makeSyncProtocol() const
void setReqCollationObserver(std::shared_ptr< ReqCollationObserver > const &req_collation_observer)
std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine > extrinsic_events_engine_
void setBabe(const std::shared_ptr< consensus::babe::Babe > &babe)
void setBlockTree(const std::shared_ptr< blockchain::BlockTree > &block_tree)
std::weak_ptr< SyncProtocolObserver > sync_observer_
std::shared_ptr< PropagateTransactionsProtocol > makePropagateTransactionsProtocol() const
std::weak_ptr< CollationObserver > collation_observer_
const application::ChainSpec & chain_spec_
const application::AppConfiguration & app_config_
std::shared_ptr< BlockAnnounceProtocol > makeBlockAnnounceProtocol() const
std::shared_ptr< boost::asio::io_context > io_context_
void setStateObserver(const std::shared_ptr< StateProtocolObserver > &state_observer)
std::shared_ptr< crypto::Hasher > hasher_
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
std::shared_ptr< subscription::ExtrinsicEventKeyRepository > ext_event_key_repo_
std::shared_ptr< ReputationRepository > reputation_repository_