aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2015-04-25 16:25:44 -0400
committerPieter Wuille <pieter.wuille@gmail.com>2015-04-30 08:16:20 -0700
commitd81cff32e50fe5f686f985d0af2e74219f328ed0 (patch)
tree4ed441d73f9e62a1d17c69c721e4cae1bd88e1de /src/net.h
parent69a5f8be0abda1e462f8ef44acadd2cbfaa850fb (diff)
downloadbitcoin-d81cff32e50fe5f686f985d0af2e74219f328ed0.tar.xz
Replace mruset setAddrKnown with CRollingBloomFilter addrKnown
Use a probabilistic bloom filter to keep track of which addresses we think we have given our peers, instead of a list. This uses much less memory, at the cost of sometimes failing to relay an address to a peer-- worst case if the bloom filter happens to be as full as it gets, 1-in-1,000. Measured memory usage of a full mruset setAddrKnown: 650Kbytes Constant memory usage of CRollingBloomFilter addrKnown: 37Kbytes. This will also help heap fragmentation, because the 37K of storage is allocated when a CNode is created (when a connection to a peer is established) and then there is no per-item-remembered memory allocation. I plan on testing by restarting a full node with an empty peers.dat, running a while with -debug=addrman and -debug=net, and making sure that the 'addr' message traffic out is reasonable. (suggestions for better tests welcome)
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/net.h b/src/net.h
index 9fc6ce68d0..24e927c9f6 100644
--- a/src/net.h
+++ b/src/net.h
@@ -300,7 +300,7 @@ public:
// flood relay
std::vector<CAddress> vAddrToSend;
- mruset<CAddress> setAddrKnown;
+ CRollingBloomFilter addrKnown;
bool fGetAddr;
std::set<uint256> setKnown;
@@ -380,7 +380,7 @@ public:
void AddAddressKnown(const CAddress& addr)
{
- setAddrKnown.insert(addr);
+ addrKnown.insert(addr.GetKey());
}
void PushAddress(const CAddress& addr)
@@ -388,7 +388,7 @@ 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() && !setAddrKnown.count(addr)) {
+ if (addr.IsValid() && !addrKnown.contains(addr.GetKey())) {
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
vAddrToSend[insecure_rand() % vAddrToSend.size()] = addr;
} else {