diff options
Diffstat (limited to 'eth/backend.go')
-rw-r--r-- | eth/backend.go | 122 |
1 files changed, 25 insertions, 97 deletions
diff --git a/eth/backend.go b/eth/backend.go index 0683705df..5bd6ac55d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -65,7 +65,7 @@ const ( var ( jsonlogger = logger.NewJsonLogger() - datadirInUseErrNos = []uint{11, 32, 35} + datadirInUseErrnos = map[uint]bool{11: true, 32: true, 35: true} portInUseErrRE = regexp.MustCompile("address already in use") defaultBootNodes = []*discover.Node{ @@ -231,9 +231,7 @@ type Ethereum struct { chainDb ethdb.Database // Block chain database dappDb ethdb.Database // Dapp database - //*** SERVICES *** - // State manager for processing new blocks and managing the over all states - blockProcessor *core.BlockProcessor + // Handlers txPool *core.TxPool blockchain *core.BlockChain accountManager *accounts.Manager @@ -286,15 +284,7 @@ func New(config *Config) (*Ethereum, error) { // Open the chain database and perform any upgrades needed chainDb, err := newdb(filepath.Join(config.DataDir, "chaindata")) if err != nil { - var ok bool - errno := uint(err.(syscall.Errno)) - for _, no := range datadirInUseErrNos { - if errno == no { - ok = true - break - } - } - if ok { + if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] { err = fmt.Errorf("%v (check if another instance of geth is already running with the same data directory '%s')", err, config.DataDir) } return nil, fmt.Errorf("blockchain db err: %v", err) @@ -311,14 +301,7 @@ func New(config *Config) (*Ethereum, error) { dappDb, err := newdb(filepath.Join(config.DataDir, "dapp")) if err != nil { - var ok bool - for _, no := range datadirInUseErrNos { - if uint(err.(syscall.Errno)) == no { - ok = true - break - } - } - if ok { + if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] { err = fmt.Errorf("%v (check if another instance of geth is already running with the same data directory '%s')", err, config.DataDir) } return nil, fmt.Errorf("dapp db err: %v", err) @@ -422,8 +405,6 @@ func New(config *Config) (*Ethereum, error) { newPool := core.NewTxPool(eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit) eth.txPool = newPool - eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.blockchain, eth.EventMux()) - eth.blockchain.SetProcessor(eth.blockProcessor) if eth.protocolManager, err = NewProtocolManager(config.FastSync, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil { return nil, err } @@ -467,62 +448,10 @@ func New(config *Config) (*Ethereum, error) { return eth, nil } -type NodeInfo struct { - Name string - NodeUrl string - NodeID string - IP string - DiscPort int // UDP listening port for discovery protocol - TCPPort int // TCP listening port for RLPx - Td string - ListenAddr string -} - -func (s *Ethereum) NodeInfo() *NodeInfo { - node := s.net.Self() - - return &NodeInfo{ - Name: s.Name(), - NodeUrl: node.String(), - NodeID: node.ID.String(), - IP: node.IP.String(), - DiscPort: int(node.UDP), - TCPPort: int(node.TCP), - ListenAddr: s.net.ListenAddr, - Td: s.BlockChain().GetTd(s.BlockChain().CurrentBlock().Hash()).String(), - } -} - -type PeerInfo struct { - ID string - Name string - Caps string - RemoteAddress string - LocalAddress string -} - -func newPeerInfo(peer *p2p.Peer) *PeerInfo { - var caps []string - for _, cap := range peer.Caps() { - caps = append(caps, cap.String()) - } - return &PeerInfo{ - ID: peer.ID().String(), - Name: peer.Name(), - Caps: strings.Join(caps, ", "), - RemoteAddress: peer.RemoteAddr().String(), - LocalAddress: peer.LocalAddr().String(), - } -} - -// PeersInfo returns an array of PeerInfo objects describing connected peers -func (s *Ethereum) PeersInfo() (peersinfo []*PeerInfo) { - for _, peer := range s.net.Peers() { - if peer != nil { - peersinfo = append(peersinfo, newPeerInfo(peer)) - } - } - return +// Network retrieves the underlying P2P network server. This should eventually +// be moved out into a protocol independent package, but for now use an accessor. +func (s *Ethereum) Network() *p2p.Server { + return s.net } func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) { @@ -552,24 +481,23 @@ func (s *Ethereum) IsMining() bool { return s.miner.Mining() } func (s *Ethereum) Miner() *miner.Miner { return s.miner } // func (s *Ethereum) Logger() logger.LogSystem { return s.logger } -func (s *Ethereum) Name() string { return s.net.Name } -func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } -func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain } -func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor } -func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } -func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper } -func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } -func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb } -func (s *Ethereum) DappDb() ethdb.Database { return s.dappDb } -func (s *Ethereum) IsListening() bool { return true } // Always listening -func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } -func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } -func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } -func (s *Ethereum) ClientVersion() string { return s.clientVersion } -func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } -func (s *Ethereum) NetVersion() int { return s.netVersionId } -func (s *Ethereum) ShhVersion() int { return s.shhVersionId } -func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader } +func (s *Ethereum) Name() string { return s.net.Name } +func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } +func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain } +func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } +func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper } +func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } +func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb } +func (s *Ethereum) DappDb() ethdb.Database { return s.dappDb } +func (s *Ethereum) IsListening() bool { return true } // Always listening +func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } +func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } +func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } +func (s *Ethereum) ClientVersion() string { return s.clientVersion } +func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } +func (s *Ethereum) NetVersion() int { return s.netVersionId } +func (s *Ethereum) ShhVersion() int { return s.shhVersionId } +func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader } // Start the ethereum func (s *Ethereum) Start() error { |