swarm: prevent forever running retrieve request loops

This commit is contained in:
Balint Gabor
2018-09-25 17:35:54 +02:00
committed by Janos Guljas
parent d3441ebb56
commit 3f7acbbeb9
7 changed files with 79 additions and 27 deletions

View File

@ -34,7 +34,7 @@ type (
)
type NetFetcher interface {
Request(ctx context.Context)
Request(ctx context.Context, hopCount uint8)
Offer(ctx context.Context, source *enode.ID)
}
@ -263,6 +263,9 @@ func (f *fetcher) Fetch(rctx context.Context) (Chunk, error) {
// If there is a source in the context then it is an offer, otherwise a request
sourceIF := rctx.Value("source")
hopCount, _ := rctx.Value("hopcount").(uint8)
if sourceIF != nil {
var source enode.ID
if err := source.UnmarshalText([]byte(sourceIF.(string))); err != nil {
@ -270,7 +273,7 @@ func (f *fetcher) Fetch(rctx context.Context) (Chunk, error) {
}
f.netFetcher.Offer(rctx, &source)
} else {
f.netFetcher.Request(rctx)
f.netFetcher.Request(rctx, hopCount)
}
// wait until either the chunk is delivered or the context is done