Revert "simplification of Fetchers (#1344)" (#1491)

This reverts commit 0b724bd4d5.
This commit is contained in:
Anton Evangelatov
2019-06-17 10:30:55 +02:00
committed by GitHub
parent 0b724bd4d5
commit 604960938b
23 changed files with 2242 additions and 742 deletions

View File

@ -192,13 +192,12 @@ func (h *Handler) Lookup(ctx context.Context, query *Query) (*cacheEntry, error)
ctx, cancel := context.WithTimeout(ctx, defaultRetrieveTimeout)
defer cancel()
r := storage.NewRequest(id.Addr())
ch, err := h.chunkStore.Get(ctx, chunk.ModeGetLookup, r)
ch, err := h.chunkStore.Get(ctx, chunk.ModeGetLookup, id.Addr())
if err != nil {
if err == context.DeadlineExceeded || err == storage.ErrNoSuitablePeer { // chunk not found
if err == context.DeadlineExceeded { // chunk not found
return nil, nil
}
return nil, err
return nil, err //something else happened or context was cancelled.
}
var request Request

View File

@ -58,8 +58,6 @@ var TimeAfter = time.After
// It should return <nil> if a value is found, but its timestamp is higher than "now"
// It should only return an error in case the handler wants to stop the
// lookup process entirely.
// If the context is canceled, it must return context.Canceled
type ReadFunc func(ctx context.Context, epoch Epoch, now uint64) (interface{}, error)
// NoClue is a hint that can be provided when the Lookup caller does not have

View File

@ -18,8 +18,8 @@ package feed
import (
"context"
"errors"
"path/filepath"
"sync"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethersphere/swarm/chunk"
@ -39,6 +39,17 @@ func (t *TestHandler) Close() {
t.chunkStore.Close()
}
type mockNetFetcher struct{}
func (m *mockNetFetcher) Request(hopCount uint8) {
}
func (m *mockNetFetcher) Offer(source *enode.ID) {
}
func newFakeNetFetcher(context.Context, storage.Address, *sync.Map) storage.NetFetcher {
return &mockNetFetcher{}
}
// NewTestHandler creates Handler object to be used for testing purposes.
func NewTestHandler(datadir string, params *HandlerParams) (*TestHandler, error) {
path := filepath.Join(datadir, testDbDirName)
@ -51,10 +62,11 @@ func NewTestHandler(datadir string, params *HandlerParams) (*TestHandler, error)
localStore := chunk.NewValidatorStore(db, storage.NewContentAddressValidator(storage.MakeHashFunc(feedsHashAlgorithm)), fh)
netStore := storage.NewNetStore(localStore, enode.ID{})
netStore.RemoteGet = func(ctx context.Context, req *storage.Request, localID enode.ID) (*enode.ID, error) {
return nil, errors.New("not found")
netStore, err := storage.NewNetStore(localStore, nil)
if err != nil {
return nil, err
}
netStore.NewNetFetcherFunc = newFakeNetFetcher
fh.SetStore(netStore)
return &TestHandler{fh}, nil
}