22 template <
typename Stream,
typename Data>
23 bool SerializeDB(Stream& stream,
const Data& data)
30 stream << hasher.GetHash();
31 }
catch (
const std::exception& e) {
32 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
38 template <
typename Data>
39 bool SerializeFileDB(
const std::string&
prefix,
const fs::path& path,
const Data& data)
50 if (fileout.IsNull()) {
53 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
57 if (!SerializeDB(fileout, data)) {
65 return error(
"%s: Failed to flush file %s", __func__, pathTmp.string());
72 return error(
"%s: Rename-into-place failed", __func__);
78 template <
typename Stream,
typename Data>
79 bool DeserializeDB(Stream& stream, Data& data,
bool fCheckSum =
true)
84 unsigned char pchMsgTmp[4];
85 verifier >> pchMsgTmp;
87 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)) != 0)
88 return error(
"%s: Invalid network magic number", __func__);
97 if (hashTmp != verifier.GetHash()) {
98 return error(
"%s: Checksum mismatch, data corrupted", __func__);
102 catch (
const std::exception& e) {
103 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
109 template <
typename Data>
110 bool DeserializeFileDB(
const fs::path& path, Data& data)
116 return error(
"%s: Failed to open file %s", __func__, path.string());
118 return DeserializeDB(filein, data);
130 return SerializeFileDB(
"banlist",
pathBanlist, banSet);
145 return SerializeFileDB(
"peers",
pathAddr, addr);
150 return DeserializeFileDB(
pathAddr, addr);
155 bool ret = DeserializeDB(ssPeers, addr,
false);
std::map< CSubNet, CBanEntry > banmap_t
const CChainParams & Params()
Return the currently selected parameters.
bool Write(const CAddrMan &addr)
bool Read(CAddrMan &addr)
Stochastical (IP) address manager.
Non-refcounted RAII wrapper for FILE*.
bool Write(const banmap_t &banSet)
bool Read(banmap_t &banSet)
const CMessageHeader::MessageStartChars & MessageStart() const
Reads data from an underlying stream, while hashing the read data.
A writer stream (for serialization) that computes a 256-bit hash.
FILE * fopen(const fs::path &p, const char *mode)
void GetRandBytes(unsigned char *buf, int num) noexcept
Overall design of the RNG and entropy sources.
bool RenameOver(fs::path src, fs::path dest)
const fs::path & GetDataDir(bool fNetSpecific)
bool FileCommit(FILE *file)
bool error(const char *fmt, const Args &... args)