Kagome
Polkadot Runtime Engine in C++17
kagome::network::StreamEngine Struct Referencefinal

#include <stream_engine.hpp>

Inheritance diagram for kagome::network::StreamEngine:
Collaboration diagram for kagome::network::StreamEngine:

Classes

struct  ProtocolDescr
 
struct  ProtocolDescr.incoming
 
struct  ProtocolDescr.outgoing
 
struct  RandomGossipStrategy
 

Public Types

enum  Direction : uint8_t { Direction::INCOMING = 1, Direction::OUTGOING = 2, Direction::BIDIRECTIONAL = 3 }
 
using PeerInfo = libp2p::peer::PeerInfo
 
using PeerId = libp2p::peer::PeerId
 
using Protocol = libp2p::peer::Protocol
 
using Stream = libp2p::connection::Stream
 
using StreamEnginePtr = std::shared_ptr< StreamEngine >
 

Public Member Functions

 StreamEngine (const StreamEngine &)=delete
 
StreamEngineoperator= (const StreamEngine &)=delete
 
 StreamEngine (StreamEngine &&)=delete
 
StreamEngineoperator= (StreamEngine &&)=delete
 
 ~StreamEngine ()=default
 
 StreamEngine (std::shared_ptr< ReputationRepository > reputation_repository)
 
outcome::result< void > addIncoming (std::shared_ptr< Stream > stream, const std::shared_ptr< ProtocolBase > &protocol)
 
outcome::result< void > addOutgoing (std::shared_ptr< Stream > stream, const std::shared_ptr< ProtocolBase > &protocol)
 
outcome::result< void > addBidirectional (std::shared_ptr< Stream > stream, const std::shared_ptr< ProtocolBase > &protocol)
 
void reserveStreams (const PeerId &peer_id, const std::shared_ptr< ProtocolBase > &protocol)
 
void del (const PeerId &peer_id)
 
bool reserveOutgoing (PeerId const &peer_id, std::shared_ptr< ProtocolBase > const &protocol)
 
void dropReserveOutgoing (PeerId const &peer_id, std::shared_ptr< ProtocolBase > const &protocol)
 
bool isAlive (PeerId const &peer_id, std::shared_ptr< ProtocolBase > const &protocol) const
 
template<typename T >
void send (const PeerId &peer_id, const std::shared_ptr< ProtocolBase > &protocol, std::shared_ptr< T > msg)
 
template<typename T >
void broadcast (const std::shared_ptr< ProtocolBase > &protocol, const std::shared_ptr< T > &msg, const std::function< bool(const PeerId &peer_id)> &predicate)
 
template<typename T >
void broadcast (const std::shared_ptr< ProtocolBase > &protocol, const std::shared_ptr< T > &msg)
 
int outgoingStreamsNumber (const std::shared_ptr< ProtocolBase > &protocol)
 
template<typename F >
size_t count (F &&filter) const
 
template<typename TPeerId , typename = std::enable_if<std::is_same_v<PeerId, TPeerId>>>
PeerInfo from (TPeerId &&peer_id) const
 
outcome::result< PeerInfofrom (std::shared_ptr< Stream > &stream) const
 
template<typename F >
void forEachPeer (F &&f)
 
template<typename F >
void forEachPeer (F &&f) const
 

Static Public Member Functions

template<typename... Args>
static StreamEnginePtr create (Args &&...args)
 

Static Public Attributes

static constexpr auto kDownVoteByDisconnectionExpirationTimeout
 

Private Types

using ProtocolMap = std::map< std::shared_ptr< ProtocolBase >, ProtocolDescr >
 
using PeerMap = std::map< PeerId, ProtocolMap >
 

Private Member Functions

outcome::result< void > add (std::shared_ptr< Stream > stream, const std::shared_ptr< ProtocolBase > &protocol, Direction direction)
 
void uploadStream (std::shared_ptr< Stream > &dst, std::shared_ptr< Stream > const &src, std::shared_ptr< ProtocolBase > const &protocol, Direction direction)
 
template<typename T >
void send (PeerId const &peer_id, std::shared_ptr< ProtocolBase > const &protocol, std::shared_ptr< Stream > stream, std::shared_ptr< T > const &msg)
 
void dump (std::string_view msg)
 
void updateStream (PeerId const &peer_id, std::shared_ptr< ProtocolBase > const &protocol, ProtocolDescr &descr)
 
template<typename T >
void updateStream (const PeerId &peer_id, const std::shared_ptr< ProtocolBase > &protocol, std::shared_ptr< T > msg)
 

Static Private Member Functions

template<typename PM , typename F >
static void forProtocol (PM &proto_map, const std::shared_ptr< ProtocolBase > &protocol, F &&f)
 
