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
|
||||
MaxPeer int
|
||||
GenAddr bool
|
||||
SeedNode string
|
||||
BootNodes string
|
||||
SecretFile string
|
||||
ExportDir string
|
||||
NonInteractive bool
|
||||
@ -101,7 +101,7 @@ func Init() {
|
||||
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
|
||||
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
||||
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(&Dial, "dial", true, "dial out connections (on)")
|
||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||
|
@ -74,6 +74,7 @@ func main() {
|
||||
KeyRing: KeyRing,
|
||||
Shh: SHH,
|
||||
Dial: Dial,
|
||||
BootNodes: BootNodes,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -133,7 +134,7 @@ func main() {
|
||||
utils.StartWebSockets(ethereum, WsPort)
|
||||
}
|
||||
|
||||
utils.StartEthereum(ethereum, SeedNode)
|
||||
utils.StartEthereum(ethereum)
|
||||
|
||||
if StartJsConsole {
|
||||
InitJsConsole(ethereum)
|
||||
|
@ -51,7 +51,7 @@ var (
|
||||
AddPeer string
|
||||
MaxPeer int
|
||||
GenAddr bool
|
||||
SeedNode string
|
||||
BootNodes string
|
||||
SecretFile string
|
||||
ExportDir string
|
||||
NonInteractive bool
|
||||
@ -116,7 +116,7 @@ func Init() {
|
||||
flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")
|
||||
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
||||
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.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
|
||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||
|
@ -59,8 +59,9 @@ func run() error {
|
||||
LogLevel: LogLevel,
|
||||
MaxPeers: MaxPeer,
|
||||
Port: OutboundPort,
|
||||
NATType: PMPGateway,
|
||||
NATType: NatType,
|
||||
PMPGateway: PMPGateway,
|
||||
BootNodes: BootNodes,
|
||||
KeyRing: KeyRing,
|
||||
Dial: true,
|
||||
})
|
||||
@ -82,7 +83,7 @@ func run() error {
|
||||
utils.RegisterInterrupt(func(os.Signal) {
|
||||
gui.Stop()
|
||||
})
|
||||
go utils.StartEthereum(ethereum, SeedNode)
|
||||
go utils.StartEthereum(ethereum)
|
||||
|
||||
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) {
|
||||
if !ui.connected {
|
||||
ui.eth.Start(SeedNode)
|
||||
ui.eth.Start()
|
||||
ui.connected = true
|
||||
button.Set("enabled", false)
|
||||
}
|
||||
|
@ -121,9 +121,9 @@ func exit(err error) {
|
||||
os.Exit(status)
|
||||
}
|
||||
|
||||
func StartEthereum(ethereum *eth.Ethereum, SeedNode string) {
|
||||
func StartEthereum(ethereum *eth.Ethereum) {
|
||||
clilogger.Infoln("Starting ", ethereum.Name())
|
||||
if err := ethereum.Start(SeedNode); err != nil {
|
||||
if err := ethereum.Start(); err != nil {
|
||||
exit(err)
|
||||
}
|
||||
RegisterInterrupt(func(sig os.Signal) {
|
||||
|
@ -2,6 +2,7 @@ package eth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
@ -17,6 +18,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/whisper"
|
||||
)
|
||||
|
||||
var logger = ethlogger.NewLogger("SERV")
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
KeyStore string
|
||||
@ -30,13 +33,28 @@ type Config struct {
|
||||
NATType string
|
||||
PMPGateway string
|
||||
|
||||
// This should be a space-separated list of
|
||||
// discovery node URLs.
|
||||
BootNodes string
|
||||
|
||||
Shh bool
|
||||
Dial bool
|
||||
|
||||
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 {
|
||||
// Channel for shutting down the ethereum
|
||||
@ -134,13 +152,14 @@ func New(config *Config) (*Ethereum, error) {
|
||||
return nil, fmt.Errorf("could not generate server key: %v", err)
|
||||
}
|
||||
eth.net = &p2p.Server{
|
||||
PrivateKey: netprv,
|
||||
Name: config.Name,
|
||||
MaxPeers: config.MaxPeers,
|
||||
Protocols: protocols,
|
||||
Blacklist: eth.blacklist,
|
||||
NAT: nat,
|
||||
NoDial: !config.Dial,
|
||||
PrivateKey: netprv,
|
||||
Name: config.Name,
|
||||
MaxPeers: config.MaxPeers,
|
||||
Protocols: protocols,
|
||||
Blacklist: eth.blacklist,
|
||||
NAT: nat,
|
||||
NoDial: !config.Dial,
|
||||
BootstrapNodes: config.parseBootNodes(),
|
||||
}
|
||||
if len(config.Port) > 0 {
|
||||
eth.net.ListenAddr = ":" + config.Port
|
||||
@ -214,7 +233,7 @@ func (s *Ethereum) Coinbase() []byte {
|
||||
}
|
||||
|
||||
// Start the ethereum
|
||||
func (s *Ethereum) Start(seedNode string) error {
|
||||
func (s *Ethereum) Start() error {
|
||||
err := s.net.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -65,12 +65,12 @@ func (tab *Table) Close() {
|
||||
// to the network if the table is empty. Bootstrap will also attempt to
|
||||
// fill the table by performing random lookup operations on the
|
||||
// network.
|
||||
func (tab *Table) Bootstrap(nodes []Node) {
|
||||
func (tab *Table) Bootstrap(nodes []*Node) {
|
||||
tab.mutex.Lock()
|
||||
// TODO: maybe filter nodes with bad fields (nil, etc.) to avoid strange crashes
|
||||
tab.nursery = make([]*Node, 0, len(nodes))
|
||||
for _, n := range nodes {
|
||||
cpy := n
|
||||
cpy := *n
|
||||
tab.nursery = append(tab.nursery, &cpy)
|
||||
}
|
||||
tab.mutex.Unlock()
|
||||
|
@ -50,7 +50,7 @@ type Server struct {
|
||||
|
||||
// Bootstrap nodes are used to establish connectivity
|
||||
// with the rest of the network.
|
||||
BootstrapNodes []discover.Node
|
||||
BootstrapNodes []*discover.Node
|
||||
|
||||
// Protocols should contain the protocols supported
|
||||
// by the server. Matching protocols are launched for
|
||||
|
Loading…
Reference in New Issue
Block a user