mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Don't return nodes with fDisconnect=true in FindNode
FindNode is only interested in active connections, especially when called from OpenNetworkConnection. Connections which are about to get disconnected and removed should be treated as if they are not existent anymore, as otherwise there is a small race between disconnecting and reconnecting nodes, causing OpenNetworkConnection to return early.
This commit is contained in:
parent
d235364534
commit
33bfaffbea
20
src/net.cpp
20
src/net.cpp
@ -323,10 +323,13 @@ bool IsReachable(const CNetAddr& addr)
|
||||
}
|
||||
|
||||
|
||||
CNode* CConnman::FindNode(const CNetAddr& ip)
|
||||
CNode* CConnman::FindNode(const CNetAddr& ip, bool fExcludeDisconnecting)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes) {
|
||||
if (fExcludeDisconnecting && pnode->fDisconnect) {
|
||||
continue;
|
||||
}
|
||||
if ((CNetAddr)pnode->addr == ip) {
|
||||
return pnode;
|
||||
}
|
||||
@ -334,10 +337,13 @@ CNode* CConnman::FindNode(const CNetAddr& ip)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CNode* CConnman::FindNode(const CSubNet& subNet)
|
||||
CNode* CConnman::FindNode(const CSubNet& subNet, bool fExcludeDisconnecting)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes) {
|
||||
if (fExcludeDisconnecting && pnode->fDisconnect) {
|
||||
continue;
|
||||
}
|
||||
if (subNet.Match((CNetAddr)pnode->addr)) {
|
||||
return pnode;
|
||||
}
|
||||
@ -345,10 +351,13 @@ CNode* CConnman::FindNode(const CSubNet& subNet)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CNode* CConnman::FindNode(const std::string& addrName)
|
||||
CNode* CConnman::FindNode(const std::string& addrName, bool fExcludeDisconnecting)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes) {
|
||||
if (fExcludeDisconnecting && pnode->fDisconnect) {
|
||||
continue;
|
||||
}
|
||||
if (pnode->GetAddrName() == addrName) {
|
||||
return pnode;
|
||||
}
|
||||
@ -356,10 +365,13 @@ CNode* CConnman::FindNode(const std::string& addrName)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CNode* CConnman::FindNode(const CService& addr)
|
||||
CNode* CConnman::FindNode(const CService& addr, bool fExcludeDisconnecting)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes) {
|
||||
if (fExcludeDisconnecting && pnode->fDisconnect) {
|
||||
continue;
|
||||
}
|
||||
if ((CService)pnode->addr == addr) {
|
||||
return pnode;
|
||||
}
|
||||
|
@ -497,10 +497,10 @@ private:
|
||||
|
||||
uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
|
||||
|
||||
CNode* FindNode(const CNetAddr& ip);
|
||||
CNode* FindNode(const CSubNet& subNet);
|
||||
CNode* FindNode(const std::string& addrName);
|
||||
CNode* FindNode(const CService& addr);
|
||||
CNode* FindNode(const CNetAddr& ip, bool fExcludeDisconnecting = true);
|
||||
CNode* FindNode(const CSubNet& subNet, bool fExcludeDisconnecting = true);
|
||||
CNode* FindNode(const std::string& addrName, bool fExcludeDisconnecting = true);
|
||||
CNode* FindNode(const CService& addr, bool fExcludeDisconnecting = true);
|
||||
|
||||
bool AttemptToEvictConnection();
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest = nullptr, bool fCountFailure = false);
|
||||
|
Loading…
Reference in New Issue
Block a user