Refactor InfoSub to remove NetworkOPs dependency

This commit is contained in:
Vinnie Falco
2013-09-01 09:34:03 -07:00
parent 01fda4c30e
commit 35598d7933
11 changed files with 125 additions and 48 deletions

View File

@@ -13,9 +13,22 @@
class Peer;
class LedgerConsensus;
/** Provides server functionality for clients.
Clients include backend applications, local commands, and connected
clients. This class acts as a proxy, fulfilling the command with local
data if possible, or asking the network and returning the results if
needed.
A backend application or local client can trust a local instance of
rippled / NetworkOPs. However, client software connecting to non-local
instances of rippled will need to be hardened to protect against hostile
or unreliable servers.
*/
class NetworkOPs
: public DeadlineTimer::Listener
, LeakChecked <NetworkOPs>
, public InfoSub::Source
, public LeakChecked <NetworkOPs>
{
public:
enum Fault
@@ -355,9 +368,9 @@ public:
void pubLedger (Ledger::ref lpAccepted);
void pubProposedTransaction (Ledger::ref lpCurrent, SerializedTransaction::ref stTxn, TER terResult);
//--------------------------------------------------------------------------
//
// Monitoring: subscriber side
// InfoSub::Source
//
void subAccount (InfoSub::ref ispListener, const boost::unordered_set<RippleAddress>& vnaAccountIDs, uint32 uLedgerIndex, bool rt);
void unsubAccount (uint64 uListener, const boost::unordered_set<RippleAddress>& vnaAccountIDs, bool rt);
@@ -382,6 +395,9 @@ public:
InfoSub::pointer findRpcSub (const std::string& strUrl);
InfoSub::pointer addRpcSub (const std::string& strUrl, InfoSub::ref rspEntry);
//
//--------------------------------------------------------------------------
private:
void setHeartbeatTimer ();
void setClusterTimer ();

View File

@@ -17,8 +17,9 @@
// VFALCO TODO Figure out how to clean up these globals
InfoSub::InfoSub ()
: mLock (this, "InfoSub", __FILE__, __LINE__)
InfoSub::InfoSub (Source& source)
: m_source (source)
, mLock (this, "InfoSub", __FILE__, __LINE__)
{
static Atomic <int> s_seq_id;
mSeq = ++s_seq_id;
@@ -26,13 +27,12 @@ InfoSub::InfoSub ()
InfoSub::~InfoSub ()
{
NetworkOPs& ops = getApp().getOPs ();
ops.unsubTransactions (mSeq);
ops.unsubRTTransactions (mSeq);
ops.unsubLedger (mSeq);
ops.unsubServer (mSeq);
ops.unsubAccount (mSeq, mSubAccountInfo, true);
ops.unsubAccount (mSeq, mSubAccountInfo, false);
m_source.unsubTransactions (mSeq);
m_source.unsubRTTransactions (mSeq);
m_source.unsubLedger (mSeq);
m_source.unsubServer (mSeq);
m_source.unsubAccount (mSeq, mSubAccountInfo, true);
m_source.unsubAccount (mSeq, mSubAccountInfo, false);
}
void InfoSub::send (const Json::Value& jvObj, const std::string& sObj, bool broadcast)

View File

@@ -12,6 +12,8 @@
class PathRequest;
/** Manages a client's subscription to data feeds.
*/
class InfoSub
: public CountedObject <InfoSub>
{
@@ -26,7 +28,58 @@ public:
typedef const boost::shared_ptr<InfoSub>& ref;
public:
InfoSub ();
/** Abstracts the source of subscription data.
*/
class Source
{
public:
// VFALCO TODO Rename the 'rt' parameters to something meaningful.
virtual void subAccount (ref ispListener,
const boost::unordered_set<RippleAddress>& vnaAccountIDs,
uint32 uLedgerIndex, bool rt) = 0;
virtual void unsubAccount (uint64 uListener,
const boost::unordered_set<RippleAddress>& vnaAccountIDs,
bool rt) = 0;
// VFALCO TODO Document the bool return value
virtual bool subLedger (ref ispListener,
Json::Value& jvResult) = 0;
virtual bool unsubLedger (uint64 uListener) = 0;
virtual bool subServer (ref ispListener,
Json::Value& jvResult) = 0;
virtual bool unsubServer (uint64 uListener) = 0;
virtual bool subBook (ref ispListener,
const uint160& currencyPays, const uint160& currencyGets,
const uint160& issuerPays, const uint160& issuerGets) = 0;
virtual bool unsubBook (uint64 uListener,
const uint160& currencyPays, const uint160& currencyGets,
const uint160& issuerPays, const uint160& issuerGets) = 0;
virtual bool subTransactions (ref ispListener) = 0;
virtual bool unsubTransactions (uint64 uListener) = 0;
virtual bool subRTTransactions (ref ispListener) = 0;
virtual bool unsubRTTransactions (uint64 uListener) = 0;
// VFALCO TODO Remove
// This was added for one particular partner, it
// "pushes" subscription data to a particular URL.
//
virtual pointer findRpcSub (const std::string& strUrl) = 0;
virtual pointer addRpcSub (const std::string& strUrl, ref rspEntry) = 0;
};
public:
explicit InfoSub (Source& source);
virtual ~InfoSub ();
@@ -53,6 +106,7 @@ protected:
LockType mLock;
private:
Source& m_source;
boost::unordered_set <RippleAddress> mSubAccountInfo;
boost::unordered_set <RippleAddress> mSubAccountTransaction;
boost::shared_ptr <PathRequest> mPathRequest;