mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Next generation supression code.
This commit is contained in:
@@ -1,39 +1,68 @@
|
||||
|
||||
#include "Suppression.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
bool SuppressionTable::addSuppression(const uint160& suppression)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mSuppressionMutex);
|
||||
DECLARE_INSTANCE(Suppression);
|
||||
|
||||
if (mSuppressionMap.find(suppression) != mSuppressionMap.end())
|
||||
return false;
|
||||
Suppression& SuppressionTable::findCreateEntry(const uint256& index, bool& created)
|
||||
{
|
||||
boost::unordered_map<uint256, Suppression>::iterator fit = mSuppressionMap.find(index);
|
||||
|
||||
if (fit != mSuppressionMap.end())
|
||||
{
|
||||
created = false;
|
||||
return fit->second;
|
||||
}
|
||||
created = true;
|
||||
|
||||
time_t now = time(NULL);
|
||||
time_t expireTime = now - mHoldTime;
|
||||
|
||||
boost::unordered_map< time_t, std::list<uint160> >::iterator
|
||||
it = mSuppressionTimes.begin(), end = mSuppressionTimes.end();
|
||||
while (it != end)
|
||||
// See if any supressions need to be expired
|
||||
std::map< time_t, std::list<uint256> >::iterator it = mSuppressionTimes.begin();
|
||||
if ((it != mSuppressionTimes.end()) && (it->first <= expireTime))
|
||||
{
|
||||
if (it->first <= expireTime)
|
||||
{
|
||||
BOOST_FOREACH(const uint160& lit, it->second)
|
||||
mSuppressionMap.erase(lit);
|
||||
it = mSuppressionTimes.erase(it);
|
||||
}
|
||||
else ++it;
|
||||
BOOST_FOREACH(const uint256& lit, it->second)
|
||||
mSuppressionMap.erase(lit);
|
||||
mSuppressionTimes.erase(it);
|
||||
}
|
||||
|
||||
mSuppressionMap[suppression] = now;
|
||||
mSuppressionTimes[now].push_back(suppression);
|
||||
|
||||
return true;
|
||||
mSuppressionTimes[now].push_back(index);
|
||||
return mSuppressionMap.insert(std::make_pair(index, Suppression())).first->second;
|
||||
}
|
||||
|
||||
bool SuppressionTable::addSuppression(const uint256& suppression)
|
||||
bool SuppressionTable::addSuppression(const uint256& index)
|
||||
{
|
||||
uint160 u;
|
||||
memcpy(u.begin(), suppression.begin() + (suppression.size() - u.size()), u.size());
|
||||
return addSuppression(u);
|
||||
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::addSuppressionFlags(const uint256& index, int flag)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mSuppressionMutex);
|
||||
|
||||
bool created;
|
||||
findCreateEntry(index, created).setFlag(flag);
|
||||
return created;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user