Merge #7350: Banlist updates

e8600c9 banlist (bugfix): allow CNode::SweepBanned() to run on interval (Philip Kaufmann)
2977c24 banlist: add more banlist infos to log / add GUI signal (Philip Kaufmann)
ce479aa banlist: better handling of banlist in StartNode() (Philip Kaufmann)
57c77fe banlist: update set dirty to be more fine grained (Philip Kaufmann)
This commit is contained in:
Wladimir J. van der Laan 2016-01-20 13:37:55 +01:00
commit 5578144413
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
1 changed files with 30 additions and 24 deletions

View File

@ -38,7 +38,7 @@
#include <math.h>
// Dump addresses to peers.dat every 15 minutes (900s)
// Dump addresses to peers.dat and banlist.dat every 15 minutes (900s)
#define DUMP_ADDRESSES_INTERVAL 900
#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
@ -573,11 +573,13 @@ void CNode::SweepBanned()
banmap_t::iterator it = setBanned.begin();
while(it != setBanned.end())
{
CSubNet subNet = (*it).first;
CBanEntry banEntry = (*it).second;
if(now > banEntry.nBanUntil)
{
setBanned.erase(it++);
setBannedIsDirty = true;
LogPrint("net", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.ToString());
}
else
++it;
@ -1492,12 +1494,7 @@ void DumpAddresses()
void DumpData()
{
DumpAddresses();
if (CNode::BannedSetIsDirty())
{
DumpBanlist();
CNode::SetBannedSetDirty(false);
}
}
void static ProcessOneShot()
@ -1938,31 +1935,36 @@ void static Discover(boost::thread_group& threadGroup)
void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler)
{
uiInterface.InitMessage(_("Loading addresses..."));
// Load addresses for peers.dat
// Load addresses from peers.dat
int64_t nStart = GetTimeMillis();
{
CAddrDB adb;
if (!adb.Read(addrman))
if (adb.Read(addrman))
LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman.size(), GetTimeMillis() - nStart);
else
LogPrintf("Invalid or missing peers.dat; recreating\n");
}
//try to read stored banlist
uiInterface.InitMessage(_("Loading banlist..."));
// Load addresses from banlist.dat
nStart = GetTimeMillis();
CBanDB bandb;
banmap_t banmap;
if (!bandb.Read(banmap))
if (bandb.Read(banmap)) {
CNode::SetBanned(banmap); // thread save setter
CNode::SetBannedSetDirty(false); // no need to write down, just read data
CNode::SweepBanned(); // sweep out unused entries
LogPrint("net", "Loaded %d banned node ips/subnets from banlist.dat %dms\n",
banmap.size(), GetTimeMillis() - nStart);
} else
LogPrintf("Invalid or missing banlist.dat; recreating\n");
CNode::SetBanned(banmap); //thread save setter
CNode::SetBannedSetDirty(false); //no need to write down just read or nonexistent data
CNode::SweepBanned(); //sweap out unused entries
LogPrintf("Loaded %i addresses from peers.dat %dms\n",
addrman.size(), GetTimeMillis() - nStart);
fAddressesInitialized = true;
if (semOutbound == NULL) {
// initialize semaphore
int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
int nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
semOutbound = new CSemaphore(nMaxOutbound);
}
@ -2622,14 +2624,18 @@ bool CBanDB::Read(banmap_t& banSet)
void DumpBanlist()
{
int64_t nStart = GetTimeMillis();
CNode::SweepBanned(); // clean unused entries (if bantime has expired)
if (!CNode::BannedSetIsDirty())
return;
int64_t nStart = GetTimeMillis();
CBanDB bandb;
banmap_t banmap;
CNode::GetBanned(banmap);
bandb.Write(banmap);
if (bandb.Write(banmap))
CNode::SetBannedSetDirty(false);
LogPrint("net", "Flushed %d banned node ips/subnets to banlist.dat %dms\n",
banmap.size(), GetTimeMillis() - nStart);