forked from cerc-io/plugeth
eth/fetcher: if peers never respond, drop them
This commit is contained in:
parent
28ec26094b
commit
7e2bbb9cbb
@ -477,10 +477,21 @@ func (f *BlockFetcher) loop() {
|
|||||||
}
|
}
|
||||||
defer req.Close()
|
defer req.Close()
|
||||||
|
|
||||||
res := <-resCh
|
timeout := time.NewTimer(2 * fetchTimeout) // 2x leeway before dropping the peer
|
||||||
res.Done <- nil
|
defer timeout.Stop()
|
||||||
|
|
||||||
f.FilterHeaders(peer, *res.Res.(*eth.BlockHeadersPacket), time.Now().Add(res.Time))
|
select {
|
||||||
|
case res := <-resCh:
|
||||||
|
res.Done <- nil
|
||||||
|
f.FilterHeaders(peer, *res.Res.(*eth.BlockHeadersPacket), time.Now().Add(res.Time))
|
||||||
|
|
||||||
|
case <-timeout.C:
|
||||||
|
// The peer didn't respond in time. The request
|
||||||
|
// was already rescheduled at this point, we were
|
||||||
|
// waiting for a catchup. With an unresponsive
|
||||||
|
// peer however, it's a protocol violation.
|
||||||
|
f.dropPeer(peer)
|
||||||
|
}
|
||||||
}(hash)
|
}(hash)
|
||||||
}
|
}
|
||||||
}(peer)
|
}(peer)
|
||||||
@ -523,11 +534,23 @@ func (f *BlockFetcher) loop() {
|
|||||||
}
|
}
|
||||||
defer req.Close()
|
defer req.Close()
|
||||||
|
|
||||||
res := <-resCh
|
timeout := time.NewTimer(2 * fetchTimeout) // 2x leeway before dropping the peer
|
||||||
res.Done <- nil
|
defer timeout.Stop()
|
||||||
|
|
||||||
txs, uncles := res.Res.(*eth.BlockBodiesPacket).Unpack()
|
select {
|
||||||
f.FilterBodies(peer, txs, uncles, time.Now())
|
case res := <-resCh:
|
||||||
|
res.Done <- nil
|
||||||
|
|
||||||
|
txs, uncles := res.Res.(*eth.BlockBodiesPacket).Unpack()
|
||||||
|
f.FilterBodies(peer, txs, uncles, time.Now())
|
||||||
|
|
||||||
|
case <-timeout.C:
|
||||||
|
// The peer didn't respond in time. The request
|
||||||
|
// was already rescheduled at this point, we were
|
||||||
|
// waiting for a catchup. With an unresponsive
|
||||||
|
// peer however, it's a protocol violation.
|
||||||
|
f.dropPeer(peer)
|
||||||
|
}
|
||||||
}(peer, hashes)
|
}(peer, hashes)
|
||||||
}
|
}
|
||||||
// Schedule the next fetch if blocks are still pending
|
// Schedule the next fetch if blocks are still pending
|
||||||
|
Loading…
Reference in New Issue
Block a user