From 80db6e122823b52a4ebe0efe4d7f346c2896876c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 23 Jul 2013 08:58:53 -0700 Subject: [PATCH] Begin work on fetch_info command. --- .../ledger/ripple_InboundLedgers.cpp | 31 +++++++++++++++++++ .../ripple_app/ledger/ripple_InboundLedgers.h | 4 +++ .../containers/ripple_KeyCache.h | 8 +++++ src/cpp/ripple/CallRPC.cpp | 13 ++++++++ src/cpp/ripple/CallRPC.h | 1 + src/cpp/ripple/NetworkOPs.cpp | 10 ++++++ src/cpp/ripple/NetworkOPs.h | 2 ++ src/cpp/ripple/RPCHandler.cpp | 16 ++++++++++ src/cpp/ripple/RPCHandler.h | 1 + 9 files changed, 86 insertions(+) diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp index b6f091a31..2705e89a9 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp @@ -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 acquires; + { + boost::mutex::scoped_lock sl (mLock); + + acquires.reserve (mLedgers.size ()); + typedef std::pair 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 diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.h b/modules/ripple_app/ledger/ripple_InboundLedgers.h index 5d034e501..1794595c9 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.h +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.h @@ -56,6 +56,10 @@ public: return mRecentFailures.isPresent (h, false); } + void clearFailures(); + + Json::Value getInfo(); + void gotFetchPack (Job&); void sweep (); diff --git a/modules/ripple_basics/containers/ripple_KeyCache.h b/modules/ripple_basics/containers/ripple_KeyCache.h index ee0678f0e..da996805d 100644 --- a/modules/ripple_basics/containers/ripple_KeyCache.h +++ b/modules/ripple_basics/containers/ripple_KeyCache.h @@ -148,6 +148,14 @@ public: return true; } + /** Empty the cache + */ + void clear () + { + boost::mutex::scoped_lock sl (mNCLock); + mCache.clear (); + } + /** Remove stale entries from the cache. */ void sweep () diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 01c3a1578..c4f69f728 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -116,6 +116,18 @@ Json::Value RPCParser::parseInternal (const Json::Value& jvParams) 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] 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 }, { "consensus_info", &RPCParser::parseAsIs, 0, 0 }, { "feature", &RPCParser::parseFeature, 0, 2 }, + { "fetch_info", &RPCParser::parseFetchInfo, 0, 1 }, { "get_counts", &RPCParser::parseGetCounts, 0, 1 }, { "json", &RPCParser::parseJson, 2, 2 }, { "ledger", &RPCParser::parseLedger, 0, 2 }, diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index bb0d2cf1e..d61bf8224 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -30,6 +30,7 @@ private: #endif Json::Value parseEvented (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 parseInternal (const Json::Value& jvParams); Json::Value parseJson (const Json::Value& jvParams); diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index cba75861d..8b9730da1 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1511,6 +1511,16 @@ Json::Value NetworkOPs::getServerInfo (bool human, bool admin) return info; } +void NetworkOPs::clearLedgerFetch () +{ + getApp().getInboundLedgers().clearFailures(); +} + +Json::Value NetworkOPs::getLedgerFetchInfo () +{ + return getApp().getInboundLedgers().getInfo(); +} + // // Monitoring: publisher side // diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index d2797f747..d5aebcb7d 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -302,6 +302,8 @@ public: } Json::Value getConsensusInfo (); Json::Value getServerInfo (bool human, bool admin); + void clearLedgerFetch (); + Json::Value getLedgerFetchInfo (); uint32 acceptLedger (); boost::unordered_map < uint160, std::list > & peekStoredProposals () diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 3329e05ca..72505827a 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1749,6 +1749,21 @@ Json::Value RPCHandler::doConsensusInfo (Json::Value, LoadType* loadType, Scoped 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 ret (Json::objectValue); @@ -3605,6 +3620,7 @@ Json::Value RPCHandler::doCommand (const Json::Value& params, int iRole, LoadTyp { "get_counts", &RPCHandler::doGetCounts, true, optNone }, { "internal", &RPCHandler::doInternal, true, optNone }, { "feature", &RPCHandler::doFeature, true, optNone }, + { "fetch_info", &RPCHandler::doFetchInfo, true, optNone }, { "ledger", &RPCHandler::doLedger, false, optNetwork }, { "ledger_accept", &RPCHandler::doLedgerAccept, true, optCurrent }, { "ledger_closed", &RPCHandler::doLedgerClosed, false, optClosed }, diff --git a/src/cpp/ripple/RPCHandler.h b/src/cpp/ripple/RPCHandler.h index f2931c6ca..59d8a59d0 100644 --- a/src/cpp/ripple/RPCHandler.h +++ b/src/cpp/ripple/RPCHandler.h @@ -97,6 +97,7 @@ private: Json::Value doConnect (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 doFetchInfo (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 doLedger (Json::Value params, LoadType* loadType, ScopedLock& mlh);