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

Finalize alternative user discovery

parent 6173ba98
No related branches found
No related tags found
2 merge requests!170Release,!145Hotfix/alt udb
...@@ -46,11 +46,6 @@ func NewUserDiscovery(client *Client) (*UserDiscovery, error) { ...@@ -46,11 +46,6 @@ func NewUserDiscovery(client *Client) (*UserDiscovery, error) {
} }
} }
// todo: docstring
func (ud *UserDiscovery) SetAlternativeUserDiscovery(address, cert, id, dhPubKey []byte) error {
return ud.SetAlternativeUserDiscovery(id, cert, address, dhPubKey)
}
// Register registers a user with user discovery. Will return an error if the // Register registers a user with user discovery. Will return an error if the
// network signatures are malformed or if the username is taken. Usernames // network signatures are malformed or if the username is taken. Usernames
// cannot be changed after registration at this time. Will fail if the user is // cannot be changed after registration at this time. Will fail if the user is
...@@ -298,3 +293,17 @@ func (ud UserDiscovery) MultiLookup(ids *IdList, callback MultiLookupCallback, ...@@ -298,3 +293,17 @@ func (ud UserDiscovery) MultiLookup(ids *IdList, callback MultiLookupCallback,
return nil return nil
} }
// SetAlternativeUserDiscovery sets the alternativeUd object within manager.
// Once set, any user discovery operation will go through the alternative
// user discovery service.
// To undo this operation, use UnsetAlternativeUserDiscovery.
func (ud *UserDiscovery) SetAlternativeUserDiscovery(address, cert, id, dhPubKey []byte) error {
return ud.ud.SetAlternativeUserDiscovery(id, cert, address, dhPubKey)
}
// UnsetAlternativeUserDiscovery clears out the information from
// the Manager object.
func (ud *UserDiscovery) UnsetAlternativeUserDiscovery() error {
return ud.ud.UnsetAlternativeUserDiscovery()
}
...@@ -25,11 +25,6 @@ type SingleInterface interface { ...@@ -25,11 +25,6 @@ type SingleInterface interface {
StartProcesses() (stoppable.Stoppable, error) StartProcesses() (stoppable.Stoppable, error)
} }
type alternateUd struct {
host *connect.Host
dhPubKey []byte
}
type Manager struct { type Manager struct {
// External // External
client *api.Client client *api.Client
...@@ -53,6 +48,14 @@ type Manager struct { ...@@ -53,6 +48,14 @@ type Manager struct {
registered *uint32 registered *uint32
} }
// alternateUd is an alternative user discovery service.
// This is used for testing, so client can avoid using
// the production server.
type alternateUd struct {
host *connect.Host
dhPubKey []byte
}
// NewManager builds a new user discovery manager. It requires that an updated // NewManager builds a new user discovery manager. It requires that an updated
// NDF is available and will error if one is not. // NDF is available and will error if one is not.
func NewManager(client *api.Client, single *single.Manager) (*Manager, error) { func NewManager(client *api.Client, single *single.Manager) (*Manager, error) {
...@@ -102,7 +105,11 @@ func NewManager(client *api.Client, single *single.Manager) (*Manager, error) { ...@@ -102,7 +105,11 @@ func NewManager(client *api.Client, single *single.Manager) (*Manager, error) {
return m, nil return m, nil
} }
func (m *Manager) SetAlternativeUserDiscovery(altId []byte, altCert []byte, altAddress string, dhPubKey []byte) error { // SetAlternativeUserDiscovery sets the alternativeUd object within manager.
// Once set, any user discovery operation will go through the alternative
// user discovery service.
// To undo this operation, use UnsetAlternativeUserDiscovery.
func (m *Manager) SetAlternativeUserDiscovery(altId, altCert, altAddress, dhPubKey []byte) error {
params := connect.GetDefaultHostParams() params := connect.GetDefaultHostParams()
params.AuthEnabled = false params.AuthEnabled = false
...@@ -112,7 +119,7 @@ func (m *Manager) SetAlternativeUserDiscovery(altId []byte, altCert []byte, altA ...@@ -112,7 +119,7 @@ func (m *Manager) SetAlternativeUserDiscovery(altId []byte, altCert []byte, altA
} }
// Add a new host and return it if it does not already exist // Add a new host and return it if it does not already exist
host, err := m.comms.AddHost(udID, altAddress, host, err := m.comms.AddHost(udID, string(altAddress),
altCert, params) altCert, params)
if err != nil { if err != nil {
return errors.WithMessage(err, "User Discovery host object could "+ return errors.WithMessage(err, "User Discovery host object could "+
...@@ -127,6 +134,17 @@ func (m *Manager) SetAlternativeUserDiscovery(altId []byte, altCert []byte, altA ...@@ -127,6 +134,17 @@ func (m *Manager) SetAlternativeUserDiscovery(altId []byte, altCert []byte, altA
return nil return nil
} }
// UnsetAlternativeUserDiscovery clears out the information from
// the Manager object.
func (m *Manager) UnsetAlternativeUserDiscovery() error {
if m.alternativeUd == nil {
return errors.New("Alternative User Discovery is already unset.")
}
m.alternativeUd = nil
return nil
}
// getHost returns the current UD host for the UD ID found in the NDF. If the // getHost 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 // host does not exist, then it is added and returned
func (m *Manager) getHost() (*connect.Host, error) { func (m *Manager) getHost() (*connect.Host, error) {
...@@ -164,6 +182,7 @@ func (m *Manager) getHost() (*connect.Host, error) { ...@@ -164,6 +182,7 @@ func (m *Manager) getHost() (*connect.Host, error) {
// getContact returns the contact for UD as retrieved from the NDF. // getContact returns the contact for UD as retrieved from the NDF.
func (m *Manager) getContact() (contact.Contact, error) { func (m *Manager) getContact() (contact.Contact, error) {
// Return alternative User discovery contact if set
if m.alternativeUd != nil { if m.alternativeUd != nil {
// Unmarshal UD DH public key // Unmarshal UD DH public key
alternativeDhPubKey := m.storage.E2e().GetGroup().NewInt(1) alternativeDhPubKey := m.storage.E2e().GetGroup().NewInt(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment