eth, eth/downloader: prevent hash repeater attack

This commit is contained in:
Péter Szilágyi
2015-05-15 01:40:16 +03:00
parent c1f0d40e34
commit cd2fb09051
4 changed files with 50 additions and 15 deletions

View File

@ -27,7 +27,7 @@ var (
errLowTd = errors.New("peer's TD is too low")
ErrBusy = errors.New("busy")
errUnknownPeer = errors.New("peer's unknown or unhealthy")
errBadPeer = errors.New("action from bad peer ignored")
ErrBadPeer = errors.New("action from bad peer ignored")
errNoPeers = errors.New("no peers to keep download active")
ErrPendingQueue = errors.New("pending items in queue")
ErrTimeout = errors.New("timeout")
@ -266,9 +266,11 @@ out:
break
}
}
d.queue.Insert(hashPack.hashes)
if !done {
// Insert all the new hashes, but only continue if got something useful
inserts := d.queue.Insert(hashPack.hashes)
if inserts == 0 && !done {
return ErrBadPeer
} else if !done {
activePeer.getHashes(hash)
continue
}