Changeset View
Changeset View
Standalone View
Standalone View
src/test/denialofservice_tests.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
// 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 = std::make_unique<PeerLogicValidation>( | ||||
*connman, nullptr, *m_node.scheduler, *m_node.chainman, | config.GetChainParams(), *connman, nullptr, *m_node.scheduler, | ||||
*m_node.mempool); | *m_node.chainman, *m_node.mempool); | ||||
// 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, 0, CAddress(), "", ConnectionType::OUTBOUND); | 0, 0, 0, CAddress(), "", ConnectionType::OUTBOUND); | ||||
dummyNode1.SetSendVersion(PROTOCOL_VERSION); | dummyNode1.SetSendVersion(PROTOCOL_VERSION); | ||||
peerLogic->InitializeNode(config, &dummyNode1); | peerLogic->InitializeNode(config, &dummyNode1); | ||||
▲ 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 = std::make_unique<PeerLogicValidation>( | ||||
*connman, nullptr, *m_node.scheduler, *m_node.chainman, | config.GetChainParams(), *connman, nullptr, *m_node.scheduler, | ||||
*m_node.mempool); | *m_node.chainman, *m_node.mempool); | ||||
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 62 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(peer_discouragement) { | ||||
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 = std::make_unique<PeerLogicValidation>( | ||||
*connman, banman.get(), *m_node.scheduler, *m_node.chainman, | config.GetChainParams(), *connman, banman.get(), *m_node.scheduler, | ||||
*m_node.mempool); | *m_node.chainman, *m_node.mempool); | ||||
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, 0, | CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 0, 0, 0, | ||||
CAddress(), "", ConnectionType::INBOUND); | CAddress(), "", ConnectionType::INBOUND); | ||||
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 45 Lines • ▼ Show 20 Lines | 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 = std::make_unique<PeerLogicValidation>( | ||||
*connman, banman.get(), *m_node.scheduler, *m_node.chainman, | config.GetChainParams(), *connman, banman.get(), *m_node.scheduler, | ||||
*m_node.mempool); | *m_node.chainman, *m_node.mempool); | ||||
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, 4, | CNode dummyNode(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr, 4, 4, 4, | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |