aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/queue.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-15 18:14:46 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-15 20:01:58 +0800
commit83226762c20dbf48939d76046ad32422a44feda0 (patch)
treedbef36842a0c42a8e9543393eb1b5208aaaf227b /eth/downloader/queue.go
parent9ad515d2dc62c5d1ce1099efa89bd0a0b3f06a67 (diff)
downloaddexon-83226762c20dbf48939d76046ad32422a44feda0.tar
dexon-83226762c20dbf48939d76046ad32422a44feda0.tar.gz
dexon-83226762c20dbf48939d76046ad32422a44feda0.tar.bz2
dexon-83226762c20dbf48939d76046ad32422a44feda0.tar.lz
dexon-83226762c20dbf48939d76046ad32422a44feda0.tar.xz
dexon-83226762c20dbf48939d76046ad32422a44feda0.tar.zst
dexon-83226762c20dbf48939d76046ad32422a44feda0.zip
eth, eth/downloader: detect and handle madeup hash attacks
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r--eth/downloader/queue.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go
index aa48c521a..13ec9a520 100644
--- a/eth/downloader/queue.go
+++ b/eth/downloader/queue.go
@@ -123,13 +123,13 @@ func (q *queue) Has(hash common.Hash) bool {
}
// Insert adds a set of hashes for the download queue for scheduling, returning
-// the number of new hashes encountered.
-func (q *queue) Insert(hashes []common.Hash) int {
+// the new hashes encountered.
+func (q *queue) Insert(hashes []common.Hash) []common.Hash {
q.lock.Lock()
defer q.lock.Unlock()
// Insert all the hashes prioritized in the arrival order
- inserts := 0
+ inserts := make([]common.Hash, 0, len(hashes))
for _, hash := range hashes {
// Skip anything we already have
if old, ok := q.hashPool[hash]; ok {
@@ -137,7 +137,9 @@ func (q *queue) Insert(hashes []common.Hash) int {
continue
}
// Update the counters and insert the hash
- q.hashCounter, inserts = q.hashCounter+1, inserts+1
+ q.hashCounter = q.hashCounter + 1
+ inserts = append(inserts, hash)
+
q.hashPool[hash] = q.hashCounter
q.hashQueue.Push(hash, float32(q.hashCounter)) // Highest gets schedules first
}