From 0f47f72e3033b4667aa870968952a7618a6facdc Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 14 Jul 2012 22:13:22 -0700 Subject: [PATCH] Work on WS account_info_subscribe. --- src/NetworkOPs.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++---- src/NetworkOPs.h | 8 ++++-- src/RPCServer.cpp | 1 + 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index aed15e198e..1a8f787d1c 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -220,10 +220,14 @@ NicknameState::pointer NetworkOPs::getNicknameState(const uint256& uLedger, cons // Json::Value NetworkOPs::getOwnerInfo(const uint256& uLedger, const NewcoinAddress& naAccount) +{ + return getOwnerInfo(mLedgerMaster->getLedgerByHash(uLedger), naAccount); +} + +Json::Value NetworkOPs::getOwnerInfo(Ledger::pointer lpLedger, const NewcoinAddress& naAccount) { Json::Value jvObjects(Json::arrayValue); - Ledger::pointer lpLedger = mLedgerMaster->getLedgerByHash(uLedger); uint256 uRootIndex = lpLedger->getOwnerDirIndex(naAccount.getAccountID()); LedgerStateParms lspNode = lepNONE; @@ -236,9 +240,9 @@ Json::Value NetworkOPs::getOwnerInfo(const uint256& uLedger, const NewcoinAddres do { STVector256 svIndexes = sleNode->getIFieldV256(sfIndexes); - std::vector& vuiIndexes = svIndexes.peekValue(); + const std::vector& vuiIndexes = svIndexes.peekValue(); - BOOST_FOREACH(uint256& uDirEntry, vuiIndexes) + BOOST_FOREACH(const uint256& uDirEntry, vuiIndexes) { LedgerStateParms lspOffer = lepNONE; SLE::pointer sleOffer = lpLedger->getOffer(lspOffer, uDirEntry); @@ -728,9 +732,23 @@ Json::Value NetworkOPs::getServerInfo() } // -// Monitoring:: publisher side +// Monitoring: publisher side // +Json::Value NetworkOPs::pubBootstrapAccountInfo(const Ledger::pointer& lpAccepted, const NewcoinAddress& naAccountID) +{ + Json::Value jvObj(Json::objectValue); + + jvObj["type"] = "accountInfoBootstrap"; + jvObj["account"] = naAccountID.humanAccountID(); + jvObj["owner"] = getOwnerInfo(lpAccepted, naAccountID); + jvObj["seq"] = lpAccepted->getLedgerSeq(); + jvObj["hash"] = lpAccepted->getHash().ToString(); + jvObj["time"] = Json::Value::UInt(lpAccepted->getCloseTimeNC()); + + return jvObj; +} + void NetworkOPs::pubAccountInfo(const NewcoinAddress& naAccountID, const Json::Value& jvObj) { boost::interprocess::sharable_lock sl(mMonitorLock); @@ -827,6 +845,24 @@ void NetworkOPs::pubLedger(const Ledger::pointer& lpAccepted) } } } + + // Publish bootsrap information for accounts. + { + boost::interprocess::scoped_lock sl(mMonitorLock); + + BOOST_FOREACH(const subInfoMapType::iterator::value_type& it, mBootAccountInfo) + { + Json::Value jvObj = pubBootstrapAccountInfo(lpAccepted, NewcoinAddress::createAccountID(it.first)); + + BOOST_FOREACH(InfoSub* ispListener, it.second) + { + ispListener->send(jvObj); + } + } + mBootAccountInfo.clear(); + } + + // XXX Publish delta information for accounts. } Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TransactionEngineResult terResult, const std::string& strStatus, int iSeq, const std::string& strType) @@ -917,7 +953,26 @@ void NetworkOPs::subAccountInfo(InfoSub* ispListener, const boost::unordered_set BOOST_FOREACH(const NewcoinAddress& naAccountID, vnaAccountIDs) { - subInfoMapType::iterator simIterator = mSubAccountInfo.find(naAccountID.getAccountID()); + // Register for bootstrap info. + subInfoMapType::iterator simIterator; + + simIterator = mBootAccountInfo.find(naAccountID.getAccountID()); + if (simIterator == mBootAccountInfo.end()) + { + // Not found + boost::unordered_set usisElement; + + usisElement.insert(ispListener); + mBootAccountInfo.insert(simIterator, make_pair(naAccountID.getAccountID(), usisElement)); + } + else + { + // Found + simIterator->second.insert(ispListener); + } + + // Register for messages. + simIterator = mSubAccountInfo.find(naAccountID.getAccountID()); if (simIterator == mSubAccountInfo.end()) { // Not found diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 15f5b0355f..2b82fce7fc 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -53,12 +53,13 @@ protected: void setMode(OperatingMode); - typedef boost::unordered_map > subInfoMapType; + typedef boost::unordered_map > subInfoMapType; typedef boost::unordered_map >::value_type subInfoMapValue; - typedef boost::unordered_map >::iterator subInfoMapIterator; + typedef boost::unordered_map >::iterator subInfoMapIterator; // XXX Split into more locks. boost::interprocess::interprocess_upgradable_mutex mMonitorLock; + subInfoMapType mBootAccountInfo; subInfoMapType mSubAccountInfo; subInfoMapType mSubAccountTransaction; boost::unordered_set mSubLedger; // ledger accepteds @@ -70,6 +71,8 @@ protected: void pubTransactionAll(const Ledger::pointer& lpCurrent, const SerializedTransaction& stTxn, TransactionEngineResult terResult, const char* pState); void pubTransactionAccounts(const Ledger::pointer& lpCurrent, const SerializedTransaction& stTxn, TransactionEngineResult terResult, const char* pState); + Json::Value pubBootstrapAccountInfo(const Ledger::pointer& lpAccepted, const NewcoinAddress& naAccountID); + public: NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster); @@ -123,6 +126,7 @@ public: // Json::Value getOwnerInfo(const uint256& uLedger, const NewcoinAddress& naAccount); + Json::Value getOwnerInfo(Ledger::pointer lpLedger, const NewcoinAddress& naAccount); // // Ripple functions diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 39ecbba081..8996b072fe 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -949,6 +949,7 @@ Json::Value RPCServer::doOfferCancel(const Json::Value ¶ms) } // owner_info || +// owner_info || [] Json::Value RPCServer::doOwnerInfo(const Json::Value& params) { std::string strIdent = params[0u].asString();