aboutsummaryrefslogtreecommitdiffstats
path: root/eth/backend.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-06 00:10:42 +0800
committerobscuren <geffobscura@gmail.com>2015-01-06 00:10:42 +0800
commit6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2 (patch)
treeb898711590694cfaa6f10dbc2a4c8591232954ef /eth/backend.go
parentb0854fbff5c3d588134f577918a39d08002235dc (diff)
downloaddexon-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.gz
dexon-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.zst
dexon-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.zip
Merge
Diffstat (limited to 'eth/backend.go')
-rw-r--r--eth/backend.go47
1 files changed, 32 insertions, 15 deletions
diff --git a/eth/backend.go b/eth/backend.go
index db8e8e029..065a4f7d8 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -36,6 +36,9 @@ type Config struct {
NATType string
PMPGateway string
+ Shh bool
+ Dial bool
+
KeyManager *crypto.KeyManager
}
@@ -130,11 +133,13 @@ func New(config *Config) (*Ethereum, error) {
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 {
@@ -142,12 +147,16 @@ func New(config *Config) (*Ethereum, error) {
}
eth.net = &p2p.Server{
- Identity: clientId,
- MaxPeers: config.MaxPeers,
- Protocols: protocols,
- ListenAddr: ":" + config.Port,
- Blacklist: eth.blacklist,
- NAT: nat,
+ Identity: clientId,
+ MaxPeers: config.MaxPeers,
+ Protocols: protocols,
+ Blacklist: eth.blacklist,
+ NAT: nat,
+ NoDial: !config.Dial,
+ }
+
+ if len(config.Port) > 0 {
+ eth.net.ListenAddr = ":" + config.Port
}
return eth, nil
@@ -219,8 +228,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{})
@@ -268,7 +283,9 @@ func (s *Ethereum) Stop() {
s.txPool.Stop()
s.eventMux.Stop()
s.blockPool.Stop()
- s.whisper.Stop()
+ if s.whisper != nil {
+ s.whisper.Stop()
+ }
logger.Infoln("Server stopped")
close(s.shutdownChan)
@@ -285,16 +302,16 @@ func (self *Ethereum) txBroadcastLoop() {
// automatically stops if unsubscribe
for obj := range self.txSub.Chan() {
event := obj.(core.TxPreEvent)
- self.net.Broadcast("eth", TxMsg, []interface{}{event.Tx.RlpData()})
+ self.net.Broadcast("eth", TxMsg, event.Tx.RlpData())
}
}
func (self *Ethereum) blockBroadcastLoop() {
// automatically stops if unsubscribe
- for obj := range self.txSub.Chan() {
+ for obj := range self.blockSub.Chan() {
switch ev := obj.(type) {
case core.NewMinedBlockEvent:
- self.net.Broadcast("eth", NewBlockMsg, ev.Block.RlpData())
+ self.net.Broadcast("eth", NewBlockMsg, ev.Block.RlpData(), ev.Block.Td)
}
}
}