|
|
@ -105,6 +105,20 @@ private: |
|
|
|
SharedMutex mutable x_nodes; |
|
|
|
}; |
|
|
|
|
|
|
|
struct NodeInfo |
|
|
|
{ |
|
|
|
NodeInfo() = default; |
|
|
|
NodeInfo(NodeId const& _id, std::string const& _address, unsigned _port, std::string const& _version): |
|
|
|
id(_id), address(_address), port(_port), version(_version) {} |
|
|
|
|
|
|
|
std::string enode() const { return "enode://" + id.hex() + "@" + address + ":" + toString(port); } |
|
|
|
|
|
|
|
NodeId id; |
|
|
|
std::string address; |
|
|
|
unsigned port; |
|
|
|
std::string version; |
|
|
|
}; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The Host class |
|
|
|
* Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe. |
|
|
@ -197,14 +211,24 @@ public: |
|
|
|
/// @returns if network is started and interactive.
|
|
|
|
bool haveNetwork() const { return m_run && !!m_nodeTable; } |
|
|
|
|
|
|
|
NodeId id() const { return m_alias.pub(); } |
|
|
|
|
|
|
|
/// Validates and starts peer session, taking ownership of _io. Disconnects and returns false upon error.
|
|
|
|
void startPeerSession(Public const& _id, RLP const& _hello, RLPXFrameCoder* _io, std::shared_ptr<RLPXSocket> const& _s); |
|
|
|
|
|
|
|
/// Get session by id
|
|
|
|
std::shared_ptr<Session> peerSession(NodeId const& _id) { RecursiveGuard l(x_sessions); return m_sessions.count(_id) ? m_sessions[_id].lock() : std::shared_ptr<Session>(); } |
|
|
|
|
|
|
|
/// Get our current node ID.
|
|
|
|
NodeId id() const { return m_alias.pub(); } |
|
|
|
|
|
|
|
/// Get the public TCP endpoint.
|
|
|
|
bi::tcp::endpoint const& tcpPublic() const { return m_tcpPublic; } |
|
|
|
|
|
|
|
/// Get the public endpoint information.
|
|
|
|
std::string enode() const { return "enode://" + id().hex() + "@" + (networkPreferences().publicIPAddress.empty() ? m_tcpPublic.address().to_string() : networkPreferences().publicIPAddress) + ":" + toString(m_tcpPublic.port()); } |
|
|
|
|
|
|
|
/// Get the node information.
|
|
|
|
p2p::NodeInfo nodeInfo() const { return NodeInfo(id(), (networkPreferences().publicIPAddress.empty() ? m_tcpPublic.address().to_string() : networkPreferences().publicIPAddress), m_tcpPublic.port(), m_clientVersion); } |
|
|
|
|
|
|
|
protected: |
|
|
|
void onNodeTableEvent(NodeId const& _n, NodeTableEventType const& _e); |
|
|
|
|
|
|
|