diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1944,8 +1944,9 @@ // need to reindex later. assert(!g_banman); - g_banman = std::make_unique(GetDataDir() / "banlist.dat", - config.GetChainParams(), &uiInterface); + g_banman = std::make_unique( + GetDataDir() / "banlist.dat", config.GetChainParams(), &uiInterface, + gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME)); assert(!g_connman); g_connman = std::make_unique( config, GetRand(std::numeric_limits::max()), diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -136,7 +136,7 @@ // new code. ~BanMan(); BanMan(fs::path ban_file, const CChainParams &chainParams, - CClientUIInterface *client_interface); + CClientUIInterface *client_interface, int64_t default_ban_time); void Ban(const CNetAddr &netAddr, const BanReason &reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false); void Ban(const CSubNet &subNet, const BanReason &reason, @@ -163,6 +163,7 @@ bool setBannedIsDirty; CClientUIInterface *clientInterface = nullptr; CBanDB m_ban_db; + int64_t m_default_ban_time; }; class NetEventsInterface; diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -555,7 +555,7 @@ CBanEntry banEntry(GetTime()); banEntry.banReason = banReason; if (bantimeoffset <= 0) { - bantimeoffset = gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME); + bantimeoffset = m_default_ban_time; sinceUnixEpoch = false; } banEntry.nBanUntil = (sinceUnixEpoch ? 0 : GetTime()) + bantimeoffset; @@ -2519,9 +2519,10 @@ } BanMan::BanMan(fs::path ban_file, const CChainParams &chainParams, - CClientUIInterface *client_interface) + CClientUIInterface *client_interface, int64_t default_ban_time) : clientInterface(client_interface), - m_ban_db(std::move(ban_file), chainParams) { + m_ban_db(std::move(ban_file), chainParams), + m_default_ban_time(default_ban_time) { if (clientInterface) { clientInterface->InitMessage(_("Loading banlist...")); } diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -230,7 +230,8 @@ std::atomic interruptDummy(false); auto banman = std::make_unique(GetDataDir() / "banlist.dat", - config.GetChainParams(), nullptr); + config.GetChainParams(), nullptr, + DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( connman.get(), banman.get(), scheduler, false); @@ -295,7 +296,8 @@ std::atomic interruptDummy(false); auto banman = std::make_unique(GetDataDir() / "banlist.dat", - config.GetChainParams(), nullptr); + config.GetChainParams(), nullptr, + DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( connman.get(), banman.get(), scheduler, false); @@ -348,7 +350,8 @@ std::atomic interruptDummy(false); auto banman = std::make_unique(GetDataDir() / "banlist.dat", - config.GetChainParams(), nullptr); + config.GetChainParams(), nullptr, + DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( connman.get(), banman.get(), scheduler, false); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -117,8 +117,9 @@ threadGroup.create_thread(&ThreadScriptCheck); } - g_banman = std::make_unique(GetDataDir() / "banlist.dat", - chainparams, nullptr); + g_banman = + std::make_unique(GetDataDir() / "banlist.dat", chainparams, + nullptr, DEFAULT_MISBEHAVING_BANTIME); // Deterministic randomness for tests. g_connman = std::make_unique(config, 0x1337, 0x1337); }