Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update to go libp2p v0.25 #815

Merged
merged 7 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/libp2p/go-libp2p/core/protocol"

logging "github.com/ipfs/go-log"
//lint:ignore SA1019 TODO migrate away from gogo pb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent 10 minutes and failed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the problem? I did this for libp2p and it should be quite straightforward. Maybe I can help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a makefile that doesn't work. It needs you to fetch certain dependencies before running make. That script needs to get updated (or removed in favor of gogenerate). Bonus points for having CI check the output.

"github.com/libp2p/go-msgio/protoio"

pb "github.com/libp2p/go-libp2p-kad-dht/pb"
Expand Down
4 changes: 1 addition & 3 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ type IpfsDHT struct {

// DHT protocols we query with. We'll only add peers to our routing
// table if they speak these protocols.
protocols []protocol.ID
protocolsStrs []string
protocols []protocol.ID

// DHT protocols we can respond to.
serverProtocols []protocol.ID
Expand Down Expand Up @@ -285,7 +284,6 @@ func makeDHT(ctx context.Context, h host.Host, cfg dhtcfg.Config) (*IpfsDHT, err
host: h,
birth: time.Now(),
protocols: protocols,
protocolsStrs: protocol.ConvertToStrings(protocols),
serverProtocols: serverProtocols,
bucketSize: cfg.BucketSize,
alpha: cfg.Concurrency,
Expand Down
15 changes: 8 additions & 7 deletions dht_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func (m *mockConn) GetStreams() []network.Stream { return [
func (m *mockConn) Stat() network.ConnStats {
return network.ConnStats{Stats: network.Stats{Direction: network.DirOutbound}}
}
func (m *mockConn) Scope() network.ConnScope { return network.NullScope }
func (m *mockConn) LocalMultiaddr() ma.Multiaddr { return m.local.Addrs[0] }
func (m *mockConn) RemoteMultiaddr() ma.Multiaddr { return m.remote.Addrs[0] }
func (m *mockConn) LocalPeer() peer.ID { return m.local.ID }
func (m *mockConn) LocalPrivateKey() ic.PrivKey { return nil }
func (m *mockConn) RemotePeer() peer.ID { return m.remote.ID }
func (m *mockConn) RemotePublicKey() ic.PubKey { return nil }
func (m *mockConn) Scope() network.ConnScope { return &network.NullScope{} }
func (m *mockConn) LocalMultiaddr() ma.Multiaddr { return m.local.Addrs[0] }
func (m *mockConn) RemoteMultiaddr() ma.Multiaddr { return m.remote.Addrs[0] }
func (m *mockConn) LocalPeer() peer.ID { return m.local.ID }
func (m *mockConn) LocalPrivateKey() ic.PrivKey { return nil }
func (m *mockConn) RemotePeer() peer.ID { return m.remote.ID }
func (m *mockConn) RemotePublicKey() ic.PubKey { return nil }
func (m *mockConn) ConnState() network.ConnectionState { return network.ConnectionState{} }

func TestFilterCaching(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
Expand Down
22 changes: 18 additions & 4 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/routing"
ma "github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multihash"
Expand Down Expand Up @@ -119,6 +120,7 @@ func setupDHT(ctx context.Context, t *testing.T, client bool, options ...Option)

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

d, err := New(ctx, host, append(baseOpts, options...)...)
Expand Down Expand Up @@ -708,6 +710,7 @@ func TestRefreshBelowMinRTThreshold(t *testing.T) {

host, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
host.Start()
Jorropo marked this conversation as resolved.
Show resolved Hide resolved

// enable auto bootstrap on A
dhtA, err := New(
Expand Down Expand Up @@ -1134,6 +1137,7 @@ func TestFindPeerWithQueryFilter(t *testing.T) {

filteredPeer, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
filteredPeer.Start()
defer filteredPeer.Close()
dhts := setupDHTS(t, ctx, 4, QueryFilter(func(_ interface{}, ai peer.AddrInfo) bool {
return ai.ID != filteredPeer.ID()
Expand Down Expand Up @@ -1603,6 +1607,7 @@ func TestHandleRemotePeerProtocolChanges(t *testing.T) {
// start host 1 that speaks dht v1
hA, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
hA.Start()
defer hA.Close()
dhtA, err := New(ctx, hA, os...)
require.NoError(t, err)
Expand All @@ -1611,6 +1616,7 @@ func TestHandleRemotePeerProtocolChanges(t *testing.T) {
// start host 2 that also speaks dht v1
hB, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
hB.Start()
defer hB.Close()
dhtB, err := New(ctx, hB, os...)
require.NoError(t, err)
Expand Down Expand Up @@ -1648,13 +1654,15 @@ func TestGetSetPluggedProtocol(t *testing.T) {

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

hB, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
hB.Start()
defer hB.Close()
dhtB, err := New(ctx, hB, os...)
require.NoError(t, err)
Expand All @@ -1679,6 +1687,7 @@ func TestGetSetPluggedProtocol(t *testing.T) {

hA, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
hA.Start()
defer hA.Close()
dhtA, err := New(ctx, hA, []Option{
ProtocolPrefix("/esh"),
Expand All @@ -1691,6 +1700,7 @@ func TestGetSetPluggedProtocol(t *testing.T) {

hB, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
hB.Start()
defer hB.Close()
dhtB, err := New(ctx, hB, []Option{
ProtocolPrefix("/lsr"),
Expand Down Expand Up @@ -1735,7 +1745,7 @@ func TestClientModeAtInit(t *testing.T) {
client := setupDHT(ctx, t, true)
pinger.Host().Peerstore().AddAddrs(client.PeerID(), client.Host().Addrs(), peerstore.AddressTTL)
err := pinger.Ping(context.Background(), client.PeerID())
assert.True(t, errors.Is(err, multistream.ErrNotSupported))
assert.True(t, errors.Is(err, multistream.ErrNotSupported[protocol.ID]{}))
}

func TestModeChange(t *testing.T) {
Expand All @@ -1746,7 +1756,7 @@ func TestModeChange(t *testing.T) {
clientToServer := setupDHT(ctx, t, true)
clientOnly.Host().Peerstore().AddAddrs(clientToServer.PeerID(), clientToServer.Host().Addrs(), peerstore.AddressTTL)
err := clientOnly.Ping(ctx, clientToServer.PeerID())
assert.True(t, errors.Is(err, multistream.ErrNotSupported))
assert.True(t, errors.Is(err, multistream.ErrNotSupported[protocol.ID]{}))
err = clientToServer.setMode(modeServer)
assert.Nil(t, err)
err = clientOnly.Ping(ctx, clientToServer.PeerID())
Expand Down Expand Up @@ -1775,7 +1785,7 @@ func TestDynamicModeSwitching(t *testing.T) {

assertDHTClient := func() {
err = prober.Ping(ctx, node.PeerID())
assert.True(t, errors.Is(err, multistream.ErrNotSupported))
assert.True(t, errors.Is(err, multistream.ErrNotSupported[protocol.ID]{}))
if l := len(prober.RoutingTable().ListPeers()); l != 0 {
t.Errorf("expected routing table length to be 0; instead is %d", l)
}
Expand Down Expand Up @@ -1966,6 +1976,7 @@ func TestBootStrapWhenRTIsEmpty(t *testing.T) {

h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
h1.Start()
dht1, err := New(
ctx,
h1,
Expand Down Expand Up @@ -2006,6 +2017,7 @@ func TestBootStrapWhenRTIsEmpty(t *testing.T) {
// AutoRefresh needs to be enabled for this.
h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
h1.Start()
dht1, err := New(
ctx,
h1,
Expand Down Expand Up @@ -2082,9 +2094,11 @@ func TestPreconnectedNodes(t *testing.T) {
// Create hosts
h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
h1.Start()
defer h1.Close()
h2, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
h2.Start()
defer h2.Close()

// Setup first DHT
Expand All @@ -2099,7 +2113,7 @@ func TestPreconnectedNodes(t *testing.T) {
// Wait until we know identify has completed by checking for supported protocols
// TODO: Is this needed? Could we do h2.Connect(h1) and that would wait for identify to complete.
require.Eventually(t, func() bool {
h1Protos, err := h2.Peerstore().SupportsProtocols(h1.ID(), d1.protocolsStrs...)
h1Protos, err := h2.Peerstore().SupportsProtocols(h1.ID(), d1.protocols...)
require.NoError(t, err)

return len(h1Protos) > 0
Expand Down
4 changes: 4 additions & 0 deletions dual/dual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ 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(swarmt.GenSwarm(t, swarmt.OptDisableReuseport), new(bhost.HostOpts))
require.NoError(t, err)
h.Start()
t.Cleanup(func() { h.Close() })

wanFilter, wanRef := MkFilterForPeer()
Expand Down Expand Up @@ -92,6 +93,7 @@ func setupDHT(ctx context.Context, t *testing.T, options ...dht.Option) *DHT {

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

baseOpts := []dht.Option{
Expand Down Expand Up @@ -148,6 +150,7 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs

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

wan, err := dht.New(
Expand All @@ -163,6 +166,7 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs

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

lan, err := dht.New(
Expand Down
9 changes: 6 additions & 3 deletions ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/routing"
"github.com/stretchr/testify/require"

record "github.com/libp2p/go-libp2p-record"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"

//lint:ignore SA1019 TODO migrate away from gogo pb
"github.com/libp2p/go-msgio/protoio"

pb "github.com/libp2p/go-libp2p-kad-dht/pb"
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestHungRequest(t *testing.T) {
for _, proto := range d.serverProtocols {
// Hang on every request.
hosts[1].SetStreamHandler(proto, func(s network.Stream) {
defer s.Reset() //nolint
defer s.Reset() // nolint
<-ctx.Done()
})
}
Expand Down Expand Up @@ -104,8 +105,10 @@ func TestGetFailures(t *testing.T) {

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

d, err := New(ctx, host1, testPrefix, DisableAutoRefresh(), Mode(ModeServer))
require.NoError(t, err)
Expand Down Expand Up @@ -285,7 +288,7 @@ func TestNotFound(t *testing.T) {
if host == peer {
continue
}
_ = peer.Peerstore().AddProtocols(host.ID(), protocol.ConvertToStrings(d.serverProtocols)...)
_ = peer.Peerstore().AddProtocols(host.ID(), d.serverProtocols...)
}
}

Expand Down
Loading