Begin work on fetch_info command.

This commit is contained in:
JoelKatz
2013-07-23 08:58:53 -07:00
parent 286158137e
commit 80db6e1228
9 changed files with 86 additions and 0 deletions

View File

@@ -263,4 +263,35 @@ void InboundLedgers::gotFetchPack (Job&)
} }
} }
void InboundLedgers::clearFailures ()
{
boost::mutex::scoped_lock sl (mLock);
mRecentFailures.clear();
mLedgers.clear();
}
Json::Value InboundLedgers::getInfo()
{
Json::Value ret(Json::objectValue);
boost::mutex::scoped_lock sl (mLock);
std::vector<InboundLedger::pointer> acquires;
{
boost::mutex::scoped_lock sl (mLock);
acquires.reserve (mLedgers.size ());
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
BOOST_FOREACH (const u256_acq_pair & it, mLedgers)
acquires.push_back (it.second);
}
BOOST_FOREACH (const InboundLedger::pointer & acquire, acquires)
{
// WRITEME
}
return ret;
}
// vim:ts=4 // vim:ts=4

View File

@@ -56,6 +56,10 @@ public:
return mRecentFailures.isPresent (h, false); return mRecentFailures.isPresent (h, false);
} }
void clearFailures();
Json::Value getInfo();
void gotFetchPack (Job&); void gotFetchPack (Job&);
void sweep (); void sweep ();

View File

@@ -148,6 +148,14 @@ public:
return true; return true;
} }
/** Empty the cache
*/
void clear ()
{
boost::mutex::scoped_lock sl (mNCLock);
mCache.clear ();
}
/** Remove stale entries from the cache. /** Remove stale entries from the cache.
*/ */
void sweep () void sweep ()

View File

@@ -116,6 +116,18 @@ Json::Value RPCParser::parseInternal (const Json::Value& jvParams)
return v; return v;
} }
// fetch_info [clear]
Json::Value RPCParser::parseFetchInfo (const Json::Value& jvParams)
{
Json::Value jvRequest (Json::objectValue);
unsigned int iParams = jvParams.size ();
if (iParams != 0)
jvRequest[jvParams[0u].asString()] = true;
return jvRequest;
}
// account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary] [count] [descending] // account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary] [count] [descending]
Json::Value RPCParser::parseAccountTransactions (const Json::Value& jvParams) Json::Value RPCParser::parseAccountTransactions (const Json::Value& jvParams)
{ {
@@ -743,6 +755,7 @@ Json::Value RPCParser::parseCommand (std::string strMethod, Json::Value jvParams
{ "connect", &RPCParser::parseConnect, 1, 2 }, { "connect", &RPCParser::parseConnect, 1, 2 },
{ "consensus_info", &RPCParser::parseAsIs, 0, 0 }, { "consensus_info", &RPCParser::parseAsIs, 0, 0 },
{ "feature", &RPCParser::parseFeature, 0, 2 }, { "feature", &RPCParser::parseFeature, 0, 2 },
{ "fetch_info", &RPCParser::parseFetchInfo, 0, 1 },
{ "get_counts", &RPCParser::parseGetCounts, 0, 1 }, { "get_counts", &RPCParser::parseGetCounts, 0, 1 },
{ "json", &RPCParser::parseJson, 2, 2 }, { "json", &RPCParser::parseJson, 2, 2 },
{ "ledger", &RPCParser::parseLedger, 0, 2 }, { "ledger", &RPCParser::parseLedger, 0, 2 },

View File

@@ -30,6 +30,7 @@ private:
#endif #endif
Json::Value parseEvented (const Json::Value& jvParams); Json::Value parseEvented (const Json::Value& jvParams);
Json::Value parseFeature (const Json::Value& jvParams); Json::Value parseFeature (const Json::Value& jvParams);
Json::Value parseFetchInfo (const Json::Value& jvParams);
Json::Value parseGetCounts (const Json::Value& jvParams); Json::Value parseGetCounts (const Json::Value& jvParams);
Json::Value parseInternal (const Json::Value& jvParams); Json::Value parseInternal (const Json::Value& jvParams);
Json::Value parseJson (const Json::Value& jvParams); Json::Value parseJson (const Json::Value& jvParams);

View File

@@ -1511,6 +1511,16 @@ Json::Value NetworkOPs::getServerInfo (bool human, bool admin)
return info; return info;
} }
void NetworkOPs::clearLedgerFetch ()
{
getApp().getInboundLedgers().clearFailures();
}
Json::Value NetworkOPs::getLedgerFetchInfo ()
{
return getApp().getInboundLedgers().getInfo();
}
// //
// Monitoring: publisher side // Monitoring: publisher side
// //

View File

@@ -302,6 +302,8 @@ public:
} }
Json::Value getConsensusInfo (); Json::Value getConsensusInfo ();
Json::Value getServerInfo (bool human, bool admin); Json::Value getServerInfo (bool human, bool admin);
void clearLedgerFetch ();
Json::Value getLedgerFetchInfo ();
uint32 acceptLedger (); uint32 acceptLedger ();
boost::unordered_map < uint160, boost::unordered_map < uint160,
std::list<LedgerProposal::pointer> > & peekStoredProposals () std::list<LedgerProposal::pointer> > & peekStoredProposals ()

