Skip to content
Snippets Groups Projects
Commit 507ee7ae authored by Josh Brooks's avatar Josh Brooks
Browse files

Remove all references to alternate in ud/

parent 6b08ecf2
No related branches found
No related tags found
2 merge requests!510Release,!323Xx 4019/new or load alt ud
...@@ -31,7 +31,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, ...@@ -31,7 +31,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID,
aFC addFactComms) (string, error) { aFC addFactComms) (string, error) {
// get UD host // get UD host
udHost, err := m.getOrAddUdHost() udHost, err := m.getHost()
if err != nil { if err != nil {
return "", err return "", err
} }
......
...@@ -20,7 +20,7 @@ func (m *Manager) ConfirmFact(confirmationID, code string) error { ...@@ -20,7 +20,7 @@ func (m *Manager) ConfirmFact(confirmationID, code string) error {
// confirmFact is a helper function for ConfirmFact. // confirmFact is a helper function for ConfirmFact.
func (m *Manager) confirmFact(confirmationID, code string, comm confirmFactComm) error { func (m *Manager) confirmFact(confirmationID, code string, comm confirmFactComm) error {
// get UD host // get UD host
udHost, err := m.getOrAddUdHost() udHost, err := m.getHost()
if err != nil { if err != nil {
return err return err
} }
......
package ud package ud
import ( import (
"gitlab.com/elixxir/crypto/fastRNG"
"sync"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/event" "gitlab.com/elixxir/client/event"
...@@ -12,9 +8,10 @@ import ( ...@@ -12,9 +8,10 @@ import (
store "gitlab.com/elixxir/client/ud/store" store "gitlab.com/elixxir/client/ud/store"
"gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id" "sync"
) )
// Manager is the control structure for the contacting the user discovery service. // Manager is the control structure for the contacting the user discovery service.
...@@ -76,7 +73,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus, ...@@ -76,7 +73,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus,
return nil, err return nil, err
} }
// Set alternative user discovery // Set user discovery
err = m.setUserDiscovery(cert, contactFile, address) err = m.setUserDiscovery(cert, contactFile, address)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -96,7 +93,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus, ...@@ -96,7 +93,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus,
// NewManagerFromBackup builds a new user discover manager from a backup. // NewManagerFromBackup builds a new user discover manager from a backup.
// It will construct a manager that is already registered and restore // It will construct a manager that is already registered and restore
// already registered facts into store. This will default to using the UD server as defined // already registered facts into store. This will default to using the UD server as defined
// by the NDF> // by the NDF.
func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus, func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus,
email, phone fact.Fact) (*Manager, error) { email, phone fact.Fact) (*Manager, error) {
jww.INFO.Println("ud.NewManagerFromBackup()") jww.INFO.Println("ud.NewManagerFromBackup()")
...@@ -134,7 +131,7 @@ func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus, ...@@ -134,7 +131,7 @@ func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus,
} }
// Create the user discovery host object // Create the user discovery host object
_, err = m.getOrAddUdHost() _, err = m.getHost()
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "User Discovery host object could "+ return nil, errors.WithMessage(err, "User Discovery host object could "+
"not be constructed.") "not be constructed.")
...@@ -181,96 +178,35 @@ func (m *Manager) GetStringifiedFacts() []string { ...@@ -181,96 +178,35 @@ func (m *Manager) GetStringifiedFacts() []string {
return m.store.GetStringifiedFacts() return m.store.GetStringifiedFacts()
} }
// GetContact returns the contact for UD as retrieved from the NDF. // GetContact returns the contact.Contact for UD.
func (m *Manager) GetContact() (contact.Contact, error) { func (m *Manager) GetContact() (contact.Contact, error) {
grp, err := m.user.GetReceptionIdentity().GetGroup() grp, err := m.user.GetReceptionIdentity().GetGroup()
if err != nil { if err != nil {
return contact.Contact{}, err return contact.Contact{}, err
} }
// Return alternative User discovery contact if set
if m.ud != nil {
// Unmarshal UD DH public key // Unmarshal UD DH public key
alternativeDhPubKey := grp.NewInt(1) dhPubKey := grp.NewInt(1)
if err := alternativeDhPubKey. if err := dhPubKey.
UnmarshalJSON(m.ud.dhPubKey); err != nil { UnmarshalJSON(m.ud.dhPubKey); err != nil {
return contact.Contact{}, return contact.Contact{},
errors.WithMessage(err, "Failed to unmarshal UD "+ errors.WithMessage(err, "Failed to unmarshal UD "+
"DH public key.") "DH public key.")
} }
// Return User discovery contact
return contact.Contact{ return contact.Contact{
ID: m.ud.host.GetId(), ID: m.ud.host.GetId(),
DhPubKey: alternativeDhPubKey,
OwnershipProof: nil,
Facts: nil,
}, nil
}
netDef := m.getCmix().GetInstance().GetPartialNdf().Get()
// Unmarshal UD ID from the NDF
udID, err := id.Unmarshal(netDef.UDB.ID)
if err != nil {
return contact.Contact{},
errors.Errorf("failed to unmarshal UD ID from NDF: %+v", err)
}
// Unmarshal UD DH public key
dhPubKey := grp.NewInt(1)
if err = dhPubKey.UnmarshalJSON(netDef.UDB.DhPubKey); err != nil {
return contact.Contact{},
errors.WithMessage(err, "Failed to unmarshal UD DH "+
"public key.")
}
return contact.Contact{
ID: udID,
DhPubKey: dhPubKey, DhPubKey: dhPubKey,
OwnershipProof: nil, OwnershipProof: nil,
Facts: nil, Facts: nil,
}, nil }, nil
}
// getOrAddUdHost returns the current UD host for the UD ID found in the NDF.
// If the host does not exist, then it is added and returned.
func (m *Manager) getOrAddUdHost() (*connect.Host, error) {
// Return alternative User discovery service if it has been set
if m.ud != nil {
return m.ud.host, nil
}
netDef := m.getCmix().GetInstance().GetPartialNdf().Get()
if netDef.UDB.Cert == "" {
return nil, errors.New("NDF does not have User Discovery information, " +
"is there network access?: Cert not present.")
} }
// Unmarshal UD ID from the NDF // getHost returns the current UD host.
udID, err := id.Unmarshal(netDef.UDB.ID) func (m *Manager) getHost() (*connect.Host, error) {
if err != nil { return m.ud.host, nil
return nil, errors.Errorf("failed to "+
"unmarshal UD ID from NDF: %+v", err)
}
// Return the host, if it exists
host, exists := m.comms.GetHost(udID)
if exists {
return host, nil
}
params := connect.GetDefaultHostParams()
params.AuthEnabled = false
params.SendTimeout = 20 * time.Second
// Add a new host and return it if it does not already exist
host, err = m.comms.AddHost(udID, netDef.UDB.Address,
[]byte(netDef.UDB.Cert), params)
if err != nil {
return nil, errors.WithMessage(err, "User Discovery host "+
"object could not be constructed.")
}
return host, nil
} }
// loadOrNewManager is a helper function which loads from storage or // loadOrNewManager is a helper function which loads from storage or
......
...@@ -49,7 +49,7 @@ EnretBzQkeKeBwoB2u6NTiOmUjk= ...@@ -49,7 +49,7 @@ EnretBzQkeKeBwoB2u6NTiOmUjk=
var testContact = `<xxc(2)LF2ccT+sdqh0AIKlFFeDOJdnxzbQQYhGStgxhOXmijIDkAZiB9kZo+Dl3bRSbBi5pXZ82rOu2IQXz9+5sspChvoccZqgC/dXGhlesmiNy/EbKxWtptTF4tcNyQxtnmCXg1p/HwKey4G2XDekTw86lq6Lpmj72jozvRWlQisqvWz/5deiPaeFGKDKC0OrrDFnIib7WnKqdYt4XyTKdmObnmbvdCbliZq0zBl7J40qKy5FypYXGlZjStIm0R1qtD4XHMZMsrMJEGxdM55zJdSzknXbR8MNahUrGMyUOTivXLHzojYLht0gFQifKMVWhrDjUoVQV43KOLPmdBwY/2Kc5KvVloDeuDXYY0i7tD63gNIp9JA3gJQUJymDdwqbS13riT1DMHHkdTzKEyGdHS+v2l7AVSlJBiTKuyM00FBNuXhhIcFR7ONFCf8cRPOPPBx3Q6iHNsvsca3KPNhwOJBgaQvHSkjIMsudiR954QbwG9rbi2vxVobIgWYMl5j6vlBS/9rfbE/uLdTEQZfNsLKDCIVCCI4I1bYZxZrDLPrfXTrN6W0sCLE7a/kRBQAAAgA7+LwJqiv9O1ogLnS4TYkSEg==xxc>` var testContact = `<xxc(2)LF2ccT+sdqh0AIKlFFeDOJdnxzbQQYhGStgxhOXmijIDkAZiB9kZo+Dl3bRSbBi5pXZ82rOu2IQXz9+5sspChvoccZqgC/dXGhlesmiNy/EbKxWtptTF4tcNyQxtnmCXg1p/HwKey4G2XDekTw86lq6Lpmj72jozvRWlQisqvWz/5deiPaeFGKDKC0OrrDFnIib7WnKqdYt4XyTKdmObnmbvdCbliZq0zBl7J40qKy5FypYXGlZjStIm0R1qtD4XHMZMsrMJEGxdM55zJdSzknXbR8MNahUrGMyUOTivXLHzojYLht0gFQifKMVWhrDjUoVQV43KOLPmdBwY/2Kc5KvVloDeuDXYY0i7tD63gNIp9JA3gJQUJymDdwqbS13riT1DMHHkdTzKEyGdHS+v2l7AVSlJBiTKuyM00FBNuXhhIcFR7ONFCf8cRPOPPBx3Q6iHNsvsca3KPNhwOJBgaQvHSkjIMsudiR954QbwG9rbi2vxVobIgWYMl5j6vlBS/9rfbE/uLdTEQZfNsLKDCIVCCI4I1bYZxZrDLPrfXTrN6W0sCLE7a/kRBQAAAgA7+LwJqiv9O1ogLnS4TYkSEg==xxc>`
func TestManager_SetAlternativeUserDiscovery(t *testing.T) { func TestManager_setUserDiscovery(t *testing.T) {
m, _ := newTestManager(t) m, _ := newTestManager(t)
altAddr := "0.0.0.0:11420" altAddr := "0.0.0.0:11420"
......
...@@ -18,7 +18,7 @@ func (m *Manager) register(username string, networkSignature []byte, ...@@ -18,7 +18,7 @@ func (m *Manager) register(username string, networkSignature []byte,
rng csprng.Source, comm registerUserComms) error { rng csprng.Source, comm registerUserComms) error {
// Initialize or get host // Initialize or get host
udHost, err := m.getOrAddUdHost() udHost, err := m.getHost()
if err != nil { if err != nil {
return errors.WithMessage(err, return errors.WithMessage(err,
"User Discovery host object could "+ "User Discovery host object could "+
......
...@@ -29,7 +29,7 @@ func (m *Manager) removeFact(f fact.Fact, ...@@ -29,7 +29,7 @@ func (m *Manager) removeFact(f fact.Fact,
rFC removeFactComms) error { rFC removeFactComms) error {
// Get UD host // Get UD host
udHost, err := m.getOrAddUdHost() udHost, err := m.getHost()
if err != nil { if err != nil {
return err return err
} }
...@@ -84,7 +84,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error { ...@@ -84,7 +84,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error {
"a username. Cannot remove fact %q", f.Fact)) "a username. Cannot remove fact %q", f.Fact))
} }
udHost, err := m.getOrAddUdHost() udHost, err := m.getHost()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -86,9 +86,9 @@ package ud ...@@ -86,9 +86,9 @@ package ud
// //
// tRFC := testRFC{} // tRFC := testRFC{}
// //
// udHost, err := m.getOrAddUdHost() // udHost, err := m.getHost()
// if err != nil { // if err != nil {
// t.Fatalf("getOrAddUdHost error: %v", err) // t.Fatalf("getHost error: %v", err)
// } // }
// //
// err = m.permanentDeleteAccount(f, mockId, &tRFC, udHost) // err = m.permanentDeleteAccount(f, mockId, &tRFC, udHost)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment