diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index c7d7659b7794f..6b29adc71447f 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -74,7 +74,7 @@ void CActiveMasternode::ManageStatus() LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString()); - CNode* pnode = ConnectNode((CAddress)service, NULL, false); + CNode* pnode = ConnectNode((CAddress)service, NULL, false, true); if (!pnode) { notCapableReason = "Could not connect to " + service.ToString(); LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason); diff --git a/src/addrman.cpp b/src/addrman.cpp index 0bd9e9fef533a..596b6bca0c1eb 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -313,7 +313,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); @@ -329,7 +329,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) diff --git a/src/addrman.h b/src/addrman.h index 92546a4fc7747..ce9786ae18e15 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -238,7 +238,7 @@ class CAddrMan 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); @@ -532,12 +532,12 @@ class CAddrMan } //! 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(); } } diff --git a/src/net.cpp b/src/net.cpp index ba2265db9baec..71cb3a74b925a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -385,7 +385,7 @@ CNode* FindNode(const CService& addr) return NULL; } -CNode* ConnectNode(CAddress addrConnect, const char* pszDest, bool obfuScationMaster) +CNode* ConnectNode(CAddress addrConnect, const char* pszDest, bool obfuScationMaster, bool fCountFailure) { if (pszDest == NULL) { // we clean masternode connections in CMasternodeMan::ProcessMasternodeConnections() @@ -419,7 +419,7 @@ CNode* ConnectNode(CAddress addrConnect, const char* pszDest, bool obfuScationMa return NULL; } - addrman.Attempt(addrConnect); + addrman.Attempt(addrConnect, fCountFailure); // Add node CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false); @@ -437,7 +437,7 @@ CNode* ConnectNode(CAddress addrConnect, const char* pszDest, bool obfuScationMa } 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; @@ -1338,7 +1338,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); } } @@ -1351,7 +1351,7 @@ void ThreadOpenConnections() ProcessOneShot(); for (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); } @@ -1432,7 +1432,7 @@ void ThreadOpenConnections() } if (addrConnect.IsValid()) - OpenNetworkConnection(addrConnect, &grant); + OpenNetworkConnection(addrConnect, (int)setConnected.size() >= min(nMaxConnections - 1, 2), &grant); } } @@ -1454,7 +1454,7 @@ void ThreadOpenAddedConnections() for (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 @@ -1496,7 +1496,7 @@ void ThreadOpenAddedConnections() } for (std::vector& 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 @@ -1504,7 +1504,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 @@ -1518,7 +1518,7 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant* grantOu } else if (FindNode(pszDest)) return false; - CNode* pnode = ConnectNode(addrConnect, pszDest); + CNode* pnode = ConnectNode(addrConnect, pszDest, false, fCountFailure); boost::this_thread::interruption_point(); if (!pnode) diff --git a/src/net.h b/src/net.h index c17d2027d3f77..b1525bdd7d62f 100644 --- a/src/net.h +++ b/src/net.h @@ -79,8 +79,8 @@ CNode* FindNode(const CNetAddr& ip); CNode* FindNode(const CSubNet& subNet); CNode* FindNode(const std::string& addrName); CNode* FindNode(const CService& ip); -CNode* ConnectNode(CAddress addrConnect, const char* pszDest = NULL, bool obfuScationMaster = false); -bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant* grantOutbound = NULL, const char* strDest = NULL, bool fOneShot = false); +CNode* ConnectNode(CAddress addrConnect, const char* pszDest = NULL, bool obfuScationMaster = false, bool fCountFailure = 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); diff --git a/src/obfuscation-relay.cpp b/src/obfuscation-relay.cpp index e7b2568f2e38f..b075415387609 100644 --- a/src/obfuscation-relay.cpp +++ b/src/obfuscation-relay.cpp @@ -77,7 +77,7 @@ void CObfuScationRelay::RelayThroughNode(int nRank) if (pmn != NULL) { //printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str()); - CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, false); + CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, false, true); if (pnode) { //printf("Connected\n"); pnode->PushMessage("dsr", (*this)); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index c1beb2f50c414..08dbe586d5274 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -144,7 +144,7 @@ UniValue masternodeconnect(const UniValue& params, bool fHelp) CService addr = CService(strAddress); - CNode* pnode = ConnectNode((CAddress)addr, NULL, false); + CNode* pnode = ConnectNode((CAddress)addr, NULL, false, true); if (pnode) { pnode->Release(); return NullUniValue; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 59cb0232be5aa..be83472b549e2 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -187,7 +187,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; }