les: address comments

This commit is contained in:
rjl493456442 2019-06-12 09:56:24 +08:00
parent 185bbd9202
commit a9e60ba852
2 changed files with 9 additions and 6 deletions

View file

@ -46,7 +46,7 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
var errTooMuchInvalidRequest = errors.New("too much invalid requests made")
var errTooManyInvalidRequest = errors.New("too many invalid requests made")
const (
softResponseLimit = 2 * 1024 * 1024 // Target maximum size of returned blocks, headers or node data.
@ -1152,8 +1152,8 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
// If the client has made too much invalid request(e.g. request a non-exist data),
// reject them to prevent SPAM attack.
if atomic.LoadUint64(&p.invalidReq) > maxRequesetErrors {
return errTooMuchInvalidRequest
if atomic.LoadUint64(&p.invalidReq) > maxRequestErrors {
return errTooManyInvalidRequest
}
return nil
}

View file

@ -43,7 +43,7 @@ var (
)
const (
maxRequesetErrors = 20 // number of invalid requests tolerated (makes the protocol less brittle but still avoids spam)
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)
)
@ -71,8 +71,12 @@ const (
)
type peer struct {
*p2p.Peer
// WARNING: The `invalidReq` field is accessed atomically. On 32 bit platforms, only
// 64-bit aligned fields can be atomic. The struct is guaranteed to be so aligned,
// so take advantage of that (https://golang.org/pkg/sync/atomic/#pkg-note-BUG).
invalidReq uint64
*p2p.Peer
rw p2p.MsgReadWriter
version int // Protocol version negotiated
@ -92,7 +96,6 @@ type peer struct {
// RequestProcessed is called
responseLock sync.Mutex
responseCount uint64
invalidReq uint64
poolEntry *poolEntry
hasBlock func(common.Hash, uint64, bool) bool