Ensure CNode::addrKnown immediately takes little memory when we disconnect the node
This commit is contained in:
28
src/net.h
28
src/net.h
@@ -432,6 +432,8 @@ public:
|
||||
CCriticalSection cs_filter;
|
||||
CBloomFilter* pfilter;
|
||||
int nRefCount;
|
||||
CRollingBloomFilter addrKnown;
|
||||
mutable CCriticalSection cs_addrKnown;
|
||||
NodeId id;
|
||||
|
||||
/**
|
||||
@@ -478,7 +480,6 @@ public:
|
||||
|
||||
// flood relay
|
||||
std::vector<CAddress> vAddrToSend;
|
||||
CRollingBloomFilter addrKnown;
|
||||
bool fGetAddr;
|
||||
std::set<uint256> setKnown;
|
||||
|
||||
@@ -561,11 +562,25 @@ public:
|
||||
nRefCount--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AddAddressKnown(const CAddress& _addr)
|
||||
bool AddAddressIfNotAlreadyKnown(const CAddress& addr)
|
||||
{
|
||||
addrKnown.insert(_addr.GetKey());
|
||||
LOCK(cs_addrKnown);
|
||||
// Avoid adding to addrKnown after it has been reset in CloseSocketDisconnect.
|
||||
if (fDisconnect) {
|
||||
return false;
|
||||
}
|
||||
if (!addrKnown.contains(addr.GetKey())) {
|
||||
addrKnown.insert(addr.GetKey());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsAddressKnown(const CAddress& addr) const
|
||||
{
|
||||
LOCK(cs_addrKnown);
|
||||
return addrKnown.contains(addr.GetKey());
|
||||
}
|
||||
|
||||
void PushAddress(const CAddress& _addr)
|
||||
@@ -578,7 +593,8 @@ public:
|
||||
// Known checking here is only to save space from duplicates.
|
||||
// SendMessages will filter it again for knowns that were added
|
||||
// after addresses were pushed.
|
||||
if (_addr.IsValid() && !addrKnown.contains(_addr.GetKey()) && addr_format_supported) {
|
||||
if (_addr.IsValid() && !IsAddressKnown(addr) && addr_format_supported) {
|
||||
|
||||
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
|
||||
vAddrToSend[insecure_rand() % vAddrToSend.size()] = _addr;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user