mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Merge pull request #73 from crowning-/patch-6
On client shutdown write directly into "peers.dat"...
This commit is contained in:
commit
592168fe8e
17
src/net.cpp
17
src/net.cpp
@ -2002,11 +2002,6 @@ CAddrDB::CAddrDB()
|
|||||||
|
|
||||||
bool CAddrDB::Write(const CAddrMan& addr)
|
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
|
// serialize addresses, checksum data up to that point, then append csum
|
||||||
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
|
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
|
||||||
ssPeers << FLATDATA(Params().MessageStart());
|
ssPeers << FLATDATA(Params().MessageStart());
|
||||||
@ -2014,12 +2009,12 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
|||||||
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
|
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
|
||||||
ssPeers << hash;
|
ssPeers << hash;
|
||||||
|
|
||||||
// open temp output file, and associate with CAutoFile
|
// open output file, and associate with CAutoFile
|
||||||
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
|
boost::filesystem::path pathAddr = GetDataDir() / "peers.dat";
|
||||||
FILE *file = fopen(pathTmp.string().c_str(), "wb");
|
FILE *file = fopen(pathAddr.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("%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
|
// Write and commit header, data
|
||||||
try {
|
try {
|
||||||
@ -2031,10 +2026,6 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
|||||||
FileCommit(fileout);
|
FileCommit(fileout);
|
||||||
fileout.fclose();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user