Skip to content

Commit 592168f

Browse files
Merge pull request #73 from crowning-/patch-6
On client shutdown write directly into "peers.dat"...
2 parents 5d14e8c + 6b8fb97 commit 592168f

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/net.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,24 +2002,19 @@ CAddrDB::CAddrDB()
20022002

20032003
bool CAddrDB::Write(const CAddrMan& addr)
20042004
{
2005-
// Generate random temporary filename
2006-
unsigned short randv = 0;
2007-
RAND_bytes((unsigned char *)&randv, sizeof(randv));
2008-
std::string tmpfn = strprintf("peers.dat.%04x", randv);
2009-
20102005
// serialize addresses, checksum data up to that point, then append csum
20112006
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
20122007
ssPeers << FLATDATA(Params().MessageStart());
20132008
ssPeers << addr;
20142009
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
20152010
ssPeers << hash;
20162011

2017-
// open temp output file, and associate with CAutoFile
2018-
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
2019-
FILE *file = fopen(pathTmp.string().c_str(), "wb");
2012+
// open output file, and associate with CAutoFile
2013+
boost::filesystem::path pathAddr = GetDataDir() / "peers.dat";
2014+
FILE *file = fopen(pathAddr.string().c_str(), "wb");
20202015
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
20212016
if (!fileout)
2022-
return error("%s : Failed to open file %s", __func__, pathTmp.string());
2017+
return error("%s : Failed to open file %s", __func__, pathAddr.string());
20232018

20242019
// Write and commit header, data
20252020
try {
@@ -2031,10 +2026,6 @@ bool CAddrDB::Write(const CAddrMan& addr)
20312026
FileCommit(fileout);
20322027
fileout.fclose();
20332028

2034-
// replace existing peers.dat, if any, with new peers.dat.XXXX
2035-
if (!RenameOver(pathTmp, pathAddr))
2036-
return error("%s : Rename-into-place failed", __func__);
2037-
20382029
return true;
20392030
}
20402031

0 commit comments

Comments
 (0)