aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2017-10-05 13:41:45 -0400
committerCarl Dong <accounts@carldong.me>2019-01-16 13:54:18 -0500
commitd0469b2e9386a7a4b268cb9725347e7517acace6 (patch)
tree77e13e31bd2204de782afafe03c1e71203392c71
parent2e56702ecedd83c4b7cb8de9de5c437c8c08e645 (diff)
banman: pass in default ban time as a parameter
Removes the dependency on arg parsing.
-rw-r--r--src/init.cpp2
-rw-r--r--src/net.cpp4
-rw-r--r--src/net.h3
-rw-r--r--src/test/denialofservice_tests.cpp6
-rw-r--r--src/test/test_bitcoin.cpp2
5 files changed, 9 insertions, 8 deletions
diff --git a/src/init.cpp b/src/init.cpp
index ded157d49e..0f59dfbef5 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1296,7 +1296,7 @@ bool AppInitMain(InitInterfaces& interfaces)
// need to reindex later.
assert(!g_banman);
- g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface);
+ g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
assert(!g_connman);
g_connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));
diff --git a/src/net.cpp b/src/net.cpp
index fd74c58292..f6491bc8db 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -537,7 +537,7 @@ void BanMan::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t bant
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;
@@ -2430,7 +2430,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
return true;
}
-BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface) : clientInterface(client_interface), m_ban_db(std::move(ban_file))
+BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time) : clientInterface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
{
if (clientInterface) clientInterface->InitMessage(_("Loading banlist..."));
diff --git a/src/net.h b/src/net.h
index 5e6fc14b38..a6a536d68a 100644
--- a/src/net.h
+++ b/src/net.h
@@ -133,7 +133,7 @@ public:
// between nodes running old code and nodes running
// new code.
~BanMan();
- BanMan(fs::path ban_file, CClientUIInterface* client_interface);
+ BanMan(fs::path ban_file, 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, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
void ClearBanned(); // needed for unit testing
@@ -157,6 +157,7 @@ private:
bool setBannedIsDirty;
CClientUIInterface* clientInterface = nullptr;
CBanDB m_ban_db;
+ int64_t m_default_ban_time;
};
class NetEventsInterface;
diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp
index 4a88613a89..29bb34bddc 100644
--- a/src/test/denialofservice_tests.cpp
+++ b/src/test/denialofservice_tests.cpp
@@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
BOOST_AUTO_TEST_CASE(DoS_banning)
{
- auto banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr);
+ auto banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
auto connman = MakeUnique<CConnman>(0x1337, 0x1337);
auto peerLogic = MakeUnique<PeerLogicValidation>(connman.get(), banman.get(), scheduler, false);
@@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
BOOST_AUTO_TEST_CASE(DoS_banscore)
{
- auto banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr);
+ auto banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
auto connman = MakeUnique<CConnman>(0x1337, 0x1337);
auto peerLogic = MakeUnique<PeerLogicValidation>(connman.get(), banman.get(), scheduler, false);
@@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
BOOST_AUTO_TEST_CASE(DoS_bantime)
{
- auto banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr);
+ auto banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
auto connman = MakeUnique<CConnman>(0x1337, 0x1337);
auto peerLogic = MakeUnique<PeerLogicValidation>(connman.get(), banman.get(), scheduler, false);
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp
index 7bce74b46b..75bd8db67e 100644
--- a/src/test/test_bitcoin.cpp
+++ b/src/test/test_bitcoin.cpp
@@ -94,7 +94,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
for (int i=0; i < nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
- g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr);
+ g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
}