diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index c06e524aea73..8eba4ad52d57 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -61,7 +61,6 @@ type KadParams struct { RetryInterval int64 // initial interval before a peer is first redialed RetryExponent int // exponent to multiply retry intervals with MaxRetries int // maximum number of redial attempts - PruneInterval int // interval between peer pruning cycles // function to sanction or prevent suggesting a peer Reachable func(OverlayAddr) bool } @@ -76,7 +75,6 @@ func NewKadParams() *KadParams { RetryInterval: 4200000000, // 4.2 sec MaxRetries: 42, RetryExponent: 2, - PruneInterval: 0, // TODO: } } @@ -576,38 +574,6 @@ func (k *Kademlia) string() string { return "\n" + strings.Join(rows, "\n") } -// Prune implements a forever loop reacting to a ticker time channel given -// as the first argument -// the loop quits if the channel is closed -// it checks each kademlia bin and if the peer count is higher than -// the MaxBinSize parameter it drops the oldest n peers such that -// the bin is reduced to MinBinSize peers thus leaving slots to newly -// connecting peers -func (k *Kademlia) Prune(c <-chan time.Time) { - go func() { - for range c { - k.lock.RLock() - conns := k.conns - k.lock.RUnlock() - total := 0 - conns.EachBin(k.base, pof, 0, func(po, size int, f func(func(pot.Val, int) bool) bool) bool { - extra := size - k.MinBinSize - if size > k.MaxBinSize { - n := 0 - f(func(v pot.Val, po int) bool { - v.(*entry).conn().Drop(fmt.Errorf("bucket full")) - n++ - return n < extra - }) - total += extra - } - return true - }) - log.Trace(fmt.Sprintf("pruned %v peers", total)) - } - }() -} - // PeerPot keeps info about expected nearest neighbours and empty bins // used for testing only type PeerPot struct { diff --git a/swarm/network/kademlia_test.go b/swarm/network/kademlia_test.go index 3a4bfc8761b6..5fc02491867d 100644 --- a/swarm/network/kademlia_test.go +++ b/swarm/network/kademlia_test.go @@ -348,55 +348,6 @@ func TestSuggestPeerRetries(t *testing.T) { } -func TestPruning(t *testing.T) { - k := newTestKademlia("00000000") - k.On("10000000", "11000000", "10100000", "10010000", "10001000", "10000100") - k.On("01000000", "01100000", "01000100", "01000010", "01000001") - k.On("00100000", "00110000", "00100010", "00100001") - k.MaxBinSize = 4 - k.MinBinSize = 3 - prune := make(chan time.Time) - defer close(prune) - k.Prune((<-chan time.Time)(prune)) - prune <- time.Now() - quitc := make(chan bool) - timeout := time.NewTimer(1000 * time.Millisecond) - n := 0 - dropped := make(map[string]error) - expDropped := []string{ - "10010000", - "10100000", - "11000000", - "01000100", - "01100000", - } - go func() { - for e := range k.dropc { - err := e.(*dropError) - dropped[err.addr] = err.error - n++ - if n == len(expDropped) { - break - } - } - close(quitc) - }() - select { - case <-quitc: - case <-timeout.C: - t.Fatalf("timeout waiting for dropped peers. expected %v, got %v", len(expDropped), len(dropped)) - } - for _, addr := range expDropped { - err := dropped[addr] - if err == nil { - t.Fatalf("expected peer %v to be dropped", addr) - } - if err.Error() != "bucket full" { - t.Fatalf("incorrect error. expected %v, got %v", "bucket full", err) - } - } -} - func TestKademliaHiveString(t *testing.T) { k := newTestKademlia("00000000").On("01000000", "00100000").Register("10000000", "10000001") k.MaxProxDisplay = 8 diff --git a/swarm/network/simulations/overlay.go b/swarm/network/simulations/overlay.go index 0c9ac4ae4594..27d1e946a943 100644 --- a/swarm/network/simulations/overlay.go +++ b/swarm/network/simulations/overlay.go @@ -53,10 +53,7 @@ func (s *Simulation) NewService(ctx *adapters.ServiceContext) (node.Service, err kp.MaxRetries = 1000 kp.RetryExponent = 2 kp.RetryInterval = 1000000 - kp.PruneInterval = 2000 kad := network.NewKademlia(addr.Over(), kp) - ticker := time.NewTicker(time.Duration(kad.PruneInterval) * time.Millisecond) - kad.Prune(ticker.C) hp := network.NewHiveParams() hp.Discovery = !*noDiscovery hp.KeepAliveInterval = 300 * time.Millisecond