Skip to content

Commit 66b0724

Browse files
committed
Only send one GetAddr response per connection.
This conserves resources from abusive peers that just send getaddr in a loop. Also makes correlating addr messages against INVs less effective.
1 parent 065c6b4 commit 66b0724

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,6 +5214,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
52145214
return true;
52155215
}
52165216

5217+
// Only send one GetAddr response per connection to reduce resource waste
5218+
// and discourage addr stamping of INV announcements.
5219+
if (pfrom->fSentAddr) {
5220+
LogPrint("net", "Ignoring repeated \"getaddr\". peer=%d\n", pfrom->id);
5221+
return true;
5222+
}
5223+
pfrom->fSentAddr = true;
5224+
52175225
pfrom->vAddrToSend.clear();
52185226
vector<CAddress> vAddr = addrman.GetAddr();
52195227
BOOST_FOREACH(const CAddress &addr, vAddr)

src/net.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
23842384
nNextAddrSend = 0;
23852385
nNextInvSend = 0;
23862386
fRelayTxes = false;
2387+
fSentAddr = false;
23872388
pfilter = new CBloomFilter();
23882389
nPingNonceSent = 0;
23892390
nPingUsecStart = 0;

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ class CNode
358358
// b) the peer may tell us in its version message that we should not relay tx invs
359359
// unless it loads a bloom filter.
360360
bool fRelayTxes;
361+
bool fSentAddr;
361362
CSemaphoreGrant grantOutbound;
362363
CCriticalSection cs_filter;
363364
CBloomFilter* pfilter;

0 commit comments

Comments
 (0)