mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
[netgroupman] Move asmap checksum calculation to NetGroupManager
This commit is contained in:
parent
1b978a7e8c
commit
4709fc2019
3 changed files with 14 additions and 9 deletions
|
@ -218,11 +218,7 @@ void AddrManImpl::Serialize(Stream& s_) const
|
||||||
}
|
}
|
||||||
// Store asmap checksum after bucket entries so that it
|
// Store asmap checksum after bucket entries so that it
|
||||||
// can be ignored by older clients for backward compatibility.
|
// can be ignored by older clients for backward compatibility.
|
||||||
uint256 asmap_checksum;
|
s << m_netgroupman.GetAsmapChecksum();
|
||||||
if (m_netgroupman.GetAsmap().size() != 0) {
|
|
||||||
asmap_checksum = SerializeHash(m_netgroupman.GetAsmap());
|
|
||||||
}
|
|
||||||
s << asmap_checksum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
|
@ -335,10 +331,7 @@ void AddrManImpl::Unserialize(Stream& s_)
|
||||||
// If the bucket count and asmap checksum haven't changed, then attempt
|
// If the bucket count and asmap checksum haven't changed, then attempt
|
||||||
// to restore the entries to the buckets/positions they were in before
|
// to restore the entries to the buckets/positions they were in before
|
||||||
// serialization.
|
// serialization.
|
||||||
uint256 supplied_asmap_checksum;
|
uint256 supplied_asmap_checksum{m_netgroupman.GetAsmapChecksum()};
|
||||||
if (m_netgroupman.GetAsmap().size() != 0) {
|
|
||||||
supplied_asmap_checksum = SerializeHash(m_netgroupman.GetAsmap());
|
|
||||||
}
|
|
||||||
uint256 serialized_asmap_checksum;
|
uint256 serialized_asmap_checksum;
|
||||||
if (format >= Format::V2_ASMAP) {
|
if (format >= Format::V2_ASMAP) {
|
||||||
s >> serialized_asmap_checksum;
|
s >> serialized_asmap_checksum;
|
||||||
|
|
|
@ -4,8 +4,16 @@
|
||||||
|
|
||||||
#include <netgroup.h>
|
#include <netgroup.h>
|
||||||
|
|
||||||
|
#include <hash.h>
|
||||||
#include <util/asmap.h>
|
#include <util/asmap.h>
|
||||||
|
|
||||||
|
uint256 NetGroupManager::GetAsmapChecksum() const
|
||||||
|
{
|
||||||
|
if (!m_asmap.size()) return {};
|
||||||
|
|
||||||
|
return SerializeHash(m_asmap);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> NetGroupManager::GetGroup(const CNetAddr& address) const
|
std::vector<unsigned char> NetGroupManager::GetGroup(const CNetAddr& address) const
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> vchRet;
|
std::vector<unsigned char> vchRet;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define BITCOIN_NETGROUP_H
|
#define BITCOIN_NETGROUP_H
|
||||||
|
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
|
#include <uint256.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -22,6 +23,9 @@ public:
|
||||||
* exists, since the data is const. */
|
* exists, since the data is const. */
|
||||||
const std::vector<bool>& GetAsmap() const { return m_asmap; }
|
const std::vector<bool>& GetAsmap() const { return m_asmap; }
|
||||||
|
|
||||||
|
/** Get a checksum identifying the asmap being used. */
|
||||||
|
uint256 GetAsmapChecksum() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the canonical identifier of the network group for address.
|
* Get the canonical identifier of the network group for address.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue