20 template <
typename Stream,
typename Data>
21 bool SerializeDB(Stream& stream,
const Data&
data)
28 stream << hasher.GetHash();
29 }
catch (
const std::exception&
e) {
30 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
36 template <
typename Data>
37 bool SerializeFileDB(
const std::string&
prefix,
const fs::path& path,
const Data& data)
40 unsigned short randv = 0;
42 std::string tmpfn =
strprintf(
"%s.%04x", prefix, randv);
49 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
52 if (!SerializeDB(fileout, data))
return false;
58 return error(
"%s: Rename-into-place failed", __func__);
63 template <
typename Stream,
typename Data>
64 bool DeserializeDB(Stream& stream, Data& data,
bool fCheckSum =
true)
69 unsigned char pchMsgTmp[4];
72 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
73 return error(
"%s: Invalid network magic number", __func__);
82 if (hashTmp != verifier.GetHash()) {
83 return error(
"%s: Checksum mismatch, data corrupted", __func__);
87 catch (
const std::exception& e) {
88 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
94 template <
typename Data>
95 bool DeserializeFileDB(
const fs::path& path, Data& data)
101 return error(
"%s: Failed to open file %s", __func__, path.string());
103 return DeserializeDB(filein, data);
115 return SerializeFileDB(
"banlist",
pathBanlist, banSet);
130 return SerializeFileDB(
"peers", pathAddr, addr);
135 return DeserializeFileDB(pathAddr, addr);
140 bool ret = DeserializeDB(ssPeers, addr,
false);
bool error(const char *fmt, const Args &...args)
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.
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*.