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

@@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethersphere/swarm/chunk"
"github.com/ethersphere/swarm/log"
"github.com/ethersphere/swarm/network/timeouts"
"github.com/ethersphere/swarm/storage"
)
@@ -74,7 +73,7 @@ func (s *SwarmSyncerServer) Close() {
// GetData retrieves the actual chunk from netstore
func (s *SwarmSyncerServer) GetData(ctx context.Context, key []byte) ([]byte, error) {
ch, err := s.netStore.Store.Get(ctx, chunk.ModeGetSync, storage.Address(key))
ch, err := s.netStore.Get(ctx, chunk.ModeGetSync, storage.Address(key))
if err != nil {
return nil, err
}
@@ -199,24 +198,9 @@ func RegisterSwarmSyncerClient(streamer *Registry, netStore *storage.NetStore) {
})
}
func (s *SwarmSyncerClient) NeedData(ctx context.Context, key []byte) (loaded bool, wait func(context.Context) error) {
start := time.Now()
fi, loaded, ok := s.netStore.GetOrCreateFetcher(ctx, key, "syncer")
if !ok {
return loaded, nil
}
return loaded, func(ctx context.Context) error {
select {
case <-fi.Delivered:
metrics.GetOrRegisterResettingTimer(fmt.Sprintf("fetcher.%s.syncer", fi.CreatedBy), nil).UpdateSince(start)
case <-time.After(timeouts.SyncerClientWaitTimeout):
metrics.GetOrRegisterCounter("fetcher.syncer.timeout", nil).Inc(1)
return fmt.Errorf("chunk not delivered through syncing after %dsec. ref=%s", timeouts.SyncerClientWaitTimeout, fmt.Sprintf("%x", key))
}
return nil
}
// NeedData
func (s *SwarmSyncerClient) NeedData(ctx context.Context, key []byte) (wait func(context.Context) error) {
return s.netStore.FetchFunc(ctx, key)
}
func (s *SwarmSyncerClient) Close() {}