mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge pull request #4378
dc942e6 Introduce whitelisted peers. (Pieter Wuille)
This commit is contained in:
19
src/main.cpp
19
src/main.cpp
@@ -212,7 +212,7 @@ struct CBlockReject {
|
||||
struct CNodeState {
|
||||
// Accumulated misbehaviour score for this peer.
|
||||
int nMisbehavior;
|
||||
// Whether this peer should be disconnected and banned.
|
||||
// Whether this peer should be disconnected and banned (unless whitelisted).
|
||||
bool fShouldBan;
|
||||
// String name of this peer (debugging/logging purposes).
|
||||
std::string name;
|
||||
@@ -1427,7 +1427,8 @@ void Misbehaving(NodeId pnode, int howmuch)
|
||||
return;
|
||||
|
||||
state->nMisbehavior += howmuch;
|
||||
if (state->nMisbehavior >= GetArg("-banscore", 100))
|
||||
int banscore = GetArg("-banscore", 100);
|
||||
if (state->nMisbehavior >= banscore && state->nMisbehavior - howmuch < banscore)
|
||||
{
|
||||
LogPrintf("Misbehaving: %s (%d -> %d) BAN THRESHOLD EXCEEDED\n", state->name, state->nMisbehavior-howmuch, state->nMisbehavior);
|
||||
state->fShouldBan = true;
|
||||
@@ -3952,6 +3953,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
unsigned int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS);
|
||||
if (nEvicted > 0)
|
||||
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
|
||||
} else if (pfrom->fWhitelisted) {
|
||||
// Always relay transactions received from whitelisted peers, even
|
||||
// if they are already in the mempool (allowing the node to function
|
||||
// as a gateway for nodes hidden behind it).
|
||||
RelayTransaction(tx);
|
||||
}
|
||||
int nDoS = 0;
|
||||
if (state.IsInvalid(nDoS))
|
||||
@@ -4445,11 +4451,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
|
||||
CNodeState &state = *State(pto->GetId());
|
||||
if (state.fShouldBan) {
|
||||
if (pto->addr.IsLocal())
|
||||
LogPrintf("Warning: not banning local node %s!\n", pto->addr.ToString());
|
||||
if (pto->fWhitelisted)
|
||||
LogPrintf("Warning: not punishing whitelisted peer %s!\n", pto->addr.ToString());
|
||||
else {
|
||||
pto->fDisconnect = true;
|
||||
CNode::Ban(pto->addr);
|
||||
if (pto->addr.IsLocal())
|
||||
LogPrintf("Warning: not banning local peer %s!\n", pto->addr.ToString());
|
||||
else
|
||||
CNode::Ban(pto->addr);
|
||||
}
|
||||
state.fShouldBan = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user