Example one: The libp2p 'host' fails to compile

Hello libp2pers. I’ve been trying to learn go-libp2p. I went through the getting started and everything worked perfectly there. Then I got to the examples and copied the first example in “The libp2p ‘host’” but it isn’t compiling.

Here is the code:

https://raw.githubusercontent.com/libp2p/go-libp2p/master/examples/libp2p-host/host.go

Here is my log:

go: finding module for package github.com/libp2p/go-libp2p-kad-dht
go: finding module for package github.com/libp2p/go-libp2p-noise
go: finding module for package github.com/libp2p/go-libp2p-core/host
go: finding module for package github.com/libp2p/go-libp2p-quic-transport
go: finding module for package github.com/libp2p/go-libp2p-core/crypto
go: finding module for package github.com/libp2p/go-libp2p
go: finding module for package github.com/libp2p/go-libp2p-tls
go: finding module for package github.com/libp2p/go-libp2p-core/routing
go: finding module for package github.com/libp2p/go-libp2p-connmgr
go: found github.com/libp2p/go-libp2p in github.com/libp2p/go-libp2p v0.14.4
go: found github.com/libp2p/go-libp2p-connmgr in github.com/libp2p/go-libp2p-connmgr v0.2.4
go: found github.com/libp2p/go-libp2p-core/crypto in github.com/libp2p/go-libp2p-core v0.9.0
go: found github.com/libp2p/go-libp2p-core/host in github.com/libp2p/go-libp2p-core v0.9.0
go: found github.com/libp2p/go-libp2p-core/routing in github.com/libp2p/go-libp2p-core v0.9.0
go: found github.com/libp2p/go-libp2p-kad-dht in github.com/libp2p/go-libp2p-kad-dht v0.13.0
go: found github.com/libp2p/go-libp2p-noise in github.com/libp2p/go-libp2p-noise v0.2.2
go: found github.com/libp2p/go-libp2p-quic-transport in github.com/libp2p/go-libp2p-quic-transport v0.11.2
go: found github.com/libp2p/go-libp2p-tls in github.com/libp2p/go-libp2p-tls v0.1.3
# github.com/libp2p/go-libp2p/p2p/protocol/identify
../../../go/pkg/mod/github.com/libp2p/go-libp2p@v0.14.4/p2p/protocol/identify/id.go:536:23: ownKey.Bytes undefined (type "github.com/libp2p/go-libp2p-core/crypto".PubKey has no field or method Bytes)

I did try to figure out the problem for a couple hours before bothering yall. Google searches. Tried commenting out various parts of the code to isolate the line that might be causing it. But no luck.

use go-libp2p-corev0.8.6; 0.9.0 has some breaking changes which havent bubbled up yet.

1 Like

Sorry I’m pretty new. Roughly speaking, how does one specify that the compiler use an older release of go-libp2p-core?

you can do this with go mod:
go get github.com/libp2p/go-libp2p-core@v0.8.6

1 Like

thanks friend. that did the trick. :+1:t2: