Fabcoin Core
0.16.2
P2P Digital Currency
|
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe. More...
#include <Host.h>
Public Member Functions | |
Host (std::string const &_clientVersion, NetworkPreferences const &_n=NetworkPreferences(), bytesConstRef _restoreNetwork=bytesConstRef()) | |
Start server, listening for connections on the given port. More... | |
Host (std::string const &_clientVersion, KeyPair const &_alias, NetworkPreferences const &_n=NetworkPreferences()) | |
Alternative constructor that allows providing the node key directly without restoring the network. More... | |
virtual | ~Host () |
Will block on network process events. More... | |
template<class T > | |
std::shared_ptr< T > | registerCapability (std::shared_ptr< T > const &_t) |
Register a peer-capability; all new peer connections will have this capability. More... | |
template<class T > | |
void | addCapability (std::shared_ptr< T > const &_p, std::string const &_name, u256 const &_version) |
bool | haveCapability (CapDesc const &_name) const |
CapDescs | caps () const |
template<class T > | |
std::shared_ptr< T > | cap () const |
void | addPeer (NodeSpec const &_s, PeerType _t) |
Add a potential peer. More... | |
void | addNode (NodeID const &_node, NodeIPEndpoint const &_endpoint) |
Add node as a peer candidate. Node is added if discovery ping is successful and table has capacity. More... | |
void | requirePeer (NodeID const &_node, NodeIPEndpoint const &_endpoint) |
Create Peer and attempt keeping peer connected. More... | |
void | requirePeer (NodeID const &_node, bi::address const &_addr, unsigned short _udpPort, unsigned short _tcpPort) |
Create Peer and attempt keeping peer connected. More... | |
void | relinquishPeer (NodeID const &_node) |
Note peer as no longer being required. More... | |
void | setIdealPeerCount (unsigned _n) |
Set ideal number of peers. More... | |
void | setPeerStretch (unsigned _n) |
Set multipier for max accepted connections. More... | |
PeerSessionInfos | peerSessionInfo () const |
Get peer information. More... | |
size_t | peerCount () const |
Get number of peers connected. More... | |
std::string | listenAddress () const |
Get the address we're listening on currently. More... | |
unsigned short | listenPort () const |
Get the port we're listening on currently. More... | |
bytes | saveNetwork () const |
Serialise the set of known peers. More... | |
Peers | getPeers () const |
NetworkPreferences const & | networkPreferences () const |
void | setNetworkPreferences (NetworkPreferences const &_p, bool _dropPeers=false) |
void | start () |
Start network. . More... | |
void | stop () |
Stop network. More... | |
bool | isStarted () const |
ReputationManager & | repMan () |
bool | haveNetwork () const |
void | startPeerSession (Public const &_id, RLP const &_hello, std::unique_ptr< RLPXFrameCoder > &&_io, std::shared_ptr< RLPXSocket > const &_s) |
Validates and starts peer session, taking ownership of _io. Disconnects and returns false upon error. More... | |
std::shared_ptr< SessionFace > | peerSession (NodeID const &_id) |
Get session by id. More... | |
NodeID | id () const |
Get our current node ID. More... | |
bi::tcp::endpoint const & | tcpPublic () const |
Get the public TCP endpoint. More... | |
std::string | enode () const |
Get the public endpoint information. More... | |
p2p::NodeInfo | nodeInfo () const |
Get the node information. More... | |
Static Public Member Functions | |
static std::unordered_map< Public, std::string > | pocHosts () |
Default hosts for current version of client. More... | |
Protected Member Functions | |
void | onNodeTableEvent (NodeID const &_n, NodeTableEventType const &_e) |
void | restoreNetwork (bytesConstRef _b) |
Deserialise the data and populate the set of known peers. More... | |
Protected Member Functions inherited from dev::Worker | |
Worker (std::string const &_name="anon", unsigned _idleWaitMs=30) | |
Worker (Worker &&_m) | |
Move-constructor. More... | |
Worker & | operator= (Worker &&_m) |
Move-assignment. More... | |
virtual | ~Worker () |
void | setName (std::string _n) |
Allows changing worker name if work is stopped. More... | |
void | startWorking () |
Starts worker thread; causes startedWorking() to be called. More... | |
void | stopWorking () |
Stop worker thread; causes call to stopWorking(). More... | |
bool | isWorking () const |
Returns if worker thread is present. More... | |
virtual void | workLoop () |
Overrides doWork(); should call shouldStop() often and exit when true. More... | |
bool | shouldStop () const |
Private Types | |
enum | PeerSlotType { Egress, Ingress } |
Private Member Functions | |
unsigned | peerSlots (PeerSlotType _type) |
bool | havePeerSession (NodeID const &_id) |
void | determinePublic () |
Determines and sets m_tcpPublic to publicly advertised address. More... | |
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 () |
Ping the peers to update the latency information and disconnect peers which have timed out. More... | |
void | disconnectLatePeers () |
Disconnect peers which didn't respond to keepAlivePeers ping prior to c_keepAliveTimeOut. More... | |
void | runAcceptor () |
Called only from startedWorking(). More... | |
virtual void | startedWorking () |
Called by Worker. Not thread-safe; to be called only by worker. More... | |
void | run (boost::system::error_code const &error) |
Called by startedWorking. Not thread-safe; to be called only be Worker. More... | |
virtual void | doWork () |
Run network. Not thread-safe; to be called only by worker. More... | |
virtual void | doneWorking () |
Shutdown network. Not thread-safe; to be called only by worker. More... | |
Static Private Member Functions | |
static KeyPair | networkAlias (bytesConstRef _b) |
Get or create host identifier (KeyPair). More... | |
Private Attributes | |
bytes | m_restoreNetwork |
Set by constructor and used to set Host key and restore network peers & nodes. More... | |
bool | m_run = false |
Whether network is running. More... | |
std::mutex | x_runTimer |
Start/stop mutex. More... | |
std::string | m_clientVersion |
Our version string. More... | |
NetworkPreferences | m_netPrefs |
Network settings. More... | |
std::set< bi::address > | m_ifAddresses |
Interface addresses (private, public) More... | |
int | m_listenPort = -1 |
What port are we listening on. -1 means binding failed or acceptor hasn't been initialized. More... | |
ba::io_service | m_ioService |
IOService for network stuff. More... | |
bi::tcp::acceptor | m_tcp4Acceptor |
Listening acceptor. More... | |
std::unique_ptr< boost::asio::deadline_timer > | m_timer |
Timer which, when network is running, calls scheduler() every c_timerInterval ms. More... | |
std::set< Peer * > | m_pendingPeerConns |
Mutex | x_pendingNodeConns |
Used only by connect(Peer&) to limit concurrently connecting to same node. See connect(shared_ptr<Peer>const&). More... | |
bi::tcp::endpoint | m_tcpPublic |
Our public listening endpoint. More... | |
KeyPair | m_alias |
Alias for network communication. Network address is k*G. k is key material. TODO: Replace KeyPair. More... | |
std::shared_ptr< NodeTable > | m_nodeTable |
Node table (uses kademlia-like discovery). More... | |
std::unordered_map< NodeID, std::shared_ptr< Peer > > | m_peers |
Shared storage of Peer objects. Peers are created or destroyed on demand by the Host. Active sessions maintain a shared_ptr to a Peer;. More... | |
std::set< NodeID > | m_requiredPeers |
Peers we try to connect regardless of p2p network. More... | |
Mutex | x_requiredPeers |
std::unordered_map< NodeID, std::weak_ptr< SessionFace > > | m_sessions |
The nodes to which we are currently connected. More... | |
RecursiveMutex | x_sessions |
std::list< std::weak_ptr< RLPXHandshake > > | m_connecting |
Pending connections. More... | |
Mutex | x_connecting |
Mutex for m_connecting. More... | |
unsigned | m_idealPeerCount = 11 |
Ideal number of peers to be connected to. More... | |
unsigned | m_stretchPeers = 7 |
Accepted connection multiplier (max peers = ideal*stretch). More... | |
std::map< CapDesc, std::shared_ptr< HostCapabilityFace > > | m_capabilities |
Each of the capabilities we support. More... | |
std::list< std::shared_ptr< boost::asio::deadline_timer > > | m_timers |
Deadline timers used for isolated network events. GC'd by run. More... | |
Mutex | x_timers |
std::chrono::steady_clock::time_point | m_lastPing |
Time we sent the last ping to all peers. More... | |
bool | m_accepting = false |
bool | m_dropPeers = false |
ReputationManager | m_repMan |
Static Private Attributes | |
static const unsigned | c_timerInterval = 100 |
Interval which m_timer is run when network is connected. More... | |
Friends | |
class | HostNodeTableHandler |
class | RLPXHandshake |
class | Session |
class | HostCapabilityFace |
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
|
private |
dev::p2p::Host::Host | ( | std::string const & | _clientVersion, |
NetworkPreferences const & | _n = NetworkPreferences() , |
||
bytesConstRef | _restoreNetwork = bytesConstRef() |
||
) |
Start server, listening for connections on the given port.
dev::p2p::Host::Host | ( | std::string const & | _clientVersion, |
KeyPair const & | _alias, | ||
NetworkPreferences const & | _n = NetworkPreferences() |
||
) |
Alternative constructor that allows providing the node key directly without restoring the network.
|
virtual |
void Host::addNode | ( | NodeID const & | _node, |
NodeIPEndpoint const & | _endpoint | ||
) |
|
inline |
|
private |
|
private |
|
private |
|
privatevirtual |
Shutdown network. Not thread-safe; to be called only by worker.
Reimplemented from dev::Worker.
|
privatevirtual |
Run network. Not thread-safe; to be called only by worker.
Reimplemented from dev::Worker.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
inline |
|
inline |
|
private |
|
inline |
|
inline |
|
staticprivate |
|
inline |
|
inline |
|
protected |
size_t Host::peerCount | ( | ) | const |
|
inline |
PeerSessionInfos Host::peerSessionInfo | ( | ) | const |
|
inlineprivate |
|
inlineprivate |
|
static |
void Host::relinquishPeer | ( | NodeID const & | _node | ) |
|
inline |
void Host::requirePeer | ( | NodeID const & | _node, |
NodeIPEndpoint const & | _endpoint | ||
) |
|
inline |
|
protected |
|
private |
|
private |
Called only from startedWorking().
Definition at line 428 of file Host.cpp.
bytes Host::saveNetwork | ( | ) | const |
|
inline |
|
inline |
|
inline |
void Host::start | ( | ) |
|
privatevirtual |
Called by Worker. Not thread-safe; to be called only by worker.
Reimplemented from dev::Worker.
Definition at line 722 of file Host.cpp.
void Host::startPeerSession | ( | Public const & | _id, |
RLP const & | _hello, | ||
std::unique_ptr< RLPXFrameCoder > && | _io, | ||
std::shared_ptr< RLPXSocket > const & | _s | ||
) |
void Host::stop | ( | ) |
|
inline |
|
friend |
|
friend |
|
friend |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
mutableprivate |