Skip to content

Commit bb6a32c

Browse files
committed
[net processing] Move Misbehaving() to PeerManager
1 parent aa114b1 commit bb6a32c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,11 +1110,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
11101110
return nEvicted;
11111111
}
11121112

1113-
/**
1114-
* Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
1115-
* to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
1116-
*/
1117-
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message)
1113+
void PeerManager::Misbehaving(const NodeId pnode, const int howmuch, const std::string& message)
11181114
{
11191115
assert(howmuch > 0);
11201116

src/net_processing.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class PeerManager final : public CValidationInterface, public NetEventsInterface
8686
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
8787
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc);
8888

89+
/**
90+
* Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
91+
* to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
92+
* Public for unit testing.
93+
*/
94+
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message);
95+
8996
private:
9097
/**
9198
* Potentially mark a node discouraged based on the contents of a BlockValidationState object

src/test/denialofservice_tests.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ struct CConnmanTest : public CConnman {
4747
extern bool AddOrphanTx(const CTransactionRef& tx, NodeId peer);
4848
extern void EraseOrphansFor(NodeId peer);
4949
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
50-
extern void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="");
5150

5251
struct COrphanTx {
5352
CTransactionRef tx;
@@ -235,7 +234,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
235234
peerLogic->InitializeNode(&dummyNode1);
236235
dummyNode1.nVersion = 1;
237236
dummyNode1.fSuccessfullyConnected = true;
238-
Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD); // Should be discouraged
237+
peerLogic->Misbehaving(dummyNode1.GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ ""); // Should be discouraged
239238
{
240239
LOCK(dummyNode1.cs_sendProcessing);
241240
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1));
@@ -249,14 +248,14 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
249248
peerLogic->InitializeNode(&dummyNode2);
250249
dummyNode2.nVersion = 1;
251250
dummyNode2.fSuccessfullyConnected = true;
252-
Misbehaving(dummyNode2.GetId(), DISCOURAGEMENT_THRESHOLD - 1);
251+
peerLogic->Misbehaving(dummyNode2.GetId(), DISCOURAGEMENT_THRESHOLD - 1, /* message */ "");
253252
{
254253
LOCK(dummyNode2.cs_sendProcessing);
255254
BOOST_CHECK(peerLogic->SendMessages(&dummyNode2));
256255
}
257256
BOOST_CHECK(!banman->IsDiscouraged(addr2)); // 2 not discouraged yet...
258257
BOOST_CHECK(banman->IsDiscouraged(addr1)); // ... but 1 still should be
259-
Misbehaving(dummyNode2.GetId(), 1); // 2 reaches discouragement threshold
258+
peerLogic->Misbehaving(dummyNode2.GetId(), 1, /* message */ ""); // 2 reaches discouragement threshold
260259
{
261260
LOCK(dummyNode2.cs_sendProcessing);
262261
BOOST_CHECK(peerLogic->SendMessages(&dummyNode2));
@@ -287,7 +286,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
287286
dummyNode.nVersion = 1;
288287
dummyNode.fSuccessfullyConnected = true;
289288

290-
Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD);
289+
peerLogic->Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD, /* message */ "");
291290
{
292291
LOCK(dummyNode.cs_sendProcessing);
293292
BOOST_CHECK(peerLogic->SendMessages(&dummyNode));

0 commit comments

Comments
 (0)