diff --git a/p2p/simulations/adapters/docker.go b/p2p/simulations/adapters/docker.go index eb20ac3318..894057256e 100644 --- a/p2p/simulations/adapters/docker.go +++ b/p2p/simulations/adapters/docker.go @@ -13,6 +13,7 @@ import ( "github.com/docker/docker/pkg/reexec" "github.com/ethereum/go-ethereum/node" + "github.com/ethereum/go-ethereum/p2p/discover" ) // DockerAdapter is a NodeAdapter which runs nodes inside Docker containers. @@ -20,7 +21,9 @@ import ( // A Docker image is built which contains the current binary at /bin/p2p-node // which when executed runs the underlying service (see the description // of the execP2PNode function for more details) -type DockerAdapter struct{} +type DockerAdapter struct { + ExecAdapter +} // NewDockerAdapter builds the p2p-node Docker image containing the current // binary and returns a DockerAdapter @@ -33,7 +36,11 @@ func NewDockerAdapter() (*DockerAdapter, error) { return nil, err } - return &DockerAdapter{}, nil + return &DockerAdapter{ + ExecAdapter{ + nodes: make(map[discover.NodeID]*ExecNode), + }, + }, nil } // Name returns the name of the adapter for logging purpoeses @@ -58,17 +65,22 @@ func (d *DockerAdapter) NewNode(config *NodeConfig) (Node, error) { Node: config, } conf.Stack.DataDir = "/data" + conf.Stack.WSHost = "0.0.0.0" + conf.Stack.WSOrigins = []string{"*"} + conf.Stack.WSExposeAll = true conf.Stack.P2P.EnableMsgEvents = true conf.Stack.P2P.NoDiscovery = true conf.Stack.P2P.NAT = nil node := &DockerNode{ ExecNode: ExecNode{ - ID: config.ID, - Config: conf, + ID: config.ID, + Config: conf, + adapter: &d.ExecAdapter, }, } node.newCmd = node.dockerCommand + d.ExecAdapter.nodes[node.ID] = &node.ExecNode return node, nil } diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 81267e097b..f7f047ef51 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -347,17 +347,24 @@ func execP2PNode() { conf.Stack.P2P.PrivateKey = conf.Node.PrivateKey // use explicit IP address in ListenAddr so that Enode URL is usable - if strings.HasPrefix(conf.Stack.P2P.ListenAddr, ":") { + 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() { - conf.Stack.P2P.ListenAddr = ip.IP.String() + conf.Stack.P2P.ListenAddr - break + return ip.IP.String() } } + log.Crit("unable to determine explicit IP address") + return "" + } + if strings.HasPrefix(conf.Stack.P2P.ListenAddr, ":") { + conf.Stack.P2P.ListenAddr = externalIP() + conf.Stack.P2P.ListenAddr + } + if conf.Stack.WSHost == "0.0.0.0" { + conf.Stack.WSHost = externalIP() } // initialize the devp2p stack