Merge pull request #3602
2fdd4c7
better std::exception logging for CAddrDb (Philip Kaufmann)
This commit is contained in:
commit
9eb1e1e8ce
19
src/net.cpp
19
src/net.cpp
@ -1944,21 +1944,21 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
|||||||
FILE *file = fopen(pathTmp.string().c_str(), "wb");
|
FILE *file = fopen(pathTmp.string().c_str(), "wb");
|
||||||
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
|
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
|
||||||
if (!fileout)
|
if (!fileout)
|
||||||
return error("CAddrman::Write() : open failed");
|
return error("%s : Failed to open file %s", __func__, pathTmp.string());
|
||||||
|
|
||||||
// Write and commit header, data
|
// Write and commit header, data
|
||||||
try {
|
try {
|
||||||
fileout << ssPeers;
|
fileout << ssPeers;
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
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);
|
FileCommit(fileout);
|
||||||
fileout.fclose();
|
fileout.fclose();
|
||||||
|
|
||||||
// replace existing peers.dat, if any, with new peers.dat.XXXX
|
// replace existing peers.dat, if any, with new peers.dat.XXXX
|
||||||
if (!RenameOver(pathTmp, pathAddr))
|
if (!RenameOver(pathTmp, pathAddr))
|
||||||
return error("CAddrman::Write() : Rename-into-place failed");
|
return error("%s : Rename-into-place failed", __func__);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1969,13 +1969,14 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|||||||
FILE *file = fopen(pathAddr.string().c_str(), "rb");
|
FILE *file = fopen(pathAddr.string().c_str(), "rb");
|
||||||
CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION);
|
CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION);
|
||||||
if (!filein)
|
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
|
// use file size to size memory buffer
|
||||||
int fileSize = boost::filesystem::file_size(pathAddr);
|
int fileSize = boost::filesystem::file_size(pathAddr);
|
||||||
int dataSize = fileSize - sizeof(uint256);
|
int dataSize = fileSize - sizeof(uint256);
|
||||||
// Don't try to resize to a negative number if file is small
|
// 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;
|
vector<unsigned char> vchData;
|
||||||
vchData.resize(dataSize);
|
vchData.resize(dataSize);
|
||||||
uint256 hashIn;
|
uint256 hashIn;
|
||||||
@ -1986,7 +1987,7 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|||||||
filein >> hashIn;
|
filein >> hashIn;
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
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();
|
filein.fclose();
|
||||||
|
|
||||||
@ -1995,7 +1996,7 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|||||||
// verify stored checksum matches input data
|
// verify stored checksum matches input data
|
||||||
uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
|
uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
|
||||||
if (hashIn != hashTmp)
|
if (hashIn != hashTmp)
|
||||||
return error("CAddrman::Read() : checksum mismatch; data corrupted");
|
return error("%s : Checksum mismatch, data corrupted", __func__);
|
||||||
|
|
||||||
unsigned char pchMsgTmp[4];
|
unsigned char pchMsgTmp[4];
|
||||||
try {
|
try {
|
||||||
@ -2004,13 +2005,13 @@ bool CAddrDB::Read(CAddrMan& addr)
|
|||||||
|
|
||||||
// ... verify the network matches ours
|
// ... verify the network matches ours
|
||||||
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
|
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
|
// de-serialize address data into one CAddrMan object
|
||||||
ssPeers >> addr;
|
ssPeers >> addr;
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
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;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user