prysm-pulse/shared/p2p/options.go
Preston Van Loon 15cac0c0b1
Disable libp2p TLS security protocols for now (#2622)
* Disable security protocols for now

* Enabling security for test only. See https://github.com/libp2p/go-libp2p-swarm/issues/124

* Fix spacing
2019-05-17 13:29:25 -04:00

45 lines
1.2 KiB
Go

package p2p
import (
"fmt"
"github.com/libp2p/go-libp2p"
ma "github.com/multiformats/go-multiaddr"
"github.com/prysmaticlabs/prysm/shared/iputils"
)
// Using package global for test. Swarm testing does not allow testing with
// NoSecurity option enabled. If this is resolved upstream, we can set up swarm
// with security disabled in the pubsub tests and remove this package global.
// https://github.com/libp2p/go-libp2p-swarm/issues/124
var disableSecurity = true
// buildOptions for the libp2p host.
// 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, maxPeers int) []libp2p.Option {
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))
if err != nil {
log.Errorf("Failed to p2p listen: %v", err)
}
opts := []libp2p.Option{
libp2p.ListenAddrs(listen),
libp2p.EnableRelay(), // Allows dialing to peers via relay.
optionConnectionManager(maxPeers),
}
if disableSecurity {
opts = append(opts, libp2p.NoSecurity)
}
return opts
}