mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
p2p/simulations: Fix the DockerAdapter
Signed-off-by: Lewis Marshall <lewis@lmars.net>
This commit is contained in:
parent
9627a75ce0
commit
898f0c1b15
2 changed files with 26 additions and 7 deletions
|
|
@ -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,6 +65,9 @@ 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
|
||||
|
|
@ -66,9 +76,11 @@ func (d *DockerAdapter) NewNode(config *NodeConfig) (Node, error) {
|
|||
ExecNode: ExecNode{
|
||||
ID: config.ID,
|
||||
Config: conf,
|
||||
adapter: &d.ExecAdapter,
|
||||
},
|
||||
}
|
||||
node.newCmd = node.dockerCommand
|
||||
d.ExecAdapter.nodes[node.ID] = &node.ExecNode
|
||||
return node, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue