Skip to content

feat(backup)_: implement remaining backups and tests #6671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions protocol/messenger_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,15 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
return 0, err
}
chatsToBackup := m.backupChats(ctx, clock)
if err != nil {
return 0, err
}

profileToBackup, err := m.backupProfile(ctx, clock)
if err != nil {
return 0, err
}
_, settings, errors := m.prepareSyncSettingsMessages(clock, true)
if len(errors) != 0 {
_, settings, err := m.prepareSyncSettingsMessages(clock, true)
if err != nil {
// return just the first error, the others have been logged
return 0, errors[0]
return 0, err
}

keypairsToBackup, err := m.backupKeypairs()
Expand Down Expand Up @@ -206,6 +204,7 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
}
}

// TODO get rid of keypairs
// Update keypairs messages encode and dispatch
for i, d := range keypairsToBackup {
pb := backupDetailsOnly()
Expand Down
14 changes: 14 additions & 0 deletions protocol/messenger_backup_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ func (m *Messenger) handleBackup(state *ReceivedMessageState, message *protobuf.
errors = append(errors, err)
}

for _, setting := range message.Settings {
err = m.handleBackedUpSettings(setting)
if err != nil {
errors = append(errors, err)
}
}

err = m.handleKeypair(message.Keypair)
if err != nil {
errors = append(errors, err)
Expand All @@ -100,6 +107,13 @@ func (m *Messenger) handleBackup(state *ReceivedMessageState, message *protobuf.
errors = append(errors, err)
}

for _, watchOnlyAccount := range message.WatchOnlyAccounts {
err = m.handleWatchOnlyAccount(watchOnlyAccount)
if err != nil {
errors = append(errors, err)
}
}

// Send signal about applied backup progress
if m.config.messengerSignalsHandler != nil {
response := wakusync.WakuBackedUpDataResponse{
Expand Down
6 changes: 2 additions & 4 deletions protocol/messenger_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (s *MessengerBackupSuite) TestBackupContacts() {
defer TearDownMessenger(&s.Suite, bob2)

// Create 2 contacts

contact1Key, err := crypto.GenerateKey()
s.Require().NoError(err)
contactID1 := types.EncodeHex(crypto.FromECDSAPub(&contact1Key.PublicKey))
Expand All @@ -61,6 +60,7 @@ func (s *MessengerBackupSuite) TestBackupContacts() {

s.Require().Len(bob1.Contacts(), 2)

// Validate contacts
actualContacts := bob1.Contacts()
if actualContacts[0].ID == contactID1 {
s.Require().Equal(actualContacts[0].ID, contactID1)
Expand All @@ -76,7 +76,6 @@ func (s *MessengerBackupSuite) TestBackupContacts() {
s.Require().True(actualContacts[1].added())

// Backup

clock, err := bob1.BackupData(context.Background())
s.Require().NoError(err)

Expand Down Expand Up @@ -825,8 +824,7 @@ func (s *MessengerBackupSuite) TestBackupCommunities() {
s.Require().NoError(err)
defer TearDownMessenger(&s.Suite, bob2)

// Create a communitie

// Create a community
description := &requests.CreateCommunity{
Membership: protobuf.CommunityPermissions_AUTO_ACCEPT,
Name: "status",
Expand Down
29 changes: 12 additions & 17 deletions protocol/messenger_local_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ func (m *Messenger) BackupDataLocally(ctx context.Context) error {
if err != nil {
return err
}
// _, settings, errors := m.prepareSyncSettingsMessages(clock, true)
// if len(errors) != 0 {
// // return just the first error, the others have been logged
// return errors[0]
// }
// woAccountsToBackup, err := m.backupWatchOnlyAccounts()
// if err != nil {
// return 0, err
// }
_, settings, err := m.prepareSyncSettingsMessages(clock, true)
if err != nil {
return err
}
woAccountsToBackup, err := m.backupWatchOnlyAccounts()
if err != nil {
return err
}

fullBackup := &protobuf.Backup{}

Expand All @@ -96,14 +95,10 @@ func (m *Messenger) BackupDataLocally(ctx context.Context) error {
for _, d := range chatsToBackup {
fullBackup.Chats = append(fullBackup.Chats, d.Chats...)
}
// for i, d := range settings {
// // TODO find a way to get all settings
// fullBackup.Setting = append(fullBackup.Setting, d)
// }
// for i, d := range woAccountsToBackup {
// // TODO find a way to get all watchonlyaccounts
// fullBackup.WatchOnlyAccount = append(fullBackup.WatchOnlyAccount, d.Keypair)
// }
fullBackup.Settings = append(fullBackup.Settings, settings...)
for _, d := range woAccountsToBackup {
fullBackup.WatchOnlyAccounts = append(fullBackup.WatchOnlyAccounts, d.WatchOnlyAccount)
}

// TODO put file in a constant
path := filepath.Join(m.config.backupConfig.DataDir, "user_data.bkp")
Expand Down
Loading