Browse Source

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)
0.13
Wladimir J. van der Laan 9 years ago
parent
commit
5578144413
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 46
      src/net.cpp

46
src/net.cpp

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

Loading…
Cancel
Save