View File

@@ -1749,6 +1749,21 @@ Json::Value RPCHandler::doConsensusInfo (Json::Value, LoadType* loadType, Scoped
return ret; return ret;
} }
Json::Value RPCHandler::doFetchInfo (Json::Value jvParams, LoadType* loadType, ScopedLock& MasterLockHolder)
{
Json::Value ret (Json::objectValue);
if (jvParams.isMember("clear") && jvParams["clear"].asBool())
{
mNetOps->clearLedgerFetch();
ret["clear"] = true;
}
ret["info"] = mNetOps->getLedgerFetchInfo();
return ret;
}
Json::Value RPCHandler::doServerInfo (Json::Value, LoadType* loadType, ScopedLock& MasterLockHolder) Json::Value RPCHandler::doServerInfo (Json::Value, LoadType* loadType, ScopedLock& MasterLockHolder)
{ {
Json::Value ret (Json::objectValue); Json::Value ret (Json::objectValue);
@@ -3605,6 +3620,7 @@ Json::Value RPCHandler::doCommand (const Json::Value& params, int iRole, LoadTyp
{ "get_counts", &RPCHandler::doGetCounts, true, optNone }, { "get_counts", &RPCHandler::doGetCounts, true, optNone },
{ "internal", &RPCHandler::doInternal, true, optNone }, { "internal", &RPCHandler::doInternal, true, optNone },
{ "feature", &RPCHandler::doFeature, true, optNone }, { "feature", &RPCHandler::doFeature, true, optNone },
{ "fetch_info", &RPCHandler::doFetchInfo, true, optNone },
{ "ledger", &RPCHandler::doLedger, false, optNetwork }, { "ledger", &RPCHandler::doLedger, false, optNetwork },
{ "ledger_accept", &RPCHandler::doLedgerAccept, true, optCurrent }, { "ledger_accept", &RPCHandler::doLedgerAccept, true, optCurrent },
{ "ledger_closed", &RPCHandler::doLedgerClosed, false, optClosed }, { "ledger_closed", &RPCHandler::doLedgerClosed, false, optClosed },

View File

@@ -97,6 +97,7 @@ private:
Json::Value doConnect (Json::Value params, LoadType* loadType, ScopedLock& mlh); Json::Value doConnect (Json::Value params, LoadType* loadType, ScopedLock& mlh);
Json::Value doConsensusInfo (Json::Value params, LoadType* loadType, ScopedLock& mlh); Json::Value doConsensusInfo (Json::Value params, LoadType* loadType, ScopedLock& mlh);
Json::Value doFeature (Json::Value params, LoadType* loadType, ScopedLock& mlh); Json::Value doFeature (Json::Value params, LoadType* loadType, ScopedLock& mlh);
Json::Value doFetchInfo (Json::Value params, LoadType* loadType, ScopedLock& mlh);
Json::Value doGetCounts (Json::Value params, LoadType* loadType, ScopedLock& mlh); Json::Value doGetCounts (Json::Value params, LoadType* loadType, ScopedLock& mlh);
Json::Value doInternal (Json::Value params, LoadType* loadType, ScopedLock& mlh); Json::Value doInternal (Json::Value params, LoadType* loadType, ScopedLock& mlh);
Json::Value doLedger (Json::Value params, LoadType* loadType, ScopedLock& mlh); Json::Value doLedger (Json::Value params, LoadType* loadType, ScopedLock& mlh);