aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/queue.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-19 06:09:12 +0800
committerobscuren <geffobscura@gmail.com>2015-04-19 06:09:12 +0800
commit71aa5fe8a31bdf12a38e940730e60964bbf4a1c0 (patch)
tree7a71713a6447f6a76e8f982f2527e73085473451 /eth/downloader/queue.go
parent84f1af6413b172c7c88d567e8b9033197196b5bd (diff)
parent164b878854b58aed833eb704579343099854735f (diff)
downloaddexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.tar
dexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.tar.gz
dexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.tar.bz2
dexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.tar.lz
dexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.tar.xz
dexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.tar.zst
dexon-71aa5fe8a31bdf12a38e940730e60964bbf4a1c0.zip
Merge branch 'downloader-proto' into develop
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r--eth/downloader/queue.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go
index 4d1aa4e93..ce3aa9850 100644
--- a/eth/downloader/queue.go
+++ b/eth/downloader/queue.go
@@ -31,6 +31,17 @@ func newqueue() *queue {
}
}
+func (c *queue) reset() {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ c.hashPool.Clear()
+ c.fetchPool.Clear()
+ c.blockHashes.Clear()
+ c.blocks = nil
+ c.fetching = make(map[string]*chunk)
+}
+
// reserve a `max` set of hashes for `p` peer.
func (c *queue) get(p *peer, max int) *chunk {
c.mu.Lock()
@@ -49,11 +60,19 @@ func (c *queue) get(p *peer, max int) *chunk {
return false
}
- hashes.Add(v)
- i++
+ // Skip any hashes that have previously been requested from the peer
+ if !p.requested.Has(v) {
+ hashes.Add(v)
+ i++
+ }
return true
})
+ // if no hashes can be requested return a nil chunk
+ if hashes.Size() == 0 {
+ return nil
+ }
+
// remove the fetchable hashes from hash pool
c.hashPool.Separate(hashes)
c.fetchPool.Merge(hashes)