Changeset View
Changeset View
Standalone View
Standalone View
src/test/denialofservice_tests.cpp
Show All 27 Lines | |||||
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); | extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); | ||||
struct COrphanTx { | struct COrphanTx { | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
NodeId fromPeer; | NodeId fromPeer; | ||||
int64_t nTimeExpire; | int64_t nTimeExpire; | ||||
}; | }; | ||||
extern std::map<uint256, COrphanTx> mapOrphanTransactions; | extern std::map<uint256, COrphanTx> mapOrphanTransactions; | ||||
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; | ||||
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds); | void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds); | ||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(DoS_bantime) { | ||||
SetMockTime(nStartTime + 60 * 60 * 24 + 1); | SetMockTime(nStartTime + 60 * 60 * 24 + 1); | ||||
BOOST_CHECK(!connman->IsBanned(addr)); | BOOST_CHECK(!connman->IsBanned(addr)); | ||||
bool dummy; | bool dummy; | ||||
peerLogic->FinalizeNode(config, dummyNode.GetId(), dummy); | peerLogic->FinalizeNode(config, dummyNode.GetId(), dummy); | ||||
} | } | ||||
CTransactionRef RandomOrphan() { | static CTransactionRef RandomOrphan() { | ||||
std::map<uint256, COrphanTx>::iterator it; | std::map<uint256, COrphanTx>::iterator it; | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
it = mapOrphanTransactions.lower_bound(InsecureRand256()); | it = mapOrphanTransactions.lower_bound(InsecureRand256()); | ||||
if (it == mapOrphanTransactions.end()) { | if (it == mapOrphanTransactions.end()) { | ||||
it = mapOrphanTransactions.begin(); | it = mapOrphanTransactions.begin(); | ||||
} | } | ||||
return it->second.tx; | return it->second.tx; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |