This reverts commit 0b724bd4d5
.
This commit is contained in:
committed by
GitHub
parent
0b724bd4d5
commit
604960938b
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user