mark peer as bad (#6250)

This commit is contained in:
Nishant Das 2020-06-14 22:10:18 +08:00 committed by GitHub
parent f9d80e4a28
commit 933ab6808b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,12 @@ func (r *Service) maintainPeerStatuses() {
runutil.RunEvery(r.ctx, interval, func() {
for _, pid := range r.p2p.Peers().Connected() {
go func(id peer.ID) {
if r.p2p.Peers().IsBad(id) {
if err := r.sendGoodByeAndDisconnect(r.ctx, codeGenericError, id); err != nil {
log.Errorf("Error when disconnecting with bad peer: %v", err)
}
return
}
// If the status hasn't been updated in the recent interval time.
lastUpdated, err := r.p2p.Peers().ChainStateLastUpdated(id)
if err != nil {
@ -36,6 +42,7 @@ func (r *Service) maintainPeerStatuses() {
if roughtime.Now().After(lastUpdated.Add(interval)) {
if err := r.reValidatePeer(r.ctx, id); err != nil {
log.WithField("peer", id).WithError(err).Error("Failed to revalidate peer")
r.p2p.Peers().IncrementBadResponses(id)
}
}
}(pid)