Avoid counting failed connect attempts when probably offline.
This commit is contained in:
committed by
lateminer
parent
0dd7c98e63
commit
d3002718b5
@@ -310,7 +310,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
|
||||
return fNew;
|
||||
}
|
||||
|
||||
void CAddrMan::Attempt_(const CService& addr, int64_t nTime)
|
||||
void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
|
||||
{
|
||||
CAddrInfo* pinfo = Find(addr);
|
||||
|
||||
@@ -326,7 +326,7 @@ void CAddrMan::Attempt_(const CService& addr, int64_t nTime)
|
||||
|
||||
// update info
|
||||
info.nLastTry = nTime;
|
||||
info.nAttempts++;
|
||||
if (fCountFailure) info.nAttempts++;
|
||||
}
|
||||
|
||||
CAddrInfo CAddrMan::Select_(bool newOnly)
|
||||
|
||||
@@ -230,7 +230,7 @@ protected:
|
||||
bool Add_(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty);
|
||||
|
||||
//! Mark an entry as attempted to connect.
|
||||
void Attempt_(const CService &addr, int64_t nTime);
|
||||
void Attempt_(const CService &addr, bool fCountFailure, int64_t nTime);
|
||||
|
||||
//! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
|
||||
CAddrInfo Select_(bool newOnly);
|
||||
@@ -521,12 +521,12 @@ public:
|
||||
}
|
||||
|
||||
//! Mark an entry as connection attempted to.
|
||||
void Attempt(const CService &addr, int64_t nTime = GetAdjustedTime())
|
||||
void Attempt(const CService &addr, bool fCountFailure, int64_t nTime = GetAdjustedTime())
|
||||
{
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
Attempt_(addr, nTime);
|
||||
Attempt_(addr, fCountFailure, nTime);
|
||||
Check();
|
||||
}
|
||||
}
|
||||
|
||||
20
src/net.cpp
20
src/net.cpp
@@ -373,7 +373,7 @@ CNode* FindNode(const NodeId nodeid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure)
|
||||
{
|
||||
if (pszDest == NULL) {
|
||||
if (IsLocal(addrConnect))
|
||||
@@ -405,7 +405,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
addrman.Attempt(addrConnect);
|
||||
addrman.Attempt(addrConnect, fCountFailure);
|
||||
|
||||
// Add node
|
||||
CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false);
|
||||
@@ -422,7 +422,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
|
||||
} else if (!proxyConnectionFailed) {
|
||||
// If connecting to the node failed, and failure is not caused by a problem connecting to
|
||||
// the proxy, mark this as an attempt.
|
||||
addrman.Attempt(addrConnect);
|
||||
addrman.Attempt(addrConnect, fCountFailure);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -1532,7 +1532,7 @@ void static ProcessOneShot()
|
||||
CAddress addr;
|
||||
CSemaphoreGrant grant(*semOutbound, true);
|
||||
if (grant) {
|
||||
if (!OpenNetworkConnection(addr, &grant, strDest.c_str(), true))
|
||||
if (!OpenNetworkConnection(addr, false, &grant, strDest.c_str(), true))
|
||||
AddOneShot(strDest);
|
||||
}
|
||||
}
|
||||
@@ -1548,7 +1548,7 @@ void ThreadOpenConnections()
|
||||
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs["-connect"])
|
||||
{
|
||||
CAddress addr;
|
||||
OpenNetworkConnection(addr, NULL, strAddr.c_str());
|
||||
OpenNetworkConnection(addr, false, NULL, strAddr.c_str());
|
||||
for (int i = 0; i < 10 && i < nLoop; i++)
|
||||
{
|
||||
MilliSleep(500);
|
||||
@@ -1632,7 +1632,7 @@ void ThreadOpenConnections()
|
||||
}
|
||||
|
||||
if (addrConnect.IsValid())
|
||||
OpenNetworkConnection(addrConnect, &grant);
|
||||
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= min(nMaxConnections - 1, 2), &grant);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1654,7 +1654,7 @@ void ThreadOpenAddedConnections()
|
||||
BOOST_FOREACH(const std::string& strAddNode, lAddresses) {
|
||||
CAddress addr;
|
||||
CSemaphoreGrant grant(*semOutbound);
|
||||
OpenNetworkConnection(addr, &grant, strAddNode.c_str());
|
||||
OpenNetworkConnection(addr, false, &grant, strAddNode.c_str());
|
||||
MilliSleep(500);
|
||||
}
|
||||
MilliSleep(120000); // Retry every 2 minutes
|
||||
@@ -1693,7 +1693,7 @@ void ThreadOpenAddedConnections()
|
||||
BOOST_FOREACH(std::vector<CService>& vserv, lservAddressesToAdd)
|
||||
{
|
||||
CSemaphoreGrant grant(*semOutbound);
|
||||
OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant);
|
||||
OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), false, &grant);
|
||||
MilliSleep(500);
|
||||
}
|
||||
MilliSleep(120000); // Retry every 2 minutes
|
||||
@@ -1701,7 +1701,7 @@ void ThreadOpenAddedConnections()
|
||||
}
|
||||
|
||||
// if successful, this moves the passed grant to the constructed node
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot)
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot)
|
||||
{
|
||||
//
|
||||
// Initiate outbound network connection
|
||||
@@ -1715,7 +1715,7 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu
|
||||
} else if (FindNode(std::string(pszDest)))
|
||||
return false;
|
||||
|
||||
CNode* pnode = ConnectNode(addrConnect, pszDest);
|
||||
CNode* pnode = ConnectNode(addrConnect, pszDest, fCountFailure);
|
||||
boost::this_thread::interruption_point();
|
||||
|
||||
if (!pnode)
|
||||
|
||||
@@ -88,7 +88,7 @@ CNode* FindNode(const std::string& addrName);
|
||||
CNode* FindNode(const CService& ip);
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL);
|
||||
CNode* FindNode(const NodeId id); //TODO: Remove this
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
|
||||
void MapPort(bool fUseUPnP);
|
||||
unsigned short GetListenPort();
|
||||
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
|
||||
|
||||
@@ -197,7 +197,7 @@ UniValue addnode(const UniValue& params, bool fHelp)
|
||||
if (strCommand == "onetry")
|
||||
{
|
||||
CAddress addr;
|
||||
OpenNetworkConnection(addr, NULL, strNode.c_str());
|
||||
OpenNetworkConnection(addr, false, NULL, strNode.c_str());
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user