diff --git a/xxdk/backupRestore.go b/backup/backupRestore.go similarity index 87% rename from xxdk/backupRestore.go rename to backup/backupRestore.go index 092b5a7fdf8d77757e0b5cd445b7c27fe09e6a01..93ba6778ea16e2a7982ee5a1c7e487b7d08bf406 100644 --- a/xxdk/backupRestore.go +++ b/backup/backupRestore.go @@ -7,7 +7,7 @@ // FIXME: This is placeholder, there's got to be a better place to put // backup restoration than inside messenger. -package xxdk +package backup import ( "github.com/pkg/errors" @@ -16,6 +16,7 @@ import ( "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/user" "gitlab.com/elixxir/client/ud" + "gitlab.com/elixxir/client/xxdk" cryptoBackup "gitlab.com/elixxir/crypto/backup" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/primitives/id" @@ -39,16 +40,16 @@ func NewClientFromBackup(ndfJSON, storageDir string, sessionPassword, usr := user.NewUserFromBackup(backUp) - def, err := ParseNDF(ndfJSON) + def, err := xxdk.ParseNDF(ndfJSON) if err != nil { return nil, "", err } - cmixGrp, e2eGrp := DecodeGroups(def) + cmixGrp, e2eGrp := xxdk.DecodeGroups(def) // Note we do not need registration here - storageSess, err := CheckVersionAndSetupStorage(def, storageDir, - []byte(sessionPassword), usr, cmixGrp, e2eGrp, + storageSess, err := xxdk.CheckVersionAndSetupStorage(def, storageDir, + sessionPassword, usr, cmixGrp, e2eGrp, backUp.RegistrationCode) if err != nil { return nil, "", err @@ -89,7 +90,6 @@ func NewClientFromBackup(ndfJSON, storageDir string, sessionPassword, phone = f } } - ud.InitStoreFromBackup(storageSess.GetKV(), username, email, phone) - - return backUp.Contacts.Identities, backUp.JSONParams, nil + err = ud.InitStoreFromBackup(storageSess.GetKV(), username, email, phone) + return backUp.Contacts.Identities, backUp.JSONParams, err } diff --git a/backup/backup_test.go b/backup/backup_test.go index 4dd347bc9353d9a319a31819579173016bfd6c6d..bcaf8cf35bb4c7d0044cbf7e2a79e445e0d9c207 100644 --- a/backup/backup_test.go +++ b/backup/backup_test.go @@ -9,6 +9,7 @@ package backup import ( "bytes" + "gitlab.com/elixxir/client/xxdk" "reflect" "strings" "testing" @@ -16,7 +17,6 @@ import ( "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/versioned" - "gitlab.com/elixxir/client/xxdk/e2eApi" "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/crypto/backup" @@ -32,7 +32,7 @@ func Test_InitializeBackup(t *testing.T) { cbChan := make(chan []byte, 2) cb := func(encryptedBackup []byte) { cbChan <- encryptedBackup } expectedPassword := "MySuperSecurePassword" - b, err := InitializeBackup(expectedPassword, cb, &e2eApi.Container{}, + b, err := InitializeBackup(expectedPassword, cb, &xxdk.Container{}, newMockE2e(t), newMockSession(t), newMockUserDiscovery(), kv, rngGen) if err != nil { @@ -84,7 +84,7 @@ func Test_ResumeBackup(t *testing.T) { cbChan1 := make(chan []byte) cb1 := func(encryptedBackup []byte) { cbChan1 <- encryptedBackup } expectedPassword := "MySuperSecurePassword" - b, err := InitializeBackup(expectedPassword, cb1, &e2eApi.Container{}, + b, err := InitializeBackup(expectedPassword, cb1, &xxdk.Container{}, newMockE2e(t), newMockSession(t), newMockUserDiscovery(), kv, rngGen) if err != nil { t.Errorf("Failed to initialize new Backup: %+v", err) @@ -106,7 +106,7 @@ func Test_ResumeBackup(t *testing.T) { // Resume the backup with a new callback cbChan2 := make(chan []byte) cb2 := func(encryptedBackup []byte) { cbChan2 <- encryptedBackup } - b2, err := ResumeBackup(cb2, &e2eApi.Container{}, newMockE2e(t), newMockSession(t), + b2, err := ResumeBackup(cb2, &xxdk.Container{}, newMockE2e(t), newMockSession(t), newMockUserDiscovery(), kv, rngGen) if err != nil { t.Errorf("ResumeBackup returned an error: %+v", err) @@ -149,7 +149,7 @@ func Test_resumeBackup_NoKeyError(t *testing.T) { expectedErr := "object not found" s := storage.InitTestingSession(t) rngGen := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG) - _, err := ResumeBackup(nil, &e2eApi.Container{}, newMockE2e(t), newMockSession(t), + _, err := ResumeBackup(nil, &xxdk.Container{}, newMockE2e(t), newMockSession(t), newMockUserDiscovery(), s.GetKV(), rngGen) if err == nil || !strings.Contains(err.Error(), expectedErr) { t.Errorf("ResumeBackup did not return the expected error when no "+ @@ -392,7 +392,7 @@ func newTestBackup(password string, cb UpdateBackupFn, t *testing.T) *Backup { b, err := InitializeBackup( password, cb, - &e2eApi.Container{}, + &xxdk.Container{}, newMockE2e(t), newMockSession(t), newMockUserDiscovery(), @@ -416,7 +416,7 @@ func Benchmark_InitializeBackup(t *testing.B) { expectedPassword := "MySuperSecurePassword" for i := 0; i < t.N; i++ { _, err := InitializeBackup(expectedPassword, cb, - &e2eApi.Container{}, + &xxdk.Container{}, newMockE2e(t), newMockSession(t), newMockUserDiscovery(), kv, rngGen) if err != nil { diff --git a/bindings/autheticatedConnection.go b/bindings/autheticatedConnection.go index b0bb6b98a0c6dad32c5ec8504ba49b01f2d6233a..6ce0cf71346cee5386414eb1c80c6c8da142d3d5 100644 --- a/bindings/autheticatedConnection.go +++ b/bindings/autheticatedConnection.go @@ -35,6 +35,6 @@ func (c *Cmix) ConnectWithAuthentication(e2eId int, recipientContact []byte) (*A return nil, err } - connection, err := connect.ConnectWithAuthentication(cont, e2eClient, connect.GetDefaultParams()) + connection, err := connect.ConnectWithAuthentication(cont, e2eClient.api, connect.GetDefaultParams()) return authenticatedConnectionTrackerSingleton.make(connection), nil } diff --git a/bindings/connect.go b/bindings/connect.go index 4740eac0ebd246be64d2139a4d06bb7a9e676667..85a905be7696960438fa8b8a44cde9b5b33a9f03 100644 --- a/bindings/connect.go +++ b/bindings/connect.go @@ -44,7 +44,7 @@ func (c *Cmix) Connect(e2eId int, recipientContact []byte) ( return nil, err } - connection, err := connect.Connect(cont, e2eClient, connect.GetDefaultParams()) + connection, err := connect.Connect(cont, e2eClient.api, connect.GetDefaultParams()) if err != nil { return nil, err } diff --git a/cmd/root.go b/cmd/root.go index b833b674ce43c7f12540a05c3eab59669782eea7..c7d84b702167ca1ea5c1cb1ef5279034c8305e51 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -558,7 +558,7 @@ func createClient() *xxdk.Cmix { } // Construct client from backup data - backupIdList, _, err := xxdk.NewClientFromBackup(string(ndfJSON), storeDir, + backupIdList, _, err := backup.NewClientFromBackup(string(ndfJSON), storeDir, pass, backupPass, backupFile) if err != nil { jww.FATAL.Panicf("%+v", err)