Merge #8065: Addrman offline attempts
6182d10 Do not increment nAttempts by more than one for every Good connection. (Gregory Maxwell) c769c4a Avoid counting failed connect attempts when probably offline. (Gregory Maxwell)
This commit is contained in:
parent
2ee817fb0d
commit
00c84ca53e
@ -182,7 +182,7 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman)
|
||||
|
||||
LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString());
|
||||
|
||||
if(!connman.ConnectNode(CAddress(service, NODE_NETWORK), NULL, true)) {
|
||||
if(!connman.ConnectNode(CAddress(service, NODE_NETWORK), NULL, false, true)) {
|
||||
nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
|
||||
strNotCapableReason = "Could not connect to " + service.ToString();
|
||||
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
|
||||
|
@ -197,6 +197,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
|
||||
@ -311,7 +314,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);
|
||||
|
||||
@ -327,7 +330,10 @@ void CAddrMan::Attempt_(const CService& addr, int64_t nTime)
|
||||
|
||||
// update info
|
||||
info.nLastTry = nTime;
|
||||
info.nAttempts++;
|
||||
if (fCountFailure && info.nLastCountAttempt < nLastGood) {
|
||||
info.nLastCountAttempt = nTime;
|
||||
info.nAttempts++;
|
||||
}
|
||||
}
|
||||
|
||||
CAddrInfo CAddrMan::Select_(bool newOnly)
|
||||
|
@ -29,6 +29,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;
|
||||
@ -66,6 +69,7 @@ public:
|
||||
{
|
||||
nLastSuccess = 0;
|
||||
nLastTry = 0;
|
||||
nLastCountAttempt = 0;
|
||||
nAttempts = 0;
|
||||
nRefCount = 0;
|
||||
fInTried = false;
|
||||
@ -200,6 +204,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:
|
||||
//! secret key to randomize bucket select with
|
||||
uint256 nKey;
|
||||
@ -230,7 +237,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);
|
||||
@ -461,6 +468,7 @@ public:
|
||||
nIdCount = 0;
|
||||
nTried = 0;
|
||||
nNew = 0;
|
||||
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
|
||||
}
|
||||
|
||||
CAddrMan()
|
||||
@ -535,12 +543,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();
|
||||
}
|
||||
}
|
||||
|
@ -1044,7 +1044,7 @@ bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector<C
|
||||
return false;
|
||||
}
|
||||
|
||||
CNode* pnode = connman.ConnectNode(addr, NULL, true);
|
||||
CNode* pnode = connman.ConnectNode(addr, NULL, false, true);
|
||||
if(pnode == NULL) {
|
||||
LogPrintf("CMasternodeMan::SendVerifyRequest -- can't connect to node to verify it, addr=%s\n", addr.ToString());
|
||||
return false;
|
||||
|
20
src/net.cpp
20
src/net.cpp
@ -343,7 +343,7 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)
|
||||
return true;
|
||||
}
|
||||
|
||||
CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMasternode)
|
||||
CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool fConnectToMasternode)
|
||||
{
|
||||
// TODO: This is different from what we have in Bitcoin which only calls ConnectNode from OpenNetworkConnection
|
||||
// If we ever switch to using OpenNetworkConnection for MNs as well, this can be removed
|
||||
@ -412,7 +412,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
}
|
||||
}
|
||||
|
||||
addrman.Attempt(addrConnect);
|
||||
addrman.Attempt(addrConnect, fCountFailure);
|
||||
|
||||
// Add node
|
||||
CNode* pnode = new CNode(GetNewNodeId(), nLocalServices, GetBestHeight(), hSocket, addrConnect, pszDest ? pszDest : "", false, true);
|
||||
@ -432,7 +432,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
} 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;
|
||||
@ -1612,7 +1612,7 @@ void CConnman::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);
|
||||
}
|
||||
}
|
||||
@ -1628,7 +1628,7 @@ void CConnman::ThreadOpenConnections()
|
||||
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs["-connect"])
|
||||
{
|
||||
CAddress addr(CService(), NODE_NONE);
|
||||
OpenNetworkConnection(addr, NULL, strAddr.c_str());
|
||||
OpenNetworkConnection(addr, false, NULL, strAddr.c_str());
|
||||
for (int i = 0; i < 10 && i < nLoop; i++)
|
||||
{
|
||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
||||
@ -1757,7 +1757,7 @@ void CConnman::ThreadOpenConnections()
|
||||
LogPrint("net", "Making feeler connection to %s\n", addrConnect.ToString());
|
||||
}
|
||||
|
||||
OpenNetworkConnection(addrConnect, &grant, NULL, false, fFeeler);
|
||||
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, NULL, false, fFeeler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1830,7 +1830,7 @@ void CConnman::ThreadOpenAddedConnections()
|
||||
// If strAddedNode is an IP/port, decode it immediately, so
|
||||
// OpenNetworkConnection can detect existing connections to that IP/port.
|
||||
CService service(LookupNumeric(info.strAddedNode.c_str(), Params().GetDefaultPort()));
|
||||
OpenNetworkConnection(CAddress(service, NODE_NONE), &grant, info.strAddedNode.c_str(), false);
|
||||
OpenNetworkConnection(CAddress(service, NODE_NONE), false, &grant, info.strAddedNode.c_str(), false);
|
||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
||||
return;
|
||||
}
|
||||
@ -1858,7 +1858,7 @@ void CConnman::ThreadMnbRequestConnections()
|
||||
std::pair<CService, std::set<uint256> > p = mnodeman.PopScheduledMnbRequestConnection();
|
||||
if(p.first == CService() || p.second.empty()) continue;
|
||||
|
||||
ConnectNode(CAddress(p.first, NODE_NETWORK), NULL, true);
|
||||
ConnectNode(CAddress(p.first, NODE_NETWORK), NULL, false, true);
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
|
||||
@ -1884,7 +1884,7 @@ void CConnman::ThreadMnbRequestConnections()
|
||||
}
|
||||
|
||||
// if successful, this moves the passed grant to the constructed node
|
||||
bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot, bool fFeeler)
|
||||
bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot, bool fFeeler)
|
||||
{
|
||||
//
|
||||
// Initiate outbound network connection
|
||||
@ -1903,7 +1903,7 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGran
|
||||
} else if (FindNode(std::string(pszDest)))
|
||||
return false;
|
||||
|
||||
CNode* pnode = ConnectNode(addrConnect, pszDest);
|
||||
CNode* pnode = ConnectNode(addrConnect, pszDest, fCountFailure);
|
||||
|
||||
if (!pnode)
|
||||
return false;
|
||||
|
@ -137,14 +137,14 @@ public:
|
||||
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
|
||||
bool GetNetworkActive() const { return fNetworkActive; };
|
||||
void SetNetworkActive(bool active);
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
|
||||
bool CheckIncomingNonce(uint64_t nonce);
|
||||
|
||||
// fConnectToMasternode should be 'true' only if you want this node to allow to connect to itself
|
||||
// and/or you want it to be disconnected on CMasternodeMan::ProcessMasternodeConnections()
|
||||
// Unfortunately, can't make this method private like in Bitcoin,
|
||||
// because it's used in many Dash-specific places (masternode, privatesend).
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL, bool fConnectToMasternode = false);
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL, bool fCountFailure = false, bool fConnectToMasternode = false);
|
||||
|
||||
struct CFullyConnectedOnly {
|
||||
bool operator() (const CNode* pnode) const {
|
||||
|
@ -889,7 +889,7 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon
|
||||
|
||||
LogPrintf("CPrivateSendClient::JoinExistingQueue -- attempt to connect to masternode from queue, addr=%s\n", infoMn.addr.ToString());
|
||||
// connect to Masternode and submit the queue request
|
||||
CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, true);
|
||||
CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, false, true);
|
||||
if(pnode) {
|
||||
infoMixingMasternode = infoMn;
|
||||
nSessionDenom = dsq.nDenom;
|
||||
@ -964,7 +964,7 @@ bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsA
|
||||
}
|
||||
|
||||
LogPrintf("CPrivateSendClient::StartNewQueue -- attempt %d connection to Masternode %s\n", nTries, infoMn.addr.ToString());
|
||||
CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, true);
|
||||
CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, false, true);
|
||||
if(pnode) {
|
||||
LogPrintf("CPrivateSendClient::StartNewQueue -- connected, addr=%s\n", infoMn.addr.ToString());
|
||||
infoMixingMasternode = infoMn;
|
||||
|
@ -213,7 +213,7 @@ UniValue addnode(const UniValue& params, bool fHelp)
|
||||
if (strCommand == "onetry")
|
||||
{
|
||||
CAddress addr;
|
||||
g_connman->OpenNetworkConnection(addr, NULL, strNode.c_str());
|
||||
g_connman->OpenNetworkConnection(addr, false, NULL, strNode.c_str());
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user