Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,308 Lines • ▼ Show 20 Lines | while (mapOrphanTransactions.size() > nMaxOrphans) { | ||||
// Evict a random orphan: | // Evict a random orphan: | ||||
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; | ||||
} | } | ||||
/** | void PeerManager::Misbehaving(const NodeId pnode, const int howmuch, | ||||
* 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(const NodeId pnode, const int howmuch, | |||||
const std::string &message) { | const std::string &message) { | ||||
assert(howmuch > 0); | assert(howmuch > 0); | ||||
PeerRef peer = GetPeerRef(pnode); | PeerRef peer = GetPeerRef(pnode); | ||||
if (peer == nullptr) { | if (peer == nullptr) { | ||||
return; | return; | ||||
} | } | ||||
LOCK(peer->m_misbehavior_mutex); | LOCK(peer->m_misbehavior_mutex); | ||||
Show All 10 Lines | if (peer->m_misbehavior_score >= DISCOURAGEMENT_THRESHOLD && | ||||
peer->m_should_discourage = true; | peer->m_should_discourage = true; | ||||
} else { | } else { | ||||
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s\n", pnode, | LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s\n", pnode, | ||||
peer->m_misbehavior_score - howmuch, peer->m_misbehavior_score, | peer->m_misbehavior_score - howmuch, peer->m_misbehavior_score, | ||||
message_prefixed); | message_prefixed); | ||||
} | } | ||||
} | } | ||||
// overloaded variant of above to operate on CNode*s | |||||
static void Misbehaving(const CNode &node, int howmuch, | |||||
const std::string &message) { | |||||
Misbehaving(node.GetId(), howmuch, message); | |||||
} | |||||
/** | /** | ||||
* Returns true if the given validation state result may result in a peer | * Returns true if the given validation state result may result in a peer | ||||
* banning/disconnecting us. We use this to determine which unaccepted | * banning/disconnecting us. We use this to determine which unaccepted | ||||
* transactions from a whitelisted peer that we can safely relay. | * transactions from a whitelisted peer that we can safely relay. | ||||
*/ | */ | ||||
static bool TxRelayMayResultInDisconnect(const TxValidationState &state) { | static bool TxRelayMayResultInDisconnect(const TxValidationState &state) { | ||||
return state.GetResult() == TxValidationResult::TX_CONSENSUS; | return state.GetResult() == TxValidationResult::TX_CONSENSUS; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 4,152 Lines • Show Last 20 Lines |