17 #include <boost/filesystem.hpp>
27 unsigned short randv = 0;
29 std::string tmpfn =
strprintf(
"banlist.dat.%04x", randv);
39 boost::filesystem::path pathTmp =
GetDataDir() / tmpfn;
40 FILE *file = fopen(pathTmp.string().c_str(),
"wb");
43 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
49 catch (
const std::exception& e) {
50 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
57 return error(
"%s: Rename-into-place failed", __func__);
65 FILE *file = fopen(
pathBanlist.string().c_str(),
"rb");
71 uint64_t fileSize = boost::filesystem::file_size(
pathBanlist);
72 uint64_t dataSize = 0;
74 if (fileSize >=
sizeof(
uint256))
75 dataSize = fileSize -
sizeof(
uint256);
76 std::vector<unsigned char> vchData;
77 vchData.resize(dataSize);
82 filein.
read((
char *)&vchData[0], dataSize);
85 catch (
const std::exception& e) {
86 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
94 if (hashIn != hashTmp)
95 return error(
"%s: Checksum mismatch, data corrupted", __func__);
97 unsigned char pchMsgTmp[4];
103 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
104 return error(
"%s: Invalid network magic number", __func__);
109 catch (
const std::exception& e) {
110 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
124 unsigned short randv = 0;
126 std::string tmpfn =
strprintf(
"peers.dat.%04x", randv);
136 boost::filesystem::path pathTmp =
GetDataDir() / tmpfn;
137 FILE *file = fopen(pathTmp.string().c_str(),
"wb");
140 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
146 catch (
const std::exception& e) {
147 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
154 return error(
"%s: Rename-into-place failed", __func__);
162 FILE *file = fopen(
pathAddr.string().c_str(),
"rb");
165 return error(
"%s: Failed to open file %s", __func__,
pathAddr.string());
168 uint64_t fileSize = boost::filesystem::file_size(
pathAddr);
169 uint64_t dataSize = 0;
171 if (fileSize >=
sizeof(
uint256))
172 dataSize = fileSize -
sizeof(
uint256);
173 std::vector<unsigned char> vchData;
174 vchData.resize(dataSize);
179 filein.
read((
char *)&vchData[0], dataSize);
182 catch (
const std::exception& e) {
183 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
191 if (hashIn != hashTmp)
192 return error(
"%s: Checksum mismatch, data corrupted", __func__);
194 return Read(addr, ssPeers);
199 unsigned char pchMsgTmp[4];
205 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
206 return error(
"%s: Invalid network magic number", __func__);
211 catch (
const std::exception& e) {
214 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
std::map< CSubNet, CBanEntry > banmap_t
const CChainParams & Params()
Return the currently selected parameters.
bool Write(const CAddrMan &addr)
bool Read(CAddrMan &addr)
boost::filesystem::path pathAddr
Stochastical (IP) address manager.
Non-refcounted RAII wrapper for FILE*.
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
bool IsNull() const
Return true if the wrapped FILE* is NULL, false otherwise.
void read(char *pch, size_t nSize)
bool Write(const banmap_t &banSet)
boost::filesystem::path pathBanlist
bool Read(banmap_t &banSet)
Double ended buffer combining vector and stream-like interfaces.
const_iterator begin() const
const_iterator end() const
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
void GetRandBytes(unsigned char *buf, int num)
Functions to gather random data via the OpenSSL PRNG.
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
void FileCommit(FILE *file)
bool error(const char *fmt, const Args &... args)