Skip to content

Commit 94e85a8

Browse files
committed
net: remove unnecessary check from AlreadyConnectedToAddress()
`CConnman::AlreadyConnectedToAddress()` searches the existent nodes by address or by address-and-port: ```cpp FindNode(static_cast<CNetAddr>(addr)) || FindNode(addr.ToStringAddrPort()) ``` but: * if there is a match by just the address, then the address-and-port search will not be evaluated and the whole condition will be `true` * if the there is no node with the same address, then the second search by address-and-port will not find a match either. The search by address-and-port is comparing against `CNode::m_addr_name` which could be a hostname, e.g. `"node.foobar.com:8333"`, but `addr.ToStringAddrPort()` is always going to be numeric.
1 parent 458720e commit 94e85a8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ CNode* CConnman::FindNode(const CService& addr)
367367

368368
bool CConnman::AlreadyConnectedToAddress(const CAddress& addr)
369369
{
370-
return FindNode(static_cast<CNetAddr>(addr)) || FindNode(addr.ToStringAddrPort());
370+
return FindNode(static_cast<CNetAddr>(addr));
371371
}
372372

373373
bool CConnman::CheckIncomingNonce(uint64_t nonce)

src/test/fuzz/netaddress.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ FUZZ_TARGET(netaddress)
101101
(void)net_addr.GetReachabilityFrom(other_net_addr);
102102
(void)sub_net.Match(other_net_addr);
103103

104-
const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
104+
const CService other_service{fuzzed_data_provider.ConsumeBool() ? net_addr : other_net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
105105
assert((service == other_service) != (service != other_service));
106106
(void)(service < other_service);
107107

108+
if (service.ToStringAddrPort() == other_service.ToStringAddrPort()) {
109+
assert(static_cast<CNetAddr>(service) == static_cast<CNetAddr>(other_service));
110+
}
111+
108112
const CSubNet sub_net_copy_1{net_addr, other_net_addr};
109113
const CSubNet sub_net_copy_2{net_addr};
110114

0 commit comments

Comments
 (0)