Skip to content

Commit

Permalink
fix: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Nov 24, 2021
1 parent bd6a65e commit ef98984
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
9 changes: 4 additions & 5 deletions pkg/topology/kademlia/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
timeToRetry = 2 * shortRetry
broadcastBinSize = 4
peerPingPollTime = 10 * time.Second // how often to ping a peer
maxFirstbin = float64(50)
)

var (
Expand Down Expand Up @@ -137,6 +138,8 @@ func New(
o Options,
) (*Kad, error) {

start := time.Now()

if o.OverSaturationCalc == nil {
o.OverSaturationCalc = defaultOverSaturationCalc
}
Expand All @@ -147,10 +150,6 @@ func New(
o.BitSuffixLength = defaultBitSuffixLength
}

for i := 0; i < int(swarm.MaxBins); i++ {
}

start := time.Now()
imc, err := im.NewCollector(metricsDB)
if err != nil {
return nil, err
Expand Down Expand Up @@ -212,7 +211,7 @@ func New(
// produces oversaturation values using an exponential decay formula, sequence is as follows:
// bin 0 -> 50, 44, 39, 34, 30, 27
func defaultOverSaturationCalc(bin uint8) int {
return int(math.Round(50 * math.Exp(-float64(bin)/8.0)))
return int(math.Round(maxFirstbin * math.Exp(-float64(bin)/8.0)))
}

type peerConnInfo struct {
Expand Down
22 changes: 12 additions & 10 deletions pkg/topology/kademlia/kademlia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ func TestNeighborhoodDepthWithReachability(t *testing.T) {

var (
conns int32 // how many connect calls were made to the p2p mock
base, kad, ab, _, signer = newTestKademlia(t, &conns, nil, kademlia.Options{})
base, kad, ab, _, signer = newTestKademlia(t, &conns, nil, kademlia.Options{
OverSaturationCalc: func(uint8) int { return 20 },
})
)

kad.SetRadius(swarm.MaxPO) // initial tests do not check for radius
Expand Down Expand Up @@ -1726,6 +1728,15 @@ func TestIteratorOpts(t *testing.T) {
})
}

func TestDefaultOverSaturationCalc(t *testing.T) {
nums := []int{50, 44, 39, 34, 30, 27, 24, 21, 18, 16, 14, 13, 11, 10}
for i, n := range nums {
if got := kademlia.DefaultOverSaturationCalc(uint8(i)); got != n {
t.Fatalf("want %d, got %d", n, got)
}
}
}

type boolgen struct {
src rand.Source
cache int64
Expand All @@ -1744,15 +1755,6 @@ func (b *boolgen) Bool() bool {
return result
}

func TestDefaultOverSaturationCalc(t *testing.T) {
nums := []int{50, 44, 39, 34, 30, 27, 24, 21, 18, 16, 14, 13, 11, 10}
for i, n := range nums {
if got := kademlia.DefaultOverSaturationCalc(uint8(i)); got != n {
t.Fatalf("want %d, got %d", n, got)
}
}
}

func mineBin(t *testing.T, base swarm.Address, bin, count int, isBalanced bool) []swarm.Address {

var rndAddrs = make([]swarm.Address, count)
Expand Down

0 comments on commit ef98984

Please sign in to comment.