mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
[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__.
This commit is contained in:
parent
d15b3afb4c
commit
a8865f8b72
1 changed files with 9 additions and 10 deletions
|
@ -1059,23 +1059,22 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
|
|||
* Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
|
||||
* to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
|
||||
*/
|
||||
void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
{
|
||||
if (howmuch == 0)
|
||||
return;
|
||||
assert(howmuch > 0);
|
||||
|
||||
CNodeState *state = State(pnode);
|
||||
if (state == nullptr)
|
||||
return;
|
||||
CNodeState* const state = State(pnode);
|
||||
if (state == nullptr) return;
|
||||
|
||||
state->nMisbehavior += howmuch;
|
||||
std::string message_prefixed = message.empty() ? "" : (": " + message);
|
||||
const std::string message_prefixed = message.empty() ? "" : (": " + message);
|
||||
if (state->nMisbehavior >= DISCOURAGEMENT_THRESHOLD && state->nMisbehavior - howmuch < DISCOURAGEMENT_THRESHOLD)
|
||||
{
|
||||
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);
|
||||
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d) DISCOURAGE THRESHOLD EXCEEDED%s\n", pnode, state->nMisbehavior - howmuch, state->nMisbehavior, message_prefixed);
|
||||
state->m_should_discourage = true;
|
||||
} else
|
||||
LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d)%s\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior, message_prefixed);
|
||||
} else {
|
||||
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s\n", pnode, state->nMisbehavior - howmuch, state->nMisbehavior, message_prefixed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue