Go-libp2p-core Migration Issue

I’m trying to migrate a small bit of code to use go-libp2p-core. After updating the imports and some types I get the following error:

# github.com/ipfs/go-bitswap/testnet
../../../../pkg/mod/github.com/ipfs/go-bitswap@v0.0.3/testnet/peernet.go:30:30: cannot use client (type "github.com/libp2p/go-libp2p-core/host".Host) as type "github.com/libp2p/go-libp2p-host".Host in argument to "github.com/ipfs/go-bitswap/network".NewFromIpfsHost:
	"github.com/libp2p/go-libp2p-core/host".Host does not implement "github.com/libp2p/go-libp2p-host".Host (wrong type for ConnManager method)
		have ConnManager() connmgr.ConnManager
		want ConnManager() ifconnmgr.ConnManager
# github.com/libp2p/go-libp2p-autonat-svc
../../../../pkg/mod/github.com/libp2p/go-libp2p-autonat-svc@v0.0.2/svc.go:50:3: cannot use dialer (type "github.com/libp2p/go-libp2p-core/host".Host) as type "github.com/libp2p/go-libp2p-host".Host in field value:
	"github.com/libp2p/go-libp2p-core/host".Host does not implement "github.com/libp2p/go-libp2p-host".Host (wrong type for ConnManager method)
		have ConnManager() connmgr.ConnManager
		want ConnManager() ifconnmgr.ConnManager

Corresponding changes can be found here: https://github.com/ChainSafe/gossamer/pull/158

It seems that github.com/ipfs/go-bitswap@v0.0.3 is rather outdated and does not have go-libp2p-core. When I update it withgo get -u github.com/ipfs/go-bitswap, it pulls the latest version (w/ go-libp2p-core) and I get this:

# github.com/libp2p/go-libp2p/p2p/host/routed
../../go/pkg/mod/github.com/libp2p/go-libp2p@v0.1.1/p2p/host/routed/routed.go:190:5: cannot use (*RoutedHost)(nil) (type *RoutedHost) as type host.Host in assignment:
        *RoutedHost does not implement host.Host (missing EventBus method)
# github.com/libp2p/go-libp2p/p2p/host/basic
../../go/pkg/mod/github.com/libp2p/go-libp2p@v0.1.1/p2p/host/basic/basic_host.go:85:5: cannot use (*BasicHost)(nil) (type *BasicHost) as type host.Host in assignment:
        *BasicHost does not implement host.Host (missing EventBus method)
../../go/pkg/mod/github.com/libp2p/go-libp2p@v0.1.1/p2p/host/basic/basic_host.go:151:32: cannot use h (type *BasicHost) as type host.Host in argument to identify.NewIDService:
        *BasicHost does not implement host.Host (missing EventBus method)
../../go/pkg/mod/github.com/libp2p/go-libp2p@v0.1.1/p2p/host/basic/basic_host.go:178:32: cannot use h (type *BasicHost) as type host.Host in argument to ping.NewPingService:
        *BasicHost does not implement host.Host (missing EventBus method)

Could someone point me in the right direction?

Hey @ansermino, thanks for pointing out those issues. It looks like the recent addition of the EventBus method is causing some problems.

Could you try pinning go-libp2p-core to the latest release without the EventBus (v0.0.3). I think you should be able to do go mod edit -require github.com/libp2p/go-libp2p-core@0.0.3

The EventBus work is happening right now and this will hopefully “fix itself” soon when this PR lands in go-libp2p and adds the EventBus type to the Host types.

@ansermino - the PR I mentioned above was merged this morning, so hopefully that will resolve the issue without needing to pin to an earlier version of go-libp2p-core. Let me know if it still gives you problems & I can try to help out!

1 Like