26class DbNotFoundError :
public std::exception {
27 using std::exception::exception;
30template <
typename Stream,
typename Data>
31bool SerializeDB(
const CChainParams &chainParams, Stream &stream,
36 hashwriter << chainParams.
DiskMagic() << data;
37 stream << hashwriter.GetHash();
38 }
catch (
const std::exception &e) {
39 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
45template <
typename Data>
47 const fs::path &path,
const Data &data,
int version) {
86template <
typename Stream,
typename Data>
96 throw std::runtime_error{
"Invalid network magic number"};
107 throw std::runtime_error{
"Checksum mismatch, data corrupted"};
112template <
typename Data>
114 Data &data,
int version) {
119 throw DbNotFoundError{};
142 }
catch (
const std::exception &) {
143 LogPrintf(
"Missing or invalid file %s\n",
169 auto addrman{std::make_unique<AddrMan>(
176 LogPrintf(
"Loaded %i addresses from peers.dat %dms\n", addrman->size(),
178 }
catch (
const DbNotFoundError &) {
180 addrman = std::make_unique<AddrMan>(
182 LogPrintf(
"Creating peers.dat because the file was not found (%s)\n",
188 strprintf(
_(
"Failed to rename invalid peers.dat file. "
189 "Please move or delete it and try again."))};
192 addrman = std::make_unique<AddrMan>(
194 LogPrintf(
"Creating new peers.dat because the file version was not "
195 "compatible (%s). Original backed up to peers.dat.bak\n",
198 }
catch (
const std::exception &
e) {
200 _(
"Invalid or corrupt peers.dat (%s). If you believe this is a "
201 "bug, please report it to %s. As a workaround, you can move the "
202 "file (%s) out of the way (rename, move, or delete) to have a "
203 "new one created on the next start."),
211 return {std::move(addrman)};
216 const std::vector<CAddress> &
anchors) {
218 "Flush %d outbound block-relay-only peer addresses to anchors.dat",
232 }
catch (
const std::exception &) {
std::vector< CAddress > ReadAnchors(const CChainParams &chainParams, const fs::path &anchors_db_path)
Read the anchor IP address database (anchors.dat)
util::Result< std::unique_ptr< AddrMan > > LoadAddrman(const CChainParams &chainparams, const std::vector< bool > &asmap, const ArgsManager &args)
Returns an error string on failure.
void ReadFromStream(const CChainParams &chainParams, AddrMan &addr, CDataStream &ssPeers)
Only used by tests.
bool DumpPeerAddresses(const CChainParams &chainParams, const ArgsManager &args, const AddrMan &addr)
void DumpAnchors(const CChainParams &chainParams, const fs::path &anchors_db_path, const std::vector< CAddress > &anchors)
Dump the anchor IP address database (anchors.dat)
static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS
Default for -checkaddrman.
Stochastic address manager.
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
bool Write(const banmap_t &banSet)
const fs::path m_ban_list_path
CBanDB(fs::path ban_list_path, const CChainParams &_chainParams)
bool Read(banmap_t &banSet)
const CChainParams & chainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const CMessageHeader::MessageMagic & DiskMagic() const
Double ended buffer combining vector and stream-like interfaces.
Reads data from an underlying stream, while hashing the read data.
Writes data to an underlying source stream, while hashing the written data.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
bool RenameOver(fs::path src, fs::path dest)
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
bool error(const char *fmt, const Args &...args)
static auto quoted(const std::string &s)
static std::string PathToString(const path &path)
Convert path object to byte string.
FILE * fopen(const fs::path &p, const char *mode)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
std::map< CSubNet, CBanEntry > banmap_t
static constexpr int ADDRV2_FORMAT
A flag that is ORed into the protocol version to designate that addresses should be serialized in (un...
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
int64_t GetTimeMillis()
Returns the system time (not mockable)
#define LOG_TIME_SECONDS(end_msg)
bilingual_str _(const char *psz)
Translation function.