diff --git a/node.go b/node.go index f1b8569..522e897 100644 --- a/node.go +++ b/node.go @@ -104,15 +104,15 @@ func (n *Node) Start() error { return nil } */ -func (n *Node) GetCachedStorageLocations(hash *encoding.Multihash, types []int) (map[encoding.NodeIdCode]*StorageLocation, error) { - locations := make(map[encoding.NodeIdCode]*StorageLocation) +func (n *Node) GetCachedStorageLocations(hash *encoding.Multihash, types []int) (map[string]*StorageLocation, error) { + locations := make(map[string]*StorageLocation) locationMap, err := n.readStorageLocationsFromDB(hash) if err != nil { return nil, err } if len(locationMap) == 0 { - return make(map[encoding.NodeIdCode]*StorageLocation), nil + return make(map[string]*StorageLocation), nil } ts := time.Now().Unix() @@ -173,11 +173,16 @@ func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.Nod return err } + nodeIdStr, err := nodeId.ToString() + if err != nil { + return err + } + // Get or create the inner map for the specific type innerMap, exists := locationDb[location.Type] if !exists { innerMap = make(nodeStorage, 1) - innerMap[nodeId.HashCode()] = make(nodeDetailsStorage, 1) + innerMap[nodeIdStr] = make(nodeDetailsStorage, 1) } // Create location map with new data @@ -187,7 +192,7 @@ func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.Nod locationMap[4] = message // Update the inner map with the new location - innerMap[nodeId.HashCode()] = locationMap + innerMap[nodeIdStr] = locationMap locationDb[location.Type] = innerMap // Serialize the updated map and store it in the database diff --git a/storage.go b/storage.go index 44c44d6..598d88f 100644 --- a/storage.go +++ b/storage.go @@ -67,7 +67,7 @@ func (ssl *SignedStorageLocation) String() string { } type storageLocationMap map[int]nodeStorage -type nodeStorage map[encoding.NodeIdCode]nodeDetailsStorage +type nodeStorage map[string]nodeDetailsStorage type nodeDetailsStorage map[int]interface{} func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error { @@ -92,11 +92,11 @@ func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error { func (s storageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error { // Create a temporary map to hold the encoded data - tempMap := make(map[int]map[encoding.NodeIdCode]map[int]interface{}) + tempMap := make(map[int]map[string]map[int]interface{}) // Populate the temporary map with data from storageLocationMap for storageKey, nodeStorages := range s { - tempNodeStorages := make(map[encoding.NodeIdCode]map[int]interface{}) + tempNodeStorages := make(map[string]map[int]interface{}) for nodeId, nodeDetails := range nodeStorages { tempNodeStorages[nodeId] = nodeDetails }