Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rm enodes #4

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions mobile/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package geth

import (
"errors"

"github.com/ethereum/go-ethereum/p2p/discv5"
)

Expand Down Expand Up @@ -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)
}
12 changes: 9 additions & 3 deletions mobile/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -108,14 +109,19 @@ 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
}

if config.PprofAddress != "" {
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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions mobile/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}