diff --git a/ud/addFact.go b/ud/addFact.go index 3cb960518d585c2270adb3e20586e89ff9d55c37..719e7d137ab1f9c3e5ce4d414c9db08876d668a4 100644 --- a/ud/addFact.go +++ b/ud/addFact.go @@ -30,12 +30,6 @@ func (m *Manager) SendRegisterFact(f fact.Fact) (string, error) { func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, aFC addFactComms) (string, error) { - // get UD host - udHost, err := m.getHost() - if err != nil { - return "", err - } - // Create a primitives Fact so we can hash it f, err := fact.NewFact(inFact.T, inFact.Fact) if err != nil { @@ -68,7 +62,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, } // Send the message - response, err := aFC.SendRegisterFact(udHost, &remFactMsg) + response, err := aFC.SendRegisterFact(m.ud.host, &remFactMsg) confirmationID := "" if response != nil { diff --git a/ud/confirmFact.go b/ud/confirmFact.go index 7ad5ddcc71e4de3fd24652d4002f2317e5685277..a55da37566945a03b5c0a276f92b7e30ec220f4d 100644 --- a/ud/confirmFact.go +++ b/ud/confirmFact.go @@ -19,17 +19,11 @@ func (m *Manager) ConfirmFact(confirmationID, code string) error { // confirmFact is a helper function for ConfirmFact. func (m *Manager) confirmFact(confirmationID, code string, comm confirmFactComm) error { - // get UD host - udHost, err := m.getHost() - if err != nil { - return err - } - msg := &pb.FactConfirmRequest{ ConfirmationID: confirmationID, Code: code, } - _, err = comm.SendConfirmFact(udHost, msg) + _, err := comm.SendConfirmFact(m.ud.host, msg) if err != nil { return err } diff --git a/ud/manager.go b/ud/manager.go index 33b2f3b3a7a55dbe34884da8cb3fff308e4e20c4..cd937f041ecff048a4aa8c33b65eea8524bafb0e 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -10,10 +10,8 @@ import ( "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/primitives/fact" - "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "sync" - "time" ) // Manager is the control structure for the contacting the user discovery service. @@ -154,13 +152,6 @@ func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus, return nil, err } - // Create the user discovery host object - _, err = m.getHost() - if err != nil { - return nil, errors.WithMessage(err, "User Discovery host object could "+ - "not be constructed.") - } - return m, nil } @@ -240,48 +231,6 @@ func (m *Manager) GetContact() (contact.Contact, error) { } -// getHost returns the current UD host. -func (m *Manager) getHost() (*connect.Host, error) { - // Return User discovery service if it has been set - if m.ud != nil { - return m.ud.host, nil - } - - // Otherwise construct one (this should be for testing purposes only) - 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 - udID, err := id.Unmarshal(netDef.UDB.ID) - if err != 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 // creates a new Manager object. func loadOrNewManager(user udE2e, comms Comms, diff --git a/ud/register.go b/ud/register.go index 8ec2914d6ee2f6b94baaecfee438f2089fa63677..495d50da5e1fb51dd0e9d0e9d0211547d3314946 100644 --- a/ud/register.go +++ b/ud/register.go @@ -17,14 +17,6 @@ import ( func (m *Manager) register(username string, networkSignature []byte, rng csprng.Source, comm registerUserComms) error { - // Initialize or get host - udHost, err := m.getHost() - if err != nil { - return errors.WithMessage(err, - "User Discovery host object could "+ - "not be constructed.") - } - // Retrieve data used for registration identity := m.user.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() @@ -86,7 +78,7 @@ func (m *Manager) register(username string, networkSignature []byte, } // Register user with user discovery - _, err = comm.SendRegisterUser(udHost, msg) + _, err = comm.SendRegisterUser(m.ud.host, msg) if err != nil { return err } diff --git a/ud/remove.go b/ud/remove.go index 0972b7e770c89c8bf071bb63e9552908a6ddcc03..ebb809c0022ab0bbc81237c092c106bcbf946bd2 100644 --- a/ud/remove.go +++ b/ud/remove.go @@ -28,12 +28,6 @@ func (m *Manager) RemoveFact(f fact.Fact) error { func (m *Manager) removeFact(f fact.Fact, rFC removeFactComms) error { - // Get UD host - udHost, err := m.getHost() - if err != nil { - return err - } - // Construct the message to send // Convert our Fact to a mixmessages Fact for sending mmFact := mixmessages.Fact{ @@ -65,7 +59,7 @@ func (m *Manager) removeFact(f fact.Fact, } // Send the message - _, err = rFC.SendRemoveFact(udHost, &remFactMsg) + _, err = rFC.SendRemoveFact(m.ud.host, &remFactMsg) if err != nil { return err } @@ -83,19 +77,13 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error { return errors.New(fmt.Sprintf("PermanentDeleteAccount must only remove "+ "a username. Cannot remove fact %q", f.Fact)) } - - udHost, err := m.getHost() - if err != nil { - return err - } - identity := m.user.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err } - return m.permanentDeleteAccount(f, identity.ID, privKey, m.comms, udHost) + return m.permanentDeleteAccount(f, identity.ID, privKey, m.comms, m.ud.host) } // permanentDeleteAccount is a helper function for PermanentDeleteAccount. diff --git a/ud/ud.go b/ud/ud.go index 9f4ec1b482fe6914a581d48e7cae352fb17349e1..5fb27e619de9d5196b24022b35277f1f26c37837 100644 --- a/ud/ud.go +++ b/ud/ud.go @@ -5,6 +5,7 @@ import ( "gitlab.com/elixxir/crypto/contact" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" + "time" ) // userDiscovery is the user discovery's contact information. @@ -20,6 +21,7 @@ func (m *Manager) setUserDiscovery(cert, contactFile []byte, address string) error { params := connect.GetDefaultHostParams() params.AuthEnabled = false + params.SendTimeout = 20 * time.Second udIdBytes, dhPubKeyBytes, err := contact.ReadContactFromFile(contactFile) if err != nil { diff --git a/ud/utils_test.go b/ud/utils_test.go index c4082605b959ef94d3ab4d031970c0b370893d05..7463081d6fd77c02b4a9260bcfbeb6c9dc76f44d 100644 --- a/ud/utils_test.go +++ b/ud/utils_test.go @@ -84,7 +84,7 @@ func newTestManager(t *testing.T) (*Manager, *testNetworkManager) { params.SendTimeout = 20 * time.Second // Add a new host and return it if it does not already exist - _, err = m.comms.AddHost(udID, netDef.UDB.Address, + host, err := m.comms.AddHost(udID, netDef.UDB.Address, []byte(netDef.UDB.Cert), params) if err != nil { t.Fatalf("User Discovery host " + @@ -95,6 +95,10 @@ func newTestManager(t *testing.T) (*Manager, *testNetworkManager) { if err != nil { t.Fatalf("Failed to get contact: %v", err) } + m.ud = &userDiscovery{ + host: host, + contact: udContact, + } tnm.c = udContact