diff --git a/src/bloom.h b/src/bloom.h --- a/src/bloom.h +++ b/src/bloom.h @@ -133,9 +133,6 @@ */ class CRollingBloomFilter { public: - // A random bloom filter calls GetRand() at creation time. Don't create - // global CRollingBloomFilter objects, as they may be constructed before the - // randomizer is properly initialized. CRollingBloomFilter(const uint32_t nElements, const double nFPRate); void insert(const std::vector &vKey); diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -840,7 +840,7 @@ // flood relay std::vector vAddrToSend; - CRollingBloomFilter addrKnown; + std::unique_ptr m_addr_known; bool fGetAddr{false}; int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0}; int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0}; @@ -986,14 +986,14 @@ void Release() { nRefCount--; } void AddAddressKnown(const CAddress &_addr) { - addrKnown.insert(_addr.GetKey()); + m_addr_known->insert(_addr.GetKey()); } void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand) { // 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())) { + if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey())) { if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) { vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr; diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -2898,7 +2898,7 @@ bool fInboundIn, bool block_relay_only) : nTimeConnected(GetSystemTimeInSeconds()), addr(addrIn), addrBind(addrBindIn), fInbound(fInboundIn), - nKeyedNetGroup(nKeyedNetGroupIn), addrKnown(5000, 0.001), + nKeyedNetGroup(nKeyedNetGroupIn), // Don't relay addr messages to peers that we connect to as // block-relay-only peers (to prevent adversaries from inferring these // links from addr traffic). @@ -2912,6 +2912,10 @@ m_tx_relay = std::make_unique(); } + if (m_addr_relay_peer) { + m_addr_known = std::make_unique(5000, 0.001); + } + for (const std::string &msg : getAllNetMessageTypes()) { mapRecvBytesPerMsgCmd[msg] = 0; } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1596,7 +1596,7 @@ // Relay to a limited number of other nodes. // Use deterministic randomness to send to the same nodes for 24 hours at a - // time so the addrKnowns of the chosen nodes prevent repeats. + // time so the m_addr_knowns of the chosen nodes prevent repeats uint64_t hashAddr = addr.GetHash(); const CSipHasher hasher = connman->GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY) @@ -4357,8 +4357,8 @@ std::vector vAddr; vAddr.reserve(pto->vAddrToSend.size()); for (const CAddress &addr : pto->vAddrToSend) { - if (!pto->addrKnown.contains(addr.GetKey())) { - pto->addrKnown.insert(addr.GetKey()); + if (!pto->m_addr_known->contains(addr.GetKey())) { + pto->m_addr_known->insert(addr.GetKey()); vAddr.push_back(addr); // receiver rejects addr messages larger than 1000 if (vAddr.size() >= 1000) {