diff options
author | Gregory Maxwell <greg@xiph.org> | 2016-04-11 01:09:34 +0000 |
---|---|---|
committer | Gregory Maxwell <greg@xiph.org> | 2016-04-11 01:09:34 +0000 |
commit | 66b07247a7a9e48e082502338176cc06edf61474 (patch) | |
tree | 3ebcc514aeed59dcb78829228b29bc3ded4757bc /src | |
parent | 065c6b443f3e9864b1b4231208b49e3cef99cef3 (diff) | |
download | bitcoin-66b07247a7a9e48e082502338176cc06edf61474.tar.xz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 8 | ||||
-rw-r--r-- | src/net.cpp | 1 | ||||
-rw-r--r-- | src/net.h | 1 |
3 files changed, 10 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index f5c7e11d6e..df494b226d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5214,6 +5214,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return true; } + // Only send one GetAddr response per connection to reduce resource waste + // and discourage addr stamping of INV announcements. + if (pfrom->fSentAddr) { + LogPrint("net", "Ignoring repeated \"getaddr\". peer=%d\n", pfrom->id); + return true; + } + pfrom->fSentAddr = true; + pfrom->vAddrToSend.clear(); vector<CAddress> vAddr = addrman.GetAddr(); BOOST_FOREACH(const CAddress &addr, vAddr) diff --git a/src/net.cpp b/src/net.cpp index e8cc753a48..77310fb162 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2384,6 +2384,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa nNextAddrSend = 0; nNextInvSend = 0; fRelayTxes = false; + fSentAddr = false; pfilter = new CBloomFilter(); nPingNonceSent = 0; nPingUsecStart = 0; @@ -358,6 +358,7 @@ public: // b) the peer may tell us in its version message that we should not relay tx invs // unless it loads a bloom filter. bool fRelayTxes; + bool fSentAddr; CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; CBloomFilter* pfilter; |