aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-19 07:39:37 +0800
committerobscuren <geffobscura@gmail.com>2015-04-19 07:39:37 +0800
commit5c59d9553218891cd33831aae607668a0b5bf022 (patch)
tree7b46d9c61b2ae7b6c4da3a44b6e993a280a3f33b /eth
parent86ecdcd5ff8c86a5d1c25322230cfcef0a2cfe8d (diff)
downloadgo-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.tar
go-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.tar.gz
go-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.tar.bz2
go-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.tar.lz
go-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.tar.xz
go-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.tar.zst
go-tangerine-5c59d9553218891cd33831aae607668a0b5bf022.zip
downloader: defer peer reset after download
Diffstat (limited to 'eth')
-rw-r--r--eth/downloader/downloader.go11
-rw-r--r--eth/downloader/peer.go1
2 files changed, 8 insertions, 4 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 2d417dcf5..6768c3e67 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -205,13 +205,13 @@ func (d *Downloader) startFetchingHashes(p *peer, hash common.Hash, ignoreInitia
// Get the first batch of hashes
p.getHashes(hash)
- failureResponse := time.NewTimer(hashTtl)
+ failureResponseTimer := time.NewTimer(hashTtl)
out:
for {
select {
case hashes := <-d.hashCh:
- failureResponse.Reset(hashTtl)
+ failureResponseTimer.Reset(hashTtl)
var done bool // determines whether we're done fetching hashes (i.e. common hash found)
hashSet := set.New()
@@ -239,7 +239,7 @@ out:
} else { // we're done
break out
}
- case <-failureResponse.C:
+ case <-failureResponseTimer.C:
glog.V(logger.Debug).Infof("Peer (%s) didn't respond in time for hash request\n", p.id)
// TODO instead of reseting the queue select a new peer from which we can start downloading hashes.
// 1. check for peer's best hash to be included in the current hash set;
@@ -258,6 +258,10 @@ func (d *Downloader) startFetchingBlocks(p *peer) error {
glog.V(logger.Detail).Infoln("Downloading", d.queue.hashPool.Size(), "block(s)")
atomic.StoreInt32(&d.downloadingBlocks, 1)
defer atomic.StoreInt32(&d.downloadingBlocks, 0)
+ // Defer the peer reset. This will empty the peer requested set
+ // and makes sure there are no lingering peers with an incorrect
+ // state
+ defer d.peers.reset()
start := time.Now()
@@ -302,7 +306,6 @@ out:
// and all failed throw an error
if len(d.queue.fetching) == 0 {
d.queue.reset()
- d.peers.reset()
return fmt.Errorf("%v avaialable = %d. total = %d", errPeersUnavailable, len(availablePeers), len(d.peers))
}
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go
index 88ede16f9..7065ca105 100644
--- a/eth/downloader/peer.go
+++ b/eth/downloader/peer.go
@@ -137,4 +137,5 @@ func (p *peer) demote() {
func (p *peer) reset() {
p.state = idleState
+ p.requested.Clear()
}