diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2016-05-28 16:22:02 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-06-13 23:53:08 +0200 |
commit | f9f5cfc50637f2cd1540923caf337e2651ec1625 (patch) | |
tree | fbf53e04f9f8cc71d9538691e5b9c153b0826a69 /src/net.cpp | |
parent | 1111b80df84aa7bc72fbddcc7bafde43f0835d90 (diff) |
Prevent duplicate connections where one is by name and another by ip
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 4d27db7604..30a6bc896d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -400,6 +400,26 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure 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); // Add node |