From 56f777b2fc77275bc636562b66a08b19afe2ec56 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 5 Feb 2015 03:16:16 +0100 Subject: cmd/ethereum, cmd/mist, core, eth, javascript, xeth: fixes for new p2p API --- eth/backend.go | 73 ++++++++++++++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 43e757435..08052c15d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -12,20 +12,19 @@ import ( "github.com/ethereum/go-ethereum/event" ethlogger "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/pow/ezp" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/whisper" ) type Config struct { - Name string - Version string - Identifier string - KeyStore string - DataDir string - LogFile string - LogLevel int - KeyRing string + Name string + KeyStore string + DataDir string + LogFile string + LogLevel int + KeyRing string MaxPeers int Port string @@ -66,8 +65,7 @@ type Ethereum struct { WsServer rpc.RpcServer keyManager *crypto.KeyManager - clientIdentity p2p.ClientIdentity - logger ethlogger.LogSystem + logger ethlogger.LogSystem synclock sync.Mutex syncGroup sync.WaitGroup @@ -103,21 +101,17 @@ func New(config *Config) (*Ethereum, error) { // Initialise the keyring keyManager.Init(config.KeyRing, 0, false) - // Create a new client id for this instance. This will help identifying the node on the network - clientId := p2p.NewSimpleClientIdentity(config.Name, config.Version, config.Identifier, keyManager.PublicKey()) - saveProtocolVersion(db) //ethutil.Config.Db = db eth := &Ethereum{ - shutdownChan: make(chan bool), - quit: make(chan bool), - db: db, - keyManager: keyManager, - clientIdentity: clientId, - blacklist: p2p.NewBlacklist(), - eventMux: &event.TypeMux{}, - logger: logger, + shutdownChan: make(chan bool), + quit: make(chan bool), + db: db, + keyManager: keyManager, + blacklist: p2p.NewBlacklist(), + eventMux: &event.TypeMux{}, + logger: logger, } eth.chainManager = core.NewChainManager(db, eth.EventMux()) @@ -132,21 +126,23 @@ func New(config *Config) (*Ethereum, error) { ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool) protocols := []p2p.Protocol{ethProto, eth.whisper.Protocol()} - nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway) if err != nil { return nil, err } - + netprv, err := crypto.GenerateKey() + if err != nil { + return nil, fmt.Errorf("could not generate server key: %v", err) + } eth.net = &p2p.Server{ - Identity: clientId, - 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, } - if len(config.Port) > 0 { eth.net.ListenAddr = ":" + config.Port } @@ -162,8 +158,8 @@ func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger } -func (s *Ethereum) ClientIdentity() p2p.ClientIdentity { - return s.clientIdentity +func (s *Ethereum) Name() string { + return s.net.Name } func (s *Ethereum) ChainManager() *core.ChainManager { @@ -241,26 +237,17 @@ func (s *Ethereum) Start(seedNode string) error { s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{}) go s.blockBroadcastLoop() - // TODO: read peers here - if len(seedNode) > 0 { - logger.Infof("Connect to seed node %v", seedNode) - if err := s.SuggestPeer(seedNode); err != nil { - logger.Infoln(err) - } - } - logger.Infoln("Server started") return nil } -func (self *Ethereum) SuggestPeer(addr string) error { +func (self *Ethereum) SuggestPeer(addr string, id discover.NodeID) error { netaddr, err := net.ResolveTCPAddr("tcp", addr) if err != nil { logger.Errorf("couldn't resolve %s:", addr, err) return err } - - self.net.SuggestPeer(netaddr.IP, netaddr.Port, nil) + self.net.SuggestPeer(netaddr.IP, netaddr.Port, id) return nil } -- cgit From 2cf4fed11b01bb99e08b838f7df2b9396f42f758 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Sat, 7 Feb 2015 00:15:04 +0100 Subject: cmd/mist, eth, javascript, p2p: use Node URLs for peer suggestions --- eth/backend.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 08052c15d..6cf2069d7 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -2,7 +2,6 @@ package eth import ( "fmt" - "net" "sync" "github.com/ethereum/go-ethereum/core" @@ -241,13 +240,12 @@ func (s *Ethereum) Start(seedNode string) error { return nil } -func (self *Ethereum) SuggestPeer(addr string, id discover.NodeID) error { - netaddr, err := net.ResolveTCPAddr("tcp", addr) +func (self *Ethereum) SuggestPeer(nodeURL string) error { + n, err := discover.ParseNode(nodeURL) if err != nil { - logger.Errorf("couldn't resolve %s:", addr, err) - return err + return fmt.Errorf("invalid node URL: %v", err) } - self.net.SuggestPeer(netaddr.IP, netaddr.Port, id) + self.net.SuggestPeer(n) return nil } -- cgit From 028775a0863946c1e9ad51fe7b22faa5c59b2605 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Sat, 7 Feb 2015 00:38:36 +0100 Subject: cmd/ethereum, cmd/mist: add flag for discovery bootstrap nodes --- eth/backend.go | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 6cf2069d7..5ad0f83f4 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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 -- cgit From f1ebad2508b6941df5802d607b30b7a5e7b2c67d Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 9 Feb 2015 16:17:07 +0100 Subject: eth: don't warn if no BootNodes are specified --- eth/backend.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 5ad0f83f4..f5ebc9033 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -46,6 +46,9 @@ type Config struct { func (cfg *Config) parseBootNodes() []*discover.Node { var ns []*discover.Node for _, url := range strings.Split(cfg.BootNodes, " ") { + if url == "" { + continue + } n, err := discover.ParseNode(url) if err != nil { logger.Errorf("Bootstrap URL %s: %v\n", url, err) -- cgit From a3cd2187194b79cd8b14c4ec4f1abca91a0147e0 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 10 Feb 2015 12:30:09 +0100 Subject: cmd/mist, cmd/ethereum: add CLI arguments for node key --- eth/backend.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index f5ebc9033..e8555061d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -1,6 +1,7 @@ package eth import ( + "crypto/ecdsa" "fmt" "strings" "sync" @@ -37,6 +38,10 @@ type Config struct { // discovery node URLs. BootNodes string + // This key is used to identify the node on the network. + // If nil, an ephemeral key is used. + NodeKey *ecdsa.PrivateKey + Shh bool Dial bool @@ -150,9 +155,11 @@ func New(config *Config) (*Ethereum, error) { if err != nil { return nil, err } - netprv, err := crypto.GenerateKey() - if err != nil { - return nil, fmt.Errorf("could not generate server key: %v", err) + netprv := config.NodeKey + if netprv == nil { + if netprv, err = crypto.GenerateKey(); err != nil { + return nil, fmt.Errorf("could not generate server key: %v", err) + } } eth.net = &p2p.Server{ PrivateKey: netprv, -- cgit From a21b30c9012572e1bbed62ac43bdb1bdc89dab92 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 10 Feb 2015 13:30:07 +0100 Subject: eth: remove unused Ethereum sync fields --- eth/backend.go | 4 ---- 1 file changed, 4 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index e8555061d..f3e4842a7 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -4,7 +4,6 @@ import ( "crypto/ecdsa" "fmt" "strings" - "sync" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" @@ -92,9 +91,6 @@ type Ethereum struct { logger ethlogger.LogSystem - synclock sync.Mutex - syncGroup sync.WaitGroup - Mining bool } -- cgit From d0a2e655c9599f462bb20bd49bc69b8e1e330a21 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 11 Feb 2015 17:19:31 +0100 Subject: cmd/ethereum, cmd/mist, eth, p2p: use package p2p/nat This deletes the old NAT implementation. --- eth/backend.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index f3e4842a7..29cf7d836 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -13,6 +13,7 @@ import ( ethlogger "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" + "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/pow/ezp" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/whisper" @@ -28,10 +29,8 @@ type Config struct { LogLevel int KeyRing string - MaxPeers int - Port string - NATType string - PMPGateway string + MaxPeers int + Port string // This should be a space-separated list of // discovery node URLs. @@ -41,6 +40,7 @@ type Config struct { // If nil, an ephemeral key is used. NodeKey *ecdsa.PrivateKey + NAT nat.Interface Shh bool Dial bool @@ -147,10 +147,6 @@ func New(config *Config) (*Ethereum, error) { ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool) protocols := []p2p.Protocol{ethProto, eth.whisper.Protocol()} - nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway) - if err != nil { - return nil, err - } netprv := config.NodeKey if netprv == nil { if netprv, err = crypto.GenerateKey(); err != nil { @@ -163,7 +159,7 @@ func New(config *Config) (*Ethereum, error) { MaxPeers: config.MaxPeers, Protocols: protocols, Blacklist: eth.blacklist, - NAT: nat, + NAT: config.NAT, NoDial: !config.Dial, BootstrapNodes: config.parseBootNodes(), } -- cgit