diff options
author | lash <nolash@users.noreply.github.com> | 2019-03-22 12:55:47 +0800 |
---|---|---|
committer | Viktor TrĂ³n <viktor.tron@gmail.com> | 2019-03-22 12:55:47 +0800 |
commit | 09924cbcaab5106951fb67648315131bb4024ac5 (patch) | |
tree | efeb2e96b97b6537ce5680a26934176567da00b3 /p2p | |
parent | 358535188852bd9d8e351ccbb0d1fa608284a77b (diff) | |
download | go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.tar go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.tar.gz go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.tar.bz2 go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.tar.lz go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.tar.xz go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.tar.zst go-tangerine-09924cbcaab5106951fb67648315131bb4024ac5.zip |
cmd/swarm, p2p, swarm: Enable ENR in binary/execadapter (#19309)
* cmd/swarm, p2p, swarm: Enable ENR in binary/execadapter
* cmd/p2p/swarm: Remove comments + config.Enode nomarshal
* p2p/simulations: Remove superfluous error check
* p2p/simulation: Move init enode comment
* swarm/api: Check error in config test
* swarm, p2p/simulations, cmd/swarm: Use nodekey in binary record sign
* cmd/swarm: Make nodekey available for swarm api config
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/simulations/adapters/exec.go | 12 | ||||
-rw-r--r-- | p2p/simulations/adapters/inproc.go | 18 | ||||
-rw-r--r-- | p2p/simulations/adapters/types.go | 28 |
3 files changed, 42 insertions, 16 deletions
diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index bd8bcbc85..6d1c13f3c 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -92,6 +92,10 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) { return nil, fmt.Errorf("error creating node directory: %s", err) } + err := config.initDummyEnode() + if err != nil { + return nil, err + } // generate the config conf := &execNodeConfig{ Stack: node.DefaultConfig, @@ -407,6 +411,14 @@ func startExecNodeStack() (*node.Node, error) { if err := json.Unmarshal([]byte(confEnv), &conf); err != nil { return nil, fmt.Errorf("error decoding %s: %v", envNodeConfig, err) } + // TODO verify that ListenAddr will contain the correct tcp addr + // if we should start using exec adapters with other host than local + nodeTcpConn, err := net.ResolveTCPAddr("tcp", conf.Stack.P2P.ListenAddr) + if err != nil { + conf.Node.initDummyEnode() + } else { + conf.Node.initEnode(nodeTcpConn.IP, nodeTcpConn.Port, nodeTcpConn.Port) + } conf.Stack.P2P.PrivateKey = conf.Node.PrivateKey conf.Stack.Logger = log.New("node.id", conf.Node.ID.String()) diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index 991573c2d..c1cf23a17 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" - "github.com/ethereum/go-ethereum/p2p/enr" "github.com/ethereum/go-ethereum/p2p/simulations/pipes" "github.com/ethereum/go-ethereum/rpc" ) @@ -93,23 +92,10 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) { } } - // dialer in simulations based on ENR records - // doesn't work unless we explicitly set localhost record - ip := enr.IP(net.IPv4(127, 0, 0, 1)) - config.Record.Set(&ip) - tcpPort := enr.TCP(0) - config.Record.Set(&tcpPort) - - err := enode.SignV4(&config.Record, config.PrivateKey) - if err != nil { - return nil, fmt.Errorf("unable to generate ENR: %v", err) - } - nod, err := enode.New(enode.V4ID{}, &config.Record) + err := config.initDummyEnode() if err != nil { - return nil, fmt.Errorf("unable to create enode: %v", err) + return nil, err } - log.Trace("simnode new", "record", config.Record) - config.node = nod n, err := node.New(&node.Config{ P2P: p2p.Config{ diff --git a/p2p/simulations/adapters/types.go b/p2p/simulations/adapters/types.go index e5e4d159c..ed4013cb7 100644 --- a/p2p/simulations/adapters/types.go +++ b/p2p/simulations/adapters/types.go @@ -27,6 +27,7 @@ import ( "github.com/docker/docker/pkg/reexec" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" @@ -265,3 +266,30 @@ func RegisterServices(services Services) { os.Exit(0) } } + +// adds the host part to the configuration's ENR, signs it +// creates and the corresponding enode object to the configuration +func (n *NodeConfig) initEnode(ip net.IP, tcpport int, udpport int) error { + enrIp := enr.IP(ip) + n.Record.Set(&enrIp) + enrTcpPort := enr.TCP(tcpport) + n.Record.Set(&enrTcpPort) + enrUdpPort := enr.UDP(tcpport) + n.Record.Set(&enrUdpPort) + + err := enode.SignV4(&n.Record, n.PrivateKey) + if err != nil { + return fmt.Errorf("unable to generate ENR: %v", err) + } + nod, err := enode.New(enode.V4ID{}, &n.Record) + if err != nil { + return fmt.Errorf("unable to create enode: %v", err) + } + log.Trace("simnode new", "record", n.Record) + n.node = nod + return nil +} + +func (n *NodeConfig) initDummyEnode() error { + return n.initEnode(net.IPv4(127, 0, 0, 1), 0, 0) +} |