aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 3133d99bf..93f3f5d8c 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -3,12 +3,15 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include "chainparams.h"
#include "db.h"
#include "util.h"
-#include "main.h"
+#include "hash.h"
+#include "addrman.h"
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
+#include <openssl/rand.h>
#ifndef WIN32
#include "sys/stat.h"
@@ -486,7 +489,6 @@ void CDBEnv::Flush(bool fShutdown)
// CAddrDB
//
-
CAddrDB::CAddrDB()
{
pathAddr = GetDataDir() / "peers.dat";
@@ -501,7 +503,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
// serialize addresses, checksum data up to that point, then append csum
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
- ssPeers << FLATDATA(pchMessageStart);
+ ssPeers << FLATDATA(Params().MessageStart());
ssPeers << addr;
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
ssPeers << hash;
@@ -541,6 +543,8 @@ bool CAddrDB::Read(CAddrMan& addr)
// use file size to size memory buffer
int fileSize = GetFilesize(filein);
int dataSize = fileSize - sizeof(uint256);
+ //Don't try to resize to a negative number if file is small
+ if ( dataSize < 0 ) dataSize = 0;
vector<unsigned char> vchData;
vchData.resize(dataSize);
uint256 hashIn;
@@ -564,11 +568,11 @@ bool CAddrDB::Read(CAddrMan& addr)
unsigned char pchMsgTmp[4];
try {
- // de-serialize file header (pchMessageStart magic number) and
+ // de-serialize file header (network specific magic number) and ..
ssPeers >> FLATDATA(pchMsgTmp);
- // verify the network matches ours
- if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
+ // ... verify the network matches ours
+ if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
return error("CAddrman::Read() : invalid network magic number");
// de-serialize address data into one CAddrMan object