mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
[asmap] Make DecodeAsmap() a utility function
DecopeAsmap is a pure utility function and doesn't have any dependencies on addrman, so move it to util/asmap. Reviewer hint: use: `git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space`
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <logging.h>
|
||||
#include <netaddress.h>
|
||||
#include <serialize.h>
|
||||
#include <util/asmap.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
@@ -1008,30 +1007,3 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
|
||||
|
||||
return mapInfo[id_old];
|
||||
}
|
||||
|
||||
std::vector<bool> CAddrMan::DecodeAsmap(fs::path path)
|
||||
{
|
||||
std::vector<bool> bits;
|
||||
FILE *filestr = fsbridge::fopen(path, "rb");
|
||||
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
|
||||
if (file.IsNull()) {
|
||||
LogPrintf("Failed to open asmap file from disk\n");
|
||||
return bits;
|
||||
}
|
||||
fseek(filestr, 0, SEEK_END);
|
||||
int length = ftell(filestr);
|
||||
LogPrintf("Opened asmap file %s (%d bytes) from disk\n", path, length);
|
||||
fseek(filestr, 0, SEEK_SET);
|
||||
uint8_t cur_byte;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
file >> cur_byte;
|
||||
for (int bit = 0; bit < 8; ++bit) {
|
||||
bits.push_back((cur_byte >> bit) & 1);
|
||||
}
|
||||
}
|
||||
if (!SanityCheckASMap(bits, 128)) {
|
||||
LogPrintf("Sanity check of asmap file %s failed\n", path);
|
||||
return {};
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user