Skip to content
Snippets Groups Projects
Commit 9afeb516 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

implemented json addition to backup needs tests+bindings

parent a5a09467
Branches
Tags
3 merge requests!231Revert "Update store to print changes to the partners list",!187Xx 3829/triggers,!181Xx 3818/jsonbackup
......@@ -53,6 +53,8 @@ type Backup struct {
store *storage.Session
backupContainer *interfaces.BackupContainer
rng *fastRNG.StreamGenerator
jsonParams string
}
// UpdateBackupFn is the callback that encrypted backup data is returned on
......@@ -141,6 +143,7 @@ func resumeBackup(updateBackupCb UpdateBackupFn, c *api.Client,
store: store,
backupContainer: backupContainer,
rng: rng,
jsonParams: loadJson(store.GetKV()),
}
// Setting backup trigger in client
......@@ -208,6 +211,20 @@ func (b *Backup) TriggerBackup(reason string) {
}
}
func (b *Backup) AddJson(newJson string) {
b.mux.Lock()
defer b.mux.Unlock()
currentJson := loadJson(b.store.GetKV())
if newJson != currentJson {
b.jsonParams = newJson
if err := storeJson(newJson, b.store.GetKV()); err != nil {
jww.FATAL.Panicf("Failed to store json: %+v", err)
}
go b.TriggerBackup("New Json")
}
}
// StopBackup stops the backup processes and deletes the user's password, key,
// salt, and parameters from storage.
func (b *Backup) StopBackup() error {
......@@ -287,5 +304,8 @@ func (b *Backup) assembleBackup() backup.Backup {
// Get contacts
bu.Contacts.Identities = b.store.E2e().GetPartners()
//add the memoized json params
bu.JSONParams = b.jsonParams
return bu
}
package backup
import (
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/netTime"
)
const (
jsonStorageVersion = 0
jsonStorageKey = "JsonStorage"
)
func storeJson(json string, kv *versioned.KV) error {
obj := &versioned.Object{
Version: jsonStorageVersion,
Timestamp: netTime.Now(),
Data: []byte(json),
}
return kv.Set(jsonStorageKey, jsonStorageVersion, obj)
}
func loadJson(kv *versioned.KV) string {
obj, err := kv.Get(passwordStorageKey, passwordStorageVersion)
if err != nil {
return ""
}
return string(obj.Data)
}
......@@ -13,7 +13,7 @@ require (
github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20220308183624-c2183e687a03
gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b
gitlab.com/elixxir/crypto v0.0.7-0.20220308234138-3b0743539e7d
gitlab.com/elixxir/ekv v0.1.6
gitlab.com/elixxir/primitives v0.0.3-0.20220222212109-d412a6e46623
gitlab.com/xx_network/comms v0.0.4-0.20220223205228-7c4974139569
......
......@@ -278,6 +278,8 @@ gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo
gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b h1:m80Ub5mshPbMzYjRC0nXuI8vtm6e5crISczRsP2YUJ4=
gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b/go.mod h1:tD6XjtQh87T2nKZL5I/pYPck5M2wLpkZ1Oz7H/LqO10=
gitlab.com/elixxir/crypto v0.0.7-0.20220308234138-3b0743539e7d h1:c8GJzgdJQPm2ckd2U5uGVPkfF1qMBy8edE4LUlYJMx8=
gitlab.com/elixxir/crypto v0.0.7-0.20220308234138-3b0743539e7d/go.mod h1:tD6XjtQh87T2nKZL5I/pYPck5M2wLpkZ1Oz7H/LqO10=
gitlab.com/elixxir/ekv v0.1.6 h1:M2hUSNhH/ChxDd+s8xBqSEKgoPtmE6hOEBqQ73KbN6A=
gitlab.com/elixxir/ekv v0.1.6/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4=
gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment