Kagome
Polkadot Runtime Engine in C++17
kagome::network::PeerManagerImpl Class Reference

#include <peer_manager_impl.hpp>

Inheritance diagram for kagome::network::PeerManagerImpl:
Collaboration diagram for kagome::network::PeerManagerImpl:

Public Types

enum  Error { Error::UNDECLARED_COLLATOR = 1, Error::OUT_OF_VIEW, Error::DUPLICATE }
 
- Public Types inherited from kagome::network::PeerManager
using PeerId = libp2p::peer::PeerId
 
using PeerInfo = libp2p::peer::PeerInfo
 
using BlockInfo = primitives::BlockInfo
 
using AdvResult = outcome::result< std::pair< network::CollatorPublicKey const &, network::ParachainId >>
 

Public Member Functions

 PeerManagerImpl (std::shared_ptr< application::AppStateManager > app_state_manager, libp2p::Host &host, std::shared_ptr< libp2p::protocol::Identify > identify, std::shared_ptr< libp2p::protocol::kademlia::Kademlia > kademlia, std::shared_ptr< libp2p::basic::Scheduler > scheduler, std::shared_ptr< StreamEngine > stream_engine, const application::AppConfiguration &app_config, std::shared_ptr< clock::SteadyClock > clock, const BootstrapNodes &bootstrap_nodes, const OwnPeerInfo &own_peer_info, std::shared_ptr< network::Router > router, std::shared_ptr< storage::BufferStorage > storage, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< ReputationRepository > reputation_repository)
 
bool prepare ()
 
bool start ()
 
void stop ()
 
void connectToPeer (const PeerInfo &peer_info) override
 
void reserveStreams (const PeerId &peer_id) const override
 
std::shared_ptr< StreamEnginegetStreamEngine () override
 
size_t activePeersNumber () const override
 
void setCollating (const PeerId &peer_id, network::CollatorPublicKey const &collator_id, network::ParachainId para_id) override
 
ParachainStateparachainState () override
 
outcome::result< std::pair< network::CollatorPublicKey const &, network::ParachainId > > insert_advertisement (PeerState &peer_state, ParachainState &parachain_state, primitives::BlockHash para_hash) override
 
void forEachPeer (std::function< void(const PeerId &)> func) const override
 
void forOnePeer (const PeerId &peer_id, std::function< void(const PeerId &)> func) const override
 
void keepAlive (const PeerId &peer_id) override
 
void startPingingPeer (const PeerId &peer_id) override
 
void updatePeerState (const PeerId &peer_id, const Status &status) override
 
void updatePeerState (const PeerId &peer_id, const BlockAnnounce &announce) override
 
void updatePeerState (const PeerId &peer_id, const GrandpaNeighborMessage &neighbor_message) override
 
std::optional< std::reference_wrapper< PeerState > > getPeerState (const PeerId &peer_id) override
 
- Public Member Functions inherited from kagome::network::PeerManager
virtual ~PeerManager ()=default
 

Static Public Attributes

static constexpr std::chrono::seconds kTimeoutForConnecting {15}
 

Private Member Functions

bool isSelfPeer (const PeerId &peer_id) const
 Right way to check self peer as it takes into account dev mode. More...
 
void align ()
 Aligns amount of connected streams. More...
 
void processDiscoveredPeer (const PeerId &peer_id)
 
void processFullyConnectedPeer (const PeerId &peer_id)
 
void connectToPeer (const PeerId &peer_id)
 Opens streams set for special peer (i.e. new-discovered) More...
 
void disconnectFromPeer (const PeerId &peer_id)
 Closes all streams of provided peer. More...
 
std::vector< scale::PeerInfoSerializableloadLastActivePeers ()
 
void storeActivePeers ()
 
void clearClosedPingingConnections ()
 

Private Attributes

std::shared_ptr< application::AppStateManagerapp_state_manager_
 
libp2p::Host & host_
 
std::shared_ptr< libp2p::protocol::Identify > identify_
 
