Skip to content

Commit

Permalink
Upgrade to go-libp2p v0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
guseggert committed Nov 29, 2021
1 parent cd05807 commit 549f282
Show file tree
Hide file tree
Showing 9 changed files with 417 additions and 222 deletions.
43 changes: 30 additions & 13 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ func setupDHT(ctx context.Context, t *testing.T, client bool, options ...Option)
baseOpts = append(baseOpts, Mode(ModeServer))
}

host, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
host, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
t.Cleanup(func() { host.Close() })

d, err := New(ctx, host, append(baseOpts, options...)...)
t.Cleanup(func() { d.Close() })
require.NoError(t, err)
return d
}
Expand Down Expand Up @@ -703,7 +705,7 @@ func TestRefreshBelowMinRTThreshold(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

host, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
host, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)

// enable auto bootstrap on A
Expand Down Expand Up @@ -1120,8 +1122,9 @@ func TestFindPeerWithQueryFilter(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

filteredPeer, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
filteredPeer, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer filteredPeer.Close()
dhts := setupDHTS(t, ctx, 4, QueryFilter(func(_ interface{}, ai peer.AddrInfo) bool {
return ai.ID != filteredPeer.ID()
}))
Expand Down Expand Up @@ -1584,15 +1587,17 @@ func TestHandleRemotePeerProtocolChanges(t *testing.T) {
}

// start host 1 that speaks dht v1
hA, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
hA, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer hA.Close()
dhtA, err := New(ctx, hA, os...)
require.NoError(t, err)
defer dhtA.Close()

// start host 2 that also speaks dht v1
hB, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
hB, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer hB.Close()
dhtB, err := New(ctx, hB, os...)
require.NoError(t, err)
defer dhtB.Close()
Expand Down Expand Up @@ -1627,15 +1632,19 @@ func TestGetSetPluggedProtocol(t *testing.T) {
DisableAutoRefresh(),
}

hA, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
hA, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer hA.Close()
dhtA, err := New(ctx, hA, os...)
require.NoError(t, err)
defer dhtA.Close()

hB, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
hB, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer hB.Close()
dhtB, err := New(ctx, hB, os...)
require.NoError(t, err)
defer dhtB.Close()

connect(t, ctx, dhtA, dhtB)

Expand All @@ -1654,25 +1663,29 @@ func TestGetSetPluggedProtocol(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

hA, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
hA, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer hA.Close()
dhtA, err := New(ctx, hA, []Option{
ProtocolPrefix("/esh"),
Mode(ModeServer),
NamespacedValidator("v", blankValidator{}),
DisableAutoRefresh(),
}...)
require.NoError(t, err)
defer dhtA.Close()

hB, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
hB, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer hB.Close()
dhtB, err := New(ctx, hB, []Option{
ProtocolPrefix("/lsr"),
Mode(ModeServer),
NamespacedValidator("v", blankValidator{}),
DisableAutoRefresh(),
}...)
require.NoError(t, err)
defer dhtB.Close()

connectNoSync(t, ctx, dhtA, dhtB)

Expand Down Expand Up @@ -1937,7 +1950,7 @@ func TestBootStrapWhenRTIsEmpty(t *testing.T) {
// to it's Routing Table.
// AutoRefresh needs to be enabled for this.

h1, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
dht1, err := New(
ctx,
Expand Down Expand Up @@ -1977,7 +1990,7 @@ func TestBootStrapWhenRTIsEmpty(t *testing.T) {
// This should add the bootstrap peers and the peer thats the bootstrap peers are connected to
// to it's Routing Table.
// AutoRefresh needs to be enabled for this.
h1, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
dht1, err := New(
ctx,
Expand Down Expand Up @@ -2053,14 +2066,17 @@ func TestPreconnectedNodes(t *testing.T) {
}

// Create hosts
h1, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
h2, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
defer h1.Close()
h2, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
defer h2.Close()

// Setup first DHT
d1, err := New(ctx, h1, opts...)
require.NoError(t, err)
defer d1.Close()

// Connect the first host to the second
err = h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
Expand All @@ -2078,6 +2094,7 @@ func TestPreconnectedNodes(t *testing.T) {
// Setup the second DHT
d2, err := New(ctx, h2, opts...)
require.NoError(t, err)
defer h2.Close()

// See if it works
peers, err := d2.GetClosestPeers(ctx, "testkey")
Expand Down
12 changes: 8 additions & 4 deletions dual/dual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func MkFilterForPeer() (func(_ interface{}, p peer.ID) bool, *customRtHelper) {
}

func setupDHTWithFilters(ctx context.Context, t *testing.T, options ...dht.Option) (*DHT, []*customRtHelper) {
h, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
h, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
t.Cleanup(func() { h.Close() })

wanFilter, wanRef := MkFilterForPeer()
wanOpts := []dht.Option{
Expand Down Expand Up @@ -89,8 +90,9 @@ func setupDHTWithFilters(ctx context.Context, t *testing.T, options ...dht.Optio
func setupDHT(ctx context.Context, t *testing.T, options ...dht.Option) *DHT {
t.Helper()

host, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
host, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
t.Cleanup(func() { host.Close() })

baseOpts := []dht.Option{
dht.NamespacedValidator("v", blankValidator{}),
Expand Down Expand Up @@ -144,8 +146,9 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs

d, hlprs := setupDHTWithFilters(ctx, t)

whost, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
whost, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
t.Cleanup(func() { whost.Close() })

wan, err := dht.New(
ctx,
Expand All @@ -158,8 +161,9 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs
hlprs[0].allow = wan.PeerID()
connect(ctx, t, d.WAN, wan)

lhost, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
lhost, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
t.Cleanup(func() { lhost.Close() })

lan, err := dht.New(
ctx,
Expand Down
4 changes: 2 additions & 2 deletions ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestGetFailures(t *testing.T) {

ctx := context.Background()

host1, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
host1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
host2, err := bhost.NewHost(ctx, swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport), new(bhost.HostOpts))
host2, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)

d, err := New(ctx, host1, testPrefix, DisableAutoRefresh(), Mode(ModeServer))
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ require (
github.com/ipfs/go-log v1.0.5
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-eventbus v0.2.1
github.com/libp2p/go-libp2p v0.14.4
github.com/libp2p/go-libp2p-core v0.8.6
github.com/libp2p/go-libp2p v0.16.0
github.com/libp2p/go-libp2p-core v0.11.0
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-peerstore v0.2.8
github.com/libp2p/go-libp2p-peerstore v0.4.0
github.com/libp2p/go-libp2p-record v0.1.3
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/libp2p/go-libp2p-swarm v0.5.3
github.com/libp2p/go-libp2p-testing v0.4.2
github.com/libp2p/go-libp2p-swarm v0.8.0
github.com/libp2p/go-libp2p-testing v0.5.0
github.com/libp2p/go-libp2p-xor v0.0.0-20210714161855-5c005aca55db
github.com/libp2p/go-msgio v0.0.6
github.com/libp2p/go-msgio v0.1.0
github.com/libp2p/go-netroute v0.1.6
github.com/multiformats/go-base32 v0.0.3
github.com/multiformats/go-multiaddr v0.3.3
github.com/multiformats/go-multiaddr v0.4.0
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multihash v0.0.15
github.com/multiformats/go-multistream v0.2.2
Expand All @@ -37,5 +37,5 @@ require (
go.opencensus.io v0.23.0
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
go.uber.org/zap v1.18.1
go.uber.org/zap v1.19.0
)
Loading

0 comments on commit 549f282

Please sign in to comment.