diff options
author | Sonic <sonic@cobinhood.com> | 2018-10-12 15:02:33 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:49 +0800 |
commit | 1da23cc940d308e5376e3056c2737ddd2f01642a (patch) | |
tree | 39543166fae33dfe2dd70ce03900384c0ebd6d51 /dex/backend.go | |
parent | cdf1f022696971d9d6209d577ed0b578e7462007 (diff) | |
download | dexon-1da23cc940d308e5376e3056c2737ddd2f01642a.tar.gz dexon-1da23cc940d308e5376e3056c2737ddd2f01642a.tar.zst dexon-1da23cc940d308e5376e3056c2737ddd2f01642a.zip |
dex: network: implement the network interface
Diffstat (limited to 'dex/backend.go')
-rw-r--r-- | dex/backend.go | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/dex/backend.go b/dex/backend.go index d01ab8040..caac0fe21 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -85,7 +85,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { if err != nil { panic(err) } - network := NewDexconNetwork() chainDb, err := CreateDB(ctx, config, "chaindata") if err != nil { @@ -116,7 +115,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { networkID: config.NetworkId, bloomRequests: make(chan chan *bloombits.Retrieval), bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms), - network: network, blockdb: db, engine: dexcon.New(¶ms.DexconConfig{}), } @@ -154,9 +152,18 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { dex.governance = NewDexconGovernance(dex.APIBackend, dex.chainConfig, config.PrivateKey) dex.app = NewDexconApp(dex.txPool, dex.blockchain, dex.governance, chainDb, config, vmConfig) - privKey := coreEcdsa.NewPrivateKeyFromECDSA(config.PrivateKey) - dex.consensus = dexCore.NewConsensus(dex.app, dex.governance, db, network, privKey) + pm, err := NewProtocolManager(dex.chainConfig, config.SyncMode, + config.NetworkId, dex.eventMux, dex.txPool, dex.engine, dex.blockchain, + chainDb, dex.governance) + if err != nil { + return nil, err + } + + dex.protocolManager = pm + dex.network = NewDexconNetwork(pm) + privKey := coreEcdsa.NewPrivateKeyFromECDSA(config.PrivateKey) + dex.consensus = dexCore.NewConsensus(dex.app, dex.governance, db, dex.network, privKey) return dex, nil } @@ -168,7 +175,24 @@ func (s *Dexon) APIs() []rpc.API { return nil } -func (s *Dexon) Start(server *p2p.Server) error { +func (s *Dexon) Start(srvr *p2p.Server) error { + // Start the bloom bits servicing goroutines + s.startBloomHandlers(params.BloomBitsBlocks) + + // Start the RPC service + s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.NetVersion()) + + // Figure out a max peers count based on the server limits + maxPeers := srvr.MaxPeers + if s.config.LightServ > 0 { + if s.config.LightPeers >= srvr.MaxPeers { + return fmt.Errorf("invalid peer config: light peer count (%d) >= total peer count (%d)", s.config.LightPeers, srvr.MaxPeers) + } + maxPeers -= s.config.LightPeers + } + // Start the networking layer and the light server if requested + s.protocolManager.Start(srvr, maxPeers) + return nil } @@ -196,3 +220,4 @@ func (d *Dexon) EventMux() *event.TypeMux { return d.eventMux } func (d *Dexon) Engine() consensus.Engine { return d.engine } func (d *Dexon) ChainDb() ethdb.Database { return d.chainDb } func (d *Dexon) Downloader() *downloader.Downloader { return d.protocolManager.downloader } +func (d *Dexon) NetVersion() uint64 { return d.networkID } |