Browse Source

implement admin_net_nodeInfo.

cl-refactor
Gav Wood 10 years ago
parent
commit
c3933466d7
  1. 28
      libp2p/Host.h
  2. 14
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  3. 1
      libweb3jsonrpc/WebThreeStubServerBase.h
  4. 10
      libwebthree/WebThree.h

28
libp2p/Host.h

@ -105,6 +105,20 @@ private:
SharedMutex mutable x_nodes; 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 * @brief The Host class
* Capabilities should be registered prior to startNetwork, since m_capabilities is not thread-safe. * 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. /// @returns if network is started and interactive.
bool haveNetwork() const { return m_run && !!m_nodeTable; } 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. /// 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); void startPeerSession(Public const& _id, RLP const& _hello, RLPXFrameCoder* _io, std::shared_ptr<RLPXSocket> const& _s);
/// Get session by id /// 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>(); } 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: protected:
void onNodeTableEvent(NodeId const& _n, NodeTableEventType const& _e); void onNodeTableEvent(NodeId const& _n, NodeTableEventType const& _e);

14
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -558,6 +558,20 @@ Json::Value WebThreeStubServerBase::admin_net_peers(std::string const& _session)
return ret; return ret;
} }
Json::Value WebThreeStubServerBase::admin_net_nodeInfo(const string& _session)
{
ADMIN;
Json::Value ret;
p2p::NodeInfo i = network()->nodeInfo();
ret["name"] = i.version;
ret["port"] = i.port;
ret["address"] = i.address;
ret["listenAddr"] = i.address + ":" + toString(i.port);
ret["id"] = i.id.hex();
ret["enode"] = i.enode();
return ret;
}
bool WebThreeStubServerBase::admin_eth_setMining(bool _on, std::string const& _session) bool WebThreeStubServerBase::admin_eth_setMining(bool _on, std::string const& _session)
{ {
ADMIN; ADMIN;

1
libweb3jsonrpc/WebThreeStubServerBase.h

@ -165,6 +165,7 @@ public:
virtual bool admin_net_stop(std::string const& _session); virtual bool admin_net_stop(std::string const& _session);
virtual bool admin_net_connect(std::string const& _node, std::string const& _session); virtual bool admin_net_connect(std::string const& _node, std::string const& _session);
virtual Json::Value admin_net_peers(std::string const& _session); virtual Json::Value admin_net_peers(std::string const& _session);
virtual Json::Value admin_net_nodeInfo(std::string const& _session);
virtual bool admin_eth_setMining(bool _on, std::string const& _session); virtual bool admin_eth_setMining(bool _on, std::string const& _session);
virtual Json::Value admin_eth_blockQueueStatus(std::string const& _session) { (void)_session; return Json::Value(); } virtual Json::Value admin_eth_blockQueueStatus(std::string const& _session) { (void)_session; return Json::Value(); }

10
libwebthree/WebThree.h

@ -53,6 +53,9 @@ namespace bzz { class Interface; }
class WebThreeNetworkFace class WebThreeNetworkFace
{ {
public: public:
/// Get information concerning this node.
virtual p2p::NodeInfo nodeInfo() const = 0;
/// Get information on the current peer set. /// Get information on the current peer set.
virtual std::vector<p2p::PeerSessionInfo> peers() = 0; virtual std::vector<p2p::PeerSessionInfo> peers() = 0;
@ -90,7 +93,8 @@ public:
/// Is network working? there may not be any peers yet. /// Is network working? there may not be any peers yet.
virtual bool isNetworkStarted() const = 0; virtual bool isNetworkStarted() const = 0;
std::string enode() const { return "enode://" + toHex(id().ref()) + "@" + (networkPreferences().publicIPAddress.empty() ? "127.0.0.1" : networkPreferences().publicIPAddress) + ":" + toString(networkPreferences().listenPort); } /// Get enode string.
virtual std::string enode() const = 0;
}; };
@ -173,8 +177,12 @@ public:
void setNetworkPreferences(p2p::NetworkPreferences const& _n, bool _dropPeers = false) override; void setNetworkPreferences(p2p::NetworkPreferences const& _n, bool _dropPeers = false) override;
p2p::NodeInfo nodeInfo() const override { return m_net.nodeInfo(); }
p2p::NodeId id() const override { return m_net.id(); } p2p::NodeId id() const override { return m_net.id(); }
std::string enode() const override { return m_net.enode(); }
/// Gets the nodes. /// Gets the nodes.
p2p::Peers nodes() const override { return m_net.getPeers(); } p2p::Peers nodes() const override { return m_net.getPeers(); }

Loading…
Cancel
Save