std::shared_ptr< libp2p::protocol::kademlia::Kademlia > kademlia_
 
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
 
std::shared_ptr< StreamEnginestream_engine_
 
const application::AppConfigurationapp_config_
 
std::shared_ptr< clock::SteadyClockclock_
 
const BootstrapNodesbootstrap_nodes_
 
const OwnPeerInfoown_peer_info_
 
std::shared_ptr< network::Routerrouter_
 
std::shared_ptr< storage::BufferStoragestorage_
 
std::shared_ptr< crypto::Hasherhasher_
 
std::shared_ptr< ReputationRepositoryreputation_repository_
 
libp2p::event::Handle add_peer_handle_
 
libp2p::event::Handle peer_disconnected_handler_
 
std::unordered_set< PeerIdpeers_in_queue_
 
std::deque< std::reference_wrapper< const PeerId > > queue_to_connect_
 
std::unordered_set< PeerIdconnecting_peers_
 
std::unordered_set< libp2p::network::ConnectionManager::ConnectionSPtr > pinging_connections_
 
std::map< PeerId, PeerDescriptoractive_peers_
 
std::unordered_map< PeerId, PeerStatepeer_states_
 
libp2p::basic::Scheduler::Handle align_timer_
 
std::set< PeerIdrecently_active_peers_
 
metrics::RegistryPtr registry_ = metrics::createRegistry()
 
metrics::Gaugesync_peer_num_
 
ParachainState parachain_state_
 
log::Logger log_
 

Detailed Description

Definition at line 52 of file peer_manager_impl.hpp.

Member Enumeration Documentation

Enumerator
UNDECLARED_COLLATOR 
OUT_OF_VIEW 
DUPLICATE 

Definition at line 57 of file peer_manager_impl.hpp.

Constructor & Destructor Documentation

kagome::network::PeerManagerImpl::PeerManagerImpl ( std::shared_ptr< application::AppStateManager app_state_manager,
libp2p::Host &  host,
std::shared_ptr< libp2p::protocol::Identify >  identify,
std::shared_ptr< libp2p::protocol::kademlia::Kademlia >  kademlia,
std::shared_ptr< libp2p::basic::Scheduler >  scheduler,
std::shared_ptr< StreamEngine stream_engine,
const application::AppConfiguration app_config,
std::shared_ptr< clock::SteadyClock clock,
const BootstrapNodes bootstrap_nodes,
const OwnPeerInfo own_peer_info,
std::shared_ptr< network::Router router,
std::shared_ptr< storage::BufferStorage storage,
std::shared_ptr< crypto::Hasher hasher,
std::shared_ptr< ReputationRepository reputation_repository 
)

Definition at line 38 of file peer_manager_impl.cpp.

Member Function Documentation

size_t kagome::network::PeerManagerImpl::activePeersNumber ( ) const
overridevirtual
void kagome::network::PeerManagerImpl::align ( )
private

Aligns amount of connected streams.

Definition at line 264 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::clearClosedPingingConnections ( )
private

Definition at line 795 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::connectToPeer ( const PeerInfo peer_info)
overridevirtual
See also
PeerManager::connectToPeer

Implements kagome::network::PeerManager.

Definition at line 200 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::connectToPeer ( const PeerId peer_id)
private

Opens streams set for special peer (i.e. new-discovered)

Definition at line 369 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::disconnectFromPeer ( const PeerId peer_id)
private

Closes all streams of provided peer.

Definition at line 433 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::forEachPeer ( std::function< void(const PeerId &)>  func) const
overridevirtual
See also
PeerManager::forEachPeer

Implements kagome::network::PeerManager.

Definition at line 217 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::forOnePeer ( const PeerId peer_id,
std::function< void(const PeerId &)>  func 
) const
overridevirtual
See also
PeerManager::forOnePeer

Implements kagome::network::PeerManager.

Definition at line 238 of file peer_manager_impl.cpp.

std::optional< std::reference_wrapper< PeerState > > kagome::network::PeerManagerImpl::getPeerState ( const PeerId peer_id)
overridevirtual
See also
PeerManager::getPeerState

