aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2020-10-16 11:10:17 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2020-10-27 11:15:21 -0400
commite8b215a086d91a8774210bb6ce8d1560aaaf0789 (patch)
tree9d4018c2fde49bf922ef39b7accdcec067ea0d74 /src/net.cpp
parent4fe338ab3ed73b3ffb20eedf95500c56ec2920e1 (diff)
Refactor test for existing peer connection into own function
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 9680e9947d..11e975c3a9 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -354,6 +354,11 @@ CNode* CConnman::FindNode(const CService& addr)
return nullptr;
}
+bool CConnman::AlreadyConnectedToAddress(const CAddress& addr)
+{
+ return FindNode(static_cast<CNetAddr>(addr)) || FindNode(addr.ToStringIPPort());
+}
+
bool CConnman::CheckIncomingNonce(uint64_t nonce)
{
LOCK(cs_vNodes);
@@ -2160,7 +2165,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
}
if (!pszDest) {
bool banned_or_discouraged = m_banman && (m_banman->IsDiscouraged(addrConnect) || m_banman->IsBanned(addrConnect));
- if (IsLocal(addrConnect) || FindNode(static_cast<CNetAddr>(addrConnect)) || banned_or_discouraged || FindNode(addrConnect.ToStringIPPort())) {
+ if (IsLocal(addrConnect) || banned_or_discouraged || AlreadyConnectedToAddress(addrConnect)) {
return;
}
} else if (FindNode(std::string(pszDest)))