From 45ffa1a98afeda698034f87e5347e4fb8f7006a0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 9 Jan 2024 06:53:09 -0500 Subject: [PATCH] refactor: switch GetCachedStorageLocations to use types.StorageLocationType --- interfaces/node.go | 3 ++- node/node.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/interfaces/node.go b/interfaces/node.go index cbb8000..d8eef30 100644 --- a/interfaces/node.go +++ b/interfaces/node.go @@ -4,6 +4,7 @@ import ( "git.lumeweb.com/LumeWeb/libs5-go/config" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/structs" + "git.lumeweb.com/LumeWeb/libs5-go/types" bolt "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -18,7 +19,7 @@ type Node interface { Logger() *zap.Logger Db() *bolt.DB Start() error - GetCachedStorageLocations(hash *encoding.Multihash, types []int) (map[string]StorageLocation, error) + GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]StorageLocation, error) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location StorageLocation, message []byte, config *config.NodeConfig) error NetworkId() string } diff --git a/node/node.go b/node/node.go index 404e538..73210a9 100644 --- a/node/node.go +++ b/node/node.go @@ -7,6 +7,7 @@ import ( "git.lumeweb.com/LumeWeb/libs5-go/service" "git.lumeweb.com/LumeWeb/libs5-go/storage" "git.lumeweb.com/LumeWeb/libs5-go/structs" + "git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/libs5-go/utils" "github.com/vmihailenco/msgpack/v5" bolt "go.etcd.io/bbolt" @@ -116,7 +117,7 @@ func (n *NodeImpl) Start() error { return nil } */ -func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []int) (map[string]interfaces.StorageLocation, error) { +func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]interfaces.StorageLocation, error) { locations := make(map[string]interfaces.StorageLocation) locationMap, err := n.readStorageLocationsFromDB(hash) @@ -129,9 +130,9 @@ func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []i ts := time.Now().Unix() - for _, t := range types { + for _, t := range kinds { - nodeMap, ok := (locationMap)[t] + nodeMap, ok := (locationMap)[int(t)] if !ok { continue } @@ -151,7 +152,7 @@ func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []i continue } - storageLocation := storage.NewStorageLocation(t, addresses, expiry) + storageLocation := storage.NewStorageLocation(int(t), addresses, expiry) if len(value) > 4 { if providerMessage, ok := value[4].([]byte); ok { (storageLocation).SetProviderMessage(providerMessage)