 |
Bitcoin Core
21.99.0
P2P Digital Currency
|
Go to the documentation of this file.
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)
49 if (fileout.IsNull()) {
52 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
56 if (!SerializeDB(fileout, data)) {
64 return error(
"%s: Failed to flush file %s", __func__, pathTmp.string());
71 return error(
"%s: Rename-into-place failed", __func__);
77 template <
typename Stream,
typename Data>
78 bool DeserializeDB(Stream& stream, Data& data,
bool fCheckSum =
true)
83 unsigned char pchMsgTmp[4];
84 verifier >> pchMsgTmp;
86 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
87 return error(
"%s: Invalid network magic number", __func__);
96 if (hashTmp != verifier.GetHash()) {
97 return error(
"%s: Checksum mismatch, data corrupted", __func__);
101 catch (
const std::exception& e) {
102 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
108 template <
typename Data>
109 bool DeserializeFileDB(
const fs::path& path, Data& data)
114 if (filein.IsNull()) {
115 LogPrintf(
"Missing or invalid file %s\n", path.string());
118 return DeserializeDB(filein, data);
122 CBanDB::CBanDB(fs::path ban_list_path) : m_ban_list_path(std::move(ban_list_path))
143 return SerializeFileDB(
"peers",
pathAddr, addr);
148 return DeserializeFileDB(
pathAddr, addr);
153 bool ret = DeserializeDB(ssPeers, addr,
false);
161 void DumpAnchors(
const fs::path& anchors_db_path,
const std::vector<CAddress>& anchors)
164 SerializeFileDB(
"anchors", anchors_db_path, anchors);
167 std::vector<CAddress>
ReadAnchors(
const fs::path& anchors_db_path)
169 std::vector<CAddress> anchors;
170 if (DeserializeFileDB(anchors_db_path, anchors)) {
171 LogPrintf(
"Loaded %i addresses from %s\n", anchors.size(), anchors_db_path.filename());
176 fs::remove(anchors_db_path);
bool Read(banmap_t &banSet)
const fs::path & GetDataDir(bool fNetSpecific)
#define LOG_TIME_SECONDS(end_msg)
Reads data from an underlying stream, while hashing the read data.
FILE * fopen(const fs::path &p, const char *mode)
void DumpAnchors(const fs::path &anchors_db_path, const std::vector< CAddress > &anchors)
Dump the anchor IP address database (anchors.dat)
bool Write(const banmap_t &banSet)
bool RenameOver(fs::path src, fs::path dest)
bool Write(const CAddrMan &addr)
Non-refcounted RAII wrapper for FILE*.
void GetRandBytes(unsigned char *buf, int num) noexcept
Overall design of the RNG and entropy sources.
const CMessageHeader::MessageStartChars & MessageStart() const
Stochastical (IP) address manager.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
A writer stream (for serialization) that computes a 256-bit hash.
const CChainParams & Params()
Return the currently selected parameters.
bool Read(CAddrMan &addr)
CBanDB(fs::path ban_list_path)
Double ended buffer combining vector and stream-like interfaces.
std::vector< CAddress > ReadAnchors(const fs::path &anchors_db_path)
Read the anchor IP address database (anchors.dat)
const fs::path m_ban_list_path
std::map< CSubNet, CBanEntry > banmap_t
bool error(const char *fmt, const Args &... args)