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 1e4d84f
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 124 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
5 changes: 4 additions & 1 deletion backoffconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ func (h *maxDialHost) Connect(ctx context.Context, ai peer.AddrInfo) error {
return h.Host.Connect(ctx, ai)
}

type hosts []host.Host

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

for i := 0; i < n; i++ {
netw := swarmt.GenSwarm(t, ctx)
netw := swarmt.GenSwarm(t)
h := bhost.NewBlankHost(netw)
t.Cleanup(func() { h.Close() })
out = append(out, h)
}

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 1e4d84f

Please sign in to comment.