From 88c48aa996cc5dfbe75d1b3bf40ab07095581938 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 9 Jan 2024 07:01:19 -0500 Subject: [PATCH] refactor: make SignedStorageLocationImpl props private, add NodeId getter, re-organize, --- interfaces/storage.go | 3 +++ storage/storage.go | 37 +++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/interfaces/storage.go b/interfaces/storage.go index adf613f..182a6e4 100644 --- a/interfaces/storage.go +++ b/interfaces/storage.go @@ -1,5 +1,7 @@ package interfaces +import "git.lumeweb.com/LumeWeb/libs5-go/encoding" + //go:generate mockgen -source=storage.go -destination=../mocks/interfaces/storage.go -package=interfaces type StorageLocationProvider interface { @@ -26,4 +28,5 @@ type StorageLocation interface { } type SignedStorageLocation interface { String() string + NodeId() *encoding.NodeId } diff --git a/storage/storage.go b/storage/storage.go index e0ec565..517363d 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -1,21 +1,30 @@ package storage import ( + "bytes" "fmt" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/interfaces" + "git.lumeweb.com/LumeWeb/libs5-go/types" "github.com/vmihailenco/msgpack/v5" + "go.uber.org/zap" "strconv" + "sync" "time" ) var ( - _ msgpack.CustomDecoder = (*StorageLocationMap)(nil) - - _ msgpack.CustomEncoder = (*StorageLocationMap)(nil) - _ interfaces.StorageLocation = (*StorageLocationImpl)(nil) + _ msgpack.CustomDecoder = (*StorageLocationMap)(nil) + _ msgpack.CustomEncoder = (*StorageLocationMap)(nil) + _ interfaces.StorageLocation = (*StorageLocationImpl)(nil) + _ interfaces.StorageLocationProvider = (*StorageLocationProviderImpl)(nil) + _ interfaces.SignedStorageLocation = (*SignedStorageLocationImpl)(nil) ) +type StorageLocationMap map[int]NodeStorage +type NodeStorage map[string]NodeDetailsStorage +type NodeDetailsStorage map[int]interface{} + type StorageLocationImpl struct { kind int parts []string @@ -90,30 +99,30 @@ func (s *StorageLocationImpl) String() string { } type SignedStorageLocationImpl struct { - NodeID encoding.NodeId - Location StorageLocationImpl + nodeID *encoding.NodeId + location interfaces.StorageLocation } -func NewSignedStorageLocation(NodeID encoding.NodeId, Location StorageLocationImpl) *SignedStorageLocationImpl { +func NewSignedStorageLocation(NodeID *encoding.NodeId, Location interfaces.StorageLocation) interfaces.SignedStorageLocation { return &SignedStorageLocationImpl{ - NodeID: NodeID, - Location: Location, + nodeID: NodeID, + location: Location, } } func (ssl *SignedStorageLocationImpl) String() string { - nodeString, _ := ssl.NodeID.ToString() + nodeString, _ := ssl.nodeID.ToString() if nodeString == "" { nodeString = "failed to decode node id" } - return "SignedStorageLocationImpl(" + ssl.Location.String() + ", " + nodeString + ")" + return "SignedStorageLocationImpl(" + ssl.location.String() + ", " + nodeString + ")" } -type StorageLocationMap map[int]NodeStorage -type NodeStorage map[string]NodeDetailsStorage -type NodeDetailsStorage map[int]interface{} +func (ssl *SignedStorageLocationImpl) NodeId() *encoding.NodeId { + return ssl.nodeID +} func (s *StorageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error { temp, err := dec.DecodeUntypedMap()