Bitcoin Core  22.99.0
P2P Digital Currency
denialofservice_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 // Unit tests for denial-of-service detection/prevention code
6 
7 #include <arith_uint256.h>
8 #include <banman.h>
9 #include <chainparams.h>
10 #include <net.h>
11 #include <net_processing.h>
12 #include <pubkey.h>
13 #include <script/sign.h>
14 #include <script/signingprovider.h>
15 #include <script/standard.h>
16 #include <serialize.h>
17 #include <test/util/net.h>
18 #include <test/util/setup_common.h>
19 #include <txorphanage.h>
20 #include <util/string.h>
21 #include <util/system.h>
22 #include <util/time.h>
23 #include <validation.h>
24 
25 #include <array>
26 #include <stdint.h>
27 
28 #include <boost/test/unit_test.hpp>
29 
30 static CService ip(uint32_t i)
31 {
32  struct in_addr s;
33  s.s_addr = i;
34  return CService(CNetAddr(s), Params().GetDefaultPort());
35 }
36 
37 static NodeId id = 0;
38 
39 void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds);
40 
41 BOOST_FIXTURE_TEST_SUITE(denialofservice_tests, TestingSetup)
42 
43 // Test eviction of an outbound peer whose chain never advances
44 // Mock a node connection, and use mocktime to simulate a peer
45 // which never sends any headers messages. PeerLogic should
46 // decide to evict that outbound peer, after the appropriate timeouts.
47 // Note that we protect 4 outbound nodes from being subject to
48 // this logic; this test takes advantage of that protection only
49 // being applied to nodes which send headers with sufficient
50 // work.
51 BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
52 {
53  const CChainParams& chainparams = Params();
54  auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
55  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
56  *m_node.chainman, *m_node.mempool, false);
57 
58  // Mock an outbound peer
59  CAddress addr1(ip(0xa0b0c001), NODE_NONE);
60  CNode dummyNode1(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr1, /* nKeyedNetGroupIn */ 0, /* nLocalHostNonceIn */ 0, CAddress(), /* pszDest */ "", ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false);
62 
63  peerLogic->InitializeNode(&dummyNode1);
64  dummyNode1.fSuccessfullyConnected = true;
65 
66  // This test requires that we have a chain with non-zero work.
67  {
68  LOCK(cs_main);
69  BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr);
70  BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0);
71  }
72 
73  // Test starts here
74  {
75  LOCK(dummyNode1.cs_sendProcessing);
76  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
77  }
78  {
79  LOCK(dummyNode1.cs_vSend);
80  BOOST_CHECK(dummyNode1.vSendMsg.size() > 0);
81  dummyNode1.vSendMsg.clear();
82  }
83 
84  int64_t nStartTime = GetTime();
85  // Wait 21 minutes
86  SetMockTime(nStartTime+21*60);
87  {
88  LOCK(dummyNode1.cs_sendProcessing);
89  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
90  }
91  {
92  LOCK(dummyNode1.cs_vSend);
93  BOOST_CHECK(dummyNode1.vSendMsg.size() > 0);
94  }
95  // Wait 3 more minutes
96  SetMockTime(nStartTime+24*60);
97  {
98  LOCK(dummyNode1.cs_sendProcessing);
99  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in disconnect
100  }
101  BOOST_CHECK(dummyNode1.fDisconnect == true);
102 
103  peerLogic->FinalizeNode(dummyNode1);
104 }
105 
106 static void AddRandomOutboundPeer(std::vector<CNode*>& vNodes, PeerManager& peerLogic, ConnmanTestMsg& connman)
107 {
109  vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr, /* nKeyedNetGroupIn */ 0, /* nLocalHostNonceIn */ 0, CAddress(), /* pszDest */ "", ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false));
110  CNode &node = *vNodes.back();
111  node.SetCommonVersion(PROTOCOL_VERSION);
112 
113  peerLogic.InitializeNode(&node);
114  node.fSuccessfullyConnected = true;
115 
116  connman.AddTestNode(node);
117 }
118 
119 BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
120 {
121  const CChainParams& chainparams = Params();
122  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
123  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
124  *m_node.chainman, *m_node.mempool, false);
125 
126  constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
127  CConnman::Options options;
129  options.m_max_outbound_full_relay = max_outbound_full_relay;
131 
132  connman->Init(options);
133  std::vector<CNode *> vNodes;
134 
135  // Mock some outbound peers
136  for (int i = 0; i < max_outbound_full_relay; ++i) {
137  AddRandomOutboundPeer(vNodes, *peerLogic, *connman);
138  }
139 
140  peerLogic->CheckForStaleTipAndEvictPeers();
141 
142  // No nodes should be marked for disconnection while we have no extra peers
143  for (const CNode *node : vNodes) {
144  BOOST_CHECK(node->fDisconnect == false);
145  }
146 
147  SetMockTime(GetTime() + 3 * chainparams.GetConsensus().nPowTargetSpacing + 1);
148 
149  // Now tip should definitely be stale, and we should look for an extra
150  // outbound peer
151  peerLogic->CheckForStaleTipAndEvictPeers();
152  BOOST_CHECK(connman->GetTryNewOutboundPeer());
153 
154  // Still no peers should be marked for disconnection
155  for (const CNode *node : vNodes) {
156  BOOST_CHECK(node->fDisconnect == false);
157  }
158 
159  // If we add one more peer, something should get marked for eviction
160  // on the next check (since we're mocking the time to be in the future, the
161  // required time connected check should be satisfied).
162  AddRandomOutboundPeer(vNodes, *peerLogic, *connman);
163 
164  peerLogic->CheckForStaleTipAndEvictPeers();
165  for (int i = 0; i < max_outbound_full_relay; ++i) {
166  BOOST_CHECK(vNodes[i]->fDisconnect == false);
167  }
168  // Last added node should get marked for eviction
169  BOOST_CHECK(vNodes.back()->fDisconnect == true);
170 
171  vNodes.back()->fDisconnect = false;
172 
173  // Update the last announced block time for the last
174  // peer, and check that the next newest node gets evicted.
175  UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), GetTime());
176 
177  peerLogic->CheckForStaleTipAndEvictPeers();
178  for (int i = 0; i < max_outbound_full_relay - 1; ++i) {
179  BOOST_CHECK(vNodes[i]->fDisconnect == false);
180  }
181  BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true);
182  BOOST_CHECK(vNodes.back()->fDisconnect == false);
183 
184  for (const CNode *node : vNodes) {
185  peerLogic->FinalizeNode(*node);
186  }
187 
188  connman->ClearTestNodes();
189 }
190 
191 BOOST_AUTO_TEST_CASE(peer_discouragement)
192 {
193  const CChainParams& chainparams = Params();
194  auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
195  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
196  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
197  *m_node.chainman, *m_node.mempool, false);
198 
199  CNetAddr tor_netaddr;
200  BOOST_REQUIRE(
201  tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
202  const CService tor_service{tor_netaddr, Params().GetDefaultPort()};
203 
204  const std::array<CAddress, 3> addr{CAddress{ip(0xa0b0c001), NODE_NONE},
205  CAddress{ip(0xa0b0c002), NODE_NONE},
206  CAddress{tor_service, NODE_NONE}};
207 
208  const CNetAddr other_addr{ip(0xa0b0ff01)}; // Not any of addr[].
209 
210  std::array<CNode*, 3> nodes;
211 
212  banman->ClearBanned();
213  nodes[0] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[0], /* nKeyedNetGroupIn */ 0,
214  /* nLocalHostNonceIn */ 0, CAddress(), /* pszDest */ "",
215  ConnectionType::INBOUND, /* inbound_onion */ false};
216  nodes[0]->SetCommonVersion(PROTOCOL_VERSION);
217  peerLogic->InitializeNode(nodes[0]);
218  nodes[0]->fSuccessfullyConnected = true;
219  connman->AddTestNode(*nodes[0]);
220  peerLogic->Misbehaving(nodes[0]->GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ ""); // Should be discouraged
221  {
222  LOCK(nodes[0]->cs_sendProcessing);
223  BOOST_CHECK(peerLogic->SendMessages(nodes[0]));
224  }
225  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
226  BOOST_CHECK(nodes[0]->fDisconnect);
227  BOOST_CHECK(!banman->IsDiscouraged(other_addr)); // Different address, not discouraged
228 
229  nodes[1] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[1], /* nKeyedNetGroupIn */ 1,
230  /* nLocalHostNonceIn */ 1, CAddress(), /* pszDest */ "",
231  ConnectionType::INBOUND, /* inbound_onion */ false};
232  nodes[1]->SetCommonVersion(PROTOCOL_VERSION);
233  peerLogic->InitializeNode(nodes[1]);
234  nodes[1]->fSuccessfullyConnected = true;
235  connman->AddTestNode(*nodes[1]);
236  peerLogic->Misbehaving(nodes[1]->GetId(), DISCOURAGEMENT_THRESHOLD - 1, /* message */ "");
237  {
238  LOCK(nodes[1]->cs_sendProcessing);
239  BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
240  }
241  // [0] is still discouraged/disconnected.
242  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
243  BOOST_CHECK(nodes[0]->fDisconnect);
244  // [1] is not discouraged/disconnected yet.
245  BOOST_CHECK(!banman->IsDiscouraged(addr[1]));
246  BOOST_CHECK(!nodes[1]->fDisconnect);
247  peerLogic->Misbehaving(nodes[1]->GetId(), 1, /* message */ ""); // [1] reaches discouragement threshold
248  {
249  LOCK(nodes[1]->cs_sendProcessing);
250  BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
251  }
252  // Expect both [0] and [1] to be discouraged/disconnected now.
253  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
254  BOOST_CHECK(nodes[0]->fDisconnect);
255  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
256  BOOST_CHECK(nodes[1]->fDisconnect);
257 
258  // Make sure non-IP peers are discouraged and disconnected properly.
259 
260  nodes[2] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[2], /* nKeyedNetGroupIn */ 1,
261  /* nLocalHostNonceIn */ 1, CAddress(), /* pszDest */ "",
262  ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false};
263  nodes[2]->SetCommonVersion(PROTOCOL_VERSION);
264  peerLogic->InitializeNode(nodes[2]);
265  nodes[2]->fSuccessfullyConnected = true;
266  connman->AddTestNode(*nodes[2]);
267  peerLogic->Misbehaving(nodes[2]->GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ "");
268  {
269  LOCK(nodes[2]->cs_sendProcessing);
270  BOOST_CHECK(peerLogic->SendMessages(nodes[2]));
271  }
272  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
273  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
274  BOOST_CHECK(banman->IsDiscouraged(addr[2]));
275  BOOST_CHECK(nodes[0]->fDisconnect);
276  BOOST_CHECK(nodes[1]->fDisconnect);
277  BOOST_CHECK(nodes[2]->fDisconnect);
278 
279  for (CNode* node : nodes) {
280  peerLogic->FinalizeNode(*node);
281  }
282  connman->ClearTestNodes();
283 }
284 
286 {
287  const CChainParams& chainparams = Params();
288  auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
289  auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
290  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
291  *m_node.chainman, *m_node.mempool, false);
292 
293  banman->ClearBanned();
294  int64_t nStartTime = GetTime();
295  SetMockTime(nStartTime); // Overrides future calls to GetTime()
296 
297  CAddress addr(ip(0xa0b0c001), NODE_NONE);
298  CNode dummyNode(id++, NODE_NETWORK, INVALID_SOCKET, addr, /* nKeyedNetGroupIn */ 4, /* nLocalHostNonceIn */ 4, CAddress(), /* pszDest */ "", ConnectionType::INBOUND, /* inbound_onion */ false);
300  peerLogic->InitializeNode(&dummyNode);
301  dummyNode.fSuccessfullyConnected = true;
302 
303  peerLogic->Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ "");
304  {
305  LOCK(dummyNode.cs_sendProcessing);
306  BOOST_CHECK(peerLogic->SendMessages(&dummyNode));
307  }
308  BOOST_CHECK(banman->IsDiscouraged(addr));
309 
310  peerLogic->FinalizeNode(dummyNode);
311 }
312 
314 {
315 public:
317  {
318  return m_orphans.size();
319  }
320 
322  {
323  std::map<uint256, OrphanTx>::iterator it;
324  it = m_orphans.lower_bound(InsecureRand256());
325  if (it == m_orphans.end())
326  it = m_orphans.begin();
327  return it->second.tx;
328  }
329 };
330 
332 {
333  std::vector<unsigned char> keydata;
334  keydata = g_insecure_rand_ctx.randbytes(32);
335  key.Set(keydata.data(), keydata.data() + keydata.size(), /*fCompressedIn*/ true);
336  assert(key.IsValid());
337 }
338 
339 BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
340 {
341  // This test had non-deterministic coverage due to
342  // randomly selected seeds.
343  // This seed is chosen so that all branches of the function
344  // ecdsa_signature_parse_der_lax are executed during this test.
345  // Specifically branches that run only when an ECDSA
346  // signature's R and S values have leading zeros.
348 
349  TxOrphanageTest orphanage;
350  CKey key;
352  FillableSigningProvider keystore;
353  BOOST_CHECK(keystore.AddKey(key));
354 
356 
357  // 50 orphan transactions:
358  for (int i = 0; i < 50; i++)
359  {
361  tx.vin.resize(1);
362  tx.vin[0].prevout.n = 0;
363  tx.vin[0].prevout.hash = InsecureRand256();
364  tx.vin[0].scriptSig << OP_1;
365  tx.vout.resize(1);
366  tx.vout[0].nValue = 1*CENT;
367  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
368 
369  orphanage.AddTx(MakeTransactionRef(tx), i);
370  }
371 
372  // ... and 50 that depend on other orphans:
373  for (int i = 0; i < 50; i++)
374  {
375  CTransactionRef txPrev = orphanage.RandomOrphan();
376 
378  tx.vin.resize(1);
379  tx.vin[0].prevout.n = 0;
380  tx.vin[0].prevout.hash = txPrev->GetHash();
381  tx.vout.resize(1);
382  tx.vout[0].nValue = 1*CENT;
383  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
384  BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
385 
386  orphanage.AddTx(MakeTransactionRef(tx), i);
387  }
388 
389  // This really-big orphan should be ignored:
390  for (int i = 0; i < 10; i++)
391  {
392  CTransactionRef txPrev = orphanage.RandomOrphan();
393 
395  tx.vout.resize(1);
396  tx.vout[0].nValue = 1*CENT;
397  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
398  tx.vin.resize(2777);
399  for (unsigned int j = 0; j < tx.vin.size(); j++)
400  {
401  tx.vin[j].prevout.n = j;
402  tx.vin[j].prevout.hash = txPrev->GetHash();
403  }
404  BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
405  // Re-use same signature for other inputs
406  // (they don't have to be valid for this test)
407  for (unsigned int j = 1; j < tx.vin.size(); j++)
408  tx.vin[j].scriptSig = tx.vin[0].scriptSig;
409 
410  BOOST_CHECK(!orphanage.AddTx(MakeTransactionRef(tx), i));
411  }
412 
413  // Test EraseOrphansFor:
414  for (NodeId i = 0; i < 3; i++)
415  {
416  size_t sizeBefore = orphanage.CountOrphans();
417  orphanage.EraseForPeer(i);
418  BOOST_CHECK(orphanage.CountOrphans() < sizeBefore);
419  }
420 
421  // Test LimitOrphanTxSize() function:
422  orphanage.LimitOrphans(40);
423  BOOST_CHECK(orphanage.CountOrphans() <= 40);
424  orphanage.LimitOrphans(10);
425  BOOST_CHECK(orphanage.CountOrphans() <= 10);
426  orphanage.LimitOrphans(0);
427  BOOST_CHECK(orphanage.CountOrphans() == 0);
428 }
429 
NodeId
int64_t NodeId
Definition: net.h:87
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:539
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:346
arith_uint256.h
assert
assert(!tx.IsCoinBase())
CNode::cs_vSend
Mutex cs_vSend
Definition: net.h:411
CNode::GetId
NodeId GetId() const
Definition: net.h:585
g_insecure_rand_ctx
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
Definition: setup_common.cpp:46
setup_common.h
MakeNewKeyWithFastRandomContext
static void MakeNewKeyWithFastRandomContext(CKey &key)
Definition: denialofservice_tests.cpp:331
NodeContext::mempool
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:44
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition: signingprovider.h:91
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:351
string.h
CNetAddr
Network address.
Definition: netaddress.h:118
arith_uint256
256-bit unsigned big integer.
Definition: arith_uint256.h:250
DEFAULT_MAX_PEER_CONNECTIONS
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:71
InsecureRand256
static uint256 InsecureRand256()
Definition: setup_common.h:66
CKey::Set
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:73
ConnectionType::OUTBOUND_FULL_RELAY
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
m_node
NodeContext & m_node
Definition: bitcoin-node.cpp:38
CNode
Information about a peer.
Definition: net.h:393
UpdateLastBlockAnnounceTime
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
Definition: net_processing.cpp:1141
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
GetTime
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:26
FastRandomContext::randbytes
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
Definition: random.cpp:626
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:387
TxOrphanageTest
Definition: denialofservice_tests.cpp:313
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
ServiceFlags
ServiceFlags
nServices flags
Definition: protocol.h:271
NODE_NETWORK
@ NODE_NETWORK
Definition: protocol.h:277
pubkey.h
chainparams.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
TxOrphanage::LimitOrphans
void EraseForBlock(const CBlock &block) LOCKS_EXCLUDED(unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans included in or invalidated by a new block.
Definition: txorphanage.h:44
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
PeerManager::make
static std::unique_ptr< PeerManager > make(const CChainParams &chainparams, CConnman &connman, CAddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
Definition: net_processing.cpp:1422
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
CNode::fDisconnect
std::atomic_bool fDisconnect
Definition: net.h:452
FillableSigningProvider::AddKey
virtual bool AddKey(const CKey &key)
Definition: signingprovider.h:152
FastRandomContext::randbits
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Definition: random.h:172
ConnmanTestMsg
Definition: net.h:18
Consensus::Params::nPowTargetSpacing
int64_t nPowTargetSpacing
Definition: params.h:103
CNode::SetCommonVersion
void SetCommonVersion(int greatest_common_version)
Definition: net.h:610
signingprovider.h
OP_1
@ OP_1
Definition: script.h:76
ConnmanTestMsg::AddTestNode
void AddTestNode(CNode &node)
Definition: net.h:20
NetEventsInterface::InitializeNode
virtual void InitializeNode(CNode *pnode)=0
Initialize a peer (setup state, queue any initial messages)
ConnectionType::INBOUND
@ INBOUND
Inbound connections are those initiated by a peer.
MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:61
AddRandomOutboundPeer
static void AddRandomOutboundPeer(std::vector< CNode * > &vNodes, PeerManager &peerLogic, ConnmanTestMsg &connman)
Definition: denialofservice_tests.cpp:106
banman.h
INVALID_SOCKET
#define INVALID_SOCKET
Definition: compat.h:53
CNetAddr::SetSpecial
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
SignSignature
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType)
Produce a script signature for a transaction.
Definition: sign.cpp:513
ip
static CService ip(uint32_t i)
Definition: denialofservice_tests.cpp:30
net.h
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:101
CNode::fSuccessfullyConnected
std::atomic_bool fSuccessfullyConnected
fSuccessfullyConnected is set to true on receiving VERACK from the peer.
Definition: net.h:449
CENT
static constexpr CAmount CENT
Definition: setup_common.h:71
time.h
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:92
sign.h
standard.h
PeerManager
Definition: net_processing.h:37
NodeContext::addrman
std::unique_ptr< CAddrMan > addrman
Definition: context.h:42
TxOrphanageTest::RandomOrphan
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Definition: denialofservice_tests.cpp:321
MAX_FEELER_CONNECTIONS
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:67
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:187
addr1
static const std::string addr1
Definition: key_tests.cpp:24
net_processing.h
CConnman::Options
Definition: net.h:744
CConnman::Options::nMaxConnections
int nMaxConnections
Definition: net.h:747
NODE_NONE
@ NODE_NONE
Definition: protocol.h:274
NODE_WITNESS
@ NODE_WITNESS
Definition: protocol.h:284
system.h
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:347
PKHash
Definition: standard.h:79
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
Definition: denialofservice_tests.cpp:51
SIGHASH_ALL
@ SIGHASH_ALL
Definition: interpreter.h:27
CConnman::Options::nMaxFeeler
int nMaxFeeler
Definition: net.h:751
CNode::cs_sendProcessing
RecursiveMutex cs_sendProcessing
Definition: net.h:419
CAddress
A CService with information about it as peer.
Definition: protocol.h:358
CKey
An encapsulated private key.
Definition: key.h:26
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:116
NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:47
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
LOCK
#define LOCK(cs)
Definition: sync.h:226
DEFAULT_MISBEHAVING_BANTIME
static constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME
Definition: banman.h:19
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:536
DISCOURAGEMENT_THRESHOLD
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
Definition: net_processing.h:24
TestingSetup
Testing setup that configures a complete environment.
Definition: setup_common.h:99
TxOrphanageTest::CountOrphans
size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Definition: denialofservice_tests.cpp:316
node
Definition: interfaces.cpp:68
serialize.h
TxOrphanage::AddTx
bool AddTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add a new orphan transaction.
Definition: txorphanage.cpp:20
CConnman::Options::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:748
TxOrphanage
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
Definition: txorphanage.h:21
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:344
TxOrphanage::EraseForPeer
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans announced by a peer (eg, after that peer disconnects)
Definition: txorphanage.cpp:88
txorphanage.h
g_cs_orphans
RecursiveMutex g_cs_orphans
Guards orphan transactions and extra txs for compact blocks.
Definition: txorphanage.cpp:18
FastRandomContext
Fast randomness source.
Definition: random.h:119
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition: object.cpp:17
ArithToUint256
uint256 ArithToUint256(const arith_uint256 &a)
Definition: arith_uint256.cpp:246
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
CChainParams::GetDefaultPort
uint16_t GetDefaultPort() const
Definition: chainparams.h:84