Skip to content

Commit

Permalink
Merge pull request ethereum#406 from ethersphere/prune-remove-2
Browse files Browse the repository at this point in the history
swarm/network: Remove pruning implementation
  • Loading branch information
nonsense authored Apr 20, 2018
2 parents 068ad8e + f4d08ce commit 54fc060
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 86 deletions.
34 changes: 0 additions & 34 deletions swarm/network/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -76,7 +75,6 @@ func NewKadParams() *KadParams {
RetryInterval: 4200000000, // 4.2 sec
MaxRetries: 42,
RetryExponent: 2,
PruneInterval: 0, // TODO:
}
}

Expand Down Expand Up @@ -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 {
Expand Down
49 changes: 0 additions & 49 deletions swarm/network/kademlia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions swarm/network/simulations/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54fc060

Please sign in to comment.