net: add CServiceHash constructor so the caller can provide the salts

This new constructor will be useful if we just want to hash a `CService`
object without the two `GetRand()` calls (in `RelayAddress()` in a
subsequent commit).
This commit is contained in:
Vasil Dimov committed 2022-02-11 15:21:50 +01:00
1 parent 97208634b9
commit 2e38a0e686
2 files changed
+12 -2

No files matched your search

+10 -2
View File
@@ -562,6 +562,14 @@ public:
class CServiceHash
{
public:
CServiceHash()
: m_salt_k0{GetRand(std::numeric_limits<uint64_t>::max())},
m_salt_k1{GetRand(std::numeric_limits<uint64_t>::max())}
{
}
CServiceHash(uint64_t salt_k0, uint64_t salt_k1) : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
size_t operator()(const CService& a) const noexcept
{
CSipHasher hasher(m_salt_k0, m_salt_k1);
@@ -572,8 +580,8 @@ public:
}
private:
const uint64_t m_salt_k0 = GetRand(std::numeric_limits<uint64_t>::max());
const uint64_t m_salt_k1 = GetRand(std::numeric_limits<uint64_t>::max());
const uint64_t m_salt_k0;
const uint64_t m_salt_k1;
};
#endif // BITCOIN_NETADDRESS_H
+2
View File
@@ -84,6 +84,8 @@ FUZZ_TARGET(netaddress)
(void)service.ToString();
(void)service.ToStringIPPort();
(void)service.ToStringPort();
(void)CServiceHash()(service);
(void)CServiceHash(0, 0)(service);
const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider);
(void)net_addr.GetReachabilityFrom(&other_net_addr);