Commit 5ad430a7 authored by acud's avatar acud Committed by GitHub

Kademlia: use swarm.MaxBins (#412)

* kademlia: use swarm maxbins
parent 6eedd003
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package kademlia package kademlia
var ( var (
MaxBins = maxBins
TimeToRetry = &timeToRetry TimeToRetry = &timeToRetry
SaturationPeers = &saturationPeers SaturationPeers = &saturationPeers
) )
...@@ -22,7 +22,6 @@ import ( ...@@ -22,7 +22,6 @@ import (
) )
const ( const (
maxBins = 16
nnLowWatermark = 2 // the number of peers in consecutive deepest bins that constitute as nearest neighbours nnLowWatermark = 2 // the number of peers in consecutive deepest bins that constitute as nearest neighbours
maxConnAttempts = 3 // when there is maxConnAttempts failed connect calls for a given peer it is considered non-connectable maxConnAttempts = 3 // when there is maxConnAttempts failed connect calls for a given peer it is considered non-connectable
) )
...@@ -86,8 +85,8 @@ func New(o Options) *Kad { ...@@ -86,8 +85,8 @@ func New(o Options) *Kad {
addressBook: o.AddressBook, addressBook: o.AddressBook,
p2p: o.P2P, p2p: o.P2P,
saturationFunc: o.SaturationFunc, saturationFunc: o.SaturationFunc,
connectedPeers: pslice.New(maxBins), connectedPeers: pslice.New(int(swarm.MaxBins)),
knownPeers: pslice.New(maxBins), knownPeers: pslice.New(int(swarm.MaxBins)),
manageC: make(chan struct{}, 1), manageC: make(chan struct{}, 1),
waitNext: make(map[string]retryInfo), waitNext: make(map[string]retryInfo),
logger: o.Logger, logger: o.Logger,
...@@ -573,7 +572,7 @@ func (k *Kad) marshal(indent bool) ([]byte, error) { ...@@ -573,7 +572,7 @@ func (k *Kad) marshal(indent bool) ([]byte, error) {
} }
var infos []binInfo var infos []binInfo
for i := (maxBins - 1); i >= 0; i-- { for i := int(swarm.MaxPO); i >= 0; i-- {
infos = append(infos, binInfo{}) infos = append(infos, binInfo{})
} }
......
...@@ -105,7 +105,7 @@ func TestNeighborhoodDepth(t *testing.T) { ...@@ -105,7 +105,7 @@ func TestNeighborhoodDepth(t *testing.T) {
kDepth(t, kad, 8) kDepth(t, kad, 8)
// fill the rest up to the bin before last and check that everything works at the edges // fill the rest up to the bin before last and check that everything works at the edges
for i := 10; i < kademlia.MaxBins-1; i++ { for i := 10; i < int(swarm.MaxBins)-1; i++ {
addr := test.RandomAddressAt(base, i) addr := test.RandomAddressAt(base, i)
addOne(t, signer, kad, ab, addr) addOne(t, signer, kad, ab, addr)
waitConn(t, &conns) waitConn(t, &conns)
......
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