refactor: move StorageLocation to a new pkg to prevent import cycle

This commit is contained in:
Derrick Hammer 2024-01-07 04:30:03 -05:00
parent 57657bd6ed
commit 1950edf181
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 9 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import (
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
"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/utils"
"github.com/vmihailenco/msgpack/v5"
@ -144,7 +145,7 @@ func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []i
continue
}
storageLocation := NewStorageLocation(t, addresses, expiry)
storageLocation := storage.NewStorageLocation(t, addresses, expiry)
if len(value) > 4 {
if providerMessage, ok := value[4].([]byte); ok {
(storageLocation).SetProviderMessage(providerMessage)
@ -156,8 +157,8 @@ func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []i
}
return locations, nil
}
func (n *NodeImpl) readStorageLocationsFromDB(hash *encoding.Multihash) (storageLocationMap, error) {
locationMap := newStorageLocationMap()
func (n *NodeImpl) readStorageLocationsFromDB(hash *encoding.Multihash) (storage.storageLocationMap, error) {
locationMap := storage.newStorageLocationMap()
bytes := n.cacheBucket.Get(hash.FullBytes())
if bytes == nil {
@ -186,8 +187,8 @@ func (n *NodeImpl) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding
// Get or create the inner map for the specific type
innerMap, exists := locationDb[location.Type()]
if !exists {
innerMap = make(nodeStorage, 1)
innerMap[nodeIdStr] = make(nodeDetailsStorage, 1)
innerMap = make(storage.nodeStorage, 1)
innerMap[nodeIdStr] = make(storage.nodeDetailsStorage, 1)
}
// Create location map with new data

View File

@ -6,7 +6,7 @@ import (
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
"git.lumeweb.com/LumeWeb/libs5-go/net"
nodep "git.lumeweb.com/LumeWeb/libs5-go/node"
"git.lumeweb.com/LumeWeb/libs5-go/storage"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"git.lumeweb.com/LumeWeb/libs5-go/utils"
"github.com/emirpasic/gods/sets/hashset"
@ -74,7 +74,7 @@ func (s *StorageLocation) HandleMessage(node interfaces.Node, peer *net.Peer, ve
nodeId := encoding.NewNodeId(publicKey)
// Assuming `node` is an instance of your NodeImpl structure
err := node.AddStorageLocation(hash, nodeId, nodep.NewStorageLocation(int(typeOfData), parts, int64(expiry)), s.raw, node.Config()) // Implement AddStorageLocation
err := node.AddStorageLocation(hash, nodeId, storage.NewStorageLocation(int(typeOfData), parts, int64(expiry)), s.raw, node.Config()) // Implement AddStorageLocation
if err != nil {
return fmt.Errorf("Failed to add storage location: %s", err)

View File

@ -1,4 +1,4 @@
package node
package storage
import (
"fmt"