10 std::shared_ptr<application::AppStateManager> app_state_manager,
15 std::shared_ptr<libp2p::protocol::Ping> ping_proto,
16 std::shared_ptr<network::ProtocolFactory> protocol_factory)
17 : app_state_manager_{app_state_manager},
28 SL_DEBUG(
log_,
"Own peer id: {}", own_info.id.toBase58());
29 if (!bootstrap_nodes.empty()) {
30 for (
const auto &peer_info : bootstrap_nodes) {
31 for (
auto &addr : peer_info.addresses) {
32 SL_DEBUG(
log_,
"Bootstrap node: {}", addr.getStringAddress());
36 SL_DEBUG(
log_,
"No bootstrap node. Dev mode.");
38 log_->error(
"No bootstrap node");
45 host_.setProtocolHandler(
47 [wp = weak_from_this()](
auto &&stream_and_proto) {
48 if (
auto self = wp.lock()) {
49 auto &stream = stream_and_proto.stream;
50 if (
auto peer_id = stream->remotePeerId()) {
52 "Handled {} protocol stream from: {}",
53 self->ping_protocol_->getProtocolId(),
54 peer_id.value().toBase58());
55 self->ping_protocol_->handle(
56 std::forward<decltype(stream_and_proto)>(stream_and_proto));
97 block_announce_protocol_->start();
98 grandpa_protocol_->start();
99 propagate_transaction_protocol_->start();
100 state_protocol_->start();
101 sync_protocol_->start();
102 collation_protocol_->start();
103 req_collation_protocol_->start();
110 for (
auto &listen_address : listen_addresses) {
113 if (not append_res) {
114 log_->error(
"Cannot append peer id info to listen addr {}. Error: {}",
115 listen_address.getStringAddress(),
116 append_res.error().message());
120 auto res =
host_.listen(listen_address);
122 log_->error(
"Cannot listen on address {}. Error: {}",
123 listen_address.getStringAddress(),
124 res.error().message());
128 auto &addr_repo =
host_.getPeerRepository().getAddressRepository();
130 auto upsert_res = addr_repo.upsertAddresses(
133 log_->error(
"Cannot add own addresses to repo: {}",
134 upsert_res.error().message());
139 const auto &host_addresses =
host_.getAddresses();
140 if (host_addresses.empty()) {
141 log_->critical(
"Host addresses is empty");
145 log_->info(
"Started with peer id: {}",
host_.getId().toBase58());
146 for (
const auto &addr : host_addresses) {
147 log_->info(
"Started listening on address: {}", addr.getStringAddress());
154 if (
host_.getNetwork().getListener().isStarted()) {
159 std::shared_ptr<BlockAnnounceProtocol>
174 std::shared_ptr<PropagateTransactionsProtocol>
197 libp2p::multi::Multiaddress &address)
const {
198 using P = libp2p::multi::Protocol::Code;
200 if (address.getProtocols().size()
202 and (address.hasProtocol(P::IP4) or address.hasProtocol(P::IP6))
203 and address.hasProtocol(P::TCP)) {
207 auto ma_res = libp2p::multi::Multiaddress::create(
208 std::string(address.getStringAddress()) +
"/p2p/" 211 return ma_res.error();
213 address = ma_res.value();
215 return outcome::success();
std::shared_ptr< libp2p::protocol::Ping > ping_protocol_
std::shared_ptr< GrandpaProtocol > getGrandpaProtocol() const override
std::shared_ptr< libp2p::protocol::Ping > getPingProtocol() const override
std::shared_ptr< SyncProtocol > sync_protocol_
virtual const std::vector< libp2p::multi::Multiaddress > & listenAddresses() const =0
std::shared_ptr< SyncProtocol > getSyncProtocol() const override
std::shared_ptr< BlockAnnounceProtocol > getBlockAnnounceProtocol() const override
std::shared_ptr< StateProtocol > getStateProtocol() const override
const application::AppConfiguration & app_config_
std::shared_ptr< BlockAnnounceProtocol > block_announce_protocol_
std::shared_ptr< CollationProtocol > getCollationProtocol() const override
std::shared_ptr< ReqCollationProtocol > req_collation_protocol_
std::shared_ptr< PropagateTransactionsProtocol > getPropagateTransactionsProtocol() const override
virtual bool isRunInDevMode() const =0
RouterLibp2p(std::shared_ptr< application::AppStateManager > app_state_manager, libp2p::Host &host, const application::AppConfiguration &app_config, const OwnPeerInfo &own_info, const BootstrapNodes &bootstrap_nodes, std::shared_ptr< libp2p::protocol::Ping > ping_proto, std::shared_ptr< network::ProtocolFactory > protocol_factory)
std::shared_ptr< CollationProtocol > collation_protocol_
const OwnPeerInfo & own_info_
std::shared_ptr< PropagateTransactionsProtocol > propagate_transaction_protocol_
outcome::result< void > appendPeerIdToAddress(libp2p::multi::Multiaddress &address) const
std::shared_ptr< application::AppStateManager > app_state_manager_
std::shared_ptr< GrandpaProtocol > grandpa_protocol_
std::shared_ptr< ReqCollationProtocol > getReqCollationProtocol() const override
Logger createLogger(const std::string &tag)
std::shared_ptr< StateProtocol > state_protocol_
std::shared_ptr< network::ProtocolFactory > protocol_factory_