Add RPC command peers.

This commit is contained in:
Arthur Britto
2012-03-10 19:06:05 -08:00
parent af929c7d49
commit 2596cce905
7 changed files with 35 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -34,6 +34,8 @@ public:
std::map<uint160, Peer::pointer> getAllConnected();
bool connectTo(const std::string& host, const std::string& port);
Json::Value getPeersJson();
};
#endif

View File

@@ -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
/*

View File

@@ -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);

View File

@@ -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 <destination> <amount>
@@ -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);

View File

@@ -41,6 +41,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
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);

View File

@@ -32,6 +32,7 @@ void printHelp()
cout << " unlock <passphrase>" << endl;
cout << " familyinfo" << endl;
cout << " connect <ip> [<port>]" << endl;
cout << " peers" << endl;
cout << " sendto <destination> <amount> [<tag>]" << endl;
cout << " tx" << endl;
cout << " ledger" << endl;