14
14
#include < script/signingprovider.h>
15
15
#include < script/standard.h>
16
16
#include < serialize.h>
17
+ #include < test/util/net.h>
18
+ #include < test/util/setup_common.h>
17
19
#include < txorphanage.h>
18
20
#include < util/string.h>
19
21
#include < util/system.h>
20
22
#include < util/time.h>
21
23
#include < validation.h>
22
24
23
- #include < test/util/setup_common.h>
24
-
25
25
#include < array>
26
26
#include < stdint.h>
27
27
28
28
#include < boost/test/unit_test.hpp>
29
29
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
-
47
30
static CService ip (uint32_t i)
48
31
{
49
32
struct in_addr s;
@@ -120,7 +103,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
120
103
peerLogic->FinalizeNode (dummyNode1);
121
104
}
122
105
123
- static void AddRandomOutboundPeer (std::vector<CNode *> & vNodes, PeerManager & peerLogic, CConnmanTest* connman)
106
+ static void AddRandomOutboundPeer (std::vector<CNode*>& vNodes, PeerManager& peerLogic, ConnmanTestMsg& connman)
124
107
{
125
108
CAddress addr (ip (g_insecure_rand_ctx.randbits (32 )), NODE_NONE);
126
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 ));
@@ -130,13 +113,13 @@ static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &pee
130
113
peerLogic.InitializeNode (&node);
131
114
node.fSuccessfullyConnected = true ;
132
115
133
- connman-> AddNode (node);
116
+ connman. AddTestNode (node);
134
117
}
135
118
136
119
BOOST_AUTO_TEST_CASE (stale_tip_peer_management)
137
120
{
138
121
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 );
140
123
auto peerLogic = PeerManager::make (chainparams, *connman, *m_node.addrman , nullptr ,
141
124
*m_node.scheduler , *m_node.chainman , *m_node.mempool , false );
142
125
@@ -150,8 +133,8 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
150
133
std::vector<CNode *> vNodes;
151
134
152
135
// 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);
155
138
}
156
139
157
140
peerLogic->CheckForStaleTipAndEvictPeers ();
@@ -176,7 +159,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
176
159
// If we add one more peer, something should get marked for eviction
177
160
// on the next check (since we're mocking the time to be in the future, the
178
161
// required time connected check should be satisfied).
179
- AddRandomOutboundPeer (vNodes, *peerLogic, connman. get () );
162
+ AddRandomOutboundPeer (vNodes, *peerLogic, * connman);
180
163
181
164
peerLogic->CheckForStaleTipAndEvictPeers ();
182
165
for (int i = 0 ; i < max_outbound_full_relay; ++i) {
@@ -202,14 +185,14 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
202
185
peerLogic->FinalizeNode (*node);
203
186
}
204
187
205
- connman->ClearNodes ();
188
+ connman->ClearTestNodes ();
206
189
}
207
190
208
191
BOOST_AUTO_TEST_CASE (peer_discouragement)
209
192
{
210
193
const CChainParams& chainparams = Params ();
211
194
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 );
213
196
auto peerLogic = PeerManager::make (chainparams, *connman, *m_node.addrman , banman.get (),
214
197
*m_node.scheduler , *m_node.chainman , *m_node.mempool , false );
215
198
@@ -233,7 +216,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
233
216
nodes[0 ]->SetCommonVersion (PROTOCOL_VERSION);
234
217
peerLogic->InitializeNode (nodes[0 ]);
235
218
nodes[0 ]->fSuccessfullyConnected = true ;
236
- connman->AddNode (*nodes[0 ]);
219
+ connman->AddTestNode (*nodes[0 ]);
237
220
peerLogic->Misbehaving (nodes[0 ]->GetId (), DISCOURAGEMENT_THRESHOLD, /* message */ " " ); // Should be discouraged
238
221
{
239
222
LOCK (nodes[0 ]->cs_sendProcessing );
@@ -249,7 +232,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
249
232
nodes[1 ]->SetCommonVersion (PROTOCOL_VERSION);
250
233
peerLogic->InitializeNode (nodes[1 ]);
251
234
nodes[1 ]->fSuccessfullyConnected = true ;
252
- connman->AddNode (*nodes[1 ]);
235
+ connman->AddTestNode (*nodes[1 ]);
253
236
peerLogic->Misbehaving (nodes[1 ]->GetId (), DISCOURAGEMENT_THRESHOLD - 1 , /* message */ " " );
254
237
{
255
238
LOCK (nodes[1 ]->cs_sendProcessing );
@@ -280,7 +263,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
280
263
nodes[2 ]->SetCommonVersion (PROTOCOL_VERSION);
281
264
peerLogic->InitializeNode (nodes[2 ]);
282
265
nodes[2 ]->fSuccessfullyConnected = true ;
283
- connman->AddNode (*nodes[2 ]);
266
+ connman->AddTestNode (*nodes[2 ]);
284
267
peerLogic->Misbehaving (nodes[2 ]->GetId (), DISCOURAGEMENT_THRESHOLD, /* message */ " " );
285
268
{
286
269
LOCK (nodes[2 ]->cs_sendProcessing );
@@ -296,7 +279,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
296
279
for (CNode* node : nodes) {
297
280
peerLogic->FinalizeNode (*node);
298
281
}
299
- connman->ClearNodes ();
282
+ connman->ClearTestNodes ();
300
283
}
301
284
302
285
BOOST_AUTO_TEST_CASE (DoS_bantime)
0 commit comments