prysm-pulse/shared/p2p/options.go

31 lines
792 B
Go
Raw Normal View History

package p2p
import (
"fmt"
libp2p "github.com/libp2p/go-libp2p"
ma "github.com/multiformats/go-multiaddr"
2018-08-14 16:16:21 +00:00
"github.com/prysmaticlabs/prysm/shared/iputils"
)
// buildOptions for the libp2p host.
2018-09-20 04:14:31 +00:00
// TODO(287): Expand on these options and provide the option configuration via flags.
// Currently, this is a random port and a (seemingly) consistent private key
// identity.
func buildOptions(port int) []libp2p.Option {
2018-08-14 16:16:21 +00:00
ip, err := iputils.ExternalIPv4()
if err != nil {
log.Errorf("Could not get IPv4 address: %v", err)
}
listen, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ip, port))
2018-07-29 00:44:24 +00:00
if err != nil {
log.Errorf("Failed to p2p listen: %v", err)
}
return []libp2p.Option{
libp2p.ListenAddrs(listen),
libp2p.EnableRelay(), // Allows dialing to peers via relay.
}
}