6 #ifndef KAGOME_NETWORK_PEERMANAGERIMPL 7 #define KAGOME_NETWORK_PEERMANAGERIMPL 14 #include <libp2p/basic/scheduler.hpp> 15 #include <libp2p/event/bus.hpp> 16 #include <libp2p/host/host.hpp> 17 #include <libp2p/protocol/identify/identify.hpp> 18 #include <libp2p/protocol/kademlia/kademlia.hpp> 53 public std::enable_shared_from_this<PeerManagerImpl> {
55 static constexpr std::chrono::seconds kTimeoutForConnecting{15};
57 enum class Error { UNDECLARED_COLLATOR = 1, OUT_OF_VIEW, DUPLICATE };
60 std::shared_ptr<application::AppStateManager> app_state_manager,
62 std::shared_ptr<libp2p::protocol::Identify> identify,
63 std::shared_ptr<libp2p::protocol::kademlia::Kademlia> kademlia,
64 std::shared_ptr<libp2p::basic::Scheduler> scheduler,
65 std::shared_ptr<StreamEngine> stream_engine,
67 std::shared_ptr<clock::SteadyClock> clock,
70 std::shared_ptr<network::Router> router,
71 std::shared_ptr<storage::BufferStorage> storage,
72 std::shared_ptr<crypto::Hasher> hasher,
73 std::shared_ptr<ReputationRepository> reputation_repository);
85 void connectToPeer(
const PeerInfo &peer_info)
override;
88 void reserveStreams(
const PeerId &peer_id)
const override;
91 std::shared_ptr<StreamEngine> getStreamEngine()
override;
94 size_t activePeersNumber()
const override;
97 void setCollating(
const PeerId &peer_id,
105 std::pair<network::CollatorPublicKey const &, network::ParachainId>>
106 insert_advertisement(
PeerState &peer_state,
111 void forEachPeer(std::function<
void(
const PeerId &)> func)
const override;
114 void forOnePeer(
const PeerId &peer_id,
115 std::function<
void(
const PeerId &)> func)
const override;
118 void keepAlive(
const PeerId &peer_id)
override;
121 void startPingingPeer(
const PeerId &peer_id)
override;
124 void updatePeerState(
const PeerId &peer_id,
const Status &status)
override;
127 void updatePeerState(
const PeerId &peer_id,
131 void updatePeerState(
136 std::optional<std::reference_wrapper<PeerState>> getPeerState(
137 const PeerId &peer_id)
override;
141 bool isSelfPeer(
const PeerId &peer_id)
const;
146 void processDiscoveredPeer(
const PeerId &peer_id);
148 void processFullyConnectedPeer(
const PeerId &peer_id);
151 void connectToPeer(
const PeerId &peer_id);
154 void disconnectFromPeer(
const PeerId &peer_id);
156 std::vector<scale::PeerInfoSerializable> loadLastActivePeers();
160 void storeActivePeers();
162 void clearClosedPingingConnections();
167 std::shared_ptr<libp2p::protocol::kademlia::Kademlia>
kademlia_;
171 std::shared_ptr<clock::SteadyClock>
clock_;
184 std::unordered_set<libp2p::network::ConnectionManager::ConnectionSPtr>
206 #endif // KAGOME_NETWORK_PEERMANAGERIMPL
const BootstrapNodes & bootstrap_nodes_
std::unordered_set< PeerId > peers_in_queue_
std::unordered_set< libp2p::network::ConnectionManager::ConnectionSPtr > pinging_connections_
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
std::shared_ptr< application::AppStateManager > app_state_manager_
libp2p::peer::PeerId PeerId
std::unordered_set< PeerId > connecting_peers_
std::shared_ptr< StreamEngine > stream_engine_
std::deque< std::reference_wrapper< const PeerId > > queue_to_connect_
std::map< PeerId, PeerDescriptor > active_peers_
crypto::Sr25519PublicKey CollatorPublicKey
OUTCOME_HPP_DECLARE_ERROR(kagome::api, JRpcServerImpl::Error)
const application::AppConfiguration & app_config_
std::unique_ptr< Registry > RegistryPtr
RegistryPtr createRegistry()
libp2p::event::Handle add_peer_handle_
metrics::Gauge * sync_peer_num_
std::shared_ptr< soralog::Logger > Logger
std::shared_ptr< ReputationRepository > reputation_repository_
std::shared_ptr< network::Router > router_
libp2p::peer::PeerInfo PeerInfo
std::shared_ptr< libp2p::protocol::kademlia::Kademlia > kademlia_
std::set< PeerId > recently_active_peers_
std::shared_ptr< clock::SteadyClock > clock_
std::unordered_map< PeerId, PeerState > peer_states_
libp2p::event::Handle peer_disconnected_handler_
libp2p::basic::Scheduler::Handle align_timer_
std::shared_ptr< crypto::Hasher > hasher_
std::shared_ptr< storage::BufferStorage > storage_
ParachainState parachain_state_
const OwnPeerInfo & own_peer_info_
A gauge metric to represent a value that can arbitrarily go up and down.
std::shared_ptr< libp2p::protocol::Identify > identify_
typename ClockType::time_point TimePoint
clock::SteadyClock::TimePoint time_point