refactor: switch to storing by the base58 id, not the hashcode
This commit is contained in:
parent
9654fadfee
commit
67be38e6c9
15
node.go
15
node.go
|
@ -104,15 +104,15 @@ func (n *Node) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
func (n *Node) GetCachedStorageLocations(hash *encoding.Multihash, types []int) (map[encoding.NodeIdCode]*StorageLocation, error) {
|
func (n *Node) GetCachedStorageLocations(hash *encoding.Multihash, types []int) (map[string]*StorageLocation, error) {
|
||||||
locations := make(map[encoding.NodeIdCode]*StorageLocation)
|
locations := make(map[string]*StorageLocation)
|
||||||
|
|
||||||
locationMap, err := n.readStorageLocationsFromDB(hash)
|
locationMap, err := n.readStorageLocationsFromDB(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(locationMap) == 0 {
|
if len(locationMap) == 0 {
|
||||||
return make(map[encoding.NodeIdCode]*StorageLocation), nil
|
return make(map[string]*StorageLocation), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := time.Now().Unix()
|
ts := time.Now().Unix()
|
||||||
|
@ -173,11 +173,16 @@ func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.Nod
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodeIdStr, err := nodeId.ToString()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get or create the inner map for the specific type
|
// Get or create the inner map for the specific type
|
||||||
innerMap, exists := locationDb[location.Type]
|
innerMap, exists := locationDb[location.Type]
|
||||||
if !exists {
|
if !exists {
|
||||||
innerMap = make(nodeStorage, 1)
|
innerMap = make(nodeStorage, 1)
|
||||||
innerMap[nodeId.HashCode()] = make(nodeDetailsStorage, 1)
|
innerMap[nodeIdStr] = make(nodeDetailsStorage, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create location map with new data
|
// Create location map with new data
|
||||||
|
@ -187,7 +192,7 @@ func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.Nod
|
||||||
locationMap[4] = message
|
locationMap[4] = message
|
||||||
|
|
||||||
// Update the inner map with the new location
|
// Update the inner map with the new location
|
||||||
innerMap[nodeId.HashCode()] = locationMap
|
innerMap[nodeIdStr] = locationMap
|
||||||
locationDb[location.Type] = innerMap
|
locationDb[location.Type] = innerMap
|
||||||
|
|
||||||
// Serialize the updated map and store it in the database
|
// Serialize the updated map and store it in the database
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (ssl *SignedStorageLocation) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type storageLocationMap map[int]nodeStorage
|
type storageLocationMap map[int]nodeStorage
|
||||||
type nodeStorage map[encoding.NodeIdCode]nodeDetailsStorage
|
type nodeStorage map[string]nodeDetailsStorage
|
||||||
type nodeDetailsStorage map[int]interface{}
|
type nodeDetailsStorage map[int]interface{}
|
||||||
|
|
||||||
func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error {
|
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 {
|
func (s storageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
|
||||||
// Create a temporary map to hold the encoded data
|
// 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
|
// Populate the temporary map with data from storageLocationMap
|
||||||
for storageKey, nodeStorages := range s {
|
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 {
|
for nodeId, nodeDetails := range nodeStorages {
|
||||||
tempNodeStorages[nodeId] = nodeDetails
|
tempNodeStorages[nodeId] = nodeDetails
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue