Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,21 +495,16 @@ bool CAddrDB::Write(const CAddrMan& addr)
{
unsigned char pchMessageStart[4] = { 0xfb, 0xc0, 0xb6, 0xdb };

// 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(pchMessageStart);
ssPeers << 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("CAddrman::Write() : open failed");
Expand All @@ -524,10 +519,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("CAddrman::Write() : Rename-into-place failed");

return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ifdef UNIT_TEST
DEFS+=-DUNIT_TEST=1
endif

STATIC = 1
LMODE = dynamic
LMODE2 = dynamic
ifdef STATIC
Expand Down