diff --git a/service/default/mediator.go b/service/default/mediator.go index 92a9535..fee7b76 100644 --- a/service/default/mediator.go +++ b/service/default/mediator.go @@ -34,7 +34,7 @@ func (m MediatorDefault) SignMessageSimple(message []byte) ([]byte, error) { } func (m MediatorDefault) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error) { - return m.Services().Storage().GetCachedStorageLocations(hash, kinds) + return m.Services().Storage().GetCachedStorageLocations(hash, kinds, false) } func (m MediatorDefault) SortNodesByScore(nodes []*encoding.NodeId) ([]*encoding.NodeId, error) { diff --git a/service/default/storage.go b/service/default/storage.go index c9c6e8d..8780601 100644 --- a/service/default/storage.go +++ b/service/default/storage.go @@ -73,7 +73,7 @@ func (n *StorageService) ProviderStore() storage.ProviderStore { return n.providerStore } -func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error) { +func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType, local bool) (map[string]storage.StorageLocation, error) { locations := make(map[string]storage.StorageLocation) locationMap, err := s.readStorageLocationsFromDB(hash) @@ -81,14 +81,16 @@ func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kin return nil, err } - local := s.getLocalStorageLocation(hash, kinds) - if local != nil { - nodeIDStr, err := s.Services().P2P().NodeId().ToString() - if err != nil { - return nil, err - } + if local { + localLocation := s.getLocalStorageLocation(hash, kinds) + if localLocation != nil { + nodeIDStr, err := s.Services().P2P().NodeId().ToString() + if err != nil { + return nil, err + } - locations[nodeIDStr] = local + locations[nodeIDStr] = localLocation + } } if len(locationMap) == 0 { diff --git a/service/storage.go b/service/storage.go index 8f71b91..fe4acd7 100644 --- a/service/storage.go +++ b/service/storage.go @@ -10,7 +10,7 @@ import ( type StorageService interface { SetProviderStore(store storage.ProviderStore) ProviderStore() storage.ProviderStore - GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error) + GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType, local bool) (map[string]storage.StorageLocation, error) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location storage.StorageLocation, message []byte) error DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error) DownloadBytesByCID(cid *encoding.CID) ([]byte, error) diff --git a/storage/provider/provider.go b/storage/provider/provider.go index d08a219..1337815 100644 --- a/storage/provider/provider.go +++ b/storage/provider/provider.go @@ -33,7 +33,7 @@ type StorageLocationProviderImpl struct { func (s *StorageLocationProviderImpl) Start() error { var err error - s.uris, err = s.services.Storage().GetCachedStorageLocations(s.hash, s.types) + s.uris, err = s.services.Storage().GetCachedStorageLocations(s.hash, s.types, true) if err != nil { return err } @@ -73,7 +73,7 @@ func (s *StorageLocationProviderImpl) Start() error { break } - newUris, err := s.services.Storage().GetCachedStorageLocations(s.hash, s.types) + newUris, err := s.services.Storage().GetCachedStorageLocations(s.hash, s.types, false) if err != nil { s.mutex.Unlock() break