1414#include < script/signingprovider.h>
1515#include < script/standard.h>
1616#include < serialize.h>
17+ #include < test/util/net.h>
18+ #include < test/util/setup_common.h>
1719#include < txorphanage.h>
1820#include < util/string.h>
1921#include < util/system.h>
2022#include < util/time.h>
2123#include < validation.h>
2224
23- #include < test/util/setup_common.h>
24-
2525#include < array>
2626#include < stdint.h>
2727
2828#include < boost/test/unit_test.hpp>
2929
30- struct CConnmanTest : public CConnman {
31- using CConnman::CConnman;
32- void AddNode (CNode& node)
33- {
34- LOCK (cs_vNodes);
35- vNodes.push_back (&node);
36- }
37- void ClearNodes ()
38- {
39- LOCK (cs_vNodes);
40- for (CNode* node : vNodes) {
41- delete node;
42- }
43- vNodes.clear ();
44- }
45- };
46-
4730static CService ip (uint32_t i)
4831{
4932 struct in_addr s;
@@ -120,7 +103,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
120103 peerLogic->FinalizeNode (dummyNode1);
121104}
122105
123- static void AddRandomOutboundPeer (std::vector<CNode *> & vNodes, PeerManager & peerLogic, CConnmanTest* connman)
106+ static void AddRandomOutboundPeer (std::vector<CNode*>& vNodes, PeerManager& peerLogic, ConnmanTestMsg& connman)
124107{
125108 CAddress addr (ip (g_insecure_rand_ctx.randbits (32 )), NODE_NONE);
126109 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 ));
@@ -130,13 +113,13 @@ static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &pee
130113 peerLogic.InitializeNode (&node);
131114 node.fSuccessfullyConnected = true ;
132115
133- connman-> AddNode (node);
116+ connman. AddTestNode (node);
134117}
135118
136119BOOST_AUTO_TEST_CASE (stale_tip_peer_management)
137120{
138121 const CChainParams& chainparams = Params ();
139- auto connman = std::make_unique<CConnmanTest >(0x1337 , 0x1337 , *m_node.addrman );
122+ auto connman = std::make_unique<ConnmanTestMsg >(0x1337 , 0x1337 , *m_node.addrman );
140123 auto peerLogic = PeerManager::make (chainparams, *connman, *m_node.addrman , nullptr ,
141124 *m_node.scheduler , *m_node.chainman , *m_node.mempool , false );
142125
@@ -150,8 +133,8 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
150133 std::vector<CNode *> vNodes;
151134
152135 // Mock some outbound peers
153- for (int i= 0 ; i< max_outbound_full_relay; ++i) {
154- AddRandomOutboundPeer (vNodes, *peerLogic, connman. get () );
136+ for (int i = 0 ; i < max_outbound_full_relay; ++i) {
137+ AddRandomOutboundPeer (vNodes, *peerLogic, * connman);
155138 }
156139
157140 peerLogic->CheckForStaleTipAndEvictPeers ();
@@ -176,7 +159,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
176159 // If we add one more peer, something should get marked for eviction
177160 // on the next check (since we're mocking the time to be in the future, the
178161 // required time connected check should be satisfied).
179- AddRandomOutboundPeer (vNodes, *peerLogic, connman. get () );
162+ AddRandomOutboundPeer (vNodes, *peerLogic, * connman);
180163
181164 peerLogic->CheckForStaleTipAndEvictPeers ();
182165 for (int i = 0 ; i < max_outbound_full_relay; ++i) {
@@ -202,14 +185,14 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
202185 peerLogic->FinalizeNode (*node);
203186 }
204187
205- connman->ClearNodes ();
188+ connman->ClearTestNodes ();
206189}
207190
208191BOOST_AUTO_TEST_CASE (peer_discouragement)
209192{
210193 const CChainParams& chainparams = Params ();
211194 auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase () / " banlist.dat" , nullptr , DEFAULT_MISBEHAVING_BANTIME);
212- auto connman = std::make_unique<CConnmanTest >(0x1337 , 0x1337 , *m_node.addrman );
195+ auto connman = std::make_unique<ConnmanTestMsg >(0x1337 , 0x1337 , *m_node.addrman );
213196 auto peerLogic = PeerManager::make (chainparams, *connman, *m_node.addrman , banman.get (),
214197 *m_node.scheduler , *m_node.chainman , *m_node.mempool , false );
215198
@@ -233,7 +216,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
233216 nodes[0 ]->SetCommonVersion (PROTOCOL_VERSION);
234217 peerLogic->InitializeNode (nodes[0 ]);
235218 nodes[0 ]->fSuccessfullyConnected = true ;
236- connman->AddNode (*nodes[0 ]);
219+ connman->AddTestNode (*nodes[0 ]);
237220 peerLogic->Misbehaving (nodes[0 ]->GetId (), DISCOURAGEMENT_THRESHOLD, /* message */ " " ); // Should be discouraged
238221 {
239222 LOCK (nodes[0 ]->cs_sendProcessing );
@@ -249,7 +232,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
249232 nodes[1 ]->SetCommonVersion (PROTOCOL_VERSION);
250233 peerLogic->InitializeNode (nodes[1 ]);
251234 nodes[1 ]->fSuccessfullyConnected = true ;
252- connman->AddNode (*nodes[1 ]);
235+ connman->AddTestNode (*nodes[1 ]);
253236 peerLogic->Misbehaving (nodes[1 ]->GetId (), DISCOURAGEMENT_THRESHOLD - 1 , /* message */ " " );
254237 {
255238 LOCK (nodes[1 ]->cs_sendProcessing );
@@ -280,7 +263,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
280263 nodes[2 ]->SetCommonVersion (PROTOCOL_VERSION);
281264 peerLogic->InitializeNode (nodes[2 ]);
282265 nodes[2 ]->fSuccessfullyConnected = true ;
283- connman->AddNode (*nodes[2 ]);
266+ connman->AddTestNode (*nodes[2 ]);
284267 peerLogic->Misbehaving (nodes[2 ]->GetId (), DISCOURAGEMENT_THRESHOLD, /* message */ " " );
285268 {
286269 LOCK (nodes[2 ]->cs_sendProcessing );
@@ -296,7 +279,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
296279 for (CNode* node : nodes) {
297280 peerLogic->FinalizeNode (*node);
298281 }
299- connman->ClearNodes ();
282+ connman->ClearTestNodes ();
300283}
301284
302285BOOST_AUTO_TEST_CASE (DoS_bantime)
0 commit comments