Skip to content

Commit bb424e4

Browse files
sipalaanwj
authored andcommitted
Limit the number of new addressses to accumulate
Rebased-From: 12a49ca
1 parent cd5164a commit bb424e4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/net.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace boost {
4040
static const unsigned int MAX_INV_SZ = 50000;
4141
/** The maximum number of entries in mapAskFor */
4242
static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
43+
/** The maximum number of new addresses to accumulate before announcing. */
44+
static const unsigned int MAX_ADDR_TO_SEND = 1000;
4345

4446
inline unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
4547
inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
@@ -400,8 +402,13 @@ class CNode
400402
// Known checking here is only to save space from duplicates.
401403
// SendMessages will filter it again for knowns that were added
402404
// after addresses were pushed.
403-
if (addr.IsValid() && !setAddrKnown.count(addr))
404-
vAddrToSend.push_back(addr);
405+
if (addr.IsValid() && !setAddrKnown.count(addr)) {
406+
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
407+
vAddrToSend[insecure_rand() % vAddrToSend.size()] = addr;
408+
} else {
409+
vAddrToSend.push_back(addr);
410+
}
411+
}
405412
}
406413

407414

0 commit comments

Comments
 (0)