mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
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.
This commit is contained in:
parent
458720e5e9
commit
94e85a82a7
2 changed files with 6 additions and 2 deletions
|
@ -367,7 +367,7 @@ CNode* CConnman::FindNode(const CService& addr)
|
|||
|
||||
bool CConnman::AlreadyConnectedToAddress(const CAddress& addr)
|
||||
{
|
||||
return FindNode(static_cast<CNetAddr>(addr)) || FindNode(addr.ToStringAddrPort());
|
||||
return FindNode(static_cast<CNetAddr>(addr));
|
||||
}
|
||||
|
||||
bool CConnman::CheckIncomingNonce(uint64_t nonce)
|
||||
|
|
|
@ -101,10 +101,14 @@ FUZZ_TARGET(netaddress)
|
|||
(void)net_addr.GetReachabilityFrom(other_net_addr);
|
||||
(void)sub_net.Match(other_net_addr);
|
||||
|
||||
const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
||||
const CService other_service{fuzzed_data_provider.ConsumeBool() ? net_addr : other_net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
||||
assert((service == other_service) != (service != other_service));
|
||||
(void)(service < other_service);
|
||||
|
||||
if (service.ToStringAddrPort() == other_service.ToStringAddrPort()) {
|
||||
assert(static_cast<CNetAddr>(service) == static_cast<CNetAddr>(other_service));
|
||||
}
|
||||
|
||||
const CSubNet sub_net_copy_1{net_addr, other_net_addr};
|
||||
const CSubNet sub_net_copy_2{net_addr};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue