aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-15 06:43:00 +0800
committerobscuren <geffobscura@gmail.com>2015-05-15 06:43:10 +0800
commitb71091e337fef7e3cfad56c61c97a42094e87531 (patch)
treee3945e86e63714aeb77569cca28329a73de608d7 /eth/downloader
parent0f76a1c6df44bc3242a64e76bef66dfe312d259b (diff)
downloaddexon-b71091e337fef7e3cfad56c61c97a42094e87531.tar
dexon-b71091e337fef7e3cfad56c61c97a42094e87531.tar.gz
dexon-b71091e337fef7e3cfad56c61c97a42094e87531.tar.bz2
dexon-b71091e337fef7e3cfad56c61c97a42094e87531.tar.lz
dexon-b71091e337fef7e3cfad56c61c97a42094e87531.tar.xz
dexon-b71091e337fef7e3cfad56c61c97a42094e87531.tar.zst
dexon-b71091e337fef7e3cfad56c61c97a42094e87531.zip
eth, eth/downloader, miner: use download events to check miner start
Diffstat (limited to 'eth/downloader')
-rw-r--r--eth/downloader/downloader.go17
-rw-r--r--eth/downloader/events.go5
2 files changed, 21 insertions, 1 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index cc75c3014..616971f73 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
)
@@ -55,6 +56,8 @@ type hashPack struct {
}
type Downloader struct {
+ mux *event.TypeMux
+
mu sync.RWMutex
queue *queue
peers *peerSet
@@ -76,8 +79,9 @@ type Downloader struct {
cancelLock sync.RWMutex // Lock to protect the cancel channel in delivers
}
-func New(hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
+func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
downloader := &Downloader{
+ mux: mux,
queue: newQueue(),
peers: newPeerSet(),
hasBlock: hasBlock,
@@ -93,6 +97,11 @@ func (d *Downloader) Stats() (current int, max int) {
return d.queue.Size()
}
+// Synchronising returns the state of the downloader
+func (d *Downloader) Synchronising() bool {
+ return atomic.LoadInt32(&d.synchronising) > 0
+}
+
// RegisterPeer injects a new download peer into the set of block source to be
// used for fetching hashes and blocks from.
func (d *Downloader) RegisterPeer(id string, head common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) error {
@@ -129,6 +138,9 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
if atomic.CompareAndSwapInt32(&d.notified, 0, 1) {
glog.V(logger.Info).Infoln("Block synchronisation started")
}
+
+ d.mux.Post(StartEvent{})
+
// Create cancel channel for aborting mid-flight
d.cancelLock.Lock()
d.cancelCh = make(chan struct{})
@@ -166,6 +178,9 @@ func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) {
// reset on error
if err != nil {
d.queue.Reset()
+ d.mux.Post(FailedEvent{err})
+ } else {
+ d.mux.Post(DoneEvent{})
}
}()
diff --git a/eth/downloader/events.go b/eth/downloader/events.go
new file mode 100644
index 000000000..333feb976
--- /dev/null
+++ b/eth/downloader/events.go
@@ -0,0 +1,5 @@
+package downloader
+
+type DoneEvent struct{}
+type StartEvent struct{}
+type FailedEvent struct{ Err error }