TARAXA
|
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe. More...
#include <Host.h>
Classes | |
struct | KnownNode |
struct | PersistentState |
Deserialise the data and populate the set of known peers. More... | |
Public Types | |
using | CapabilityList = std::vector< std::shared_ptr< CapabilityFace > > |
using | CapabilitiesFactory = std::function< CapabilityList(std::weak_ptr< Host >)> |
Public Member Functions | |
Capabilities | getSupportedCapabilities () |
~Host () | |
ba::io_context::count_type | do_work () |
ba::io_context::count_type | do_discov () |
bool | isRunning () |
uint64_t | peer_count () const |
unsigned short | listenPort () const |
Get the port we're listening on currently. More... | |
NodeID | id () const |
Get our current node ID. More... | |
auto | getNodeCount () const |
std::list< NodeEntry > | getNodes () const |
void | addNode (Node const &_node) |
void | invalidateNode (NodeID const &_node) |
void | disconnect (NodeID const &_nodeID, DisconnectReason _reason) |
void | send (NodeID const &node_id, std::string capability_name, unsigned packet_type, bytes payload, std::function< void()> &&on_done={}) |
std::string | enode () const |
Get the endpoint information. More... | |
bool | nodeTableHasNode (Public const &_id) const |
Static Public Member Functions | |
static std::shared_ptr< Host > | make (std::string _clientVersion, CapabilitiesFactory const &cap_factory, KeyPair const &kp, NetworkConfig _n, TaraxaNetworkConfig taraxa_conf={}, std::filesystem::path state_file_path={}) |
Private Types | |
enum | PeerSlotType { Egress , Ingress } |
Private Member Functions | |
Host (std::string _clientVersion, KeyPair const &kp, NetworkConfig _n, TaraxaNetworkConfig taraxa_conf, std::filesystem::path state_file_path) | |
Node | nodeFromNodeTable (Public const &_id) const |
bool | addKnownNodeToNodeTable (KnownNode const &node) |
bool | haveCapability (CapDesc const &_name) const |
std::string | listenAddress () const |
Get the address we're listening on currently. More... | |
NetworkConfig const & | networkConfig () const |
bi::tcp::endpoint const & | tcpPublic () const |
Get the public TCP endpoint. More... | |
p2p::NodeInfo | nodeInfo () const |
Get the node information. More... | |
ENR | enr () const |
Get Ethereum Node Record of the host. More... | |
size_t | peer_count_ () const |
Get number of peers connected. More... | |
PeerSessionInfos | peerSessionInfos () const |
Get peer information. More... | |
std::shared_ptr< Session > | peerSession (NodeID const &_id) const |
Get session by id. More... | |
void | startPeerSession (Public const &_id, RLP const &_hello, std::unique_ptr< RLPXFrameCoder > _io, std::shared_ptr< RLPXSocket > const &_s) |
void | onNodeTableEvent (NodeID const &_n, NodeTableEventType const &_e) |
void | save_state () const |
Serialise the set of known peers. More... | |
std::optional< PersistentState > | restore_state () |
unsigned | peerSlots (PeerSlotType _type) const |
bool | havePeerSession (NodeID const &_id) |
bool | isHandshaking (NodeID const &_id) const |
bi::tcp::endpoint | determinePublic () const |
Determines publicly advertised address. More... | |
ENR | updateENR (ENR const &_restoredENR, bi::tcp::endpoint const &_tcpPublic, uint16_t const &_listenPort) |
void | connect (std::shared_ptr< Peer > const &_p) |
bool | peerSlotsAvailable (PeerSlotType _type=Ingress) |
Returns true if pending and connected peer count is less than maximum. More... | |
void | keepAlivePeers () |
void | logActivePeers () |
Log count of active peers and information about each peer. More... | |
void | runAcceptor () |
void | main_loop_body () |
std::pair< Secret, ENR > | restoreENR (bytesConstRef _b, NetworkConfig const &_networkConfig) |
Get or create host's Ethereum Node record. More... | |
bool | isAllowedEndpoint (NodeIPEndpoint const &_endpointToCheck) const |
std::shared_ptr< Peer > | peer (NodeID const &_n) const |
Private Attributes | |
std::atomic< bool > | fully_initialized_ = false |
ba::io_context | ioc_ |
ba::executor_work_guard< ba::io_context::executor_type > | ioc_w_ |
ba::io_context | session_ioc_ |
ba::executor_work_guard< ba::io_context::executor_type > | session_ioc_w_ |
ba::io_context::strand | strand_ |
bi::tcp::acceptor | m_tcp4Acceptor |
ba::steady_timer | m_runTimer |
std::filesystem::path | state_file_path_ |
std::string | m_clientVersion |
Our version string. More... | |
NetworkConfig | m_netConfig |
Network settings. More... | |
TaraxaNetworkConfig | taraxa_conf_ |
unsigned | m_idealPeerCount = 0 |
Ideal number of peers to be connected to. More... | |
unsigned | m_stretchPeers = 0 |
Capabilities | m_capabilities |
Each of the capabilities we support. More... | |
unsigned | m_listenPort |
bi::tcp::endpoint | m_tcpPublic |
KeyPair | m_alias |
Alias for network communication. More... | |
std::shared_ptr< RLPXHandshake::HostContext > | handshake_ctx_ |
std::set< Peer * > | m_pendingPeerConns |
std::unordered_map< NodeID, std::shared_ptr< Peer > > | m_peers |
std::unordered_map< NodeID, std::weak_ptr< Session > > | m_sessions |
std::list< std::weak_ptr< RLPXHandshake > > | m_connecting |
std::chrono::steady_clock::time_point | m_lastPing |
Time we sent the last ping to all peers. More... | |
std::chrono::steady_clock::time_point | m_lastPeerLogMessage |
std::unique_ptr< NodeTable > | m_nodeTable |
Node table (uses kademlia-like discovery). More... | |
std::atomic< uint64_t > | peer_count_snapshot_ = 0 |
Logger | m_logger {createLogger(VerbosityDebug, "net")} |
Logger | m_detailsLogger {createLogger(VerbosityTrace, "net")} |
Logger | m_infoLogger {createLogger(VerbosityInfo, "net")} |
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe.
determinePublic: ipv6, udp
per-session keepalive/ping instead of broadcast; set ping-timeout via median-latency
struct dev::p2p::Host::KnownNode |
struct dev::p2p::Host::PersistentState |
using dev::p2p::Host::CapabilitiesFactory = std::function<CapabilityList(std::weak_ptr<Host>)> |
using dev::p2p::Host::CapabilityList = std::vector<std::shared_ptr<CapabilityFace> > |
|
private |
|
private |
!! this needs to be post to session_ioc_ as main_loop_body handles peer/session related stuff
Host::~Host | ( | ) |
|
private |
void Host::addNode | ( | Node const & | _node | ) |
|
private |
|
private |
Determines publicly advertised address.
|
inline |
ba::io_context::count_type Host::do_discov | ( | ) |
ba::io_context::count_type Host::do_work | ( | ) |
|
inline |
Get the endpoint information.
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
inlineprivate |
|
inline |
Get our current node ID.
void Host::invalidateNode | ( | NodeID const & | _node | ) |
|
inlineprivate |
Determines if a node with the supplied endpoint should be included in or restored from the serialized network configuration data
|
private |
|
inline |
|
private |
Ping the peers to update the latency information and disconnect peers which have timed out.
|
inlineprivate |
Get the address we're listening on currently.
|
inline |
Get the port we're listening on currently.
|
private |
Log count of active peers and information about each peer.
|
private |
|
static |
|
inlineprivate |
|
inlineprivate |
Get the node information.
bool Host::nodeTableHasNode | ( | Public const & | _id | ) | const |
|
private |
|
inline |
|
private |
Get number of peers connected.
|
private |
Get peer information.
|
inlineprivate |
|
private |
Returns true if pending and connected peer count is less than maximum.
|
private |
|
private |
Get or create host's Ethereum Node record.
|
private |
|
private |
Serialise the set of known peers.
|
inline |
|
private |
Validates and starts peer session, taking ownership of _io. Disconnects and returns false upon error.
|
inlineprivate |
Get the public TCP endpoint.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Alias for network communication.
|
private |
Each of the capabilities we support.
|
private |
Our version string.
|
private |
Pending connections. Completed handshakes are garbage-collected in run() (a handshake is complete when there are no more shared_ptrs in handlers)
|
private |
|
private |
Ideal number of peers to be connected to.
|
private |
|
private |
When the last "active peers" message was logged - used to throttle logging to once every c_logActivePeersInterval seconds
|
private |
Time we sent the last ping to all peers.
|
private |
|
mutableprivate |
|
private |
Network settings.
|
private |
Node table (uses kademlia-like discovery).
|
private |
The nodes to which we are currently connected. Used by host to service peer requests and keepAlivePeers and for shutdown. (see run()) Mutable because we flush zombie entries (null-weakptrs) as regular maintenance from a const method.
|
private |
|
private |
Accepted connection multiplier (max peers = ideal*stretch).
|
private |
|
private |
Our public listening endpoint.
|
private |
|
private |
|
private |
|
private |
|
private |
Listening acceptor. Timer which, when network is running, calls run() every c_timerInterval ms.
|
private |