mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
net: merge AlreadyConnectedToAddress() and FindNode(CNetAddr)
`CConnman::AlreadyConnectedToAddress()` is the only caller of `CConnman::FindNode(CNetAddr)`, so merge the two in one function. The unit test that checked whether `AlreadyConnectedToAddress()` ignores the port is now unnecessary because now the function takes a `CNetAddr` argument. It has no access to the port.
This commit is contained in:
16
src/net.cpp
16
src/net.cpp
@@ -331,17 +331,6 @@ bool IsLocal(const CService& addr)
|
||||
return mapLocalHost.count(addr) > 0;
|
||||
}
|
||||
|
||||
CNode* CConnman::FindNode(const CNetAddr& ip)
|
||||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
for (CNode* pnode : m_nodes) {
|
||||
if (static_cast<CNetAddr>(pnode->addr) == ip) {
|
||||
return pnode;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CNode* CConnman::FindNode(const std::string& addrName)
|
||||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
@@ -364,9 +353,10 @@ CNode* CConnman::FindNode(const CService& addr)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CConnman::AlreadyConnectedToAddress(const CAddress& addr)
|
||||
bool CConnman::AlreadyConnectedToAddress(const CNetAddr& addr) const
|
||||
{
|
||||
return FindNode(static_cast<CNetAddr>(addr));
|
||||
LOCK(m_nodes_mutex);
|
||||
return std::ranges::any_of(m_nodes, [&addr](CNode* node) { return node->addr == addr; });
|
||||
}
|
||||
|
||||
bool CConnman::CheckIncomingNonce(uint64_t nonce)
|
||||
|
||||
Reference in New Issue
Block a user