diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-05-07 17:59:19 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-05-07 17:59:19 +0800 |
commit | 45f8304f3c44e5379c7e30ab144d73e591e270af (patch) | |
tree | 4516358d4916867d26249795917903eb9ff1fd11 /eth/downloader/downloader.go | |
parent | 4800c94392e814a2cb9d343aab4706be0cd0851d (diff) | |
download | dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.tar dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.tar.gz dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.tar.bz2 dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.tar.lz dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.tar.xz dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.tar.zst dexon-45f8304f3c44e5379c7e30ab144d73e591e270af.zip |
eth/downloader: fix expiration not running while fetching
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r-- | eth/downloader/downloader.go | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 608acf499..25b251112 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -346,13 +346,28 @@ out: d.peers.setState(blockPack.peerId, idleState) } case <-ticker.C: - // after removing bad peers make sure we actually have sufficient peer left to keep downloading + // Check for bad peers. Bad peers may indicate a peer not responding + // to a `getBlocks` message. A timeout of 5 seconds is set. Peers + // that badly or poorly behave are removed from the peer set (not banned). + // Bad peers are excluded from the available peer set and therefor won't be + // reused. XXX We could re-introduce peers after X time. + badPeers := d.queue.Expire(blockTtl) + for _, pid := range badPeers { + // XXX We could make use of a reputation system here ranking peers + // in their performance + // 1) Time for them to respond; + // 2) Measure their speed; + // 3) Amount and availability. + if peer := d.peers[pid]; peer != nil { + peer.demote() + peer.reset() + } + } + // After removing bad peers make sure we actually have sufficient peer left to keep downloading if len(d.peers) == 0 { d.queue.Reset() - return errNoPeers } - // If there are unrequested hashes left start fetching // from the available peers. if d.queue.Pending() > 0 { @@ -392,25 +407,6 @@ out: // safely assume we're done. Another part of the process will check // for parent errors and will re-request anything that's missing break out - } else { - // Check for bad peers. Bad peers may indicate a peer not responding - // to a `getBlocks` message. A timeout of 5 seconds is set. Peers - // that badly or poorly behave are removed from the peer set (not banned). - // Bad peers are excluded from the available peer set and therefor won't be - // reused. XXX We could re-introduce peers after X time. - badPeers := d.queue.Expire(blockTtl) - for _, pid := range badPeers { - // XXX We could make use of a reputation system here ranking peers - // in their performance - // 1) Time for them to respond; - // 2) Measure their speed; - // 3) Amount and availability. - if peer := d.peers[pid]; peer != nil { - peer.demote() - peer.reset() - } - } - } } } |