template<typename PM , typename F >
static void forSubscriber (PeerId const &peer_id, PM &streams, std::shared_ptr< ProtocolBase > const &protocol, F &&f)
 

Private Attributes

std::shared_ptr< ReputationRepositoryreputation_repository_
 
log::Logger logger_
 
SafeObject< PeerMapstreams_
 

Detailed Description

Is the manager class to manipulate streams. It supports next structure Peer ProtocolName_0 ProtocolPtr_0, Incoming_Stream_0 Outgoing_Stream_0 MessagesQueue for creating outgoing stream

Definition at line 40 of file stream_engine.hpp.


Class Documentation

struct kagome::network::StreamEngine::ProtocolDescr.incoming

Definition at line 81 of file stream_engine.hpp.

Collaboration diagram for kagome::network::StreamEngine::ProtocolDescr.incoming:
Class Members
shared_ptr< Stream > stream
struct kagome::network::StreamEngine::ProtocolDescr.outgoing

Definition at line 85 of file stream_engine.hpp.

Collaboration diagram for kagome::network::StreamEngine::ProtocolDescr.outgoing:
Class Members
bool reserved
shared_ptr< Stream > stream

Member Typedef Documentation

using kagome::network::StreamEngine::PeerId = libp2p::peer::PeerId

Definition at line 42 of file stream_engine.hpp.

using kagome::network::StreamEngine::PeerInfo = libp2p::peer::PeerInfo

Definition at line 41 of file stream_engine.hpp.

Definition at line 144 of file stream_engine.hpp.

using kagome::network::StreamEngine::Protocol = libp2p::peer::Protocol

Definition at line 43 of file stream_engine.hpp.

using kagome::network::StreamEngine::ProtocolMap = std::map<std::shared_ptr<ProtocolBase>, ProtocolDescr>
private

Definition at line 143 of file stream_engine.hpp.

using kagome::network::StreamEngine::Stream = libp2p::connection::Stream

Definition at line 44 of file stream_engine.hpp.

Definition at line 45 of file stream_engine.hpp.

Member Enumeration Documentation

Enumerator
INCOMING 
OUTGOING 
BIDIRECTIONAL 

Definition at line 50 of file stream_engine.hpp.

Constructor & Destructor Documentation

kagome::network::StreamEngine::StreamEngine ( const StreamEngine )
delete
kagome::network::StreamEngine::StreamEngine ( StreamEngine &&  )
delete
kagome::network::StreamEngine::~StreamEngine ( )
default
kagome::network::StreamEngine::StreamEngine ( std::shared_ptr< ReputationRepository reputation_repository)
inline

Definition at line 154 of file stream_engine.hpp.

Member Function Documentation

outcome::result<void> kagome::network::StreamEngine::add ( std::shared_ptr< Stream stream,
const std::shared_ptr< ProtocolBase > &  protocol,
Direction  direction 
)
inlineprivate

Definition at line 164 of file stream_engine.hpp.

outcome::result<void> kagome::network::StreamEngine::addBidirectional ( std::shared_ptr< Stream stream,
const std::shared_ptr< ProtocolBase > &  protocol 
)
inline

Definition at line 222 of file stream_engine.hpp.

outcome::result<void> kagome::network::StreamEngine::addIncoming ( std::shared_ptr< Stream stream,
const std::shared_ptr< ProtocolBase > &  protocol 
)
inline

Definition at line 210 of file stream_engine.hpp.

outcome::result<void> kagome::network::StreamEngine::addOutgoing ( std::shared_ptr< Stream stream,
const std::shared_ptr< ProtocolBase > &  protocol 
)
inline

Definition at line 216 of file stream_engine.hpp.

template<typename T >
void kagome::network::StreamEngine::broadcast ( const std::shared_ptr< ProtocolBase > &  protocol,
const std::shared_ptr< T > &  msg,
const std::function< bool(const PeerId &peer_id)> &  predicate 
)
inline

Definition at line 319 of file stream_engine.hpp.

template<typename T >
void kagome::network::StreamEngine::broadcast ( const std::shared_ptr< ProtocolBase > &  protocol,
const std::shared_ptr< T > &  msg 
)
inline

Definition at line 340 of file stream_engine.hpp.

template<typename F >
size_t kagome::network::StreamEngine::count ( F &&  filter) const
inline

Definition at line 361 of file stream_engine.hpp.

template<typename... Args>
static StreamEnginePtr kagome::network::StreamEngine::create ( Args &&...  args)
inlinestatic

Definition at line 159 of file stream_engine.hpp.

void kagome::network::StreamEngine::del ( const PeerId peer_id)
inline

Definition at line 245 of file stream_engine.hpp.

