@ -38,7 +38,7 @@
@@ -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()
@@ -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()
@@ -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)
@@ -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 ) )
LogPrintf ( " Invalid or missing banlist.dat; recreating \n " ) ;
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
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
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 ;
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)
@@ -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)
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 ) ;