Implements kagome::network::PeerManager.

Definition at line 530 of file peer_manager_impl.cpp.

std::shared_ptr< StreamEngine > kagome::network::PeerManagerImpl::getStreamEngine ( )
overridevirtual
outcome::result< std::pair< network::CollatorPublicKey const &, network::ParachainId > > kagome::network::PeerManagerImpl::insert_advertisement ( PeerState peer_state,
ParachainState parachain_state,
primitives::BlockHash  para_hash 
)
overridevirtual

Store advertisement from a peer to later processing;

Implements kagome::network::PeerManager.

Definition at line 247 of file peer_manager_impl.cpp.

bool kagome::network::PeerManagerImpl::isSelfPeer ( const PeerId peer_id) const
private

Right way to check self peer as it takes into account dev mode.

Definition at line 734 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::keepAlive ( const PeerId peer_id)
overridevirtual
See also
PeerManager::forOnePeer

Implements kagome::network::PeerManager.

Definition at line 442 of file peer_manager_impl.cpp.

std::vector< scale::PeerInfoSerializable > kagome::network::PeerManagerImpl::loadLastActivePeers ( )
private

Definition at line 739 of file peer_manager_impl.cpp.

ParachainState & kagome::network::PeerManagerImpl::parachainState ( )
overridevirtual
See also
PeerManager::parachainState

Implements kagome::network::PeerManager.

Definition at line 507 of file peer_manager_impl.cpp.

bool kagome::network::PeerManagerImpl::prepare ( )
See also
AppStateManager::takeControl

Definition at line 87 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::processDiscoveredPeer ( const PeerId peer_id)
private

Definition at line 538 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::processFullyConnectedPeer ( const PeerId peer_id)
private

Definition at line 565 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::reserveStreams ( const PeerId peer_id) const
overridevirtual
See also
PeerManager::reserveStreams

Implements kagome::network::PeerManager.

Definition at line 720 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::setCollating ( const PeerId peer_id,
network::CollatorPublicKey const &  collator_id,
network::ParachainId  para_id 
)
overridevirtual
See also
PeerManager::setCollating

Implements kagome::network::PeerManager.

Definition at line 224 of file peer_manager_impl.cpp.

bool kagome::network::PeerManagerImpl::start ( )
See also
AppStateManager::takeControl

Definition at line 98 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::startPingingPeer ( const PeerId peer_id)
overridevirtual
void kagome::network::PeerManagerImpl::stop ( )
See also
AppStateManager::takeControl

Definition at line 194 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::storeActivePeers ( )
private

Stores peers addresses to the state storage to warm up the following node start

Definition at line 760 of file peer_manager_impl.cpp.

void kagome::network::PeerManagerImpl::updatePeerState ( const PeerId peer_id,
const Status status 
)
overridevirtual
void kagome::network::PeerManagerImpl::updatePeerState ( const PeerId peer_id,
const BlockAnnounce announce 
)
overridevirtual
void kagome::network::PeerManagerImpl::updatePeerState ( const PeerId peer_id,
const GrandpaNeighborMessage neighbor_message 
)
overridevirtual

Member Data Documentation

std::map<PeerId, PeerDescriptor> kagome::network::PeerManagerImpl::active_peers_
private

Definition at line 187 of file peer_manager_impl.hpp.

libp2p::event::Handle kagome::network::PeerManagerImpl::add_peer_handle_
private

Definition at line 179 of file peer_manager_impl.hpp.

libp2p::basic::Scheduler::Handle kagome::network::PeerManagerImpl::align_timer_
private

Definition at line 189 of file peer_manager_impl.hpp.

const application::AppConfiguration& kagome::network::PeerManagerImpl::app_config_
private

Definition at line 170 of file peer_manager_impl.hpp.

std::shared_ptr<application::AppStateManager> kagome::network::PeerManagerImpl::app_state_manager_
private

Definition at line 164 of file peer_manager_impl.hpp.

