Browse Source

Do not increment nAttempts by more than one for every Good connection.

This slows the increase of the nAttempts in addrman while partitioned,
 even if the node hasn't yet noticed the partitioning.
0.13
Gregory Maxwell 10 years ago
parent
commit
6182d10503
  1. 8
      src/addrman.cpp
  2. 8
      src/addrman.h
  3. 2
      src/net.cpp

8
src/addrman.cpp

@ -197,6 +197,9 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
void CAddrMan::Good_(const CService& addr, int64_t nTime) void CAddrMan::Good_(const CService& addr, int64_t nTime)
{ {
int nId; int nId;
nLastGood = nTime;
CAddrInfo* pinfo = Find(addr, &nId); CAddrInfo* pinfo = Find(addr, &nId);
// if not found, bail out // if not found, bail out
@ -327,7 +330,10 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
// update info // update info
info.nLastTry = nTime; info.nLastTry = nTime;
if (fCountFailure) info.nAttempts++; if (fCountFailure && info.nLastCountAttempt < nLastGood) {
info.nLastCountAttempt = nTime;
info.nAttempts++;
}
} }
CAddrInfo CAddrMan::Select_(bool newOnly) CAddrInfo CAddrMan::Select_(bool newOnly)

8
src/addrman.h

@ -29,6 +29,9 @@ public:
//! last try whatsoever by us (memory only) //! last try whatsoever by us (memory only)
int64_t nLastTry; int64_t nLastTry;
//! last counted attempt (memory only)
int64_t nLastCountAttempt;
private: private:
//! where knowledge about this address first came from //! where knowledge about this address first came from
CNetAddr source; CNetAddr source;
@ -66,6 +69,7 @@ public:
{ {
nLastSuccess = 0; nLastSuccess = 0;
nLastTry = 0; nLastTry = 0;
nLastCountAttempt = 0;
nAttempts = 0; nAttempts = 0;
nRefCount = 0; nRefCount = 0;
fInTried = false; fInTried = false;
@ -200,6 +204,9 @@ private:
//! list of "new" buckets //! list of "new" buckets
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE]; int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
//! last time Good was called (memory only)
int64_t nLastGood;
protected: protected:
//! secret key to randomize bucket select with //! secret key to randomize bucket select with
uint256 nKey; uint256 nKey;
@ -458,6 +465,7 @@ public:
nIdCount = 0; nIdCount = 0;
nTried = 0; nTried = 0;
nNew = 0; nNew = 0;
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
} }
CAddrMan() CAddrMan()

2
src/net.cpp

@ -1633,7 +1633,7 @@ void ThreadOpenConnections()
} }
if (addrConnect.IsValid()) if (addrConnect.IsValid())
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= min(nMaxConnections - 1, 2), &grant); OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant);
} }
} }

Loading…
Cancel
Save