Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
move out-of-the-box decay and bump functions to go-libp2p-core.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed May 14, 2020
1 parent be11534 commit 489f0dd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 162 deletions.
69 changes: 0 additions & 69 deletions decay_presets.go

This file was deleted.

27 changes: 13 additions & 14 deletions decay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/peer"

"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/peer"
tu "github.com/libp2p/go-libp2p-core/test"

"github.com/benbjohnson/clock"
Expand All @@ -18,7 +17,7 @@ func TestDecayExpire(t *testing.T) {
mgr, decay, mockClock = testDecayTracker(t)
)

tag, err := decay.RegisterDecayingTag("pop", 250*time.Millisecond, ExpireWhenInactive(1*time.Second), SumUnbounded())
tag, err := decay.RegisterDecayingTag("pop", 250*time.Millisecond, connmgr.DecayExpireWhenInactive(1*time.Second), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestMultipleBumps(t *testing.T) {
mgr, decay, _ = testDecayTracker(t)
)

tag, err := decay.RegisterDecayingTag("pop", 250*time.Millisecond, ExpireWhenInactive(1*time.Second), SumBounded(10, 20))
tag, err := decay.RegisterDecayingTag("pop", 250*time.Millisecond, connmgr.DecayExpireWhenInactive(1*time.Second), connmgr.BumpSumBounded(10, 20))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -85,17 +84,17 @@ func TestMultipleTagsNoDecay(t *testing.T) {
mgr, decay, _ = testDecayTracker(t)
)

tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, NoDecay(), SumBounded(0, 100))
tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, connmgr.DecayNone(), connmgr.BumpSumBounded(0, 100))
if err != nil {
t.Fatal(err)
}

tag2, err := decay.RegisterDecayingTag("bop", 250*time.Millisecond, NoDecay(), SumBounded(0, 100))
tag2, err := decay.RegisterDecayingTag("bop", 250*time.Millisecond, connmgr.DecayNone(), connmgr.BumpSumBounded(0, 100))
if err != nil {
t.Fatal(err)
}

tag3, err := decay.RegisterDecayingTag("foo", 250*time.Millisecond, NoDecay(), SumBounded(0, 100))
tag3, err := decay.RegisterDecayingTag("foo", 250*time.Millisecond, connmgr.DecayNone(), connmgr.BumpSumBounded(0, 100))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -128,17 +127,17 @@ func TestCustomFunctions(t *testing.T) {
mgr, decay, mockClock = testDecayTracker(t)
)

tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, FixedDecay(10), SumUnbounded())
tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, connmgr.DecayFixed(10), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}

tag2, err := decay.RegisterDecayingTag("bop", 100*time.Millisecond, FixedDecay(5), SumUnbounded())
tag2, err := decay.RegisterDecayingTag("bop", 100*time.Millisecond, connmgr.DecayFixed(5), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}

tag3, err := decay.RegisterDecayingTag("foo", 50*time.Millisecond, FixedDecay(1), SumUnbounded())
tag3, err := decay.RegisterDecayingTag("foo", 50*time.Millisecond, connmgr.DecayFixed(1), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -179,17 +178,17 @@ func TestMultiplePeers(t *testing.T) {
mgr, decay, mockClock = testDecayTracker(t)
)

tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, FixedDecay(10), SumUnbounded())
tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, connmgr.DecayFixed(10), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}

tag2, err := decay.RegisterDecayingTag("bop", 100*time.Millisecond, FixedDecay(5), SumUnbounded())
tag2, err := decay.RegisterDecayingTag("bop", 100*time.Millisecond, connmgr.DecayFixed(5), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}

tag3, err := decay.RegisterDecayingTag("foo", 50*time.Millisecond, FixedDecay(1), SumUnbounded())
tag3, err := decay.RegisterDecayingTag("foo", 50*time.Millisecond, connmgr.DecayFixed(1), connmgr.BumpSumUnbounded())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -233,7 +232,7 @@ func TestLinearDecayOverwrite(t *testing.T) {
mgr, decay, mockClock = testDecayTracker(t)
)

tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, LinearDecay(0.5), Overwrite())
tag1, err := decay.RegisterDecayingTag("beep", 250*time.Millisecond, connmgr.DecayLinear(0.5), connmgr.BumpOverwrite())
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module github.com/libp2p/go-libp2p-connmgr

go 1.13

require (
github.com/benbjohnson/clock v1.0.0
github.com/benbjohnson/clock v1.0.1
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-log v0.0.1
github.com/libp2p/go-libp2p-core v0.5.4-0.20200507161646-506c5fa958cd
github.com/ipfs/go-log v1.0.4
github.com/libp2p/go-libp2p-core v0.5.4-0.20200514121551-d3277047d6ca
github.com/multiformats/go-multiaddr v0.2.1
github.com/smola/gocompat v0.2.0 // indirect
)

go 1.13
Loading

0 comments on commit 489f0dd

Please sign in to comment.