22 #include <validation.h> 27 #include <boost/test/unit_test.hpp> 36 BOOST_FIXTURE_TEST_SUITE(denialofservice_tests,
TestingSetup)
56 CNode dummyNode1{
id++,
84 LOCK(dummyNode1.cs_sendProcessing);
88 LOCK(dummyNode1.cs_vSend);
90 dummyNode1.vSendMsg.clear();
97 LOCK(dummyNode1.cs_sendProcessing);
101 LOCK(dummyNode1.cs_vSend);
107 LOCK(dummyNode1.cs_sendProcessing);
118 vNodes.emplace_back(
new CNode{
id++,
131 node.fSuccessfullyConnected =
true;
149 const auto time_init{GetTime<std::chrono::seconds>()};
151 const auto time_later{time_init + 3 * std::chrono::seconds{
m_node.
chainman->GetConsensus().nPowTargetSpacing} + 1s};
152 connman->Init(options);
153 std::vector<CNode *> vNodes;
156 for (
int i = 0; i < max_outbound_full_relay; ++i) {
160 peerLogic->CheckForStaleTipAndEvictPeers();
171 peerLogic->CheckForStaleTipAndEvictPeers();
186 peerLogic->CheckForStaleTipAndEvictPeers();
187 for (
int i = 0; i < max_outbound_full_relay; ++i) {
193 vNodes.back()->fDisconnect =
false;
197 peerLogic->UpdateLastBlockAnnounceTime(vNodes.back()->GetId(),
GetTime());
199 peerLogic->CheckForStaleTipAndEvictPeers();
200 for (
int i = 0; i < max_outbound_full_relay - 1; ++i) {
203 BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect ==
true);
207 peerLogic->FinalizeNode(*
node);
210 connman->ClearTestNodes();
227 connman->Init(options);
228 std::vector<CNode*> vNodes;
231 for (
int i = 0; i < max_outbound_block_relay; ++i) {
234 peerLogic->CheckForStaleTipAndEvictPeers();
236 for (
int i = 0; i < max_outbound_block_relay; ++i) {
242 peerLogic->CheckForStaleTipAndEvictPeers();
245 for (
int i = 0; i < max_outbound_block_relay; ++i) {
251 peerLogic->CheckForStaleTipAndEvictPeers();
252 for (
int i = 0; i < max_outbound_block_relay; ++i) {
259 vNodes.back()->fDisconnect =
false;
260 vNodes.back()->m_last_block_time = GetTime<std::chrono::seconds>();
262 peerLogic->CheckForStaleTipAndEvictPeers();
263 for (
int i = 0; i < max_outbound_block_relay - 1; ++i) {
266 BOOST_CHECK(vNodes[max_outbound_block_relay - 1]->fDisconnect ==
true);
270 peerLogic->FinalizeNode(*
node);
272 connman->ClearTestNodes();
284 tor_netaddr.SetSpecial(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
293 std::array<CNode*, 3> nodes;
295 banman->ClearBanned();
297 nodes[0] =
new CNode{
id++,
308 nodes[0]->fSuccessfullyConnected =
true;
309 connman->AddTestNode(*nodes[0]);
312 LOCK(nodes[0]->cs_sendProcessing);
319 nodes[1] =
new CNode{
id++,
330 nodes[1]->fSuccessfullyConnected =
true;
331 connman->AddTestNode(*nodes[1]);
334 LOCK(nodes[1]->cs_sendProcessing);
343 peerLogic->UnitTestMisbehaving(nodes[1]->GetId(), 1);
345 LOCK(nodes[1]->cs_sendProcessing);
356 nodes[2] =
new CNode{
id++,
367 nodes[2]->fSuccessfullyConnected =
true;
368 connman->AddTestNode(*nodes[2]);
371 LOCK(nodes[2]->cs_sendProcessing);
382 peerLogic->FinalizeNode(*
node);
384 connman->ClearTestNodes();
394 banman->ClearBanned();
395 int64_t nStartTime =
GetTime();
400 CNode dummyNode{
id++,
411 dummyNode.fSuccessfullyConnected =
true;
415 LOCK(dummyNode.cs_sendProcessing);
420 peerLogic->FinalizeNode(dummyNode);
int m_max_outbound_full_relay
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
void SetPeerConnectTimeout(std::chrono::seconds timeout)
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
ServiceFlags
nServices flags
Inbound connections are those initiated by a peer.
int m_max_outbound_block_relay
void TestOnlyResetTimeData()
Reset the internal state of GetTimeOffset(), GetAdjustedTime() and AddTimeData(). ...
std::unique_ptr< const NetGroupManager > netgroupman
std::unique_ptr< AddrMan > addrman
These are the default connections that we use to connect with the network.
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
uint16_t GetDefaultPort() const
std::unique_ptr< CTxMemPool > mempool
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
virtual void InitializeNode(CNode &node, ServiceFlags our_services)=0
Initialize a peer (setup state, queue any initial messages)
static const std::string addr1
A combination of a network address (CNetAddr) and a (TCP) port.
BOOST_AUTO_TEST_SUITE_END()
static void AddRandomOutboundPeer(NodeId &id, std::vector< CNode *> &vNodes, PeerManager &peerLogic, ConnmanTestMsg &connman, ConnectionType connType)
virtual void FinalizeNode(const CNode &node)=0
Handle removal of a peer (clear state)
A CService with information about it as peer.
static CService ip(uint32_t i)
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
static constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME
const CChainParams & Params()
Return the currently selected parameters.
void Handshake(CNode &node, bool successfully_connected, ServiceFlags remote_services, ServiceFlags local_services, int32_t version, bool relay_txs)
static const int PROTOCOL_VERSION
network protocol versioning
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
ConnectionType
Different types of connections to a peer.
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc)
std::unique_ptr< CConnman > connman
Information about a peer.
static constexpr auto MINIMUM_CONNECT_TIME
Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict...
int64_t GetTime()
DEPRECATED, see GetTime.
void AddTestNode(CNode &node)
std::unique_ptr< ChainstateManager > chainman
Testing setup that configures a complete environment.
We use block-relay-only connections to help prevent against partition attacks.
#define BOOST_CHECK(expr)
virtual bool SendMessages(CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode -> cs_sendProcessing)=0
Send queued protocol messages to a given node.
std::unique_ptr< PeerManager > peerman