Skip to content

Commit 4709fc2

Browse files
committed
[netgroupman] Move asmap checksum calculation to NetGroupManager
1 parent 1b978a7 commit 4709fc2

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/addrman.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,7 @@ void AddrManImpl::Serialize(Stream& s_) const
218218
}
219219
// Store asmap checksum after bucket entries so that it
220220
// can be ignored by older clients for backward compatibility.
221-
uint256 asmap_checksum;
222-
if (m_netgroupman.GetAsmap().size() != 0) {
223-
asmap_checksum = SerializeHash(m_netgroupman.GetAsmap());
224-
}
225-
s << asmap_checksum;
221+
s << m_netgroupman.GetAsmapChecksum();
226222
}
227223

228224
template <typename Stream>
@@ -335,10 +331,7 @@ void AddrManImpl::Unserialize(Stream& s_)
335331
// If the bucket count and asmap checksum haven't changed, then attempt
336332
// to restore the entries to the buckets/positions they were in before
337333
// serialization.
338-
uint256 supplied_asmap_checksum;
339-
if (m_netgroupman.GetAsmap().size() != 0) {
340-
supplied_asmap_checksum = SerializeHash(m_netgroupman.GetAsmap());
341-
}
334+
uint256 supplied_asmap_checksum{m_netgroupman.GetAsmapChecksum()};
342335
uint256 serialized_asmap_checksum;
343336
if (format >= Format::V2_ASMAP) {
344337
s >> serialized_asmap_checksum;

src/netgroup.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44

55
#include <netgroup.h>
66

7+
#include <hash.h>
78
#include <util/asmap.h>
89

10+
uint256 NetGroupManager::GetAsmapChecksum() const
11+
{
12+
if (!m_asmap.size()) return {};
13+
14+
return SerializeHash(m_asmap);
15+
}
16+
917
std::vector<unsigned char> NetGroupManager::GetGroup(const CNetAddr& address) const
1018
{
1119
std::vector<unsigned char> vchRet;

src/netgroup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_NETGROUP_H
77

88
#include <netaddress.h>
9+
#include <uint256.h>
910

1011
#include <vector>
1112

@@ -22,6 +23,9 @@ class NetGroupManager {
2223
* exists, since the data is const. */
2324
const std::vector<bool>& GetAsmap() const { return m_asmap; }
2425

26+
/** Get a checksum identifying the asmap being used. */
27+
uint256 GetAsmapChecksum() const;
28+
2529
/**
2630
* Get the canonical identifier of the network group for address.
2731
*

0 commit comments

Comments
 (0)