Browse Source

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.
0.13
Gregory Maxwell 9 years ago
parent
commit
66b07247a7
  1. 8
      src/main.cpp
  2. 1
      src/net.cpp
  3. 1
      src/net.h

8
src/main.cpp

@ -5214,6 +5214,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true; 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(); pfrom->vAddrToSend.clear();
vector<CAddress> vAddr = addrman.GetAddr(); vector<CAddress> vAddr = addrman.GetAddr();
BOOST_FOREACH(const CAddress &addr, vAddr) BOOST_FOREACH(const CAddress &addr, vAddr)

1
src/net.cpp

@ -2384,6 +2384,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
nNextAddrSend = 0; nNextAddrSend = 0;
nNextInvSend = 0; nNextInvSend = 0;
fRelayTxes = false; fRelayTxes = false;
fSentAddr = false;
pfilter = new CBloomFilter(); pfilter = new CBloomFilter();
nPingNonceSent = 0; nPingNonceSent = 0;
nPingUsecStart = 0; nPingUsecStart = 0;

1
src/net.h

@ -358,6 +358,7 @@ public:
// b) the peer may tell us in its version message that we should not relay tx invs // b) the peer may tell us in its version message that we should not relay tx invs
// unless it loads a bloom filter. // unless it loads a bloom filter.
bool fRelayTxes; bool fRelayTxes;
bool fSentAddr;
CSemaphoreGrant grantOutbound; CSemaphoreGrant grantOutbound;
CCriticalSection cs_filter; CCriticalSection cs_filter;
CBloomFilter* pfilter; CBloomFilter* pfilter;

Loading…
Cancel
Save