Kagome
Polkadot Runtime Engine in C++17
bootstrap_nodes.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_NETWORK_BOOTSTRAPNODES
7 #define KAGOME_NETWORK_BOOTSTRAPNODES
8 
9 #include <libp2p/peer/peer_info.hpp>
10 
11 #include <boost/range/join.hpp>
12 
15 
16 namespace kagome::network {
17 
18  struct BootstrapNodes : public std::vector<libp2p::peer::PeerInfo> {
19  BootstrapNodes() = delete;
20  BootstrapNodes(const BootstrapNodes &) = delete;
21  BootstrapNodes(BootstrapNodes &&) noexcept = delete;
22  BootstrapNodes &operator=(const BootstrapNodes &) = delete;
23  BootstrapNodes &operator=(BootstrapNodes &&) noexcept = delete;
24 
26  const application::ChainSpec &chain_spec) {
27  std::unordered_map<libp2p::peer::PeerId,
28  std::set<libp2p::multi::Multiaddress>>
29  addresses_by_peer_id;
30 
31  for (auto &address :
32  boost::join(chain_spec.bootNodes(), app_config.bootNodes())) {
33  auto peer_id_base58_opt = address.getPeerId();
34  if (peer_id_base58_opt) {
35  auto peer_id_res =
36  libp2p::peer::PeerId::fromBase58(peer_id_base58_opt.value());
37  if (peer_id_res.has_value()) {
38  addresses_by_peer_id[peer_id_res.value()].emplace(address);
39  }
40  }
41  }
42 
43  reserve(addresses_by_peer_id.size());
44  for (auto &item : addresses_by_peer_id) {
45  emplace_back(libp2p::peer::PeerInfo{
46  .id = item.first,
47  .addresses = {std::make_move_iterator(item.second.begin()),
48  std::make_move_iterator(item.second.end())}});
49  }
50  }
51  };
52 
53 } // namespace kagome::network
54 
55 #endif // KAGOME_NETWORK_BOOTSTRAPNODES
BootstrapNodes & operator=(const BootstrapNodes &)=delete
BootstrapNodes(const application::AppConfiguration &app_config, const application::ChainSpec &chain_spec)
libp2p::peer::PeerInfo PeerInfo
libp2p::peer::PeerId PeerId
virtual const std::vector< libp2p::multi::Multiaddress > & bootNodes() const =0
Return ids of peer nodes of the current node.
virtual const std::vector< libp2p::multi::Multiaddress > & bootNodes() const =0