aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-01-20 13:37:55 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-01-20 13:38:40 +0100
commit55781444130c359307d0611b310c6f5e8a511e91 (patch)
tree9e557ebdf8887bbb3e60412134493af55a43cc51
parentf48e59df0a9d71d90f5edcff0e27696ceb34c621 (diff)
parent5bc4fb7b602c420be1c746442edad6b2d8e333ab (diff)
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)
-rw-r--r--src/net.cpp54
1 files changed, 30 insertions, 24 deletions
diff --git a/src/net.cpp b/src/net.cpp
index db8f97abc2..48e9e10157 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -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);
- }
+ DumpBanlist();
}
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);
}
@@ -2609,30 +2611,34 @@ bool CBanDB::Read(banmap_t& banSet)
// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
return error("%s: Invalid network magic number", __func__);
-
+
// de-serialize address data into one CAddrMan object
ssBanlist >> banSet;
}
catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
-
+
return true;
}
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;
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);
+ banmap.size(), GetTimeMillis() - nStart);
}
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {