Skip to content
Snippets Groups Projects
Commit dc6e3f15 authored by Jake Taylor's avatar Jake Taylor
Browse files

switch to gob encoding

parent 7d25a8b8
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
package storage package storage
import ( import (
"encoding/json" "bytes"
"encoding/gob"
"gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/ekv" "gitlab.com/elixxir/ekv"
...@@ -83,14 +84,19 @@ func (s *Session) getNodeKeys() (map[string]user.NodeKeys, error) { ...@@ -83,14 +84,19 @@ func (s *Session) getNodeKeys() (map[string]user.NodeKeys, error) {
return nil, err return nil, err
} }
// Encode the new map
nodeKeys = make(map[string]user.NodeKeys) nodeKeys = make(map[string]user.NodeKeys)
data, err := json.Marshal(nodeKeys) var nodeKeysBuffer bytes.Buffer
enc := gob.NewEncoder(&nodeKeysBuffer)
err = enc.Encode(nodeKeys)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Store the new map
vo := &VersionedObject{ vo := &VersionedObject{
Timestamp: ts, Timestamp: ts,
Data: data, Data: nodeKeysBuffer.Bytes(),
} }
err = s.kv.Set(key, vo) err = s.kv.Set(key, vo)
if err != nil { if err != nil {
...@@ -101,8 +107,12 @@ func (s *Session) getNodeKeys() (map[string]user.NodeKeys, error) { ...@@ -101,8 +107,12 @@ func (s *Session) getNodeKeys() (map[string]user.NodeKeys, error) {
return nodeKeys, nil return nodeKeys, nil
} }
// If the map exists, return it // If the map exists, decode and return it
err = json.Unmarshal(v.Data, &nodeKeys) var nodeKeyBuffer bytes.Buffer
nodeKeyBuffer.Write(v.Data)
dec := gob.NewDecoder(&nodeKeyBuffer)
err = dec.Decode(&nodeKeys)
return nodeKeys, err return nodeKeys, err
} }
...@@ -133,11 +143,10 @@ func (s *Session) PushNodeKey(id *id.ID, key user.NodeKeys) error { ...@@ -133,11 +143,10 @@ func (s *Session) PushNodeKey(id *id.ID, key user.NodeKeys) error {
// Set new value inside of map // Set new value inside of map
nodeKeys[id.String()] = key nodeKeys[id.String()] = key
// Marshal the map // Encode the map
pushValue, err := json.Marshal(nodeKeys) var nodeKeysBuffer bytes.Buffer
if err != nil { enc := gob.NewEncoder(&nodeKeysBuffer)
return err err = enc.Encode(nodeKeys)
}
// Insert the map back into the Session // Insert the map back into the Session
ts, err := time.Now().MarshalText() ts, err := time.Now().MarshalText()
...@@ -146,7 +155,7 @@ func (s *Session) PushNodeKey(id *id.ID, key user.NodeKeys) error { ...@@ -146,7 +155,7 @@ func (s *Session) PushNodeKey(id *id.ID, key user.NodeKeys) error {
} }
vo := &VersionedObject{ vo := &VersionedObject{
Timestamp: ts, Timestamp: ts,
Data: pushValue, Data: nodeKeysBuffer.Bytes(),
} }
return s.kv.Set("NodeKeys", vo) return s.kv.Set("NodeKeys", vo)
} }
......
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Copyright © 2019 Privategrity Corporation / // Copyright © 2020 Privategrity Corporation /
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -142,7 +142,7 @@ func LoadSession(store globals.Storage, password string) (Session, error) { ...@@ -142,7 +142,7 @@ func LoadSession(store globals.Storage, password string) (Session, error) {
} }
} }
//extract teh session from the wrapper //extract the session from the wrapper
var sessionBytes bytes.Buffer var sessionBytes bytes.Buffer
sessionBytes.Write(wrappedSession.Session) sessionBytes.Write(wrappedSession.Session)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment