mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
Merge branch 'addrman' of https://github.com/sipa/bitcoin
This commit is contained in:
73
src/db.cpp
73
src/db.cpp
@@ -624,44 +624,65 @@ bool CAddrDB::WriteAddress(const CAddress& addr)
|
||||
return Write(make_pair(string("addr"), addr.GetKey()), addr);
|
||||
}
|
||||
|
||||
bool CAddrDB::WriteAddrman(const CAddrMan& addrman)
|
||||
{
|
||||
return Write(string("addrman"), addrman);
|
||||
}
|
||||
|
||||
bool CAddrDB::EraseAddress(const CAddress& addr)
|
||||
{
|
||||
return Erase(make_pair(string("addr"), addr.GetKey()));
|
||||
}
|
||||
|
||||
bool CAddrDB::LoadAddresses()
|
||||
bool CAddrDB::LoadAddresses(bool &fUpdate)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_mapAddresses)
|
||||
bool fAddrMan = false;
|
||||
if (Read(string("addrman"), addrman))
|
||||
{
|
||||
// Get cursor
|
||||
Dbc* pcursor = GetCursor();
|
||||
if (!pcursor)
|
||||
printf("Loaded %i addresses\n", addrman.size());
|
||||
fAddrMan = true;
|
||||
}
|
||||
|
||||
vector<CAddress> vAddr;
|
||||
|
||||
// Get cursor
|
||||
Dbc* pcursor = GetCursor();
|
||||
if (!pcursor)
|
||||
return false;
|
||||
|
||||
loop
|
||||
{
|
||||
// Read next record
|
||||
CDataStream ssKey;
|
||||
CDataStream ssValue;
|
||||
int ret = ReadAtCursor(pcursor, ssKey, ssValue);
|
||||
if (ret == DB_NOTFOUND)
|
||||
break;
|
||||
else if (ret != 0)
|
||||
return false;
|
||||
|
||||
loop
|
||||
// Unserialize
|
||||
string strType;
|
||||
ssKey >> strType;
|
||||
if (strType == "addr")
|
||||
{
|
||||
// Read next record
|
||||
CDataStream ssKey;
|
||||
CDataStream ssValue;
|
||||
int ret = ReadAtCursor(pcursor, ssKey, ssValue);
|
||||
if (ret == DB_NOTFOUND)
|
||||
break;
|
||||
else if (ret != 0)
|
||||
return false;
|
||||
|
||||
// Unserialize
|
||||
string strType;
|
||||
ssKey >> strType;
|
||||
if (strType == "addr")
|
||||
if (fAddrMan)
|
||||
fUpdate = true;
|
||||
else
|
||||
{
|
||||
CAddress addr;
|
||||
ssValue >> addr;
|
||||
mapAddresses.insert(make_pair(addr.GetKey(), addr));
|
||||
vAddr.push_back(addr);
|
||||
}
|
||||
}
|
||||
pcursor->close();
|
||||
|
||||
printf("Loaded %d addresses\n", mapAddresses.size());
|
||||
}
|
||||
}
|
||||
pcursor->close();
|
||||
|
||||
if (!fAddrMan)
|
||||
{
|
||||
addrman.Add(vAddr, CNetAddr("0.0.0.0"));
|
||||
printf("Loaded %i addresses\n", addrman.size());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -669,7 +690,11 @@ bool CAddrDB::LoadAddresses()
|
||||
|
||||
bool LoadAddresses()
|
||||
{
|
||||
return CAddrDB("cr+").LoadAddresses();
|
||||
bool fUpdate = false;
|
||||
bool fRet = CAddrDB("cr+").LoadAddresses(fUpdate);
|
||||
if (fUpdate)
|
||||
CDB::Rewrite("addr.dat", "\004addr");
|
||||
return fRet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user