diff --git a/service/default/storage.go b/service/default/storage.go index 8fe611b..dcd3d7d 100644 --- a/service/default/storage.go +++ b/service/default/storage.go @@ -125,8 +125,36 @@ func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kin locations[key] = storageLocation } } + + local := s.getLocalStorageLocation(hash, kinds) + if local != nil { + nodeIDStr, err := s.Services().P2P().NodeId().ToString() + if err != nil { + return nil, err + } + + locations[nodeIDStr] = local + } + return locations, nil } + +func (s *StorageService) getLocalStorageLocation(hash *encoding.Multihash, kinds []types.StorageLocationType) storage.StorageLocation { + if s.ProviderStore() != nil { + if s.ProviderStore().CanProvide(hash, kinds) { + location, _ := s.ProviderStore().Provide(hash, kinds) + + message := storage.PrepareProvideMessage(s.Services().P2P().Config().KeyPair, hash, location) + + location.SetProviderMessage(message) + + return location + } + } + + return nil +} + func (s *StorageService) readStorageLocationsFromDB(hash *encoding.Multihash) (storage.StorageLocationMap, error) { var locationMap storage.StorageLocationMap diff --git a/storage/provider/provider.go b/storage/provider/provider.go index 04f4a87..d08a219 100644 --- a/storage/provider/provider.go +++ b/storage/provider/provider.go @@ -62,17 +62,6 @@ func (s *StorageLocationProviderImpl) Start() error { s.isTimedOut = false s.mutex.Unlock() - local := s.checkLocal() - if local != nil { - s.availableNodes = append([]*encoding.NodeId{local.NodeId()}, s.availableNodes...) - nodeIdStr, err := local.NodeId().ToString() - if err != nil { - s.logger.Error("Error decoding node id", zap.Error(err)) - return err - } - s.uris[nodeIdStr] = local.Location() - } - go func() { requestSent := false @@ -109,7 +98,7 @@ func (s *StorageLocationProviderImpl) Start() error { s.logger.Error("Error decoding node id", zap.Error(err)) continue } - if containsNode(s.excludeNodes, nodeId) { + if containsNode(s.excludeNodes, nodeId) && requestSent { continue } if !containsNode(s.availableNodes, nodeId) { @@ -226,22 +215,6 @@ func (s *StorageLocationProviderImpl) Downvote(uri storage.SignedStorageLocation return nil } -func (s *StorageLocationProviderImpl) checkLocal() storage.SignedStorageLocation { - if s.services.Storage().ProviderStore() != nil { - if s.services.Storage().ProviderStore().CanProvide(s.hash, s.types) { - location, _ := s.services.Storage().ProviderStore().Provide(s.hash, s.types) - - message := storage.PrepareProvideMessage(s.services.P2P().Config().KeyPair, s.hash, location) - - location.SetProviderMessage(message) - - return storage.NewSignedStorageLocation(s.services.P2P().NodeId(), location) - } - } - - return nil -} - func NewStorageLocationProvider(params StorageLocationProviderParams) *StorageLocationProviderImpl { if params.LocationTypes == nil { params.LocationTypes = []types.StorageLocationType{