|
|
|
@ -1944,21 +1944,21 @@ bool CAddrDB::Write(const CAddrMan& addr)
@@ -1944,21 +1944,21 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
|
|
|
|
FILE *file = fopen(pathTmp.string().c_str(), "wb"); |
|
|
|
|
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION); |
|
|
|
|
if (!fileout) |
|
|
|
|
return error("CAddrman::Write() : open failed"); |
|
|
|
|
return error("%s : Failed to open file %s", __func__, pathTmp.string()); |
|
|
|
|
|
|
|
|
|
// Write and commit header, data
|
|
|
|
|
try { |
|
|
|
|
fileout << ssPeers; |
|
|
|
|
} |
|
|
|
|
catch (std::exception &e) { |
|
|
|
|
return error("CAddrman::Write() : I/O error"); |
|
|
|
|
return error("%s : Serialize or I/O error - %s", __func__, e.what()); |
|
|
|
|
} |
|
|
|
|
FileCommit(fileout); |
|
|
|
|
fileout.fclose(); |
|
|
|
|
|
|
|
|
|
// replace existing peers.dat, if any, with new peers.dat.XXXX
|
|
|
|
|
if (!RenameOver(pathTmp, pathAddr)) |
|
|
|
|
return error("CAddrman::Write() : Rename-into-place failed"); |
|
|
|
|
return error("%s : Rename-into-place failed", __func__); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -1969,13 +1969,14 @@ bool CAddrDB::Read(CAddrMan& addr)
@@ -1969,13 +1969,14 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|
|
|
|
FILE *file = fopen(pathAddr.string().c_str(), "rb"); |
|
|
|
|
CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION); |
|
|
|
|
if (!filein) |
|
|
|
|
return error("CAddrman::Read() : open failed"); |
|
|
|
|
return error("%s : Failed to open file %s", __func__, pathAddr.string()); |
|
|
|
|
|
|
|
|
|
// use file size to size memory buffer
|
|
|
|
|
int fileSize = boost::filesystem::file_size(pathAddr); |
|
|
|
|
int dataSize = fileSize - sizeof(uint256); |
|
|
|
|
// Don't try to resize to a negative number if file is small
|
|
|
|
|
if ( dataSize < 0 ) dataSize = 0; |
|
|
|
|
if (dataSize < 0) |
|
|
|
|
dataSize = 0; |
|
|
|
|
vector<unsigned char> vchData; |
|
|
|
|
vchData.resize(dataSize); |
|
|
|
|
uint256 hashIn; |
|
|
|
@ -1986,7 +1987,7 @@ bool CAddrDB::Read(CAddrMan& addr)
@@ -1986,7 +1987,7 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|
|
|
|
filein >> hashIn; |
|
|
|
|
} |
|
|
|
|
catch (std::exception &e) { |
|
|
|
|
return error("CAddrman::Read() 2 : I/O error or stream data corrupted"); |
|
|
|
|
return error("%s : Deserialize or I/O error - %s", __func__, e.what()); |
|
|
|
|
} |
|
|
|
|
filein.fclose(); |
|
|
|
|
|
|
|
|
@ -1995,7 +1996,7 @@ bool CAddrDB::Read(CAddrMan& addr)
@@ -1995,7 +1996,7 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|
|
|
|
// verify stored checksum matches input data
|
|
|
|
|
uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end()); |
|
|
|
|
if (hashIn != hashTmp) |
|
|
|
|
return error("CAddrman::Read() : checksum mismatch; data corrupted"); |
|
|
|
|
return error("%s : Checksum mismatch, data corrupted", __func__); |
|
|
|
|
|
|
|
|
|
unsigned char pchMsgTmp[4]; |
|
|
|
|
try { |
|
|
|
@ -2004,13 +2005,13 @@ bool CAddrDB::Read(CAddrMan& addr)
@@ -2004,13 +2005,13 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|
|
|
|
|
|
|
|
|
// ... verify the network matches ours
|
|
|
|
|
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) |
|
|
|
|
return error("CAddrman::Read() : invalid network magic number"); |
|
|
|
|
return error("%s : Invalid network magic number", __func__); |
|
|
|
|
|
|
|
|
|
// de-serialize address data into one CAddrMan object
|
|
|
|
|
ssPeers >> addr; |
|
|
|
|
} |
|
|
|
|
catch (std::exception &e) { |
|
|
|
|
return error("CAddrman::Read() : I/O error or stream data corrupted"); |
|
|
|
|
return error("%s : Deserialize or I/O error - %s", __func__, e.what()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|