cmd, mobile, node, p2p: surface the discovery V5 bootnodes
This commit is contained in:
@ -23,28 +23,14 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||
)
|
||||
|
||||
// MainnetBootnodes returns the enode URLs of the P2P bootstrap nodes running
|
||||
// on the main network.
|
||||
//
|
||||
// Note, this needs to be a method to prevent gomobile generating a setter for it.
|
||||
func MainnetBootnodes() *Enodes {
|
||||
nodes := &Enodes{nodes: make([]*discover.Node, len(utils.MainnetBootnodes))}
|
||||
for i, node := range utils.MainnetBootnodes {
|
||||
nodes.nodes[i] = node
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// TestnetBootnodes returns the enode URLs of the P2P bootstrap nodes running
|
||||
// on the test network.
|
||||
//
|
||||
// Note, this needs to be a method to prevent gomobile generating a setter for it.
|
||||
func TestnetBootnodes() *Enodes {
|
||||
nodes := &Enodes{nodes: make([]*discover.Node, len(utils.TestnetBootnodes))}
|
||||
for i, node := range utils.TestnetBootnodes {
|
||||
// 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(utils.DiscoveryV5Bootnodes))}
|
||||
for i, node := range utils.DiscoveryV5Bootnodes {
|
||||
nodes.nodes[i] = node
|
||||
}
|
||||
return nodes
|
||||
@ -52,7 +38,7 @@ func TestnetBootnodes() *Enodes {
|
||||
|
||||
// Enode represents a host on the network.
|
||||
type Enode struct {
|
||||
node *discover.Node
|
||||
node *discv5.Node
|
||||
}
|
||||
|
||||
// NewEnode parses a node designator.
|
||||
@ -79,7 +65,7 @@ type Enode struct {
|
||||
//
|
||||
// enode://<hex node id>@10.3.58.6:30303?discport=30301
|
||||
func NewEnode(rawurl string) (*Enode, error) {
|
||||
node, err := discover.ParseNode(rawurl)
|
||||
node, err := discv5.ParseNode(rawurl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -87,12 +73,12 @@ func NewEnode(rawurl string) (*Enode, error) {
|
||||
}
|
||||
|
||||
// Enodes represents a slice of accounts.
|
||||
type Enodes struct{ nodes []*discover.Node }
|
||||
type Enodes struct{ nodes []*discv5.Node }
|
||||
|
||||
// NewEnodes creates a slice of uninitialized enodes.
|
||||
func NewEnodes(size int) *Enodes {
|
||||
return &Enodes{
|
||||
nodes: make([]*discover.Node, size),
|
||||
nodes: make([]*discv5.Node, size),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,11 +78,11 @@ type NodeConfig struct {
|
||||
// defaultNodeConfig contains the default node configuration values to use if all
|
||||
// or some fields are missing from the user's specified list.
|
||||
var defaultNodeConfig = &NodeConfig{
|
||||
BootstrapNodes: MainnetBootnodes(),
|
||||
BootstrapNodes: FoundationBootnodes(),
|
||||
MaxPeers: 25,
|
||||
EthereumEnabled: true,
|
||||
EthereumNetworkID: 1,
|
||||
EthereumChainConfig: MainnetChainConfig,
|
||||
EthereumChainConfig: MainnetChainConfig(),
|
||||
EthereumDatabaseCache: 16,
|
||||
}
|
||||
|
||||
@ -106,17 +106,21 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
|
||||
if config.MaxPeers == 0 {
|
||||
config.MaxPeers = defaultNodeConfig.MaxPeers
|
||||
}
|
||||
if config.BootstrapNodes == nil || config.BootstrapNodes.Size() == 0 {
|
||||
config.BootstrapNodes = defaultNodeConfig.BootstrapNodes
|
||||
}
|
||||
// Create the empty networking stack
|
||||
nodeConf := &node.Config{
|
||||
Name: clientIdentifier,
|
||||
DataDir: datadir,
|
||||
KeyStoreDir: filepath.Join(datadir, "keystore"), // Mobile should never use internal keystores!
|
||||
NoDiscovery: true,
|
||||
DiscoveryV5: true,
|
||||
BootstrapNodes: config.BootstrapNodes.nodes,
|
||||
ListenAddr: ":0",
|
||||
NAT: nat.Any(),
|
||||
MaxPeers: config.MaxPeers,
|
||||
Name: clientIdentifier,
|
||||
DataDir: datadir,
|
||||
KeyStoreDir: filepath.Join(datadir, "keystore"), // Mobile should never use internal keystores!
|
||||
NoDiscovery: true,
|
||||
DiscoveryV5: true,
|
||||
DiscoveryV5Addr: ":0",
|
||||
BootstrapNodesV5: config.BootstrapNodes.nodes,
|
||||
ListenAddr: ":0",
|
||||
NAT: nat.Any(),
|
||||
MaxPeers: config.MaxPeers,
|
||||
}
|
||||
stack, err := node.New(nodeConf)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user