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

Commit

Permalink
feat: plumb peerstore contexts changes through
Browse files Browse the repository at this point in the history
  • Loading branch information
guseggert committed Nov 10, 2021
1 parent 6983a7e commit 902ef56
Show file tree
Hide file tree
Showing 5 changed files with 652 additions and 125 deletions.
20 changes: 13 additions & 7 deletions backoffcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func TestBackoffDiscoverySingleBackoff(t *testing.T) {

discServer := newDiscoveryServer()

h1 := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h2 := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h1 := bhost.NewBlankHost(swarmt.GenSwarm(t))
defer h1.Close()
h2 := bhost.NewBlankHost(swarmt.GenSwarm(t))
defer h2.Close()
d1 := &mockDiscoveryClient{h1, discServer}
d2 := &mockDiscoveryClient{h2, discServer}

Expand Down Expand Up @@ -100,8 +102,10 @@ func TestBackoffDiscoveryMultipleBackoff(t *testing.T) {

discServer := newDiscoveryServer()

h1 := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h2 := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h1 := bhost.NewBlankHost(swarmt.GenSwarm(t))
defer h1.Close()
h2 := bhost.NewBlankHost(swarmt.GenSwarm(t))
defer h2.Close()
d1 := &mockDiscoveryClient{h1, discServer}
d2 := &mockDiscoveryClient{h2, discServer}

Expand Down Expand Up @@ -152,7 +156,8 @@ func TestBackoffDiscoverySimultaneousQuery(t *testing.T) {
advertisers := make([]discovery.Discovery, n)

for i := 0; i < n; i++ {
h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h := bhost.NewBlankHost(swarmt.GenSwarm(t))
defer h.Close()
advertisers[i] = &mockDiscoveryClient{h, discServer}
}

Expand Down Expand Up @@ -210,11 +215,12 @@ func TestBackoffDiscoveryCacheCapacity(t *testing.T) {
advertisers := make([]discovery.Discovery, n)

for i := 0; i < n; i++ {
h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h := bhost.NewBlankHost(swarmt.GenSwarm(t))
defer h.Close()
advertisers[i] = &mockDiscoveryClient{h, discServer}
}

h1 := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h1 := bhost.NewBlankHost(swarmt.GenSwarm(t))
d1 := &mockDiscoveryClient{h1, discServer}

const discoveryInterval = time.Millisecond * 100
Expand Down
13 changes: 11 additions & 2 deletions backoffconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ func (h *maxDialHost) Connect(ctx context.Context, ai peer.AddrInfo) error {
return h.Host.Connect(ctx, ai)
}

func getNetHosts(t *testing.T, ctx context.Context, n int) []host.Host {
type hosts []host.Host

func (h hosts) Close() {
for _, s := range h {
s.Close()
}
}

func getNetHosts(t *testing.T, ctx context.Context, n int) hosts {
var out []host.Host

for i := 0; i < n; i++ {
netw := swarmt.GenSwarm(t, ctx)
netw := swarmt.GenSwarm(t)
h := bhost.NewBlankHost(netw)
out = append(out, h)
}
Expand All @@ -63,6 +71,7 @@ func TestBackoffConnector(t *testing.T) {
defer cancel()

hosts := getNetHosts(t, ctx, 5)
defer hosts.Close()
primary := &maxDialHost{
Host: hosts[0],
mux: sync.Mutex{},
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module github.com/libp2p/go-libp2p-discovery

require (
github.com/hashicorp/golang-lru v0.5.4
github.com/ipfs/go-cid v0.0.6
github.com/ipfs/go-log v1.0.4
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-log v1.0.5
github.com/libp2p/go-libp2p-blankhost v0.2.0
github.com/libp2p/go-libp2p-core v0.6.0
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p-swarm v0.2.8
github.com/multiformats/go-multihash v0.0.13
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
github.com/libp2p/go-libp2p-core v0.11.0
github.com/libp2p/go-libp2p-peerstore v0.4.0
github.com/libp2p/go-libp2p-swarm v0.8.0
github.com/multiformats/go-multihash v0.0.15
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)

go 1.15
Loading

0 comments on commit 902ef56

Please sign in to comment.