add shh command line option to switch on/off whisper

This commit is contained in:
zelig 2015-01-03 16:34:33 +00:00
parent 9380644db0
commit ba0ede1201
4 changed files with 18 additions and 8 deletions

View file

@ -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")

View file

@ -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

View file

@ -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)
}

View file

@ -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()
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()
if s.whisper != nil {
s.whisper.Stop()
}
ethlogger.Infoln("Server stopped")
close(s.shutdownChan)