Bitcoin Core  22.99.0
P2P Digital Currency
denialofservice_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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  // Disable inactivity checks for this test to avoid interference
56  static_cast<ConnmanTestMsg*>(connman.get())->SetPeerConnectTimeout(99999s);
57  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
58  *m_node.chainman, *m_node.mempool, false);
59 
60  // Mock an outbound peer
61  CAddress addr1(ip(0xa0b0c001), NODE_NONE);
62  CNode dummyNode1(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr1, /*nKeyedNetGroupIn=*/0, /*nLocalHostNonceIn=*/0, CAddress(), /*addrNameIn=*/"", ConnectionType::OUTBOUND_FULL_RELAY, /*inbound_onion=*/false);
64 
65  peerLogic->InitializeNode(&dummyNode1);
66  dummyNode1.fSuccessfullyConnected = true;
67 
68  // This test requires that we have a chain with non-zero work.
69  {
70  LOCK(cs_main);
71  BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr);
72  BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0);
73  }
74 
75  // Test starts here
76  {
77  LOCK(dummyNode1.cs_sendProcessing);
78  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
79  }
80  {
81  LOCK(dummyNode1.cs_vSend);
82  BOOST_CHECK(dummyNode1.vSendMsg.size() > 0);
83  dummyNode1.vSendMsg.clear();
84  }
85 
86  int64_t nStartTime = GetTime();
87  // Wait 21 minutes
88  SetMockTime(nStartTime+21*60);
89  {
90  LOCK(dummyNode1.cs_sendProcessing);
91  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
92  }
93  {
94  LOCK(dummyNode1.cs_vSend);
95  BOOST_CHECK(dummyNode1.vSendMsg.size() > 0);
96  }
97  // Wait 3 more minutes
98  SetMockTime(nStartTime+24*60);
99  {
100  LOCK(dummyNode1.cs_sendProcessing);
101  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in disconnect
102  }
103  BOOST_CHECK(dummyNode1.fDisconnect == true);
104 
105  peerLogic->FinalizeNode(dummyNode1);
106 }
107 
108 static void AddRandomOutboundPeer(std::vector<CNode*>& vNodes, PeerManager& peerLogic, ConnmanTestMsg& connman, ConnectionType connType)
109 {
111  vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr, /*nKeyedNetGroupIn=*/0, /*nLocalHostNonceIn=*/0, CAddress(), /*addrNameIn=*/"", connType, /*inbound_onion=*/false));
112  CNode &node = *vNodes.back();
113  node.SetCommonVersion(PROTOCOL_VERSION);
114 
115  peerLogic.InitializeNode(&node);
116  node.fSuccessfullyConnected = true;
117 
118  connman.AddTestNode(node);
119 }
120 
121 BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
122 {
123  const CChainParams& chainparams = Params();
124  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
125  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
126  *m_node.chainman, *m_node.mempool, false);
127 
128  constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
129  CConnman::Options options;
131  options.m_max_outbound_full_relay = max_outbound_full_relay;
133 
134  const auto time_init{GetTime<std::chrono::seconds>()};
135  SetMockTime(time_init);
136  const auto time_later{time_init + 3 * std::chrono::seconds{chainparams.GetConsensus().nPowTargetSpacing} + 1s};
137  connman->Init(options);
138  std::vector<CNode *> vNodes;
139 
140  // Mock some outbound peers
141  for (int i = 0; i < max_outbound_full_relay; ++i) {
142  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
143  }
144 
145  peerLogic->CheckForStaleTipAndEvictPeers();
146 
147  // No nodes should be marked for disconnection while we have no extra peers
148  for (const CNode *node : vNodes) {
149  BOOST_CHECK(node->fDisconnect == false);
150  }
151 
152  SetMockTime(time_later);
153 
154  // Now tip should definitely be stale, and we should look for an extra
155  // outbound peer
156  peerLogic->CheckForStaleTipAndEvictPeers();
157  BOOST_CHECK(connman->GetTryNewOutboundPeer());
158 
159  // Still no peers should be marked for disconnection
160  for (const CNode *node : vNodes) {
161  BOOST_CHECK(node->fDisconnect == false);
162  }
163 
164  // If we add one more peer, something should get marked for eviction
165  // on the next check (since we're mocking the time to be in the future, the
166  // required time connected check should be satisfied).
167  SetMockTime(time_init);
168  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
169  SetMockTime(time_later);
170 
171  peerLogic->CheckForStaleTipAndEvictPeers();
172  for (int i = 0; i < max_outbound_full_relay; ++i) {
173  BOOST_CHECK(vNodes[i]->fDisconnect == false);
174  }
175  // Last added node should get marked for eviction
176  BOOST_CHECK(vNodes.back()->fDisconnect == true);
177 
178  vNodes.back()->fDisconnect = false;
179 
180  // Update the last announced block time for the last
181  // peer, and check that the next newest node gets evicted.
182  UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), GetTime());
183 
184  peerLogic->CheckForStaleTipAndEvictPeers();
185  for (int i = 0; i < max_outbound_full_relay - 1; ++i) {
186  BOOST_CHECK(vNodes[i]->fDisconnect == false);
187  }
188  BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true);
189  BOOST_CHECK(vNodes.back()->fDisconnect == false);
190 
191  for (const CNode *node : vNodes) {
192  peerLogic->FinalizeNode(*node);
193  }
194 
195  connman->ClearTestNodes();
196 }
197 
198 BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
199 {
200  const CChainParams& chainparams = Params();
201  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
202  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
203  *m_node.chainman, *m_node.mempool, false);
204 
205  constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
206  constexpr int64_t MINIMUM_CONNECT_TIME{30};
207  CConnman::Options options;
210  options.m_max_outbound_block_relay = max_outbound_block_relay;
211 
212  connman->Init(options);
213  std::vector<CNode*> vNodes;
214 
215  // Add block-relay-only peers up to the limit
216  for (int i = 0; i < max_outbound_block_relay; ++i) {
217  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::BLOCK_RELAY);
218  }
219  peerLogic->CheckForStaleTipAndEvictPeers();
220 
221  for (int i = 0; i < max_outbound_block_relay; ++i) {
222  BOOST_CHECK(vNodes[i]->fDisconnect == false);
223  }
224 
225  // Add an extra block-relay-only peer breaking the limit (mocks logic in ThreadOpenConnections)
226  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::BLOCK_RELAY);
227  peerLogic->CheckForStaleTipAndEvictPeers();
228 
229  // The extra peer should only get marked for eviction after MINIMUM_CONNECT_TIME
230  for (int i = 0; i < max_outbound_block_relay; ++i) {
231  BOOST_CHECK(vNodes[i]->fDisconnect == false);
232  }
233  BOOST_CHECK(vNodes.back()->fDisconnect == false);
234 
236  peerLogic->CheckForStaleTipAndEvictPeers();
237  for (int i = 0; i < max_outbound_block_relay; ++i) {
238  BOOST_CHECK(vNodes[i]->fDisconnect == false);
239  }
240  BOOST_CHECK(vNodes.back()->fDisconnect == true);
241 
242  // Update the last block time for the extra peer,
243  // and check that the next youngest peer gets evicted.
244  vNodes.back()->fDisconnect = false;
245  vNodes.back()->m_last_block_time = GetTime<std::chrono::seconds>();
246 
247  peerLogic->CheckForStaleTipAndEvictPeers();
248  for (int i = 0; i < max_outbound_block_relay - 1; ++i) {
249  BOOST_CHECK(vNodes[i]->fDisconnect == false);
250  }
251  BOOST_CHECK(vNodes[max_outbound_block_relay - 1]->fDisconnect == true);
252  BOOST_CHECK(vNodes.back()->fDisconnect == false);
253 
254  for (const CNode* node : vNodes) {
255  peerLogic->FinalizeNode(*node);
256  }
257  connman->ClearTestNodes();
258 }
259 
260 BOOST_AUTO_TEST_CASE(peer_discouragement)
261 {
262  const CChainParams& chainparams = Params();
263  auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
264  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
265  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
266  *m_node.chainman, *m_node.mempool, false);
267 
268  CNetAddr tor_netaddr;
269  BOOST_REQUIRE(
270  tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
271  const CService tor_service{tor_netaddr, Params().GetDefaultPort()};
272 
273  const std::array<CAddress, 3> addr{CAddress{ip(0xa0b0c001), NODE_NONE},
274  CAddress{ip(0xa0b0c002), NODE_NONE},
275  CAddress{tor_service, NODE_NONE}};
276 
277  const CNetAddr other_addr{ip(0xa0b0ff01)}; // Not any of addr[].
278 
279  std::array<CNode*, 3> nodes;
280 
281  banman->ClearBanned();
282  nodes[0] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[0], /*nKeyedNetGroupIn=*/0,
283  /*nLocalHostNonceIn=*/0, CAddress(), /*addrNameIn=*/"",
284  ConnectionType::INBOUND, /*inbound_onion=*/false};
285  nodes[0]->SetCommonVersion(PROTOCOL_VERSION);
286  peerLogic->InitializeNode(nodes[0]);
287  nodes[0]->fSuccessfullyConnected = true;
288  connman->AddTestNode(*nodes[0]);
289  peerLogic->Misbehaving(nodes[0]->GetId(), DISCOURAGEMENT_THRESHOLD, /*message=*/""); // Should be discouraged
290  {
291  LOCK(nodes[0]->cs_sendProcessing);
292  BOOST_CHECK(peerLogic->SendMessages(nodes[0]));
293  }
294  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
295  BOOST_CHECK(nodes[0]->fDisconnect);
296  BOOST_CHECK(!banman->IsDiscouraged(other_addr)); // Different address, not discouraged
297 
298  nodes[1] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[1], /*nKeyedNetGroupIn=*/1,
299  /*nLocalHostNonceIn=*/1, CAddress(), /*addrNameIn=*/"",
300  ConnectionType::INBOUND, /*inbound_onion=*/false};
301  nodes[1]->SetCommonVersion(PROTOCOL_VERSION);
302  peerLogic->InitializeNode(nodes[1]);
303  nodes[1]->fSuccessfullyConnected = true;
304  connman->AddTestNode(*nodes[1]);
305  peerLogic->Misbehaving(nodes[1]->GetId(), DISCOURAGEMENT_THRESHOLD - 1, /*message=*/"");
306  {
307  LOCK(nodes[1]->cs_sendProcessing);
308  BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
309  }
310  // [0] is still discouraged/disconnected.
311  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
312  BOOST_CHECK(nodes[0]->fDisconnect);
313  // [1] is not discouraged/disconnected yet.
314  BOOST_CHECK(!banman->IsDiscouraged(addr[1]));
315  BOOST_CHECK(!nodes[1]->fDisconnect);
316  peerLogic->Misbehaving(nodes[1]->GetId(), 1, /*message=*/""); // [1] reaches discouragement threshold
317  {
318  LOCK(nodes[1]->cs_sendProcessing);
319  BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
320  }
321  // Expect both [0] and [1] to be discouraged/disconnected now.
322  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
323  BOOST_CHECK(nodes[0]->fDisconnect);
324  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
325  BOOST_CHECK(nodes[1]->fDisconnect);
326 
327  // Make sure non-IP peers are discouraged and disconnected properly.
328 
329  nodes[2] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[2], /*nKeyedNetGroupIn=*/1,
330  /*nLocalHostNonceIn=*/1, CAddress(), /*addrNameIn=*/"",
331  ConnectionType::OUTBOUND_FULL_RELAY, /*inbound_onion=*/false};
332  nodes[2]->SetCommonVersion(PROTOCOL_VERSION);
333  peerLogic->InitializeNode(nodes[2]);
334  nodes[2]->fSuccessfullyConnected = true;
335  connman->AddTestNode(*nodes[2]);
336  peerLogic->Misbehaving(nodes[2]->GetId(), DISCOURAGEMENT_THRESHOLD, /*message=*/"");
337  {
338  LOCK(nodes[2]->cs_sendProcessing);
339  BOOST_CHECK(peerLogic->SendMessages(nodes[2]));
340  }
341  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
342  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
343  BOOST_CHECK(banman->IsDiscouraged(addr[2]));
344  BOOST_CHECK(nodes[0]->fDisconnect);
345  BOOST_CHECK(nodes[1]->fDisconnect);
346  BOOST_CHECK(nodes[2]->fDisconnect);
347 
348  for (CNode* node : nodes) {
349  peerLogic->FinalizeNode(*node);
350  }
351  connman->ClearTestNodes();
352 }
353 
355 {
356  const CChainParams& chainparams = Params();
357  auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
358  auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
359  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
360  *m_node.chainman, *m_node.mempool, false);
361 
362  banman->ClearBanned();
363  int64_t nStartTime = GetTime();
364  SetMockTime(nStartTime); // Overrides future calls to GetTime()
365 
366  CAddress addr(ip(0xa0b0c001), NODE_NONE);
367  CNode dummyNode(id++, NODE_NETWORK, INVALID_SOCKET, addr, /*nKeyedNetGroupIn=*/4, /*nLocalHostNonceIn=*/4, CAddress(), /*addrNameIn=*/"", ConnectionType::INBOUND, /*inbound_onion=*/false);
369  peerLogic->InitializeNode(&dummyNode);
370  dummyNode.fSuccessfullyConnected = true;
371 
372  peerLogic->Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD, /*message=*/"");
373  {
374  LOCK(dummyNode.cs_sendProcessing);
375  BOOST_CHECK(peerLogic->SendMessages(&dummyNode));
376  }
377  BOOST_CHECK(banman->IsDiscouraged(addr));
378 
379  peerLogic->FinalizeNode(dummyNode);
380 }
381 
383 {
384 public:
386  {
387  return m_orphans.size();
388  }
389 
391  {
392  std::map<uint256, OrphanTx>::iterator it;
393  it = m_orphans.lower_bound(InsecureRand256());
394  if (it == m_orphans.end())
395  it = m_orphans.begin();
396  return it->second.tx;
397  }
398 };
399 
401 {
402  std::vector<unsigned char> keydata;
403  keydata = g_insecure_rand_ctx.randbytes(32);
404  key.Set(keydata.data(), keydata.data() + keydata.size(), /*fCompressedIn=*/true);
405  assert(key.IsValid());
406 }
407 
408 BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
409 {
410  // This test had non-deterministic coverage due to
411  // randomly selected seeds.
412  // This seed is chosen so that all branches of the function
413  // ecdsa_signature_parse_der_lax are executed during this test.
414  // Specifically branches that run only when an ECDSA
415  // signature's R and S values have leading zeros.
417 
418  TxOrphanageTest orphanage;
419  CKey key;
421  FillableSigningProvider keystore;
422  BOOST_CHECK(keystore.AddKey(key));
423 
425 
426  // 50 orphan transactions:
427  for (int i = 0; i < 50; i++)
428  {
430  tx.vin.resize(1);
431  tx.vin[0].prevout.n = 0;
432  tx.vin[0].prevout.hash = InsecureRand256();
433  tx.vin[0].scriptSig << OP_1;
434  tx.vout.resize(1);
435  tx.vout[0].nValue = 1*CENT;
436  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
437 
438  orphanage.AddTx(MakeTransactionRef(tx), i);
439  }
440 
441  // ... and 50 that depend on other orphans:
442  for (int i = 0; i < 50; i++)
443  {
444  CTransactionRef txPrev = orphanage.RandomOrphan();
445 
447  tx.vin.resize(1);
448  tx.vin[0].prevout.n = 0;
449  tx.vin[0].prevout.hash = txPrev->GetHash();
450  tx.vout.resize(1);
451  tx.vout[0].nValue = 1*CENT;
452  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
453  BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
454 
455  orphanage.AddTx(MakeTransactionRef(tx), i);
456  }
457 
458  // This really-big orphan should be ignored:
459  for (int i = 0; i < 10; i++)
460  {
461  CTransactionRef txPrev = orphanage.RandomOrphan();
462 
464  tx.vout.resize(1);
465  tx.vout[0].nValue = 1*CENT;
466  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
467  tx.vin.resize(2777);
468  for (unsigned int j = 0; j < tx.vin.size(); j++)
469  {
470  tx.vin[j].prevout.n = j;
471  tx.vin[j].prevout.hash = txPrev->GetHash();
472  }
473  BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
474  // Re-use same signature for other inputs
475  // (they don't have to be valid for this test)
476  for (unsigned int j = 1; j < tx.vin.size(); j++)
477  tx.vin[j].scriptSig = tx.vin[0].scriptSig;
478 
479  BOOST_CHECK(!orphanage.AddTx(MakeTransactionRef(tx), i));
480  }
481 
482  // Test EraseOrphansFor:
483  for (NodeId i = 0; i < 3; i++)
484  {
485  size_t sizeBefore = orphanage.CountOrphans();
486  orphanage.EraseForPeer(i);
487  BOOST_CHECK(orphanage.CountOrphans() < sizeBefore);
488  }
489 
490  // Test LimitOrphanTxSize() function:
491  orphanage.LimitOrphans(40);
492  BOOST_CHECK(orphanage.CountOrphans() <= 40);
493  orphanage.LimitOrphans(10);
494  BOOST_CHECK(orphanage.CountOrphans() <= 10);
495  orphanage.LimitOrphans(0);
496  BOOST_CHECK(orphanage.CountOrphans() == 0);
497 }
498 
NodeId
int64_t NodeId
Definition: net.h:88
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:528
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:412
CNode::GetId
NodeId GetId() const
Definition: net.h:586
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:58
AddRandomOutboundPeer
static void AddRandomOutboundPeer(std::vector< CNode * > &vNodes, PeerManager &peerLogic, ConnmanTestMsg &connman, ConnectionType connType)
Definition: denialofservice_tests.cpp:108
setup_common.h
MakeNewKeyWithFastRandomContext
static void MakeNewKeyWithFastRandomContext(CKey &key)
Definition: denialofservice_tests.cpp:400
node::NodeContext::addrman
std::unique_ptr< AddrMan > addrman
Definition: context.h:43
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition: signingprovider.h:90
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:310
string.h
MINIMUM_CONNECT_TIME
static constexpr auto MINIMUM_CONNECT_TIME
Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict.
Definition: net_processing.cpp:73
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:72
InsecureRand256
static uint256 InsecureRand256()
Definition: setup_common.h:73
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.
CNode
Information about a peer.
Definition: net.h:394
UpdateLastBlockAnnounceTime
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
Definition: net_processing.cpp:1158
m_node
node::NodeContext m_node
Definition: bitcoin-gui.cpp:36
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:382
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
PeerManager::make
static std::unique_ptr< PeerManager > make(const CChainParams &chainparams, CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
Definition: net_processing.cpp:1475
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
node::NodeContext::mempool
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:45
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
CNode::fDisconnect
std::atomic_bool fDisconnect
Definition: net.h:453
FillableSigningProvider::AddKey
virtual bool AddKey(const CKey &key)
Definition: signingprovider.h:151
FastRandomContext::randbits
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Definition: random.h:172
ConnmanTestMsg
Definition: net.h:19
Consensus::Params::nPowTargetSpacing
int64_t nPowTargetSpacing
Definition: params.h:103
CNode::SetCommonVersion
void SetCommonVersion(int greatest_common_version)
Definition: net.h:611
signingprovider.h
OP_1
@ OP_1
Definition: script.h:76
ConnmanTestMsg::AddTestNode
void AddTestNode(CNode &node)
Definition: net.h:27
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:62
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:516
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:450
CENT
static constexpr CAmount CENT
Definition: setup_common.h:78
time.h
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:93
sign.h
standard.h
CConnman::Options::m_max_outbound_block_relay
int m_max_outbound_block_relay
Definition: net.h:750
PeerManager
Definition: net_processing.h:37
TxOrphanageTest::RandomOrphan
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Definition: denialofservice_tests.cpp:390
MAX_FEELER_CONNECTIONS
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:68
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:745
CConnman::Options::nMaxConnections
int nMaxConnections
Definition: net.h:748
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:752
CNode::cs_sendProcessing
RecursiveMutex cs_sendProcessing
Definition: net.h:420
MAX_BLOCK_RELAY_ONLY_CONNECTIONS
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:66
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:138
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:561
node::NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:48
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:107
TxOrphanageTest::CountOrphans
size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Definition: denialofservice_tests.cpp:385
node
Definition: init.h:22
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
ConnectionType::BLOCK_RELAY
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
CConnman::Options::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:749
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
ConnectionType
ConnectionType
Different types of connections to a peer.
Definition: net.h:121
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