mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
Merge pull request #286 from ethersphere/docker_discovery_tests
Fix Docker discovery tests setup
This commit is contained in:
commit
9a5a9ded71
4 changed files with 31 additions and 24 deletions
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
)
|
)
|
||||||
|
|
@ -99,7 +98,10 @@ func (d *DockerAdapter) NewNode(config *NodeConfig) (Node, error) {
|
||||||
conf.Stack.P2P.NoDiscovery = true
|
conf.Stack.P2P.NoDiscovery = true
|
||||||
conf.Stack.P2P.NAT = nil
|
conf.Stack.P2P.NAT = nil
|
||||||
conf.Stack.NoUSB = true
|
conf.Stack.NoUSB = true
|
||||||
conf.Stack.Logger = log.New("node.id", config.ID.String())
|
|
||||||
|
// listen on all interfaces on a given port, which we set when we
|
||||||
|
// initialise NodeConfig (usually a random port)
|
||||||
|
conf.Stack.P2P.ListenAddr = fmt.Sprintf(":%d", config.Port)
|
||||||
|
|
||||||
node := &DockerNode{
|
node := &DockerNode{
|
||||||
ExecNode: ExecNode{
|
ExecNode: ExecNode{
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) {
|
||||||
|
|
||||||
// listen on a localhost port, which we set when we
|
// listen on a localhost port, which we set when we
|
||||||
// initialise NodeConfig (usually a random port)
|
// initialise NodeConfig (usually a random port)
|
||||||
conf.Stack.P2P.ListenAddr = fmt.Sprintf("127.0.0.1:%d", config.Port)
|
conf.Stack.P2P.ListenAddr = fmt.Sprintf(":%d", config.Port)
|
||||||
|
|
||||||
node := &ExecNode{
|
node := &ExecNode{
|
||||||
ID: config.ID,
|
ID: config.ID,
|
||||||
|
|
@ -338,6 +338,21 @@ type execNodeConfig struct {
|
||||||
PeerAddrs map[string]string `json:"peer_addrs,omitempty"`
|
PeerAddrs map[string]string `json:"peer_addrs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExternalIP gets an external IP address so that Enode URL is usable
|
||||||
|
func ExternalIP() net.IP {
|
||||||
|
addrs, err := net.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
log.Crit("error getting IP address", "err", err)
|
||||||
|
}
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() && !ip.IP.IsLinkLocalUnicast() {
|
||||||
|
return ip.IP
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Crit("unable to determine explicit IP address")
|
||||||
|
return net.IP{127, 0, 0, 1}
|
||||||
|
}
|
||||||
|
|
||||||
// execP2PNode starts a devp2p node when the current binary is executed with
|
// execP2PNode starts a devp2p node when the current binary is executed with
|
||||||
// argv[0] being "p2p-node", reading the service / ID from argv[1] / argv[2]
|
// argv[0] being "p2p-node", reading the service / ID from argv[1] / argv[2]
|
||||||
// and the node config from the _P2P_NODE_CONFIG environment variable
|
// and the node config from the _P2P_NODE_CONFIG environment variable
|
||||||
|
|
@ -361,25 +376,11 @@ func execP2PNode() {
|
||||||
conf.Stack.P2P.PrivateKey = conf.Node.PrivateKey
|
conf.Stack.P2P.PrivateKey = conf.Node.PrivateKey
|
||||||
conf.Stack.Logger = log.New("node.id", conf.Node.ID.String())
|
conf.Stack.Logger = log.New("node.id", conf.Node.ID.String())
|
||||||
|
|
||||||
// use explicit IP address in ListenAddr so that Enode URL is usable
|
|
||||||
externalIP := func() string {
|
|
||||||
addrs, err := net.InterfaceAddrs()
|
|
||||||
if err != nil {
|
|
||||||
log.Crit("error getting IP address", "err", err)
|
|
||||||
}
|
|
||||||
for _, addr := range addrs {
|
|
||||||
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
|
|
||||||
return ip.IP.String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Crit("unable to determine explicit IP address")
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(conf.Stack.P2P.ListenAddr, ":") {
|
if strings.HasPrefix(conf.Stack.P2P.ListenAddr, ":") {
|
||||||
conf.Stack.P2P.ListenAddr = externalIP() + conf.Stack.P2P.ListenAddr
|
conf.Stack.P2P.ListenAddr = ExternalIP().String() + conf.Stack.P2P.ListenAddr
|
||||||
}
|
}
|
||||||
if conf.Stack.WSHost == "0.0.0.0" {
|
if conf.Stack.WSHost == "0.0.0.0" {
|
||||||
conf.Stack.WSHost = externalIP()
|
conf.Stack.WSHost = ExternalIP().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the devp2p stack
|
// initialize the devp2p stack
|
||||||
|
|
|
||||||
|
|
@ -427,10 +427,10 @@ func NewAddrFromNodeID(id discover.NodeID) *BzzAddr {
|
||||||
|
|
||||||
// NewAddrFromNodeIDAndPort constucts a BzzAddr from a discover.NodeID and port uint16
|
// NewAddrFromNodeIDAndPort constucts a BzzAddr from a discover.NodeID and port uint16
|
||||||
// the overlay address is derived as the hash of the nodeID
|
// the overlay address is derived as the hash of the nodeID
|
||||||
func NewAddrFromNodeIDAndPort(id discover.NodeID, port uint16) *BzzAddr {
|
func NewAddrFromNodeIDAndPort(id discover.NodeID, host net.IP, port uint16) *BzzAddr {
|
||||||
return &BzzAddr{
|
return &BzzAddr{
|
||||||
OAddr: ToOverlayAddr(id.Bytes()),
|
OAddr: ToOverlayAddr(id.Bytes()),
|
||||||
UAddr: []byte(discover.NewNode(id, net.IP{127, 0, 0, 1}, port, port).String()),
|
UAddr: []byte(discover.NewNode(id, host, port, port).String()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
"github.com/ethereum/go-ethereum/swarm/network"
|
"github.com/ethereum/go-ethereum/swarm/network"
|
||||||
|
colorable "github.com/mattn/go-colorable"
|
||||||
)
|
)
|
||||||
|
|
||||||
// serviceName is used with the exec adapter so the exec'd binary knows which
|
// serviceName is used with the exec adapter so the exec'd binary knows which
|
||||||
|
|
@ -44,7 +45,8 @@ func init() {
|
||||||
// protocol when using the exec adapter
|
// protocol when using the exec adapter
|
||||||
adapters.RegisterServices(services)
|
adapters.RegisterServices(services)
|
||||||
|
|
||||||
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(os.Stderr, log.TerminalFormat(false))))
|
log.PrintOrigins(true)
|
||||||
|
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true))))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Benchmarks to test the average time it takes for an N-node ring
|
// Benchmarks to test the average time it takes for an N-node ring
|
||||||
|
|
@ -70,7 +72,7 @@ func BenchmarkDiscovery_64_4(b *testing.B) { benchmarkDiscovery(b, 64, 4) }
|
||||||
func BenchmarkDiscovery_128_4(b *testing.B) { benchmarkDiscovery(b, 128, 4) }
|
func BenchmarkDiscovery_128_4(b *testing.B) { benchmarkDiscovery(b, 128, 4) }
|
||||||
func BenchmarkDiscovery_256_4(b *testing.B) { benchmarkDiscovery(b, 256, 4) }
|
func BenchmarkDiscovery_256_4(b *testing.B) { benchmarkDiscovery(b, 256, 4) }
|
||||||
|
|
||||||
func XTestDiscoverySimulationDockerAdapter(t *testing.T) {
|
func TestDiscoverySimulationDockerAdapter(t *testing.T) {
|
||||||
testDiscoverySimulationDockerAdapter(t, *nodeCount, *initCount)
|
testDiscoverySimulationDockerAdapter(t, *nodeCount, *initCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,7 +307,9 @@ func triggerChecks(trigger chan discover.NodeID, net *simulations.Network, id di
|
||||||
}
|
}
|
||||||
|
|
||||||
func newService(ctx *adapters.ServiceContext) (node.Service, error) {
|
func newService(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||||
addr := network.NewAddrFromNodeIDAndPort(ctx.Config.ID, ctx.Config.Port)
|
host := adapters.ExternalIP()
|
||||||
|
|
||||||
|
addr := network.NewAddrFromNodeIDAndPort(ctx.Config.ID, host, ctx.Config.Port)
|
||||||
|
|
||||||
kp := network.NewKadParams()
|
kp := network.NewKadParams()
|
||||||
kp.MinProxBinSize = testMinProxBinSize
|
kp.MinProxBinSize = testMinProxBinSize
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue