swarm/storage/feed/lookup: more comments

This commit is contained in:
Javier Peletier 2019-04-08 19:12:22 +02:00
parent 2096c44071
commit 709cc6f3ea

View file

@ -100,7 +100,7 @@ func LongEarthAlgorithm(ctx context.Context, now uint64, hint Epoch, read ReadFu
lookAhead() lookAhead()
case <-ctxR.Done(): case <-ctxR.Done():
if valueR != nil { if valueR != nil {
lookAhead() lookAhead() // only look ahead if R was successful
} }
case <-ctxA.Done(): case <-ctxA.Done():
} }
@ -115,7 +115,7 @@ func LongEarthAlgorithm(ctx context.Context, now uint64, hint Epoch, read ReadFu
lookBack() lookBack()
case <-ctxR.Done(): case <-ctxR.Done():
if valueR == nil { if valueR == nil {
lookBack() lookBack() // only look back in case R failed
} }
case <-ctxB.Done(): case <-ctxB.Done():
} }
@ -162,13 +162,18 @@ func LongEarthAlgorithm(ctx context.Context, now uint64, hint Epoch, read ReadFu
return value, nil return value, nil
} }
// at this point the algorithm did not return a value,
// so we challenge the hint given.
value, err := read(ctx, hint, now) value, err := read(ctx, hint, now)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if value != nil { if value != nil {
return value, nil return value, nil // hint is valid, return it.
} }
// hint is invalid. Invoke the algorithm
// without hint.
now = hint.Base() now = hint.Base()
if hint.Level == HighestLevel { if hint.Level == HighestLevel {
now-- now--