From b44289ec1279bf1e6ac4ffc49df20119fde74175 Mon Sep 17 00:00:00 2001 From: zelig Date: Sat, 3 Jan 2015 16:34:33 +0000 Subject: [PATCH] add shh command line option to switch on/off whisper --- cmd/ethereum/flags.go | 2 ++ cmd/ethereum/main.go | 3 +++ eth/backend.go | 25 ++++++++++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index 40bb1318db..5e32562085 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -59,6 +59,7 @@ var ( DumpNumber int VmType int ImportChain string + SHH bool ) // flags specific to cli client @@ -94,6 +95,7 @@ func Init() { flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") flag.BoolVar(&UseSeed, "seed", true, "seed peers") + flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)") flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given") diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 389d9f45f7..85ed20171b 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -64,10 +64,13 @@ func main() { NATType: PMPGateway, PMPGateway: PMPGateway, KeyRing: KeyRing, + Shh: SHH, }) + if err != nil { clilogger.Fatalln(err) } + utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) if Dump { diff --git a/eth/backend.go b/eth/backend.go index 352316ad54..8f6ef32f9c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -36,6 +36,8 @@ type Config struct { NATType string PMPGateway string + Shh bool + KeyManager *crypto.KeyManager } @@ -124,17 +126,18 @@ func New(config *Config) (*Ethereum, error) { eth.txPool = core.NewTxPool(eth.EventMux()) eth.blockManager = core.NewBlockManager(eth.txPool, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockManager) - eth.whisper = whisper.New() hasBlock := eth.chainManager.HasBlock insertChain := eth.chainManager.InsertChain eth.blockPool = NewBlockPool(hasBlock, insertChain, ezp.Verify) - // Start services - eth.txPool.Start() - ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool) - protocols := []p2p.Protocol{ethProto, eth.whisper.Protocol()} + protocols := []p2p.Protocol{ethProto} + + if config.Shh { + eth.whisper = whisper.New() + protocols = append(protocols, eth.whisper.Protocol()) + } nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway) if err != nil { @@ -222,8 +225,14 @@ func (s *Ethereum) Start(seed bool) error { if err != nil { return err } + + // Start services + s.txPool.Start() s.blockPool.Start() - s.whisper.Start() + + if s.whisper != nil { + s.whisper.Start() + } // broadcast transactions s.txSub = s.eventMux.Subscribe(core.TxPreEvent{}) @@ -271,7 +280,9 @@ func (s *Ethereum) Stop() { s.txPool.Stop() s.eventMux.Stop() s.blockPool.Stop() - s.whisper.Stop() + if s.whisper != nil { + s.whisper.Stop() + } ethlogger.Infoln("Server stopped") close(s.shutdownChan)