This commit is contained in:
obscuren 2014-12-15 11:37:23 +01:00
parent 1d959cb0ca
commit f111fc0608
2 changed files with 18 additions and 47 deletions

View File

@ -3,7 +3,6 @@ package eth
import ( import (
"encoding/json" "encoding/json"
"net" "net"
"path"
"sync" "sync"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -32,7 +31,6 @@ type Ethereum struct {
db ethutil.Database db ethutil.Database
// State manager for processing new blocks and managing the over all states // State manager for processing new blocks and managing the over all states
blockManager *core.BlockManager blockManager *core.BlockManager
// The transaction pool. Transaction can be pushed on this pool // The transaction pool. Transaction can be pushed on this pool
// for later including in the blocks // for later including in the blocks
txPool *core.TxPool txPool *core.TxPool
@ -43,22 +41,11 @@ type Ethereum struct {
// Event // Event
eventMux *event.TypeMux eventMux *event.TypeMux
// Nonce
Nonce uint64
ListenAddr string
blacklist p2p.Blacklist blacklist p2p.Blacklist
server *p2p.Server server *p2p.Server
txSub event.Subscription txSub event.Subscription
blockSub event.Subscription blockSub event.Subscription
// Capabilities for outgoing peers
// serverCaps Caps
peersFile string
Mining bool
RpcServer *rpc.JsonRpcServer RpcServer *rpc.JsonRpcServer
keyManager *crypto.KeyManager keyManager *crypto.KeyManager
@ -71,6 +58,8 @@ type Ethereum struct {
filterMu sync.RWMutex filterMu sync.RWMutex
filterId int filterId int
filters map[int]*core.Filter filters map[int]*core.Filter
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) (*Ethereum, error) {
@ -78,28 +67,13 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke
saveProtocolVersion(db) saveProtocolVersion(db)
ethutil.Config.Db = db ethutil.Config.Db = db
// FIXME:
blacklist := p2p.NewBlacklist()
// Sorry Py person. I must blacklist. you perform badly
blacklist.Put(ethutil.Hex2Bytes("64656330303561383532336435376331616537643864663236623336313863373537353163636634333530626263396330346237336262623931383064393031"))
peersFile := path.Join(ethutil.Config.ExecPath, "known_peers.json")
nonce, _ := ethutil.RandomUint64()
listenAddr := ":" + port
eth := &Ethereum{ eth := &Ethereum{
shutdownChan: make(chan bool), shutdownChan: make(chan bool),
quit: make(chan bool), quit: make(chan bool),
db: db, db: db,
Nonce: nonce,
// serverCaps: caps,
peersFile: peersFile,
ListenAddr: listenAddr,
keyManager: keyManager, keyManager: keyManager,
clientIdentity: identity, clientIdentity: identity,
blacklist: blacklist, blacklist: p2p.NewBlocklist(),
eventMux: &event.TypeMux{}, eventMux: &event.TypeMux{},
filters: make(map[int]*core.Filter), filters: make(map[int]*core.Filter),
} }
@ -111,9 +85,7 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke
hasBlock := eth.chainManager.HasBlock hasBlock := eth.chainManager.HasBlock
insertChain := eth.chainManager.InsertChain insertChain := eth.chainManager.InsertChain
pow := ezp.New() eth.blockPool = NewBlockPool(hasBlock, insertChain, ezp.Verify)
verifyPoW := pow.Verify
eth.blockPool = NewBlockPool(hasBlock, insertChain, verifyPoW)
// Start the tx pool // Start the tx pool
eth.txPool.Start() eth.txPool.Start()
@ -125,7 +97,7 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke
Identity: identity, Identity: identity,
MaxPeers: maxPeers, MaxPeers: maxPeers,
Protocols: protocols, Protocols: protocols,
ListenAddr: listenAddr, ListenAddr: ":" + port,
Blacklist: blacklist, Blacklist: blacklist,
NAT: nat, NAT: nat,
} }
@ -171,11 +143,8 @@ func (s *Ethereum) IsMining() bool {
} }
func (s *Ethereum) IsListening() bool { func (s *Ethereum) IsListening() bool {
if s.ListenAddr == "" { // XXX TODO
return false return false
} else {
return true
}
} }
func (s *Ethereum) PeerCount() int { func (s *Ethereum) PeerCount() int {
@ -231,8 +200,6 @@ func (s *Ethereum) Stop() {
// Close the database // Close the database
defer s.db.Close() defer s.db.Close()
//
// WritePeers(s.peersFile, s.server.PeerAddresses())
close(s.quit) close(s.quit)
s.txSub.Unsubscribe() // quits txBroadcastLoop s.txSub.Unsubscribe() // quits txBroadcastLoop

View File

@ -59,7 +59,7 @@ func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte {
} }
sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes()) sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes())
if pow.verify(hash, diff, sha) { if verify(hash, diff, sha) {
return sha return sha
} }
} }
@ -72,7 +72,11 @@ func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte {
return nil return nil
} }
func (pow *EasyPow) verify(hash []byte, diff *big.Int, nonce []byte) bool { func (pow *EasyPow) Verify(block pow.Block) bool {
return Verify(block)
}
func verify(hash []byte, diff *big.Int, nonce []byte) bool {
sha := sha3.NewKeccak256() sha := sha3.NewKeccak256()
d := append(hash, nonce...) d := append(hash, nonce...)
@ -84,6 +88,6 @@ func (pow *EasyPow) verify(hash []byte, diff *big.Int, nonce []byte) bool {
return res.Cmp(verification) <= 0 return res.Cmp(verification) <= 0
} }
func (pow *EasyPow) Verify(block pow.Block) bool { func Verify(block pow.Block) bool {
return pow.verify(block.HashNoNonce(), block.Diff(), block.N()) return verify(block.HashNoNonce(), block.Diff(), block.N())
} }