From 1cf9156fc33ab9169fb60cf7b4684694e9ff7fee Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 24 Jun 2012 20:02:55 -0700 Subject: [PATCH] Add some monitoring support to NetworkOPs. --- src/NetworkOPs.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++-- src/NetworkOPs.h | 38 ++++++++++++++++-- 2 files changed, 127 insertions(+), 7 deletions(-) diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index ebf6284143..d381d8392d 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -1,15 +1,16 @@ #include "NetworkOPs.h" -#include -#include - #include "utils.h" #include "Application.h" #include "Transaction.h" #include "LedgerConsensus.h" #include "LedgerTiming.h" #include "Log.h" +#include "NewcoinAddress.h" + +#include +#include // This is the primary interface into the "client" portion of the program. // Code that wants to do normal operations on the network such as @@ -553,7 +554,6 @@ bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, } return mConsensus->peerPosition(proposal); - } SHAMap::pointer NetworkOPs::getTXMap(const uint256& hash) @@ -663,4 +663,92 @@ Json::Value NetworkOPs::getServerInfo() return info; } +// +// Monitoring:: publisher side +// + +void NetworkOPs::pubAccountInfo(const NewcoinAddress& naAccountID, const Json::Value& jvObj) +{ + boost::interprocess::sharable_lock sl(mMonitorLock); + + subInfoMapType::iterator simIterator = mSubAccountInfo.find(naAccountID); + + if (simIterator == mSubAccountInfo.end()) + { + // Address not found do nothing. + nothing(); + } + else + { + // Found it. + BOOST_FOREACH(InfoSub* ispListener, simIterator->second) + { + ispListener->send(jvObj); + } + } +} + +// +// Monitoring +// + +void NetworkOPs::subAccountInfo(InfoSub* ispListener, const std::vector& vnaAccountIDs) +{ + boost::interprocess::scoped_lock sl(mMonitorLock); + + BOOST_FOREACH(NewcoinAddress naAccountID, vnaAccountIDs) + { + subInfoMapType::iterator simIterator = mSubAccountInfo.find(naAccountID); + if (simIterator == mSubAccountInfo.end()) + { + // Not found + boost::unordered_set usisElement; + + usisElement.insert(ispListener); + mSubAccountInfo.insert(simIterator, make_pair(naAccountID, usisElement)); + } + else + { + // Found + simIterator->second.insert(ispListener); + } + } +} + +void NetworkOPs::unsubAccountInfo(InfoSub* ispListener, const std::vector& vnaAccountIDs) +{ + boost::interprocess::scoped_lock sl(mMonitorLock); + + BOOST_FOREACH(NewcoinAddress naAccountID, vnaAccountIDs) + { + subInfoMapType::iterator simIterator = mSubAccountInfo.find(naAccountID); + if (simIterator == mSubAccountInfo.end()) + { + // Not found. Done. + nothing(); + } + else + { + // Found + simIterator->second.erase(ispListener); + + if (simIterator->second.empty()) + { + // Don't need hash entry. + mSubAccountInfo.erase(simIterator); + } + } + } +} + + +void NetworkOPs::subAccountChanges(InfoSub* ispListener, const uint256 uLedgerHash) +{ +} + +void NetworkOPs::unsubAccountChanges(InfoSub* ispListener) +{ +} + + // vim:ts=4 diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 3925f150be..278808b799 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -1,13 +1,16 @@ #ifndef __NETWORK_OPS__ #define __NETWORK_OPS__ -#include "LedgerMaster.h" #include "AccountState.h" -#include "RippleState.h" +#include "LedgerMaster.h" #include "NicknameState.h" +#include "RippleState.h" #include "SerializedValidation.h" -// #include +#include +#include +#include +#include // Operations that clients may wish to perform against the network // Master operational handler, server sequencer, network tracker @@ -15,6 +18,12 @@ class Peer; class LedgerConsensus; +class InfoSub +{ +public: + virtual void send(const Json::Value& jvObj) = 0; +}; + class NetworkOPs { public: @@ -41,6 +50,12 @@ protected: void setMode(OperatingMode); + typedef boost::unordered_map > subInfoMapType; + typedef boost::unordered_map >::iterator subInfoMapIterator; + + boost::interprocess::interprocess_upgradable_mutex mMonitorLock; + subInfoMapType mSubAccountInfo; + public: NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster); @@ -133,6 +148,23 @@ public: // client information retrieval functions std::vector< std::pair > getAffectedAccounts(const NewcoinAddress& account, uint32 minLedger, uint32 maxLedger); + + // + // Monitoring: publisher side + // + + void pubAccountInfo(const NewcoinAddress& naAccountID, const Json::Value& jvObj); + + // + // Monitoring: subscriber side + // + + // --> vnaAddress: empty = all + void subAccountInfo(InfoSub* ispListener, const std::vector& vnaAccountIDs); + void unsubAccountInfo(InfoSub* ispListener, const std::vector& vnaAccountIDs); + + void subAccountChanges(InfoSub* ispListener, const uint256 uLedgerHash); + void unsubAccountChanges(InfoSub* ispListener); }; #endif