21 template <
typename Stream,
typename Data>
22 bool SerializeDB(Stream& stream,
const Data& data)
29 stream << hasher.GetHash();
30 }
catch (
const std::exception& e) {
31 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
37 template <
typename Data>
38 bool SerializeFileDB(
const std::string&
prefix,
const fs::path& path,
const Data& data)
41 unsigned short randv = 0;
43 std::string tmpfn =
strprintf(
"%s.%04x", prefix, randv);
50 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
53 if (!SerializeDB(fileout, data))
return false;
59 return error(
"%s: Rename-into-place failed", __func__);
64 template <
typename Stream,
typename Data>
65 bool DeserializeDB(Stream& stream, Data& data,
bool fCheckSum =
true)
70 unsigned char pchMsgTmp[4];
73 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
74 return error(
"%s: Invalid network magic number", __func__);
83 if (hashTmp != verifier.GetHash()) {
84 return error(
"%s: Checksum mismatch, data corrupted", __func__);
88 catch (
const std::exception& e) {
89 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
95 template <
typename Data>
96 bool DeserializeFileDB(
const fs::path& path, Data& data)
102 return error(
"%s: Failed to open file %s", __func__, path.string());
104 return DeserializeDB(filein, data);
116 return SerializeFileDB(
"banlist",
pathBanlist, banSet);
131 return SerializeFileDB(
"peers", pathAddr, addr);
136 return DeserializeFileDB(pathAddr, addr);
141 bool ret = DeserializeDB(ssPeers, addr,
false);
FILE * fopen(const fs::path &p, const char *mode)
void FileCommit(FILE *file)
Double ended buffer combining vector and stream-like interfaces.
Reads data from an underlying stream, while hashing the read data.
Stochastical (IP) address manager.
std::map< CSubNet, CBanEntry > banmap_t
bool Write(const CAddrMan &addr)
bool RenameOver(fs::path src, fs::path dest)
bool Write(const banmap_t &banSet)
bool Read(banmap_t &banSet)
const CChainParams & Params()
Return the currently selected parameters.
void GetRandBytes(unsigned char *buf, int num)
Functions to gather random data via the OpenSSL PRNG.
bool error(const char *fmt, const Args &... args)
A writer stream (for serialization) that computes a 256-bit hash.
const fs::path & GetDataDir(bool fNetSpecific)
bool Read(CAddrMan &addr)
Non-refcounted RAII wrapper for FILE*.