mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Supression table.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "NetworkOPs.h"
|
||||
#include "TaggedCache.h"
|
||||
#include "ValidationCollection.h"
|
||||
#include "Suppression.h"
|
||||
#include "../database/database.h"
|
||||
|
||||
|
||||
@@ -46,6 +47,7 @@ class Application
|
||||
NetworkOPs mNetOps;
|
||||
NodeCache mNodeCache;
|
||||
ValidationCollection mValidations;
|
||||
SuppressionTable mSuppressions;
|
||||
|
||||
DatabaseCon *mTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB;
|
||||
|
||||
@@ -77,6 +79,8 @@ public:
|
||||
TransactionMaster& getMasterTransaction() { return mMasterTransaction; }
|
||||
NodeCache& getNodeCache() { return mNodeCache; }
|
||||
ValidationCollection& getValidations() { return mValidations; }
|
||||
bool suppress(const uint256& s) { return mSuppressions.addSuppression(s); }
|
||||
bool suppress(const uint160& s) { return mSuppressions.addSuppression(s); }
|
||||
|
||||
DatabaseCon* getTxnDB() { return mTxnDB; }
|
||||
DatabaseCon* getLedgerDB() { return mLedgerDB; }
|
||||
|
||||
37
src/Suppression.cpp
Normal file
37
src/Suppression.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#include "Suppression.h"
|
||||
|
||||
bool SuppressionTable::addSuppression(const uint160& suppression)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mSuppressionMutex);
|
||||
|
||||
if (mSuppressionMap.find(suppression) != mSuppressionMap.end())
|
||||
return false;
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
boost::unordered_map< time_t, std::list<uint160> >::iterator it = mSuppressionTimes.begin();
|
||||
while (it != mSuppressionTimes.end())
|
||||
{
|
||||
if ((it->first + mHoldTime) < now)
|
||||
{
|
||||
for (std::list<uint160>::iterator lit = it->second.begin(), end = it->second.end();
|
||||
lit != end; ++lit)
|
||||
mSuppressionMap.erase(*lit);
|
||||
mSuppressionTimes.erase(it++);
|
||||
}
|
||||
else ++it;
|
||||
}
|
||||
|
||||
mSuppressionMap[suppression] = now;
|
||||
mSuppressionTimes[now].push_back(suppression);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SuppressionTable::addSuppression(const uint256& suppression)
|
||||
{
|
||||
uint160 u;
|
||||
memcpy(u.begin(), suppression.begin() + (suppression.size() - u.size()), u.size());
|
||||
return addSuppression(u);
|
||||
}
|
||||
34
src/Suppression.h
Normal file
34
src/Suppression.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __SUPPRESSION__
|
||||
#define __SUPPRESSION__
|
||||
|
||||
#include <list>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
extern std::size_t hash_value(const uint160& u);
|
||||
|
||||
class SuppressionTable
|
||||
{
|
||||
protected:
|
||||
|
||||
boost::mutex mSuppressionMutex;
|
||||
|
||||
// Stores all suppressed hashes and their expiration time
|
||||
boost::unordered_map<uint160, time_t> mSuppressionMap;
|
||||
|
||||
// Stores all expiration times and the hashes indexed for them
|
||||
boost::unordered_map< time_t, std::list<uint160> > mSuppressionTimes;
|
||||
|
||||
int mHoldTime;
|
||||
|
||||
public:
|
||||
SuppressionTable(int holdTime = 120) : mHoldTime(holdTime) { ; }
|
||||
|
||||
bool addSuppression(const uint256& suppression);
|
||||
bool addSuppression(const uint160& suppression);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user