diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index 5ff475a618..0af0736d47 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -28,11 +28,15 @@ #include #include #include +#include +#include +#include +#include +#include + #include #include #include -#include -#include #include #include @@ -46,8 +50,10 @@ #include #include #include +#include #include #include +#include //------------------------------------------------------------------------------ @@ -128,6 +134,7 @@ // New abstract interfaces #include "src/cpp/ripple/ripple_IFeatures.h" #include "src/cpp/ripple/ripple_IFeeVote.h" +#include "src/cpp/ripple/ripple_IHashRouter.h" #include "src/cpp/ripple/ripple_ILoadFeeTrack.h" #include "src/cpp/ripple/ripple_IValidations.h" #include "src/cpp/ripple/ripple_IUniqueNodeList.h" @@ -238,7 +245,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/ripple_HashValue.cpp" // sockets -#include "src/cpp/ripple/Suppression.cpp" // no log #include "src/cpp/ripple/SNTPClient.cpp" #include "src/cpp/ripple/ConnectionPool.cpp" #include "src/cpp/ripple/NetworkOPs.cpp" @@ -265,6 +271,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) // Implementation of interfaces #include "src/cpp/ripple/ripple_FeeVote.cpp" +#include "src/cpp/ripple/ripple_HashRouter.cpp" #include "src/cpp/ripple/ripple_LoadFeeTrack.cpp" #include "src/cpp/ripple/ripple_Validations.cpp" #include "src/cpp/ripple/ripple_UniqueNodeList.cpp" diff --git a/newcoin.vcxproj b/newcoin.vcxproj index c67d9a7e43..a0efa77db2 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -1106,7 +1106,7 @@ true true - + true true true @@ -1674,7 +1674,7 @@ - + diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index c60ebd198b..16a6233f55 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -786,9 +786,6 @@ 1. Modules\ripple_main\sockets - - 1. Modules\ripple_main\sockets - 1. Modules\ripple_main\sockets @@ -801,6 +798,9 @@ 1. Modules\ripple_main\sockets + + 1. Modules\ripple_main\sockets + @@ -1478,15 +1478,15 @@ 1. Modules\ripple_main\sockets - - 1. Modules\ripple_main\sockets - 1. Modules\ripple_main\sockets 1. Modules\ripple_main\sockets + + 1. Modules\ripple_main\sockets + diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index 7be6cb9ccf..b37446d213 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -36,6 +36,7 @@ Application::Application () // VFALCO: New stuff , mFeeVote (IFeeVote::New (10, 50 * SYSTEM_CURRENCY_PARTS, 12.5 * SYSTEM_CURRENCY_PARTS)) , mFeeTrack (ILoadFeeTrack::New ()) + , mHashRouter (IHashRouter::New (IHashRouter::getDefaultHoldTime ())) , mValidations (IValidations::New ()) , mUNL (IUniqueNodeList::New (mIOService)) // VFALCO: End new stuff @@ -105,6 +106,7 @@ void sigIntHandler(int) } #endif +// VFALCO: TODO, Figure this out it looks like the wrong tool static void runAux(boost::asio::io_service& svc) { setCallingThreadName("aux"); @@ -117,6 +119,26 @@ static void runIO(boost::asio::io_service& io) io.run(); } +bool Application::isNew(const uint256& s) +{ + return mHashRouter->addSuppression(s); +} + +bool Application::isNew(const uint256& s, uint64 p) +{ + return mHashRouter->addSuppressionPeer(s, p); +} + +bool Application::isNew(const uint256& s, uint64 p, int& f) +{ + return mHashRouter->addSuppressionPeer(s, p, f); +} + +bool Application::isNewFlag(const uint256& s, int f) +{ + return mHashRouter->setFlag(s, f); +} + void Application::setup() { mJobQueue.setThreadCount(); diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index 47a0ad501a..60b2204a98 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -16,7 +16,6 @@ #include "Peer.h" #include "NetworkOPs.h" #include "WSDoor.h" -#include "Suppression.h" #include "SNTPClient.h" #include "JobQueue.h" #include "RPCHandler.h" @@ -30,6 +29,7 @@ // VFALCO: TODO, Fix forward declares required for header dependency loops class IFeatureTable; class IFeeVote; +class IHashRouter; class ILoadFeeTrack; class IValidations; class IUniqueNodeList; @@ -52,7 +52,6 @@ class Application TransactionMaster mMasterTransaction; NetworkOPs mNetOps; NodeCache mTempNodeCache; - SuppressionTable mSuppressions; HashedObjectStore mHashedObjectStore; SLECache mSLECache; SNTPClient mSNTPClient; @@ -63,8 +62,9 @@ class Application OrderBookDB mOrderBookDB; // VFALCO: Clean stuff - beast::ScopedPointer mFeeVote; - beast::ScopedPointer mFeeTrack; + beast::ScopedPointer mFeeVote; + beast::ScopedPointer mFeeTrack; + beast::ScopedPointer mHashRouter; beast::ScopedPointer mValidations; beast::ScopedPointer mUNL; // VFALCO: End Clean stuff @@ -116,7 +116,7 @@ public: NodeCache& getTempNodeCache() { return mTempNodeCache; } HashedObjectStore& getHashedObjectStore() { return mHashedObjectStore; } JobQueue& getJobQueue() { return mJobQueue; } - SuppressionTable& getSuppression() { return mSuppressions; } + IHashRouter& getHashRouter() { return *mHashRouter; } boost::recursive_mutex& getMasterLock() { return mMasterLock; } ProofOfWorkGenerator& getPowGen() { return mPOWGen; } LoadManager& getLoadManager() { return mLoadMgr; } @@ -130,11 +130,14 @@ public: ILoadFeeTrack& getFeeTrack() { return *mFeeTrack; } IValidations& getValidations() { return *mValidations; } - bool isNew(const uint256& s) { return mSuppressions.addSuppression(s); } - bool isNew(const uint256& s, uint64 p) { return mSuppressions.addSuppressionPeer(s, p); } - bool isNew(const uint256& s, uint64 p, int& f) { return mSuppressions.addSuppressionPeer(s, p, f); } - bool isNewFlag(const uint256& s, int f) { return mSuppressions.setFlag(s, f); } - bool running() { return mTxnDB != NULL; } + // VFALCO: TODO, eliminate these, change callers to just call IHashRouter directly! + bool isNew(const uint256& s); + bool isNew(const uint256& s, uint64 p); + bool isNew(const uint256& s, uint64 p, int& f); + bool isNewFlag(const uint256& s, int f); + + // VFALCO: TODO, Move these to the .cpp + bool running() { return mTxnDB != NULL; } // VFALCO: TODO, replace with nullptr when beast is available bool getSystemTimeOffset(int& offset) { return mSNTPClient.getOffset(offset); } DatabaseCon* getRpcDB() { return mRpcDB; } diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index 65db04a62e..eebec8c7bf 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -1004,7 +1004,7 @@ void LedgerConsensus::playbackProposals() } #if 0 // FIXME: We can't do delayed relay because we don't have the signature std::set peers - if (relay && theApp->getSuppression().swapSet(proposal.getSuppress(), set, SF_RELAYED)) + if (relay && theApp->getHashRouter().swapSet(proposal.getSuppress(), set, SF_RELAYED)) { WriteLog (lsDEBUG, LedgerConsensus) << "Stored proposal delayed relay"; ripple::TMProposeSet set; diff --git a/src/cpp/ripple/LedgerProposal.h b/src/cpp/ripple/LedgerProposal.h index fa5337df39..10991c50c2 100644 --- a/src/cpp/ripple/LedgerProposal.h +++ b/src/cpp/ripple/LedgerProposal.h @@ -48,7 +48,7 @@ public: const uint160& getPeerID() const { return mPeerID; } const uint256& getCurrentHash() const { return mCurrentHash; } const uint256& getPrevLedger() const { return mPreviousLedger; } - const uint256& getSuppression() const { return mSuppression; } + const uint256& getHashRouter() const { return mSuppression; } uint32 getProposeSeq() const { return mProposeSeq; } uint32 getCloseTime() const { return mCloseTime; } const RippleAddress& peekPublic() const { return mPublicKey; } diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index c713cb46cd..493aa3ed4e 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -292,7 +292,7 @@ void NetworkOPs::runTransactionQueue() if (didApply || (mMode != omFULL)) { std::set peers; - if (theApp->getSuppression().swapSet(txn->getID(), peers, SF_RELAYED)) + if (theApp->getHashRouter().swapSet(txn->getID(), peers, SF_RELAYED)) { ripple::TMTransaction tx; Serializer s; @@ -318,7 +318,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, { LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtTXN_PROC, "ProcessTXN"); - int newFlags = theApp->getSuppression().getFlags(trans->getID()); + int newFlags = theApp->getHashRouter().getFlags(trans->getID()); if ((newFlags & SF_BAD) != 0) { // cached bad trans->setStatus(INVALID); @@ -392,7 +392,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, if (didApply || (mMode != omFULL)) { std::set peers; - if (theApp->getSuppression().swapSet(trans->getID(), peers, SF_RELAYED)) + if (theApp->getHashRouter().swapSet(trans->getID(), peers, SF_RELAYED)) { ripple::TMTransaction tx; Serializer s; @@ -921,7 +921,7 @@ void NetworkOPs::processTrustedProposal(LedgerProposal::pointer proposal, if (relay) { std::set peers; - theApp->getSuppression().swapSet(proposal->getSuppression(), peers, SF_RELAYED); + theApp->getHashRouter().swapSet(proposal->getHashRouter(), peers, SF_RELAYED); PackedMessage::pointer message = boost::make_shared(*set, ripple::mtPROPOSE_LEDGER); theApp->getConnectionPool().relayMessageBut(peers, message); } diff --git a/src/cpp/ripple/NetworkStatus.h b/src/cpp/ripple/NetworkStatus.h deleted file mode 100644 index d147600571..0000000000 --- a/src/cpp/ripple/NetworkStatus.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __NETWORKSTATUS__ -#define __NETWORKSTATUS__ - -struct NSBit -{ // a network status bit - const char *name, *description; - int number; -}; - -struct NetworkStatus -{ - static const int nsbConnected=0; // connected to the network - static const int nsbAccepted=1; // accept this as the real network - static const int nsbFastSynching=2; // catching up, skipping transactions - static const int nsbSlowSynching=3; // catching up, txn by txn - static const int nsbSynched=4; // in synch with the network - static const int nsbIdentifiable=5; // not hiding our identity - static const int nsbLedgerSync=6; // participating in ledger sync - static const int nsbStuck=7; // unable to sync - static const int nsbShuttingDown=8; // node is shutting down - - static const int nnbCount=32; - std::bitset nsbValues; - std::map nsbData; -}; - -#endif diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index 9a49e1bf66..a13628abda 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -842,12 +842,12 @@ static void checkTransaction(Job&, int flags, SerializedTransaction::pointer stx tx = boost::make_shared(stx, true); if (tx->getStatus() == INVALID) { - theApp->getSuppression().setFlag(stx->getTransactionID(), SF_BAD); + theApp->getHashRouter().setFlag(stx->getTransactionID(), SF_BAD); Peer::punishPeer(peer, LT_InvalidSignature); return; } else - theApp->getSuppression().setFlag(stx->getTransactionID(), SF_SIGGOOD); + theApp->getHashRouter().setFlag(stx->getTransactionID(), SF_SIGGOOD); } else tx = boost::make_shared(stx, false); @@ -858,7 +858,7 @@ static void checkTransaction(Job&, int flags, SerializedTransaction::pointer stx } catch (...) { - theApp->getSuppression().setFlags(stx->getTransactionID(), SF_BAD); + theApp->getHashRouter().setFlags(stx->getTransactionID(), SF_BAD); punishPeer(peer, LT_InvalidRequest); } #endif @@ -962,7 +962,7 @@ static void checkPropose(Job& job, boost::shared_ptr packe { // relay untrusted proposal WriteLog (lsTRACE, Peer) << "relaying untrusted proposal"; std::set peers; - theApp->getSuppression().swapSet(proposal->getSuppression(), peers, SF_RELAYED); + theApp->getHashRouter().swapSet(proposal->getHashRouter(), peers, SF_RELAYED); PackedMessage::pointer message = boost::make_shared(set, ripple::mtPROPOSE_LEDGER); theApp->getConnectionPool().relayMessageBut(peers, message); } @@ -1069,7 +1069,7 @@ static void checkValidation(Job&, SerializedValidation::pointer val, uint256 sig std::set peers; if (theApp->getOPs().recvValidation(val, source) && - theApp->getSuppression().swapSet(signingHash, peers, SF_RELAYED)) + theApp->getHashRouter().swapSet(signingHash, peers, SF_RELAYED)) { PackedMessage::pointer message = boost::make_shared(*packet, ripple::mtVALIDATION); theApp->getConnectionPool().relayMessageBut(peers, message); diff --git a/src/cpp/ripple/Suppression.cpp b/src/cpp/ripple/Suppression.cpp deleted file mode 100644 index f6bcb8847b..0000000000 --- a/src/cpp/ripple/Suppression.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "Suppression.h" - -#include - -DECLARE_INSTANCE(Suppression); - -Suppression& SuppressionTable::findCreateEntry(const uint256& index, bool& created) -{ - boost::unordered_map::iterator fit = mSuppressionMap.find(index); - - if (fit != mSuppressionMap.end()) - { - created = false; - return fit->second; - } - created = true; - - int now = UptimeTimer::getInstance().getElapsedSeconds (); - int expireTime = now - mHoldTime; - - // See if any supressions need to be expired - std::map< int, std::list >::iterator it = mSuppressionTimes.begin(); - if ((it != mSuppressionTimes.end()) && (it->first <= expireTime)) - { - BOOST_FOREACH(const uint256& lit, it->second) - mSuppressionMap.erase(lit); - mSuppressionTimes.erase(it); - } - - mSuppressionTimes[now].push_back(index); - return mSuppressionMap.emplace(index, Suppression()).first->second; -} - -bool SuppressionTable::addSuppression(const uint256& index) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - findCreateEntry(index, created); - return created; -} - -Suppression SuppressionTable::getEntry(const uint256& index) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - return findCreateEntry(index, created); -} - -bool SuppressionTable::addSuppressionPeer(const uint256& index, uint64 peer) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - findCreateEntry(index, created).addPeer(peer); - return created; -} - -bool SuppressionTable::addSuppressionPeer(const uint256& index, uint64 peer, int& flags) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - Suppression &s = findCreateEntry(index, created); - s.addPeer(peer); - flags = s.getFlags(); - return created; -} - -int SuppressionTable::getFlags(const uint256& index) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - return findCreateEntry(index, created).getFlags(); -} - -bool SuppressionTable::addSuppressionFlags(const uint256& index, int flag) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - findCreateEntry(index, created).setFlag(flag); - return created; -} - -bool SuppressionTable::setFlag(const uint256& index, int flag) -{ // return: true = changed, false = unchanged - assert(flag != 0); - - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - Suppression &s = findCreateEntry(index, created); - - if ((s.getFlags() & flag) == flag) - return false; - - s.setFlag(flag); - return true; -} - -bool SuppressionTable::swapSet(const uint256& index, std::set& peers, int flag) -{ - boost::mutex::scoped_lock sl(mSuppressionMutex); - - bool created; - Suppression &s = findCreateEntry(index, created); - - if ((s.getFlags() & flag) == flag) - return false; - - s.swapSet(peers); - s.setFlag(flag); - - return true; -} diff --git a/src/cpp/ripple/Suppression.h b/src/cpp/ripple/Suppression.h deleted file mode 100644 index ca4f4f08c5..0000000000 --- a/src/cpp/ripple/Suppression.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef __SUPPRESSION__ -#define __SUPPRESSION__ - -#include -#include -#include - -#include -#include - -DEFINE_INSTANCE(Suppression); - -#define SF_RELAYED 0x01 // Has already been relayed to other nodes -#define SF_BAD 0x02 // Signature/format is bad -#define SF_SIGGOOD 0x04 // Signature is good -#define SF_SAVED 0x08 -#define SF_RETRY 0x10 // Transaction can be retried -#define SF_TRUSTED 0x20 // comes from trusted source - -class Suppression : private IS_INSTANCE(Suppression) -{ -protected: - int mFlags; - std::set mPeers; - -public: - Suppression() : mFlags(0) { ; } - - const std::set& peekPeers() { return mPeers; } - void addPeer(uint64 peer) { if (peer != 0) mPeers.insert(peer); } - bool hasPeer(uint64 peer) { return mPeers.count(peer) > 0; } - - int getFlags(void) { return mFlags; } - bool hasFlag(int f) { return (mFlags & f) != 0; } - void setFlag(int f) { mFlags |= f; } - void clearFlag(int f) { mFlags &= ~f; } - void swapSet(std::set& s) { mPeers.swap(s); } -}; - -class SuppressionTable -{ -protected: - - boost::mutex mSuppressionMutex; - - // Stores all suppressed hashes and their expiration time - boost::unordered_map mSuppressionMap; - - // Stores all expiration times and the hashes indexed for them - std::map< int, std::list > mSuppressionTimes; - - int mHoldTime; - - Suppression& findCreateEntry(const uint256&, bool& created); - -public: - SuppressionTable(int holdTime = 120) : mHoldTime(holdTime) { ; } - - bool addSuppression(const uint256& index); - - bool addSuppressionPeer(const uint256& index, uint64 peer); - bool addSuppressionPeer(const uint256& index, uint64 peer, int& flags); - bool addSuppressionFlags(const uint256& index, int flag); - bool setFlag(const uint256& index, int flag); - int getFlags(const uint256& index); - - Suppression getEntry(const uint256&); - - bool swapSet(const uint256& index, std::set& peers, int flag); - bool swapSet(const uint256& index, std::set& peers); -}; - -#endif diff --git a/src/cpp/ripple/ripple_HashRouter.cpp b/src/cpp/ripple/ripple_HashRouter.cpp new file mode 100644 index 0000000000..693fa911a2 --- /dev/null +++ b/src/cpp/ripple/ripple_HashRouter.cpp @@ -0,0 +1,155 @@ + +DECLARE_INSTANCE(HashRouterEntry); + +// VFALCO: TODO Inline the function definitions +class HashRouter : public IHashRouter +{ +public: + explicit HashRouter (int holdTime) + : mHoldTime (holdTime) + { + } + + bool addSuppression(const uint256& index); + + bool addSuppressionPeer(const uint256& index, uint64 peer); + bool addSuppressionPeer(const uint256& index, uint64 peer, int& flags); + bool addSuppressionFlags(const uint256& index, int flag); + bool setFlag(const uint256& index, int flag); + int getFlags(const uint256& index); + + HashRouterEntry getEntry(const uint256&); + + bool swapSet(const uint256& index, std::set& peers, int flag); + +private: + boost::mutex mSuppressionMutex; + + // Stores all suppressed hashes and their expiration time + boost::unordered_map mSuppressionMap; + + // Stores all expiration times and the hashes indexed for them + std::map< int, std::list > mSuppressionTimes; + + int mHoldTime; + + HashRouterEntry& findCreateEntry(const uint256&, bool& created); +}; + +HashRouterEntry& HashRouter::findCreateEntry(const uint256& index, bool& created) +{ + boost::unordered_map::iterator fit = mSuppressionMap.find(index); + + if (fit != mSuppressionMap.end()) + { + created = false; + return fit->second; + } + created = true; + + int now = UptimeTimer::getInstance().getElapsedSeconds (); + int expireTime = now - mHoldTime; + + // See if any supressions need to be expired + std::map< int, std::list >::iterator it = mSuppressionTimes.begin(); + if ((it != mSuppressionTimes.end()) && (it->first <= expireTime)) + { + BOOST_FOREACH(const uint256& lit, it->second) + mSuppressionMap.erase(lit); + mSuppressionTimes.erase(it); + } + + mSuppressionTimes[now].push_back(index); + return mSuppressionMap.emplace(index, HashRouterEntry ()).first->second; +} + +bool HashRouter::addSuppression(const uint256& index) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + findCreateEntry(index, created); + return created; +} + +HashRouterEntry HashRouter::getEntry(const uint256& index) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + return findCreateEntry(index, created); +} + +bool HashRouter::addSuppressionPeer(const uint256& index, uint64 peer) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + findCreateEntry(index, created).addPeer(peer); + return created; +} + +bool HashRouter::addSuppressionPeer(const uint256& index, uint64 peer, int& flags) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + HashRouterEntry &s = findCreateEntry(index, created); + s.addPeer(peer); + flags = s.getFlags(); + return created; +} + +int HashRouter::getFlags(const uint256& index) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + return findCreateEntry(index, created).getFlags(); +} + +bool HashRouter::addSuppressionFlags(const uint256& index, int flag) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + findCreateEntry(index, created).setFlag(flag); + return created; +} + +bool HashRouter::setFlag(const uint256& index, int flag) +{ // return: true = changed, false = unchanged + assert(flag != 0); + + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + HashRouterEntry &s = findCreateEntry(index, created); + + if ((s.getFlags() & flag) == flag) + return false; + + s.setFlag(flag); + return true; +} + +bool HashRouter::swapSet(const uint256& index, std::set& peers, int flag) +{ + boost::mutex::scoped_lock sl(mSuppressionMutex); + + bool created; + HashRouterEntry &s = findCreateEntry(index, created); + + if ((s.getFlags() & flag) == flag) + return false; + + s.swapSet(peers); + s.setFlag(flag); + + return true; +} + +IHashRouter* IHashRouter::New (int holdTime) +{ + return new HashRouter (holdTime); +} diff --git a/src/cpp/ripple/ripple_IHashRouter.h b/src/cpp/ripple/ripple_IHashRouter.h new file mode 100644 index 0000000000..0fa9293f1a --- /dev/null +++ b/src/cpp/ripple/ripple_IHashRouter.h @@ -0,0 +1,65 @@ +#ifndef RIPPLE_HASHROUTER_H +#define RIPPLE_HASHROUTER_H + +DEFINE_INSTANCE (HashRouterEntry); + +// VFALCO: TODO, convert these macros to int constants +#define SF_RELAYED 0x01 // Has already been relayed to other nodes +#define SF_BAD 0x02 // Signature/format is bad +#define SF_SIGGOOD 0x04 // Signature is good +#define SF_SAVED 0x08 +#define SF_RETRY 0x10 // Transaction can be retried +#define SF_TRUSTED 0x20 // comes from trusted source + +// VFALCO: TODO move this class into the scope of class HashRouter +class HashRouterEntry : private IS_INSTANCE (HashRouterEntry) +{ +protected: + int mFlags; + std::set mPeers; + +public: + HashRouterEntry () : mFlags(0) { ; } + + const std::set& peekPeers() { return mPeers; } + void addPeer(uint64 peer) { if (peer != 0) mPeers.insert(peer); } + bool hasPeer(uint64 peer) { return mPeers.count(peer) > 0; } + + int getFlags(void) { return mFlags; } + bool hasFlag(int f) { return (mFlags & f) != 0; } + void setFlag(int f) { mFlags |= f; } + void clearFlag(int f) { mFlags &= ~f; } + void swapSet(std::set& s) { mPeers.swap(s); } +}; + +class IHashRouter +{ +public: + // VFALCO: NOTE, this preferred alternative to default parameters makes + // behavior clear. + // + static inline int getDefaultHoldTime () + { + return 120; + } + + // VFALCO: TODO rename the parameter to entryHoldTimeInSeconds + static IHashRouter* New (int holdTime); + + virtual ~IHashRouter () { } + + virtual bool addSuppression(const uint256& index) = 0; + + virtual bool addSuppressionPeer(const uint256& index, uint64 peer) = 0; + virtual bool addSuppressionPeer(const uint256& index, uint64 peer, int& flags) = 0; + virtual bool addSuppressionFlags(const uint256& index, int flag) = 0; + virtual bool setFlag(const uint256& index, int flag) = 0; + virtual int getFlags(const uint256& index) = 0; + + virtual HashRouterEntry getEntry(const uint256&) = 0; + + virtual bool swapSet(const uint256& index, std::set& peers, int flag) = 0; +}; + + +#endif