Commit 06ce0488 authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

block peers on disconnect threshold (#694)

parent 159efc59
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"sync" "sync"
"time"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
...@@ -253,7 +254,7 @@ func (a *Accounting) Debit(peer swarm.Address, price uint64) error { ...@@ -253,7 +254,7 @@ func (a *Accounting) Debit(peer swarm.Address, price uint64) error {
if nextBalance >= int64(a.paymentThreshold+a.paymentTolerance) { if nextBalance >= int64(a.paymentThreshold+a.paymentTolerance) {
// peer too much in debt // peer too much in debt
a.metrics.AccountingDisconnectsCount.Inc() a.metrics.AccountingDisconnectsCount.Inc()
return p2p.NewDisconnectError(ErrDisconnectThresholdExceeded) return p2p.NewBlockPeerError(10000*time.Hour, ErrDisconnectThresholdExceeded)
} }
return nil return nil
......
...@@ -197,7 +197,7 @@ func TestAccountingReserve(t *testing.T) { ...@@ -197,7 +197,7 @@ func TestAccountingReserve(t *testing.T) {
} }
} }
// TestAccountingDisconnect tests that exceeding the disconnect threshold with Debit returns a p2p.DisconnectError // TestAccountingDisconnect tests that exceeding the disconnect threshold with Debit returns a p2p.BlockPeerError
func TestAccountingDisconnect(t *testing.T) { func TestAccountingDisconnect(t *testing.T) {
logger := logging.New(ioutil.Discard, 0) logger := logging.New(ioutil.Discard, 0)
...@@ -231,9 +231,9 @@ func TestAccountingDisconnect(t *testing.T) { ...@@ -231,9 +231,9 @@ func TestAccountingDisconnect(t *testing.T) {
t.Fatal("expected Add to return error") t.Fatal("expected Add to return error")
} }
var e *p2p.DisconnectError var e *p2p.BlockPeerError
if !errors.As(err, &e) { if !errors.As(err, &e) {
t.Fatalf("expected DisconnectError, got %v", err) t.Fatalf("expected BlockPeerError, got %v", err)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment