// To construct a simple host with all the default settings, just use `New`
h, err := libp2p.New(ctx)
if err != nil {
panic(err)
}
// We've created the identity, now we need to store it.
// A peerstore holds information about peers, including your own
ps := pstore.NewPeerstore()
ps.AddPrivKey(pid, priv)
ps.AddPubKey(pid, pub)
fmt.Printf("Hello World, my hosts ID is %s\n", h.ID())
```
Next, you'll need at least one address that you want to listen on. You can go from a string to a multiaddr like this:
If you want more control over the configuration, you can specify some options to the constructor. In this snippet we generate our own ID and specified on which address we want to listen:
Now you know who you are, and where you live (in a manner of speaking). The next step is setting up a 'swarm network' to handle all the peers you will connect to. The swarm handles incoming connections from other peers, and handles the negotiation of new outbound connections.
h2, err := libp2p.New(ctx,
// Use your own created keypair
libp2p.Identity(priv),
```go
import (
"context"
swarm "github.com/libp2p/go-libp2p-swarm"
// Set your own listen address
// The config takes an array of addresses, specify as many as you want.