pick_more_peer_fetch_header_and_body

This commit is contained in:
pegasas 2018-12-18 00:37:28 +08:00
parent 472c23a801
commit eccab312cc

View file

@ -369,13 +369,15 @@ func (f *Fetcher) loop() {
for hash, announces := range f.announced { for hash, announces := range f.announced {
if time.Since(announces[0].time) > arriveTimeout-gatherSlack { if time.Since(announces[0].time) > arriveTimeout-gatherSlack {
// Pick a random peer to retrieve from, reset all others // Pick a random peer to retrieve from, reset all others
announce := announces[rand.Intn(len(announces))]
f.forgetHash(hash) f.forgetHash(hash)
// If the block still didn't arrive, queue for fetching // If the block still didn't arrive, queue for fetching
if f.getBlock(hash) == nil { if f.getBlock(hash) == nil {
// Pick more peers to retrieve from
for _, announce := range announces {
request[announce.origin] = append(request[announce.origin], hash) request[announce.origin] = append(request[announce.origin], hash)
f.fetching[hash] = announce }
f.fetching[hash] = announces[rand.Intn(len(announces))]
} }
} }
} }
@ -404,13 +406,14 @@ func (f *Fetcher) loop() {
for hash, announces := range f.fetched { for hash, announces := range f.fetched {
// Pick a random peer to retrieve from, reset all others // Pick a random peer to retrieve from, reset all others
announce := announces[rand.Intn(len(announces))]
f.forgetHash(hash) f.forgetHash(hash)
// If the block still didn't arrive, queue for completion // If the block still didn't arrive, queue for completion
if f.getBlock(hash) == nil { if f.getBlock(hash) == nil {
for _, announce := range announces {
request[announce.origin] = append(request[announce.origin], hash) request[announce.origin] = append(request[announce.origin], hash)
f.completing[hash] = announce }
f.completing[hash] = announces[rand.Intn(len(announces))]
} }
} }
// Send out all block body requests // Send out all block body requests