diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-12 19:33:42 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-12 19:36:01 +0800 |
commit | 7dcb9825c3a3afe1a287ad544a5ad0500c0027a7 (patch) | |
tree | 98d7933f1e426b766ffeb33b138e7828d9189616 /eth/downloader/peer.go | |
parent | 6efa8db8887c70679aedeaec44411f886976d2e1 (diff) | |
download | go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.tar go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.tar.gz go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.tar.bz2 go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.tar.lz go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.tar.xz go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.tar.zst go-tangerine-7dcb9825c3a3afe1a287ad544a5ad0500c0027a7.zip |
downloader: return an error for peer.fetch and return chunk to queue
If a peer was somehow already fetching and somehow managed to end up in
the `available` pool it should return it's work.
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r-- | eth/downloader/peer.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go index 486c09e38..318da59b7 100644 --- a/eth/downloader/peer.go +++ b/eth/downloader/peer.go @@ -1,6 +1,7 @@ package downloader import ( + "errors" "math/big" "sync" @@ -31,10 +32,14 @@ func newPeer(id string, td *big.Int, hash common.Hash, getHashes hashFetcherFn, } // fetch a chunk using the peer -func (p *peer) fetch(chunk *chunk) { +func (p *peer) fetch(chunk *chunk) error { p.mu.Lock() defer p.mu.Unlock() + if p.state == workingState { + return errors.New("peer already fetching chunk") + } + // set working state p.state = workingState // convert the set to a fetchable slice @@ -45,4 +50,6 @@ func (p *peer) fetch(chunk *chunk) { return true }) p.getBlocks(hashes) + + return nil } |