fix(dkg): let probes on mainnet ignore existing inbound connections (#4908)

This commit is contained in:
UdjinM6 2022-07-07 10:49:55 +03:00
parent 394bf42fef
commit 25071e647b
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9

View File

@ -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<CNetAddr>(addrConnect))) ||
(Params().AllowMultiplePorts() && FindNode(static_cast<CService>(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<CService>(addrConnect)) :
FindNode(static_cast<CNetAddr>(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);