Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,161 Lines • ▼ Show 20 Lines | while (mapOrphanTransactions.size() > nMaxOrphans) { | ||||
size_t randompos = rng.randrange(g_orphan_list.size()); | size_t randompos = rng.randrange(g_orphan_list.size()); | ||||
EraseOrphanTx(g_orphan_list[randompos]->first); | EraseOrphanTx(g_orphan_list[randompos]->first); | ||||
++nEvicted; | ++nEvicted; | ||||
} | } | ||||
return nEvicted; | return nEvicted; | ||||
} | } | ||||
/** | /** | ||||
* Mark a misbehaving peer to be banned depending upon the value of `-banscore`. | * 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) { | void Misbehaving(NodeId pnode, int howmuch, const std::string &message) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (howmuch == 0) { | if (howmuch == 0) { | ||||
return; | return; | ||||
} | } | ||||
CNodeState *state = State(pnode); | CNodeState *state = State(pnode); | ||||
if (state == nullptr) { | if (state == nullptr) { | ||||
return; | return; | ||||
} | } | ||||
state->nMisbehavior += howmuch; | state->nMisbehavior += howmuch; | ||||
int banscore = gArgs.GetArg("-banscore", DEFAULT_BANSCORE_THRESHOLD); | |||||
std::string message_prefixed = message.empty() ? "" : (": " + message); | std::string message_prefixed = message.empty() ? "" : (": " + message); | ||||
if (state->nMisbehavior >= banscore && | if (state->nMisbehavior >= DISCOURAGEMENT_THRESHOLD && | ||||
state->nMisbehavior - howmuch < banscore) { | state->nMisbehavior - howmuch < DISCOURAGEMENT_THRESHOLD) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"%s: %s peer=%d (%d -> %d) BAN THRESHOLD EXCEEDED%s\n", | "%s: %s peer=%d (%d -> %d) BAN THRESHOLD EXCEEDED%s\n", | ||||
__func__, state->name, pnode, state->nMisbehavior - howmuch, | __func__, state->name, pnode, state->nMisbehavior - howmuch, | ||||
state->nMisbehavior, message_prefixed); | state->nMisbehavior, message_prefixed); | ||||
state->m_should_discourage = true; | state->m_should_discourage = true; | ||||
} else { | } else { | ||||
LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d)%s\n", __func__, | LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d)%s\n", __func__, | ||||
state->name, pnode, state->nMisbehavior - howmuch, | state->name, pnode, state->nMisbehavior - howmuch, | ||||
▲ Show 20 Lines • Show All 4,138 Lines • Show Last 20 Lines |