Commit e603b936 authored by Ivar Derksen's avatar Ivar Derksen Committed by Sietse Ringers

Feat: client storage fully in bbolt

parent b6ab049f
This diff is collapsed.
......@@ -2,6 +2,7 @@ package irmaclient
import (
"encoding/json"
"github.com/privacybydesign/gabi"
"time"
"github.com/privacybydesign/irmago"
......@@ -42,14 +43,11 @@ var clientUpdates = []func(client *Client) error{
// 6: Remove earlier log items of wrong format
nil, // No longer necessary
// 7: Concert log entries to bbolt database
// 7: Convert log entries to bbolt database
func(client *Client) error {
var logs []*LogEntry
var err error
// If loading logs fails, the logs file is likely empty and then there are no log entries to update
// Therefore throw away the error and mark the update as successful.
if err = client.storage.load(&logs, logsFile); err != nil {
if err = client.storage.loadFromFile(&logs, logsFile); err != nil {
return nil
}
// Open one bolt transaction to process all our log entries in
......@@ -74,6 +72,80 @@ var clientUpdates = []func(client *Client) error{
})
return err
},
// 8: Move other user storage to bbolt database
func(client *Client) error {
sk, err := client.storage.LoadSecretKeyFile()
if err != nil {
return err
}
// When no secret key is found, it means the storage is fresh. No update is needed.
if sk == nil {
return nil
}
attrs, err := client.storage.LoadAttributesFile()
if err != nil {
return err
}
sigs := make(map[string]*gabi.CLSignature)
for _, attrlistlist := range attrs {
for _, attrlist := range attrlistlist {
sig, err := client.storage.LoadSignatureFile(attrlist)
if err != nil {
return err
}
sigs[attrlist.Hash()] = sig
}
}
ksses, err := client.storage.LoadKeyshareServersFile()
if err != nil {
return err
}
prefs, err := client.storage.LoadPreferencesFile()
if err != nil {
return err
}
// Preferences are already loaded in client, refresh
client.Preferences = prefs
client.applyPreferences()
updates, err := client.storage.LoadUpdatesFile()
if err != nil {
return err
}
return client.storage.db.Update(func(tx *bbolt.Tx) error {
err = client.storage.TxStoreSecretKey(tx, sk)
if err != nil {
return err
}
err := client.storage.TxStoreAttributes(tx, attrs)
if err != nil {
return err
}
for hash, sig := range sigs {
err = client.storage.TxStoreSignature(tx, hash, sig)
if err != nil {
return err
}
}
err = client.storage.TxStoreKeyshareServers(tx, ksses)
if err != nil {
return err
}
err = client.storage.TxStorePreferences(tx, prefs)
if err != nil {
return err
}
return client.storage.TxStoreUpdates(tx, updates)
})
},
}
// update performs any function from clientUpdates that has not
......@@ -85,6 +157,13 @@ func (client *Client) update() error {
if client.updates, err = client.storage.LoadUpdates(); err != nil {
return err
}
// When no updates are found, it can either be a fresh storage or the storage has not been updated
// to bbolt yet. Therefore also check the updates file.
if len(client.updates) == 0 {
if client.updates, err = client.storage.LoadUpdatesFile(); err != nil {
return err
}
}
// Perform all new updates
for i := len(client.updates); i < len(clientUpdates); i++ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment