diff --git a/backup/backup.go b/backup/backup.go index b8b72f2563844980c21d8d0ebb9309b85c996221..2e0eaab92eb69ad6c496b16e54f2d54226561216 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -302,6 +302,11 @@ func (b *Backup) assembleBackup() backup.Backup { // Get contacts bu.Contacts.Identities = b.store.E2e().GetPartners() + // Get pending auth requests + // NOTE: Received requests don't matter here, as those are either + // not yet noticed by user OR explicitly rejected. + bu.Contacts.Identities = append(bu.Contacts.Identities, + b.store.Auth().GetAllSentIDs()...) //add the memoized json params bu.JSONParams = b.jsonParams diff --git a/bindings/restoreContacts.go b/bindings/restoreContacts.go index b970c77a2ed8cbf5664f76a6754904edb9b8d0f0..7d50b09fc97dff0b2c326dbbf84e05be72d464fe 100644 --- a/bindings/restoreContacts.go +++ b/bindings/restoreContacts.go @@ -9,6 +9,7 @@ package bindings import ( "gitlab.com/elixxir/client/xxmutils" + "gitlab.com/elixxir/crypto/contact" "gitlab.com/xx_network/primitives/id" ) @@ -74,11 +75,20 @@ func (r *RestoreContactsReport) GetRestoreContactsError() string { // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. func RestoreContactsFromBackup(backupPartnerIDs []byte, client *Client, - udManager *UserDiscovery, + udManager *UserDiscovery, lookupCB LookupCallback, updatesCb RestoreContactsUpdater) *RestoreContactsReport { + extLookupCB := func(c contact.Contact, myErr error) { + bindingsContact := &Contact{c: &c} + errStr := myErr.Error() + if lookupCB != nil { + lookupCB.Callback(bindingsContact, errStr) + } + } + restored, failed, errs, err := xxmutils.RestoreContactsFromBackup( - backupPartnerIDs, &client.api, udManager.ud, updatesCb) + backupPartnerIDs, &client.api, udManager.ud, extLookupCB, + updatesCb) return &RestoreContactsReport{ restored: restored, diff --git a/cmd/ud.go b/cmd/ud.go index dc940811b9ff1888ae4b221b8fa8ad5accb66e7a..a8f6205a4fe173d62af1d9ef10c1b85574ad63e9 100644 --- a/cmd/ud.go +++ b/cmd/ud.go @@ -169,7 +169,7 @@ var udCmd = &cobra.Command{ jww.FATAL.Panicf("BATCHADD: Couldn't read file: %+v", err) } restored, _, _, err := xxmutils.RestoreContactsFromBackup( - idListFile, client, userDiscoveryMgr, nil) + idListFile, client, userDiscoveryMgr, nil, nil) if err != nil { jww.FATAL.Panicf("%+v", err) } diff --git a/storage/auth/store.go b/storage/auth/store.go index f0a48c6d7dd1c80b19d6c11aac046bb4da9a209d..2d81f960cf767702f21b5401e26e780c0ff74603 100644 --- a/storage/auth/store.go +++ b/storage/auth/store.go @@ -9,6 +9,8 @@ package auth import ( "encoding/json" + "sync" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" @@ -20,7 +22,6 @@ import ( "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "sync" ) const NoRequest = "Request Not Found" @@ -291,6 +292,20 @@ func (s *Store) GetAllReceived() []contact.Contact { return cList } +// GetAllReceived returns all pending received contact requests from storage. +func (s *Store) GetAllSentIDs() []*id.ID { + s.mux.RLock() + defer s.mux.RUnlock() + cList := make([]*id.ID, 0, len(s.requests)) + for key := range s.requests { + r := s.requests[key] + if r.rt == Sent { + cList = append(cList, r.sent.partner) + } + } + return cList +} + // GetFingerprint can return either a private key or a sentRequest if the // fingerprint is found. If it returns a sentRequest, then it takes the lock to // ensure there is only one operator at a time. The user of the API must release diff --git a/xxmutils/restoreContacts.go b/xxmutils/restoreContacts.go index b64947418cb401ea797c99cc8c5935a60335bfb9..4c7a9d119d3bf958865a3374228c5df5c32abc87 100644 --- a/xxmutils/restoreContacts.go +++ b/xxmutils/restoreContacts.go @@ -27,6 +27,8 @@ import ( "gitlab.com/xx_network/primitives/id" ) +type LookupCallback func(c contact.Contact, myErr error) + // RestoreContactsFromBackup takes as input the jason output of the // `NewClientFromBackup` function, unmarshals it into IDs, looks up // each ID in user discovery, and initiates a session reset request. @@ -36,7 +38,7 @@ import ( // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client, - udManager *ud.Manager, + udManager *ud.Manager, lookupCB LookupCallback, updatesCb interfaces.RestoreContactsUpdater) ([]*id.ID, []*id.ID, []error, error) { @@ -92,7 +94,8 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client, rsWg := &sync.WaitGroup{} rsWg.Add(numRoutines) for i := 0; i < numRoutines; i++ { - go LookupContacts(lookupCh, foundCh, failCh, udManager, lcWg) + go LookupContacts(lookupCh, foundCh, failCh, udManager, lookupCB, + lcWg) go ResetSessions(resetContactCh, restoredCh, failCh, *client, rsWg) } @@ -172,13 +175,13 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client, // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. func LookupContacts(in chan *id.ID, out chan *contact.Contact, - failCh chan failure, udManager *ud.Manager, + failCh chan failure, udManager *ud.Manager, extLookupCB LookupCallback, wg *sync.WaitGroup) { defer wg.Done() // Start looking up contacts with user discovery and feed this // contacts channel. for lookupID := range in { - c, err := LookupContact(lookupID, udManager) + c, err := LookupContact(lookupID, udManager, extLookupCB) if err == nil { out <- c continue @@ -220,8 +223,8 @@ func ResetSessions(in, out chan *contact.Contact, failCh chan failure, // xxDK users should not use this function. This function is used by // the mobile phone apps and are not intended to be part of the xxDK. It // should be treated as internal functions specific to the phone apps. -func LookupContact(userID *id.ID, udManager *ud.Manager) ( - *contact.Contact, error) { +func LookupContact(userID *id.ID, udManager *ud.Manager, + extLookupCB LookupCallback) (*contact.Contact, error) { // This is a little wonky, but wait until we get called then // set the result to the contact objects details if there is // no error @@ -230,6 +233,7 @@ func LookupContact(userID *id.ID, udManager *ud.Manager) ( var err error lookupCB := func(c contact.Contact, myErr error) { defer waiter.Unlock() + defer extLookupCB(c, myErr) if myErr != nil { err = myErr }