les: reject client if it makes too many invalid requests (#19691)

* les: reject client connection if it makes too much invalid req

* les: address comments

* les: use uint32

* les: fix variable name

* les: add invalid counter for duplicate invalid req
This commit is contained in:
gary rong
2019-06-12 19:09:40 +08:00
committed by Péter Szilágyi
parent b3f7609d7d
commit c8c3ebd593
3 changed files with 40 additions and 14 deletions

View File

@ -42,7 +42,10 @@ var (
errNotRegistered = errors.New("peer is not registered")
)
const maxResponseErrors = 50 // number of invalid responses tolerated (makes the protocol less brittle but still avoids spam)
const (
maxRequestErrors = 20 // number of invalid requests tolerated (makes the protocol less brittle but still avoids spam)
maxResponseErrors = 50 // number of invalid responses tolerated (makes the protocol less brittle but still avoids spam)
)
// capacity limitation for parameter updates
const (
@ -69,7 +72,6 @@ const (
type peer struct {
*p2p.Peer
rw p2p.MsgReadWriter
version int // Protocol version negotiated
@ -89,6 +91,7 @@ type peer struct {
// RequestProcessed is called
responseLock sync.Mutex
responseCount uint64
invalidCount uint32
poolEntry *poolEntry
hasBlock func(common.Hash, uint64, bool) bool