Changeset View
Changeset View
Standalone View
Standalone View
src/test/denialofservice_tests.cpp
// Copyright (c) 2011-2019 The Bitcoin Core developers | // Copyright (c) 2011-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
// Unit tests for denial-of-service detection/prevention code | // Unit tests for denial-of-service detection/prevention code | ||||
#include <banman.h> | #include <banman.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <net_processing.h> | #include <net_processing.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <script/signingprovider.h> | #include <script/signingprovider.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <txorphanage.h> | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <test/util/net.h> | #include <test/util/net.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
Show All 14 Lines | void ClearNodes() { | ||||
} | } | ||||
vNodes.clear(); | vNodes.clear(); | ||||
} | } | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
// Tests these internal-to-net_processing.cpp methods: | // Tests these internal-to-net_processing.cpp methods: | ||||
extern bool AddOrphanTx(const CTransactionRef &tx, NodeId peer); | extern bool AddOrphanTx(const CTransactionRef &tx, NodeId peer); | ||||
extern void EraseOrphansFor(NodeId peer); | |||||
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); | |||||
struct COrphanTx { | |||||
CTransactionRef tx; | |||||
NodeId fromPeer; | |||||
int64_t nTimeExpire; | |||||
}; | |||||
extern std::map<uint256, COrphanTx> | |||||
mapOrphanTransactions GUARDED_BY(g_cs_orphans); | |||||
static CService ip(uint32_t i) { | static CService ip(uint32_t i) { | ||||
struct in_addr s; | struct in_addr s; | ||||
s.s_addr = i; | s.s_addr = i; | ||||
return CService(CNetAddr(s), Params().GetDefaultPort()); | return CService(CNetAddr(s), Params().GetDefaultPort()); | ||||
} | } | ||||
static NodeId id = 0; | static NodeId id = 0; | ||||
▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(DoS_bantime) { | ||||
} | } | ||||
BOOST_CHECK(banman->IsDiscouraged(addr)); | BOOST_CHECK(banman->IsDiscouraged(addr)); | ||||
bool dummy; | bool dummy; | ||||
peerLogic->FinalizeNode(config, dummyNode, dummy); | peerLogic->FinalizeNode(config, dummyNode, dummy); | ||||
} | } | ||||
static CTransactionRef RandomOrphan() { | static CTransactionRef RandomOrphan() { | ||||
std::map<uint256, COrphanTx>::iterator it; | std::map<TxId, COrphanTx>::iterator it; | ||||
LOCK2(cs_main, g_cs_orphans); | LOCK2(cs_main, g_cs_orphans); | ||||
it = mapOrphanTransactions.lower_bound(InsecureRand256()); | it = mapOrphanTransactions.lower_bound(TxId{InsecureRand256()}); | ||||
if (it == mapOrphanTransactions.end()) { | if (it == mapOrphanTransactions.end()) { | ||||
it = mapOrphanTransactions.begin(); | it = mapOrphanTransactions.begin(); | ||||
} | } | ||||
return it->second.tx; | return it->second.tx; | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(DoS_mapOrphans) { | BOOST_AUTO_TEST_CASE(DoS_mapOrphans) { | ||||
CKey key; | CKey key; | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |