mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Add a filter field in CNode, add filterload+filteradd+filterclear
This commit is contained in:
parent
133a546074
commit
422d122537
45
src/main.cpp
45
src/main.cpp
@ -3332,6 +3332,51 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
}
|
||||
|
||||
|
||||
else if (strCommand == "filterload")
|
||||
{
|
||||
CBloomFilter filter;
|
||||
vRecv >> filter;
|
||||
|
||||
if (!filter.IsWithinSizeConstraints())
|
||||
// There is no excuse for sending a too-large filter
|
||||
pfrom->Misbehaving(100);
|
||||
else
|
||||
{
|
||||
LOCK(pfrom->cs_filter);
|
||||
delete pfrom->pfilter;
|
||||
pfrom->pfilter = new CBloomFilter(filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if (strCommand == "filteradd")
|
||||
{
|
||||
vector<unsigned char> vData;
|
||||
vRecv >> vData;
|
||||
|
||||
// Nodes must NEVER send a data item > 520 bytes (the max size for a script data object,
|
||||
// and thus, the maximum size any matched object can have) in a filteradd message
|
||||
if (vData.size() > 520)
|
||||
{
|
||||
pfrom->Misbehaving(100);
|
||||
} else {
|
||||
LOCK(pfrom->cs_filter);
|
||||
if (pfrom->pfilter)
|
||||
pfrom->pfilter->insert(vData);
|
||||
else
|
||||
pfrom->Misbehaving(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if (strCommand == "filterclear")
|
||||
{
|
||||
LOCK(pfrom->cs_filter);
|
||||
delete pfrom->pfilter;
|
||||
pfrom->pfilter = NULL;
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
// Ignore unknown commands for extensibility
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "protocol.h"
|
||||
#include "addrman.h"
|
||||
#include "hash.h"
|
||||
#include "bloom.h"
|
||||
|
||||
class CNode;
|
||||
class CBlockIndex;
|
||||
@ -152,6 +153,8 @@ public:
|
||||
bool fSuccessfullyConnected;
|
||||
bool fDisconnect;
|
||||
CSemaphoreGrant grantOutbound;
|
||||
CCriticalSection cs_filter;
|
||||
CBloomFilter* pfilter;
|
||||
protected:
|
||||
int nRefCount;
|
||||
|
||||
@ -209,6 +212,7 @@ public:
|
||||
fGetAddr = false;
|
||||
nMisbehavior = 0;
|
||||
setInventoryKnown.max_size(SendBufferSize() / 1000);
|
||||
pfilter = NULL;
|
||||
|
||||
// Be shy and don't send version until we hear
|
||||
if (!fInbound)
|
||||
@ -222,6 +226,8 @@ public:
|
||||
closesocket(hSocket);
|
||||
hSocket = INVALID_SOCKET;
|
||||
}
|
||||
if (pfilter)
|
||||
delete pfilter;
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user