mobile: remove enodes type declaration

This commit is contained in:
Marius van der Wijden 2020-04-21 17:17:07 +02:00
parent 7599999dcd
commit ffea2e9151
3 changed files with 12 additions and 50 deletions

View file

@ -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)
}

View file

@ -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,

View file

@ -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
}