From ba0ede120109ec10f685d9943dcf39bec8976f97 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 | 2 +- cmd/utils/cmd.go | 4 ++-- eth/backend.go | 18 +++++++++++++----- 4 files changed, 18 insertions(+), 8 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 8d46b279e4..16aa0c8939 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -76,7 +76,7 @@ func main() { clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier, string(keyManager.PublicKey())) - ethereum := utils.NewEthereum(db, clientIdentity, keyManager, utils.NatType(NatType, PMPGateway), OutboundPort, MaxPeer) + ethereum := utils.NewEthereum(db, clientIdentity, keyManager, utils.NatType(NatType, PMPGateway), OutboundPort, MaxPeer, SHH) if Dump { var block *types.Block diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 466c513835..4355760387 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -167,8 +167,8 @@ func NatType(natType string, gateway string) (nat p2p.NAT) { return } -func NewEthereum(db ethutil.Database, clientIdentity p2p.ClientIdentity, keyManager *crypto.KeyManager, nat p2p.NAT, OutboundPort string, MaxPeer int) *eth.Ethereum { - ethereum, err := eth.New(db, clientIdentity, keyManager, nat, OutboundPort, MaxPeer) +func NewEthereum(db ethutil.Database, clientIdentity p2p.ClientIdentity, keyManager *crypto.KeyManager, nat p2p.NAT, OutboundPort string, MaxPeer int, SHH bool) *eth.Ethereum { + ethereum, err := eth.New(db, clientIdentity, keyManager, nat, OutboundPort, MaxPeer, SHH) if err != nil { clilogger.Fatalln("eth start err:", err) } diff --git a/eth/backend.go b/eth/backend.go index ac696eca7f..dd14d4aef0 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -54,7 +54,7 @@ type Ethereum struct { Mining bool } -func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.KeyManager, nat p2p.NAT, port string, maxPeers int) (*Ethereum, error) { +func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.KeyManager, nat p2p.NAT, port string, maxPeers int, shh bool) (*Ethereum, error) { saveProtocolVersion(db) ethutil.Config.Db = db @@ -73,7 +73,6 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke eth.txPool = core.NewTxPool(eth.chainManager, 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 @@ -83,7 +82,12 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke eth.txPool.Start() ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool) - protocols := []p2p.Protocol{ethProto, eth.whisper.Protocol()} + protocols := []p2p.Protocol{ethProto} + + if shh { + eth.whisper = whisper.New() + protocols = append(protocols, eth.whisper.Protocol()) + } server := &p2p.Server{ Identity: identity, @@ -165,7 +169,9 @@ func (s *Ethereum) Start(seed bool) error { return err } s.blockPool.Start() - s.whisper.Start() + if s.whisper != nil { + s.whisper.Start() + } // broadcast transactions s.txSub = s.eventMux.Subscribe(core.TxPreEvent{}) @@ -213,7 +219,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)