From ffea2e9151a4d89b077b2ed7f5f23863d69b2af9 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 21 Apr 2020 17:17:07 +0200 Subject: [PATCH] mobile: remove enodes type declaration --- mobile/discover.go | 44 -------------------------------------------- mobile/geth.go | 12 +++++++++--- mobile/params.go | 6 +++--- 3 files changed, 12 insertions(+), 50 deletions(-) diff --git a/mobile/discover.go b/mobile/discover.go index 9b3c93ccd9..d85edb1a31 100644 --- a/mobile/discover.go +++ b/mobile/discover.go @@ -20,8 +20,6 @@ package geth import ( - "errors" - "github.com/ethereum/go-ethereum/p2p/discv5" ) @@ -60,45 +58,3 @@ func NewEnode(rawurl string) (enode *Enode, _ error) { } return &Enode{node}, nil } - -// Enodes represents a slice of accounts. -type Enodes struct{ nodes []*discv5.Node } - -// NewEnodes creates a slice of uninitialized enodes. -func NewEnodes(size int) *Enodes { - return &Enodes{ - nodes: make([]*discv5.Node, size), - } -} - -// NewEnodesEmpty creates an empty slice of Enode values. -func NewEnodesEmpty() *Enodes { - return NewEnodes(0) -} - -// Size returns the number of enodes in the slice. -func (e *Enodes) Size() int { - return len(e.nodes) -} - -// Get returns the enode at the given index from the slice. -func (e *Enodes) Get(index int) (enode *Enode, _ error) { - if index < 0 || index >= len(e.nodes) { - return nil, errors.New("index out of bounds") - } - return &Enode{e.nodes[index]}, nil -} - -// Set sets the enode at the given index in the slice. -func (e *Enodes) Set(index int, enode *Enode) error { - if index < 0 || index >= len(e.nodes) { - return errors.New("index out of bounds") - } - e.nodes[index] = enode.node - return nil -} - -// Append adds a new enode element to the end of the slice. -func (e *Enodes) Append(enode *Enode) { - e.nodes = append(e.nodes, enode.node) -} diff --git a/mobile/geth.go b/mobile/geth.go index 27f1c4ed97..da18dd17cb 100644 --- a/mobile/geth.go +++ b/mobile/geth.go @@ -33,6 +33,7 @@ import ( "github.com/ethereum/go-ethereum/les" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/p2p/discv5" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/params" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" @@ -44,7 +45,7 @@ import ( // complexity. type NodeConfig struct { // Bootstrap nodes used to establish connectivity with the rest of the network. - BootstrapNodes *Enodes + BootstrapNodes []Enode // MaxPeers is the maximum number of peers that can be connected. If this is // set to zero, then only the configured static and trusted peers can connect. @@ -108,7 +109,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) { if config.MaxPeers == 0 { config.MaxPeers = defaultNodeConfig.MaxPeers } - if config.BootstrapNodes == nil || config.BootstrapNodes.Size() == 0 { + if config.BootstrapNodes == nil || len(config.BootstrapNodes) == 0 { config.BootstrapNodes = defaultNodeConfig.BootstrapNodes } @@ -116,6 +117,11 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) { debug.StartPProf(config.PprofAddress) } + nodes := make([]*discv5.Node, 0, len(config.BootstrapNodes)) + for _, node := range config.BootstrapNodes { + nodes = append(nodes, node.node) + } + // Create the empty networking stack nodeConf := &node.Config{ Name: clientIdentifier, @@ -125,7 +131,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) { P2P: p2p.Config{ NoDiscovery: true, DiscoveryV5: true, - BootstrapNodesV5: config.BootstrapNodes.nodes, + BootstrapNodesV5: nodes, ListenAddr: ":0", NAT: nat.Any(), MaxPeers: config.MaxPeers, diff --git a/mobile/params.go b/mobile/params.go index 25d3b8565b..b4a7a7a613 100644 --- a/mobile/params.go +++ b/mobile/params.go @@ -61,10 +61,10 @@ func GoerliGenesis() string { // FoundationBootnodes returns the enode URLs of the P2P bootstrap nodes operated // by the foundation running the V5 discovery protocol. -func FoundationBootnodes() *Enodes { - nodes := &Enodes{nodes: make([]*discv5.Node, len(params.DiscoveryV5Bootnodes))} +func FoundationBootnodes() []Enode { + nodes := make([]Enode, len(params.DiscoveryV5Bootnodes)) for i, url := range params.DiscoveryV5Bootnodes { - nodes.nodes[i] = discv5.MustParseNode(url) + nodes[i].node = discv5.MustParseNode(url) } return nodes }