diff --git a/src/net.cpp b/src/net.cpp index adb8dc3ebd..b9d7686a84 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2497,20 +2497,6 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai if (!fNetworkActive) { return; } - if (!pszDest) { - // banned or exact match? - if ((m_banman && m_banman->IsBanned(addrConnect)) || FindNode(addrConnect.ToStringIPPort())) - return; - // local and not a connection to itself? - bool fAllowLocal = Params().AllowMultiplePorts() && addrConnect.GetPort() != GetListenPort(); - if (!fAllowLocal && IsLocal(addrConnect)) - return; - // if multiple ports for same IP are allowed, search for IP:PORT match, otherwise search for IP-only match - if ((!Params().AllowMultiplePorts() && FindNode(static_cast(addrConnect))) || - (Params().AllowMultiplePorts() && FindNode(static_cast(addrConnect)))) - return; - } else if (FindNode(std::string(pszDest))) - return; auto getIpStr = [&]() { if (fLogIPs) { @@ -2520,6 +2506,29 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai } }; + if (!pszDest) { + // banned or exact match? + if ((m_banman && m_banman->IsBanned(addrConnect)) || FindNode(addrConnect.ToStringIPPort())) + return; + // local and not a connection to itself? + bool fAllowLocal = Params().AllowMultiplePorts() && addrConnect.GetPort() != GetListenPort(); + if (!fAllowLocal && IsLocal(addrConnect)) + return; + // Search for IP:PORT match: + // - if multiple ports for the same IP are allowed, + // - for probe connections + // Search for IP-only match otherwise + bool searchIPPort = Params().AllowMultiplePorts() || masternode_probe_connection; + bool skip = searchIPPort ? + FindNode(static_cast(addrConnect)) : + FindNode(static_cast(addrConnect)); + if (skip) { + LogPrintf("CConnman::%s -- Failed to open new connection to %s, already connected\n", __func__, getIpStr()); + return; + } + } else if (FindNode(std::string(pszDest))) + return; + LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- connecting to %s\n", __func__, getIpStr()); CNode* pnode = ConnectNode(addrConnect, pszDest, fCountFailure, manual_connection);