Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ const (

// Number of application errors that can be tolerated before banning the node and disconnecting
toleranceOfApplicationErrors = 3

// time for soft ban
dynamicBanTime = 4 * time.Hour
)

var (
ErrorProgressTimeout = errors.New("progress timeout")
ErrorProgressTimeout = errors.New("progress timeout")
ErrorApplicationTimeout = errors.New("application timeout")
)

Expand Down Expand Up @@ -798,7 +801,7 @@ func (h *handler) handle(p *peer) error {
// protocol handler. We should band these clients immediately.
// ex: go-corex, Efireal, Geth all with caps=[opera/62]
if !strings.Contains(strings.ToLower(p.Name()), "opera") {
discfilter.Ban(p.ID())
discfilter.BanStatic(p.ID())
return p2p.DiscProtocolError
}

Expand Down Expand Up @@ -827,7 +830,7 @@ func (h *handler) handle(p *peer) error {
)
if err := p.Handshake(h.NetworkID, myProgress, common.Hash(genesis)); err != nil {
p.Log().Debug("Handshake failed", "err", err)
discfilter.Ban(p.ID())
discfilter.BanStatic(p.ID())
return err
}

Expand Down Expand Up @@ -890,30 +893,30 @@ func (h *handler) handle(p *peer) error {
progressWatchDogTimer.Reset(noProgressTime)
} else {
p.Log().Warn("progress timer timeout: ", "name", p.Name(), "node", p.Node().String())
discfilter.Ban(p.ID())
discfilter.BanDynamic(p.ID(), dynamicBanTime)
return ErrorProgressTimeout
}
case <- applicationWatchDogTimer.C:
case <-applicationWatchDogTimer.C:
if p.IsApplicationProgressing() {
applicationWatchDogTimer.Reset(noAppMessageTime)
} else {
p.Log().Warn("application timer timeout: ", "name", p.Name(), "node", p.Node().String())
discfilter.Ban(p.ID())
discfilter.BanDynamic(p.ID(), dynamicBanTime)
return ErrorApplicationTimeout
}
default:
err := h.handleMsg(p)
if err != nil {
p.Log().Debug("Message handling failed", "err", err)
if strings.Contains(err.Error(), errorToString[ErrPeerNotProgressing]) {
discfilter.Ban(p.ID())
discfilter.BanDynamic(p.ID(), dynamicBanTime)
return err
}
// Ban peer and disconnect if the number of errors in the handling of application message
// crosses a threshold.
noOfApplicationErrors++
if noOfApplicationErrors > toleranceOfApplicationErrors {
discfilter.Ban(p.ID())
discfilter.BanDynamic(p.ID(), dynamicBanTime)
return err
}
}
Expand Down