const BootstrapNodes& kagome::network::PeerManagerImpl::bootstrap_nodes_
private

Definition at line 172 of file peer_manager_impl.hpp.

std::shared_ptr<clock::SteadyClock> kagome::network::PeerManagerImpl::clock_
private

Definition at line 171 of file peer_manager_impl.hpp.

std::unordered_set<PeerId> kagome::network::PeerManagerImpl::connecting_peers_
private

Definition at line 183 of file peer_manager_impl.hpp.

std::shared_ptr<crypto::Hasher> kagome::network::PeerManagerImpl::hasher_
private

Definition at line 176 of file peer_manager_impl.hpp.

libp2p::Host& kagome::network::PeerManagerImpl::host_
private

Definition at line 165 of file peer_manager_impl.hpp.

std::shared_ptr<libp2p::protocol::Identify> kagome::network::PeerManagerImpl::identify_
private

Definition at line 166 of file peer_manager_impl.hpp.

std::shared_ptr<libp2p::protocol::kademlia::Kademlia> kagome::network::PeerManagerImpl::kademlia_
private

Definition at line 167 of file peer_manager_impl.hpp.

constexpr std::chrono::seconds kagome::network::PeerManagerImpl::kTimeoutForConnecting {15}
static

Definition at line 55 of file peer_manager_impl.hpp.

log::Logger kagome::network::PeerManagerImpl::log_
private

Definition at line 199 of file peer_manager_impl.hpp.

const OwnPeerInfo& kagome::network::PeerManagerImpl::own_peer_info_
private

Definition at line 173 of file peer_manager_impl.hpp.

ParachainState kagome::network::PeerManagerImpl::parachain_state_
private

Definition at line 197 of file peer_manager_impl.hpp.

libp2p::event::Handle kagome::network::PeerManagerImpl::peer_disconnected_handler_
private

Definition at line 180 of file peer_manager_impl.hpp.

std::unordered_map<PeerId, PeerState> kagome::network::PeerManagerImpl::peer_states_
private

Definition at line 188 of file peer_manager_impl.hpp.

std::unordered_set<PeerId> kagome::network::PeerManagerImpl::peers_in_queue_
private

Definition at line 181 of file peer_manager_impl.hpp.

std::unordered_set<libp2p::network::ConnectionManager::ConnectionSPtr> kagome::network::PeerManagerImpl::pinging_connections_
private

Definition at line 185 of file peer_manager_impl.hpp.

std::deque<std::reference_wrapper<const PeerId> > kagome::network::PeerManagerImpl::queue_to_connect_
private

Definition at line 182 of file peer_manager_impl.hpp.

std::set<PeerId> kagome::network::PeerManagerImpl::recently_active_peers_
private

Definition at line 190 of file peer_manager_impl.hpp.

metrics::RegistryPtr kagome::network::PeerManagerImpl::registry_ = metrics::createRegistry()
private

Definition at line 193 of file peer_manager_impl.hpp.

std::shared_ptr<ReputationRepository> kagome::network::PeerManagerImpl::reputation_repository_
private

Definition at line 177 of file peer_manager_impl.hpp.

std::shared_ptr<network::Router> kagome::network::PeerManagerImpl::router_
private

Definition at line 174 of file peer_manager_impl.hpp.

std::shared_ptr<libp2p::basic::Scheduler> kagome::network::PeerManagerImpl::scheduler_
private

Definition at line 168 of file peer_manager_impl.hpp.

std::shared_ptr<storage::BufferStorage> kagome::network::PeerManagerImpl::storage_
private

Definition at line 175 of file peer_manager_impl.hpp.

std::shared_ptr<StreamEngine> kagome::network::PeerManagerImpl::stream_engine_
private

Definition at line 169 of file peer_manager_impl.hpp.

metrics::Gauge* kagome::network::PeerManagerImpl::sync_peer_num_
private

Definition at line 194 of file peer_manager_impl.hpp.


The documentation for this class was generated from the following files: