Skip to content

Commit a8865f8

Browse files
committed
[net processing] Tidy up Misbehaving()
- Make const things const. - Replace conditional return with assert. - Don't log the peer's IP address. - Log the name Misbehaving directly instead of relying on __func__.
1 parent d15b3af commit a8865f8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,23 +1059,22 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
10591059
* Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
10601060
* to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
10611061
*/
1062-
void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1062+
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
10631063
{
1064-
if (howmuch == 0)
1065-
return;
1064+
assert(howmuch > 0);
10661065

1067-
CNodeState *state = State(pnode);
1068-
if (state == nullptr)
1069-
return;
1066+
CNodeState* const state = State(pnode);
1067+
if (state == nullptr) return;
10701068

10711069
state->nMisbehavior += howmuch;
1072-
std::string message_prefixed = message.empty() ? "" : (": " + message);
1070+
const std::string message_prefixed = message.empty() ? "" : (": " + message);
10731071
if (state->nMisbehavior >= DISCOURAGEMENT_THRESHOLD && state->nMisbehavior - howmuch < DISCOURAGEMENT_THRESHOLD)
10741072
{
1075-
LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d) DISCOURAGE THRESHOLD EXCEEDED%s\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior, message_prefixed);
1073+
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d) DISCOURAGE THRESHOLD EXCEEDED%s\n", pnode, state->nMisbehavior - howmuch, state->nMisbehavior, message_prefixed);
10761074
state->m_should_discourage = true;
1077-
} else
1078-
LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d)%s\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior, message_prefixed);
1075+
} else {
1076+
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s\n", pnode, state->nMisbehavior - howmuch, state->nMisbehavior, message_prefixed);
1077+
}
10791078
}
10801079

10811080
/**

0 commit comments

Comments
 (0)