Changeset View
Changeset View
Standalone View
Standalone View
src/test/denialofservice_tests.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
// Note that we protect 4 outbound nodes from being subject to this logic; this | // Note that we protect 4 outbound nodes from being subject to this logic; this | ||||
// test takes advantage of that protection only being applied to nodes which | // test takes advantage of that protection only being applied to nodes which | ||||
// send headers with sufficient work. | // send headers with sufficient work. | ||||
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) { | BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) { | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
std::atomic<bool> interruptDummy(false); | std::atomic<bool> interruptDummy(false); | ||||
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = | ||||
connman.get(), nullptr, *m_node.scheduler); | std::make_unique<PeerLogicValidation>(connman.get(), nullptr); | ||||
// Mock an outbound peer | // Mock an outbound peer | ||||
CAddress addr1(ip(0xa0b0c001), NODE_NONE); | CAddress addr1(ip(0xa0b0c001), NODE_NONE); | ||||
CNode dummyNode1(id++, ServiceFlags(NODE_NETWORK), 0, INVALID_SOCKET, addr1, | CNode dummyNode1(id++, ServiceFlags(NODE_NETWORK), 0, INVALID_SOCKET, addr1, | ||||
0, 0, CAddress(), "", | 0, 0, CAddress(), "", | ||||
/*fInboundIn=*/false); | /*fInboundIn=*/false); | ||||
dummyNode1.SetSendVersion(PROTOCOL_VERSION); | dummyNode1.SetSendVersion(PROTOCOL_VERSION); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | static void AddRandomOutboundPeer(const Config &config, | ||||
connman->AddNode(node); | connman->AddNode(node); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(stale_tip_peer_management) { | BOOST_AUTO_TEST_CASE(stale_tip_peer_management) { | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = | ||||
connman.get(), nullptr, *m_node.scheduler); | std::make_unique<PeerLogicValidation>(connman.get(), nullptr); | ||||
const Consensus::Params &consensusParams = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | config.GetChainParams().GetConsensus(); | ||||
constexpr int max_outbound_full_relay = 8; | constexpr int max_outbound_full_relay = 8; | ||||
CConnman::Options options; | CConnman::Options options; | ||||
options.nMaxConnections = 125; | options.nMaxConnections = 125; | ||||
options.m_max_outbound_full_relay = max_outbound_full_relay; | options.m_max_outbound_full_relay = max_outbound_full_relay; | ||||
options.nMaxFeeler = 1; | options.nMaxFeeler = 1; | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
BOOST_AUTO_TEST_CASE(DoS_banning) { | BOOST_AUTO_TEST_CASE(DoS_banning) { | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
std::atomic<bool> interruptDummy(false); | std::atomic<bool> interruptDummy(false); | ||||
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", | auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", | ||||
config.GetChainParams(), nullptr, | config.GetChainParams(), nullptr, | ||||
DEFAULT_MISBEHAVING_BANTIME); | DEFAULT_MISBEHAVING_BANTIME); | ||||
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = | ||||
connman.get(), banman.get(), *m_node.scheduler); | std::make_unique<PeerLogicValidation>(connman.get(), banman.get()); | ||||
banman->ClearBanned(); | banman->ClearBanned(); | ||||
CAddress addr1(ip(0xa0b0c001), NODE_NONE); | CAddress addr1(ip(0xa0b0c001), NODE_NONE); | ||||
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 0, 0, | CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 0, 0, | ||||
CAddress(), "", true); | CAddress(), "", true); | ||||
dummyNode1.SetSendVersion(PROTOCOL_VERSION); | dummyNode1.SetSendVersion(PROTOCOL_VERSION); | ||||
peerLogic->InitializeNode(config, &dummyNode1); | peerLogic->InitializeNode(config, &dummyNode1); | ||||
dummyNode1.nVersion = 1; | dummyNode1.nVersion = 1; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
BOOST_AUTO_TEST_CASE(DoS_banscore) { | BOOST_AUTO_TEST_CASE(DoS_banscore) { | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
std::atomic<bool> interruptDummy(false); | std::atomic<bool> interruptDummy(false); | ||||
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", | auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", | ||||
config.GetChainParams(), nullptr, | config.GetChainParams(), nullptr, | ||||
DEFAULT_MISBEHAVING_BANTIME); | DEFAULT_MISBEHAVING_BANTIME); | ||||
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = | ||||
connman.get(), banman.get(), *m_node.scheduler); | std::make_unique<PeerLogicValidation>(connman.get(), banman.get()); | ||||
banman->ClearBanned(); | banman->ClearBanned(); | ||||
// because 11 is my favorite number. | // because 11 is my favorite number. | ||||
gArgs.ForceSetArg("-banscore", "111"); | gArgs.ForceSetArg("-banscore", "111"); | ||||
CAddress addr1(ip(0xa0b0c001), NODE_NONE); | CAddress addr1(ip(0xa0b0c001), NODE_NONE); | ||||
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, | CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, | ||||
CAddress(), "", true); | CAddress(), "", true); | ||||
dummyNode1.SetSendVersion(PROTOCOL_VERSION); | dummyNode1.SetSendVersion(PROTOCOL_VERSION); | ||||
Show All 39 Lines | |||||
BOOST_AUTO_TEST_CASE(DoS_bantime) { | BOOST_AUTO_TEST_CASE(DoS_bantime) { | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
std::atomic<bool> interruptDummy(false); | std::atomic<bool> interruptDummy(false); | ||||
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", | auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", | ||||
config.GetChainParams(), nullptr, | config.GetChainParams(), nullptr, | ||||
DEFAULT_MISBEHAVING_BANTIME); | DEFAULT_MISBEHAVING_BANTIME); | ||||
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = | ||||
connman.get(), banman.get(), *m_node.scheduler); | std::make_unique<PeerLogicValidation>(connman.get(), banman.get()); | ||||
banman->ClearBanned(); | banman->ClearBanned(); | ||||
int64_t nStartTime = GetTime(); | int64_t nStartTime = GetTime(); | ||||
// Overrides future calls to GetTime() | // Overrides future calls to GetTime() | ||||
SetMockTime(nStartTime); | SetMockTime(nStartTime); | ||||
CAddress addr(ip(0xa0b0c001), NODE_NONE); | CAddress addr(ip(0xa0b0c001), NODE_NONE); | ||||
CNode dummyNode(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr, 4, 4, | CNode dummyNode(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr, 4, 4, | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |