server: Check whitelist before ban on read errs.

This modifies the code that was fairly recently added to ban peers
sending messages that do not conform to the wire protocol to only apply
when they are not whitelisted.
This commit is contained in:
Dave Collins 2020-09-19 02:08:18 -05:00
parent 2f8ae33148
commit daf84ebd36
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -1429,12 +1429,15 @@ func (sp *serverPeer) OnAddr(p *peer.Peer, msg *wire.MsgAddr) {
// OnRead is invoked when a peer receives a message and it is used to update
// the bytes received by the server.
func (sp *serverPeer) OnRead(p *peer.Peer, bytesRead int, msg wire.Message, err error) {
// Ban peers sending messages that do not conform to the wire protocol.
// Ban non-whitelisted peers sending messages that do not conform to the
// wire protocol.
var errCode wire.ErrorCode
if errors.As(err, &errCode) {
peerLog.Errorf("Unable to read wire message from %s: %v", sp, err)
sp.server.BanPeer(sp)
sp.Disconnect()
if !cfg.DisableBanning && !sp.isWhitelisted {
sp.server.BanPeer(sp)
sp.Disconnect()
}
}
sp.server.AddBytesReceived(uint64(bytesRead))