9

Does the main Bitcoin client blacklist any addresses that send too many erroneous messages? If so, how can one whitelist a particular address? I am developing an app that will be communicating with the main client and I don't want the program to ban it during testing.

morsecoder
  • 14,008
  • 2
  • 42
  • 92
ThePiachu
  • 42,931
  • 25
  • 138
  • 347

1 Answers1

9

There is a ban mechanism which is handled in net.cpp.

Any node which misbehave by more than -banscore (defaults to 100) is banned for -bantime (defaults to 60×60×24 seconds = 1 day). However, nodes with a local ip address are exempted, and for those a warning is shown in the logs after each misbehavior.

Also bans are not persistent, they are lifted when the client is restarted.

So, during development, just make sure that your app connects with a local address to the bitcoin client, and you will not be bothered by bans.


Here is the relevant piece of code:

bool CNode::Misbehaving(int howmuch)
{
    if (addr.IsLocal())
    {
        printf("Warning: local node %s misbehaving\n", addr.ToString().c_str());
        return false;
    }

    nMisbehavior += howmuch;
    if (nMisbehavior >= GetArg("-banscore", 100))
    {
        int64 banTime = GetTime()+GetArg("-bantime", 60*60*24);  // Default 24-hour ban
        CRITICAL_BLOCK(cs_setBanned)
            if (setBanned[addr.ip] < banTime)
                setBanned[addr.ip] = banTime;
        CloseSocketDisconnect();
        printf("Disconnected %s for misbehavior (score=%d)\n", addr.ToString().c_str(), nMisbehavior);
        return true;
    }
    return false;
}
Stéphane Gimenez
  • 5,104
  • 3
  • 31
  • 37