Merge pull request #73 from crowning-/patch-6

On client shutdown write directly into "peers.dat"...
This commit is contained in:
Darkcoin 2014-12-13 08:16:45 -07:00
commit 592168fe8e

View File

@ -2002,11 +2002,6 @@ CAddrDB::CAddrDB()
bool CAddrDB::Write(const CAddrMan& addr)
{
// Generate random temporary filename
unsigned short randv = 0;
RAND_bytes((unsigned char *)&randv, sizeof(randv));
std::string tmpfn = strprintf("peers.dat.%04x", randv);
// serialize addresses, checksum data up to that point, then append csum
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
ssPeers << FLATDATA(Params().MessageStart());
@ -2014,12 +2009,12 @@ bool CAddrDB::Write(const CAddrMan& addr)
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
ssPeers << hash;
// open temp output file, and associate with CAutoFile
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
FILE *file = fopen(pathTmp.string().c_str(), "wb");
// open output file, and associate with CAutoFile
boost::filesystem::path pathAddr = GetDataDir() / "peers.dat";
FILE *file = fopen(pathAddr.string().c_str(), "wb");
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
if (!fileout)
return error("%s : Failed to open file %s", __func__, pathTmp.string());
return error("%s : Failed to open file %s", __func__, pathAddr.string());
// Write and commit header, data
try {
@ -2031,10 +2026,6 @@ bool CAddrDB::Write(const CAddrMan& addr)
FileCommit(fileout);
fileout.fclose();
// replace existing peers.dat, if any, with new peers.dat.XXXX
if (!RenameOver(pathTmp, pathAddr))
return error("%s : Rename-into-place failed", __func__);
return true;
}