void kagome::network::StreamEngine::dropReserveOutgoing ( PeerId const &  peer_id,
std::shared_ptr< ProtocolBase > const &  protocol 
)
inline

Definition at line 272 of file stream_engine.hpp.

void kagome::network::StreamEngine::dump ( std::string_view  msg)
inlineprivate

Definition at line 492 of file stream_engine.hpp.

template<typename F >
void kagome::network::StreamEngine::forEachPeer ( F &&  f)
inline

Definition at line 391 of file stream_engine.hpp.

template<typename F >
void kagome::network::StreamEngine::forEachPeer ( F &&  f) const
inline

Definition at line 400 of file stream_engine.hpp.

template<typename PM , typename F >
static void kagome::network::StreamEngine::forProtocol ( PM &  proto_map,
const std::shared_ptr< ProtocolBase > &  protocol,
F &&  f 
)
inlinestaticprivate

Definition at line 471 of file stream_engine.hpp.

template<typename PM , typename F >
static void kagome::network::StreamEngine::forSubscriber ( PeerId const &  peer_id,
PM &  streams,
std::shared_ptr< ProtocolBase > const &  protocol,
F &&  f 
)
inlinestaticprivate

Definition at line 481 of file stream_engine.hpp.

template<typename TPeerId , typename = std::enable_if<std::is_same_v<PeerId, TPeerId>>>
PeerInfo kagome::network::StreamEngine::from ( TPeerId &&  peer_id) const
inline

Definition at line 376 of file stream_engine.hpp.

outcome::result<PeerInfo> kagome::network::StreamEngine::from ( std::shared_ptr< Stream > &  stream) const
inline

Definition at line 380 of file stream_engine.hpp.

bool kagome::network::StreamEngine::isAlive ( PeerId const &  peer_id,
std::shared_ptr< ProtocolBase > const &  protocol 
) const
inline

Definition at line 282 of file stream_engine.hpp.

StreamEngine& kagome::network::StreamEngine::operator= ( const StreamEngine )
delete
StreamEngine& kagome::network::StreamEngine::operator= ( StreamEngine &&  )
delete
int kagome::network::StreamEngine::outgoingStreamsNumber ( const std::shared_ptr< ProtocolBase > &  protocol)
inline

Definition at line 347 of file stream_engine.hpp.

bool kagome::network::StreamEngine::reserveOutgoing ( PeerId const &  peer_id,
std::shared_ptr< ProtocolBase > const &  protocol 
)
inline

Definition at line 262 of file stream_engine.hpp.

void kagome::network::StreamEngine::reserveStreams ( const PeerId peer_id,
const std::shared_ptr< ProtocolBase > &  protocol 
)
inline

Definition at line 228 of file stream_engine.hpp.

template<typename T >
void kagome::network::StreamEngine::send ( const PeerId peer_id,
const std::shared_ptr< ProtocolBase > &  protocol,
std::shared_ptr< T >  msg 
)
inline

Definition at line 296 of file stream_engine.hpp.

template<typename T >
void kagome::network::StreamEngine::send ( PeerId const &  peer_id,
std::shared_ptr< ProtocolBase > const &  protocol,
std::shared_ptr< Stream stream,
std::shared_ptr< T > const &  msg 
)
inlineprivate

Definition at line 442 of file stream_engine.hpp.

void kagome::network::StreamEngine::updateStream ( PeerId const &  peer_id,
std::shared_ptr< ProtocolBase > const &  protocol,
ProtocolDescr descr 
)
inlineprivate

Definition at line 510 of file stream_engine.hpp.

template<typename T >
void kagome::network::StreamEngine::updateStream ( const PeerId peer_id,
const std::shared_ptr< ProtocolBase > &  protocol,
std::shared_ptr< T >  msg 
)
inlineprivate

Definition at line 576 of file stream_engine.hpp.

void kagome::network::StreamEngine::uploadStream ( std::shared_ptr< Stream > &  dst,
std::shared_ptr< Stream > const &  src,
std::shared_ptr< ProtocolBase > const &  protocol,
Direction  direction 
)
inlineprivate

Definition at line 409 of file stream_engine.hpp.

Member Data Documentation

constexpr auto kagome::network::StreamEngine::kDownVoteByDisconnectionExpirationTimeout
static
Initial value:
=
std::chrono::seconds(30)

Definition at line 47 of file stream_engine.hpp.

log::Logger kagome::network::StreamEngine::logger_
private

Definition at line 594 of file stream_engine.hpp.

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

Definition at line 593 of file stream_engine.hpp.

SafeObject<PeerMap> kagome::network::StreamEngine::streams_
private

Definition at line 596 of file stream_engine.hpp.


The documentation for this struct was generated from the following file: