@@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
210
210
{
211
211
const CChainParams& chainparams = Params ();
212
212
auto banman = std::make_unique<BanMan>(GetDataDir () / " banlist.dat" , nullptr , DEFAULT_MISBEHAVING_BANTIME);
213
- auto connman = std::make_unique<CConnman >(0x1337 , 0x1337 , *m_node.addrman );
213
+ auto connman = std::make_unique<CConnmanTest >(0x1337 , 0x1337 , *m_node.addrman );
214
214
auto peerLogic = PeerManager::make (chainparams, *connman, *m_node.addrman , banman.get (),
215
215
*m_node.scheduler , *m_node.chainman , *m_node.mempool , false );
216
216
@@ -228,12 +228,14 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
228
228
nodes[0 ]->SetCommonVersion (PROTOCOL_VERSION);
229
229
peerLogic->InitializeNode (nodes[0 ]);
230
230
nodes[0 ]->fSuccessfullyConnected = true ;
231
+ connman->AddNode (*nodes[0 ]);
231
232
peerLogic->Misbehaving (nodes[0 ]->GetId (), DISCOURAGEMENT_THRESHOLD, /* message */ " " ); // Should be discouraged
232
233
{
233
234
LOCK (nodes[0 ]->cs_sendProcessing );
234
235
BOOST_CHECK (peerLogic->SendMessages (nodes[0 ]));
235
236
}
236
237
BOOST_CHECK (banman->IsDiscouraged (addr[0 ]));
238
+ BOOST_CHECK (nodes[0 ]->fDisconnect );
237
239
BOOST_CHECK (!banman->IsDiscouraged (other_addr)); // Different address, not discouraged
238
240
239
241
nodes[1 ] = new CNode{id++, NODE_NETWORK, INVALID_SOCKET, addr[1 ], /* nKeyedNetGroupIn */ 1 ,
@@ -242,26 +244,33 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
242
244
nodes[1 ]->SetCommonVersion (PROTOCOL_VERSION);
243
245
peerLogic->InitializeNode (nodes[1 ]);
244
246
nodes[1 ]->fSuccessfullyConnected = true ;
247
+ connman->AddNode (*nodes[1 ]);
245
248
peerLogic->Misbehaving (nodes[1 ]->GetId (), DISCOURAGEMENT_THRESHOLD - 1 , /* message */ " " );
246
249
{
247
250
LOCK (nodes[1 ]->cs_sendProcessing );
248
251
BOOST_CHECK (peerLogic->SendMessages (nodes[1 ]));
249
252
}
250
- BOOST_CHECK (!banman->IsDiscouraged (addr[1 ])); // [1] not discouraged yet...
251
- BOOST_CHECK (banman->IsDiscouraged (addr[0 ])); // ... but [0] still should be
253
+ // [0] is still discouraged/disconnected.
254
+ BOOST_CHECK (banman->IsDiscouraged (addr[0 ]));
255
+ BOOST_CHECK (nodes[0 ]->fDisconnect );
256
+ // [1] is not discouraged/disconnected yet.
257
+ BOOST_CHECK (!banman->IsDiscouraged (addr[1 ]));
258
+ BOOST_CHECK (!nodes[1 ]->fDisconnect );
252
259
peerLogic->Misbehaving (nodes[1 ]->GetId (), 1 , /* message */ " " ); // [1] reaches discouragement threshold
253
260
{
254
261
LOCK (nodes[1 ]->cs_sendProcessing );
255
262
BOOST_CHECK (peerLogic->SendMessages (nodes[1 ]));
256
263
}
257
- // Expect both [0] and [1] to be discouraged now.
264
+ // Expect both [0] and [1] to be discouraged/disconnected now.
258
265
BOOST_CHECK (banman->IsDiscouraged (addr[0 ]));
266
+ BOOST_CHECK (nodes[0 ]->fDisconnect );
259
267
BOOST_CHECK (banman->IsDiscouraged (addr[1 ]));
268
+ BOOST_CHECK (nodes[1 ]->fDisconnect );
260
269
261
270
for (CNode* node : nodes) {
262
271
peerLogic->FinalizeNode (*node);
263
- delete node;
264
272
}
273
+ connman->ClearNodes ();
265
274
}
266
275
267
276
BOOST_AUTO_TEST_CASE (DoS_bantime)
0 commit comments