Skip to content

Commit 6870599

Browse files
committed
Merge pull request #5419
12a49ca Limit the number of new addressses to accumulate (Pieter Wuille)
2 parents 9ddc8c6 + 12a49ca commit 6870599

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
@@ -44,6 +44,8 @@ static const int PING_INTERVAL = 2 * 60;
4444
static const int TIMEOUT_INTERVAL = 20 * 60;
4545
/** The maximum number of entries in an 'inv' protocol message */
4646
static const unsigned int MAX_INV_SZ = 50000;
47+
/** The maximum number of new addresses to accumulate before announcing. */
48+
static const unsigned int MAX_ADDR_TO_SEND = 1000;
4749
/** -listen default */
4850
static const bool DEFAULT_LISTEN = true;
4951
/** -upnp default */
@@ -368,8 +370,13 @@ class CNode
368370
// Known checking here is only to save space from duplicates.
369371
// SendMessages will filter it again for knowns that were added
370372
// after addresses were pushed.
371-
if (addr.IsValid() && !setAddrKnown.count(addr))
372-
vAddrToSend.push_back(addr);
373+
if (addr.IsValid() && !setAddrKnown.count(addr)) {
374+
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
375+
vAddrToSend[insecure_rand() % vAddrToSend.size()] = addr;
376+
} else {
377+
vAddrToSend.push_back(addr);
378+
}
379+
}
373380
}
374381

375382

0 commit comments

Comments
 (0)