Browse Source

Prevent duplicate connections where one is by name and another by ip

0.13
Pieter Wuille 9 years ago
parent
commit
f9f5cfc506
  1. 20
      src/net.cpp

20
src/net.cpp

@ -400,6 +400,26 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure
return NULL; return NULL;
} }
if (pszDest && addrConnect.IsValid()) {
// It is possible that we already have a connection to the IP/port pszDest resolved to.
// In that case, drop the connection that was just created, and return the existing CNode instead.
// Also store the name we used to connect in that CNode, so that future FindNode() calls to that
// name catch this early.
CNode* pnode = FindNode((CService)addrConnect);
if (pnode)
{
pnode->AddRef();
{
LOCK(cs_vNodes);
if (pnode->addrName.empty()) {
pnode->addrName = std::string(pszDest);
}
}
CloseSocket(hSocket);
return pnode;
}
}
addrman.Attempt(addrConnect, fCountFailure); addrman.Attempt(addrConnect, fCountFailure);
// Add node // Add node

Loading…
Cancel
Save