diff --git a/src/ConnectionPool.cpp b/src/ConnectionPool.cpp index 48ea049671..094cea531d 100644 --- a/src/ConnectionPool.cpp +++ b/src/ConnectionPool.cpp @@ -108,3 +108,16 @@ bool ConnectionPool::connectTo(const std::string& host, const std::string& port) } return true; } + +Json::Value ConnectionPool::getPeersJson() +{ + Json::Value ret(Json::arrayValue); + + BOOST_FOREACH(Peer::pointer peer, mPeers) + { + ret.append(peer->getJson()); + } + + return ret; +} + diff --git a/src/ConnectionPool.h b/src/ConnectionPool.h index 0d39a37a4f..dfe4b36a1c 100644 --- a/src/ConnectionPool.h +++ b/src/ConnectionPool.h @@ -34,6 +34,8 @@ public: std::map getAllConnected(); bool connectTo(const std::string& host, const std::string& port); + + Json::Value getPeersJson(); }; #endif diff --git a/src/Peer.cpp b/src/Peer.cpp index 8726284e9d..375f298674 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -538,6 +538,15 @@ void Peer::punishPeer(PeerPunish) { } +Json::Value Peer::getJson() { + Json::Value ret(Json::objectValue); + + ret["ip"] = mSocket.remote_endpoint().address().to_string(); + ret["hanko"] = mHanko.ToString(); + + return ret; +} + #if 0 /* diff --git a/src/Peer.h b/src/Peer.h index a85d9f7cde..459a36919a 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -92,6 +92,8 @@ public: void punishPeer(PeerPunish pp); + Json::Value getJson(); + //static PackedMessage::pointer createFullLedger(Ledger::pointer ledger); static PackedMessage::pointer createLedgerProposal(Ledger::pointer ledger); static PackedMessage::pointer createValidation(Ledger::pointer ledger); diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 67017af4fe..615d1eb2eb 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -349,6 +349,12 @@ Json::Value RPCServer::doConnect(Json::Value& params) return "connecting"; } +Json::Value RPCServer::doPeers(Json::Value& params) +{ + // peers + return theApp->getConnectionPool().getPeersJson(); +} + Json::Value RPCServer::doSendTo(Json::Value& params) { // Implement simple sending without gathering // sendto @@ -504,6 +510,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params if(command=="unlock") return doUnlock(params); if(command=="sendto") return doSendTo(params); if(command=="connect") return doConnect(params); + if(command=="peers") return doPeers(params); if(command=="tx") return doTx(params); if(command=="ledger") return doLedger(params); diff --git a/src/RPCServer.h b/src/RPCServer.h index eb9bee52cf..ddeb970ef1 100644 --- a/src/RPCServer.h +++ b/src/RPCServer.h @@ -41,6 +41,7 @@ class RPCServer : public boost::enable_shared_from_this Json::Value doUnlock(Json::Value& params); Json::Value doSendTo(Json::Value& params); Json::Value doConnect(Json::Value& params); + Json::Value doPeers(Json::Value& params); Json::Value doTx(Json::Value& params); Json::Value doLedger(Json::Value& params); Json::Value doAccount(Json::Value& params); diff --git a/src/main.cpp b/src/main.cpp index 6e322b4a36..cb859f911d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ void printHelp() cout << " unlock " << endl; cout << " familyinfo" << endl; cout << " connect []" << endl; + cout << " peers" << endl; cout << " sendto []" << endl; cout << " tx" << endl; cout << " ledger" << endl;