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.
This commit is contained in:
Gregory Maxwell
2015-04-19 13:39:38 -07:00
committed by lateminer
parent d3002718b5
commit 798fb2f972
3 changed files with 16 additions and 2 deletions

View File

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

View File

@@ -28,6 +28,9 @@ public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;
//! last counted attempt (memory only)
int64_t nLastCountAttempt;
private:
//! where knowledge about this address first came from
CNetAddr source;
@@ -65,6 +68,7 @@ public:
{
nLastSuccess = 0;
nLastTry = 0;
nLastCountAttempt = 0;
nAttempts = 0;
nRefCount = 0;
fInTried = false;
@@ -202,6 +206,9 @@ private:
//! list of "new" buckets
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
//! last time Good was called (memory only)
int64_t nLastGood;
protected:
//! Find an entry.
@@ -447,6 +454,7 @@ public:
nIdCount = 0;
nTried = 0;
nNew = 0;
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
}
CAddrMan()

View File

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