forked from cerc-io/plugeth
cmd/ethereum, cmd/mist: add flag for discovery bootstrap nodes
This commit is contained in:
parent
2cf4fed11b
commit
028775a086
@ -49,7 +49,7 @@ var (
|
|||||||
AddPeer string
|
AddPeer string
|
||||||
MaxPeer int
|
MaxPeer int
|
||||||
GenAddr bool
|
GenAddr bool
|
||||||
SeedNode string
|
BootNodes string
|
||||||
SecretFile string
|
SecretFile string
|
||||||
ExportDir string
|
ExportDir string
|
||||||
NonInteractive bool
|
NonInteractive bool
|
||||||
@ -101,7 +101,7 @@ func Init() {
|
|||||||
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
|
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
|
||||||
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
||||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
flag.StringVar(&SeedNode, "seednode", "poc-8.ethdev.com:30303", "ip:port of seed node to connect to. Set to blank for skip")
|
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
|
||||||
flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)")
|
flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)")
|
||||||
flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
|
flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
|
@ -74,6 +74,7 @@ func main() {
|
|||||||
KeyRing: KeyRing,
|
KeyRing: KeyRing,
|
||||||
Shh: SHH,
|
Shh: SHH,
|
||||||
Dial: Dial,
|
Dial: Dial,
|
||||||
|
BootNodes: BootNodes,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,7 +134,7 @@ func main() {
|
|||||||
utils.StartWebSockets(ethereum, WsPort)
|
utils.StartWebSockets(ethereum, WsPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.StartEthereum(ethereum, SeedNode)
|
utils.StartEthereum(ethereum)
|
||||||
|
|
||||||
if StartJsConsole {
|
if StartJsConsole {
|
||||||
InitJsConsole(ethereum)
|
InitJsConsole(ethereum)
|
||||||
|
@ -51,7 +51,7 @@ var (
|
|||||||
AddPeer string
|
AddPeer string
|
||||||
MaxPeer int
|
MaxPeer int
|
||||||
GenAddr bool
|
GenAddr bool
|
||||||
SeedNode string
|
BootNodes string
|
||||||
SecretFile string
|
SecretFile string
|
||||||
ExportDir string
|
ExportDir string
|
||||||
NonInteractive bool
|
NonInteractive bool
|
||||||
@ -116,7 +116,7 @@ func Init() {
|
|||||||
flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")
|
flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")
|
||||||
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
||||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
flag.StringVar(&SeedNode, "seednode", "poc-8.ethdev.com:30303", "ip:port of seed node to connect to. Set to blank for skip")
|
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
|
flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
|
||||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||||
|
@ -59,8 +59,9 @@ func run() error {
|
|||||||
LogLevel: LogLevel,
|
LogLevel: LogLevel,
|
||||||
MaxPeers: MaxPeer,
|
MaxPeers: MaxPeer,
|
||||||
Port: OutboundPort,
|
Port: OutboundPort,
|
||||||
NATType: PMPGateway,
|
NATType: NatType,
|
||||||
PMPGateway: PMPGateway,
|
PMPGateway: PMPGateway,
|
||||||
|
BootNodes: BootNodes,
|
||||||
KeyRing: KeyRing,
|
KeyRing: KeyRing,
|
||||||
Dial: true,
|
Dial: true,
|
||||||
})
|
})
|
||||||
@ -82,7 +83,7 @@ func run() error {
|
|||||||
utils.RegisterInterrupt(func(os.Signal) {
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
gui.Stop()
|
gui.Stop()
|
||||||
})
|
})
|
||||||
go utils.StartEthereum(ethereum, SeedNode)
|
go utils.StartEthereum(ethereum)
|
||||||
|
|
||||||
fmt.Println("ETH stack took", time.Since(tstart))
|
fmt.Println("ETH stack took", time.Since(tstart))
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ func (ui *UiLib) Muted(content string) {
|
|||||||
|
|
||||||
func (ui *UiLib) Connect(button qml.Object) {
|
func (ui *UiLib) Connect(button qml.Object) {
|
||||||
if !ui.connected {
|
if !ui.connected {
|
||||||
ui.eth.Start(SeedNode)
|
ui.eth.Start()
|
||||||
ui.connected = true
|
ui.connected = true
|
||||||
button.Set("enabled", false)
|
button.Set("enabled", false)
|
||||||
}
|
}
|
||||||
|
@ -121,9 +121,9 @@ func exit(err error) {
|
|||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartEthereum(ethereum *eth.Ethereum, SeedNode string) {
|
func StartEthereum(ethereum *eth.Ethereum) {
|
||||||
clilogger.Infoln("Starting ", ethereum.Name())
|
clilogger.Infoln("Starting ", ethereum.Name())
|
||||||
if err := ethereum.Start(SeedNode); err != nil {
|
if err := ethereum.Start(); err != nil {
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
RegisterInterrupt(func(sig os.Signal) {
|
RegisterInterrupt(func(sig os.Signal) {
|
||||||
|
@ -2,6 +2,7 @@ package eth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
@ -17,6 +18,8 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/whisper"
|
"github.com/ethereum/go-ethereum/whisper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var logger = ethlogger.NewLogger("SERV")
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string
|
||||||
KeyStore string
|
KeyStore string
|
||||||
@ -30,13 +33,28 @@ type Config struct {
|
|||||||
NATType string
|
NATType string
|
||||||
PMPGateway string
|
PMPGateway string
|
||||||
|
|
||||||
|
// This should be a space-separated list of
|
||||||
|
// discovery node URLs.
|
||||||
|
BootNodes string
|
||||||
|
|
||||||
Shh bool
|
Shh bool
|
||||||
Dial bool
|
Dial bool
|
||||||
|
|
||||||
KeyManager *crypto.KeyManager
|
KeyManager *crypto.KeyManager
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = ethlogger.NewLogger("SERV")
|
func (cfg *Config) parseBootNodes() []*discover.Node {
|
||||||
|
var ns []*discover.Node
|
||||||
|
for _, url := range strings.Split(cfg.BootNodes, " ") {
|
||||||
|
n, err := discover.ParseNode(url)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ns = append(ns, n)
|
||||||
|
}
|
||||||
|
return ns
|
||||||
|
}
|
||||||
|
|
||||||
type Ethereum struct {
|
type Ethereum struct {
|
||||||
// Channel for shutting down the ethereum
|
// Channel for shutting down the ethereum
|
||||||
@ -141,6 +159,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
Blacklist: eth.blacklist,
|
Blacklist: eth.blacklist,
|
||||||
NAT: nat,
|
NAT: nat,
|
||||||
NoDial: !config.Dial,
|
NoDial: !config.Dial,
|
||||||
|
BootstrapNodes: config.parseBootNodes(),
|
||||||
}
|
}
|
||||||
if len(config.Port) > 0 {
|
if len(config.Port) > 0 {
|
||||||
eth.net.ListenAddr = ":" + config.Port
|
eth.net.ListenAddr = ":" + config.Port
|
||||||
@ -214,7 +233,7 @@ func (s *Ethereum) Coinbase() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the ethereum
|
// Start the ethereum
|
||||||
func (s *Ethereum) Start(seedNode string) error {
|
func (s *Ethereum) Start() error {
|
||||||
err := s.net.Start()
|
err := s.net.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -65,12 +65,12 @@ func (tab *Table) Close() {
|
|||||||
// to the network if the table is empty. Bootstrap will also attempt to
|
// to the network if the table is empty. Bootstrap will also attempt to
|
||||||
// fill the table by performing random lookup operations on the
|
// fill the table by performing random lookup operations on the
|
||||||
// network.
|
// network.
|
||||||
func (tab *Table) Bootstrap(nodes []Node) {
|
func (tab *Table) Bootstrap(nodes []*Node) {
|
||||||
tab.mutex.Lock()
|
tab.mutex.Lock()
|
||||||
// TODO: maybe filter nodes with bad fields (nil, etc.) to avoid strange crashes
|
// TODO: maybe filter nodes with bad fields (nil, etc.) to avoid strange crashes
|
||||||
tab.nursery = make([]*Node, 0, len(nodes))
|
tab.nursery = make([]*Node, 0, len(nodes))
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
cpy := n
|
cpy := *n
|
||||||
tab.nursery = append(tab.nursery, &cpy)
|
tab.nursery = append(tab.nursery, &cpy)
|
||||||
}
|
}
|
||||||
tab.mutex.Unlock()
|
tab.mutex.Unlock()
|
||||||
|
@ -50,7 +50,7 @@ type Server struct {
|
|||||||
|
|
||||||
// Bootstrap nodes are used to establish connectivity
|
// Bootstrap nodes are used to establish connectivity
|
||||||
// with the rest of the network.
|
// with the rest of the network.
|
||||||
BootstrapNodes []discover.Node
|
BootstrapNodes []*discover.Node
|
||||||
|
|
||||||
// Protocols should contain the protocols supported
|
// Protocols should contain the protocols supported
|
||||||
// by the server. Matching protocols are launched for
|
// by the server. Matching protocols are launched for
|
||||||
|
Loading…
Reference in New Issue
Block a user