diff --git a/src/addrman.h b/src/addrman.h --- a/src/addrman.h +++ b/src/addrman.h @@ -352,9 +352,6 @@ // would be re-bucketed accordingly. std::vector<bool> m_asmap; - // Read asmap from provided binary file - static std::vector<bool> DecodeAsmap(fs::path path); - /** * Serialized format. * * format version byte (@see `Format`) diff --git a/src/addrman.cpp b/src/addrman.cpp --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -8,7 +8,6 @@ #include <hash.h> #include <logging.h> #include <serialize.h> -#include <util/asmap.h> #include <cmath> @@ -743,29 +742,3 @@ 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); - char 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; -} diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2500,7 +2500,7 @@ InitError(strprintf(_("Could not find asmap file %s"), asmap_path)); return false; } - std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path); + std::vector<bool> asmap = DecodeAsmap(asmap_path); if (asmap.size() == 0) { InitError( strprintf(_("Could not parse asmap file %s"), asmap_path)); diff --git a/src/util/asmap.h b/src/util/asmap.h --- a/src/util/asmap.h +++ b/src/util/asmap.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_UTIL_ASMAP_H #define BITCOIN_UTIL_ASMAP_H +#include <fs.h> + #include <cstdint> #include <vector> @@ -12,4 +14,7 @@ bool SanityCheckASMap(const std::vector<bool> &asmap, int bits); +/** Read asmap from provided binary file */ +std::vector<bool> DecodeAsmap(fs::path path); + #endif // BITCOIN_UTIL_ASMAP_H diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp --- a/src/util/asmap.cpp +++ b/src/util/asmap.cpp @@ -2,7 +2,12 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include <util/asmap.h> + +#include <clientversion.h> #include <crypto/common.h> +#include <logging.h> +#include <streams.h> #include <cassert> #include <map> @@ -284,3 +289,29 @@ // Reached EOF without RETURN instruction return false; } + +std::vector<bool> 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); + char 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; +}