Skip to content
Snippets Groups Projects
Commit 0f522bb2 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Modify restore to call user-defined bindings callback. Add Sent requests to...

Modify restore to call user-defined bindings callback. Add Sent requests to the list of ID's in the backed up list
parent 994ca738
No related branches found
No related tags found
3 merge requests!233Modify restore to call user-defined bindings callback. Add Sent requests to...,!231Revert "Update store to print changes to the partners list",!192Hotfix/improved restore
...@@ -302,6 +302,11 @@ func (b *Backup) assembleBackup() backup.Backup { ...@@ -302,6 +302,11 @@ func (b *Backup) assembleBackup() backup.Backup {
// Get contacts // Get contacts
bu.Contacts.Identities = b.store.E2e().GetPartners() 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 //add the memoized json params
bu.JSONParams = b.jsonParams bu.JSONParams = b.jsonParams
......
...@@ -9,6 +9,7 @@ package bindings ...@@ -9,6 +9,7 @@ package bindings
import ( import (
"gitlab.com/elixxir/client/xxmutils" "gitlab.com/elixxir/client/xxmutils"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
...@@ -74,11 +75,20 @@ func (r *RestoreContactsReport) GetRestoreContactsError() string { ...@@ -74,11 +75,20 @@ func (r *RestoreContactsReport) GetRestoreContactsError() string {
// the mobile phone apps and are not intended to be part of the xxDK. It // 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. // should be treated as internal functions specific to the phone apps.
func RestoreContactsFromBackup(backupPartnerIDs []byte, client *Client, func RestoreContactsFromBackup(backupPartnerIDs []byte, client *Client,
udManager *UserDiscovery, udManager *UserDiscovery, lookupCB LookupCallback,
updatesCb RestoreContactsUpdater) *RestoreContactsReport { 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( restored, failed, errs, err := xxmutils.RestoreContactsFromBackup(
backupPartnerIDs, &client.api, udManager.ud, updatesCb) backupPartnerIDs, &client.api, udManager.ud, extLookupCB,
updatesCb)
return &RestoreContactsReport{ return &RestoreContactsReport{
restored: restored, restored: restored,
......
...@@ -169,7 +169,7 @@ var udCmd = &cobra.Command{ ...@@ -169,7 +169,7 @@ var udCmd = &cobra.Command{
jww.FATAL.Panicf("BATCHADD: Couldn't read file: %+v", err) jww.FATAL.Panicf("BATCHADD: Couldn't read file: %+v", err)
} }
restored, _, _, err := xxmutils.RestoreContactsFromBackup( restored, _, _, err := xxmutils.RestoreContactsFromBackup(
idListFile, client, userDiscoveryMgr, nil) idListFile, client, userDiscoveryMgr, nil, nil)
if err != nil { if err != nil {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
......
...@@ -9,6 +9,8 @@ package auth ...@@ -9,6 +9,8 @@ package auth
import ( import (
"encoding/json" "encoding/json"
"sync"
"github.com/cloudflare/circl/dh/sidh" "github.com/cloudflare/circl/dh/sidh"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -20,7 +22,6 @@ import ( ...@@ -20,7 +22,6 @@ import (
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"sync"
) )
const NoRequest = "Request Not Found" const NoRequest = "Request Not Found"
...@@ -291,6 +292,20 @@ func (s *Store) GetAllReceived() []contact.Contact { ...@@ -291,6 +292,20 @@ func (s *Store) GetAllReceived() []contact.Contact {
return cList 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 // 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 // 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 // ensure there is only one operator at a time. The user of the API must release
......
...@@ -27,6 +27,8 @@ import ( ...@@ -27,6 +27,8 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
type LookupCallback func(c contact.Contact, myErr error)
// RestoreContactsFromBackup takes as input the jason output of the // RestoreContactsFromBackup takes as input the jason output of the
// `NewClientFromBackup` function, unmarshals it into IDs, looks up // `NewClientFromBackup` function, unmarshals it into IDs, looks up
// each ID in user discovery, and initiates a session reset request. // each ID in user discovery, and initiates a session reset request.
...@@ -36,7 +38,7 @@ import ( ...@@ -36,7 +38,7 @@ import (
// the mobile phone apps and are not intended to be part of the xxDK. It // 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. // should be treated as internal functions specific to the phone apps.
func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client, func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client,
udManager *ud.Manager, udManager *ud.Manager, lookupCB LookupCallback,
updatesCb interfaces.RestoreContactsUpdater) ([]*id.ID, []*id.ID, updatesCb interfaces.RestoreContactsUpdater) ([]*id.ID, []*id.ID,
[]error, error) { []error, error) {
...@@ -92,7 +94,8 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client, ...@@ -92,7 +94,8 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client,
rsWg := &sync.WaitGroup{} rsWg := &sync.WaitGroup{}
rsWg.Add(numRoutines) rsWg.Add(numRoutines)
for i := 0; i < numRoutines; i++ { 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, go ResetSessions(resetContactCh, restoredCh, failCh, *client,
rsWg) rsWg)
} }
...@@ -172,13 +175,13 @@ func RestoreContactsFromBackup(backupPartnerIDs []byte, client *api.Client, ...@@ -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 // 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. // should be treated as internal functions specific to the phone apps.
func LookupContacts(in chan *id.ID, out chan *contact.Contact, 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) { wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
// Start looking up contacts with user discovery and feed this // Start looking up contacts with user discovery and feed this
// contacts channel. // contacts channel.
for lookupID := range in { for lookupID := range in {
c, err := LookupContact(lookupID, udManager) c, err := LookupContact(lookupID, udManager, extLookupCB)
if err == nil { if err == nil {
out <- c out <- c
continue continue
...@@ -220,8 +223,8 @@ func ResetSessions(in, out chan *contact.Contact, failCh chan failure, ...@@ -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 // 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 // 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. // should be treated as internal functions specific to the phone apps.
func LookupContact(userID *id.ID, udManager *ud.Manager) ( func LookupContact(userID *id.ID, udManager *ud.Manager,
*contact.Contact, error) { extLookupCB LookupCallback) (*contact.Contact, error) {
// This is a little wonky, but wait until we get called then // This is a little wonky, but wait until we get called then
// set the result to the contact objects details if there is // set the result to the contact objects details if there is
// no error // no error
...@@ -230,6 +233,7 @@ func LookupContact(userID *id.ID, udManager *ud.Manager) ( ...@@ -230,6 +233,7 @@ func LookupContact(userID *id.ID, udManager *ud.Manager) (
var err error var err error
lookupCB := func(c contact.Contact, myErr error) { lookupCB := func(c contact.Contact, myErr error) {
defer waiter.Unlock() defer waiter.Unlock()
defer extLookupCB(c, myErr)
if myErr != nil { if myErr != nil {
err = myErr err = myErr
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment