aboutsummaryrefslogtreecommitdiff
path: root/src/netaddress.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-11-29 12:00:40 +0100
committerVasil Dimov <vd@FreeBSD.org>2022-02-11 15:21:50 +0100
commit2e38a0e6865187d1f0d0f016d3df7cce414a7c4f (patch)
tree01d9f8ff7c8f61f1f80ef38e1be9c078e1722af3 /src/netaddress.h
parent97208634b96f2d9a55f2ead7b0ef407da729d7bd (diff)
downloadbitcoin-2e38a0e6865187d1f0d0f016d3df7cce414a7c4f.tar.xz
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).
Diffstat (limited to 'src/netaddress.h')
-rw-r--r--src/netaddress.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/netaddress.h b/src/netaddress.h
index b06b6c65b6..debe03988c 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -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