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

Merge branch 'hotfix/UnifyBindingUdCalls' into 'XX-4019/NewOrLoadAltUd'

Fix documentation

See merge request !327
parents e2d31b32 8f8c920e
No related branches found
No related tags found
3 merge requests!510Release,!327Fix documentation,!323Xx 4019/new or load alt ud
...@@ -129,7 +129,7 @@ type UdNetworkStatus interface { ...@@ -129,7 +129,7 @@ type UdNetworkStatus interface {
// You may use the UD server run by the xx network team by using E2e.GetUdAddressFromNdf. // You may use the UD server run by the xx network team by using E2e.GetUdAddressFromNdf.
// //
// Returns // Returns
// - A Manager object which is registered to the specified alternate UD service. // - A Manager object which is registered to the specified UD service.
func NewOrLoadUd(e2eID int, follower UdNetworkStatus, func NewOrLoadUd(e2eID int, follower UdNetworkStatus,
username string, registrationValidationSignature, username string, registrationValidationSignature,
cert, contactFile []byte, address string) ( cert, contactFile []byte, address string) (
......
...@@ -38,9 +38,9 @@ type Manager struct { ...@@ -38,9 +38,9 @@ type Manager struct {
// may cause unexpected behaviour. // may cause unexpected behaviour.
factMux sync.Mutex factMux sync.Mutex
// alternativeUd is an alternate User discovery service to circumvent // ud is the tracker for the contact information of the specified UD server.
// production. This is for testing with a separately deployed UD service. // This information is specified in NewOrLoad.
alternativeUd *alternateUd ud *userDiscovery
} }
// NewOrLoad loads an existing Manager from storage or creates a // NewOrLoad loads an existing Manager from storage or creates a
...@@ -57,15 +57,16 @@ type Manager struct { ...@@ -57,15 +57,16 @@ type Manager struct {
// provides if through the bindings. // provides if through the bindings.
// - networkValidationSig is a signature provided by the network (i.e. the client registrar). This may // - networkValidationSig is a signature provided by the network (i.e. the client registrar). This may
// be nil, however UD may return an error in some cases (e.g. in a production level environment). // be nil, however UD may return an error in some cases (e.g. in a production level environment).
// - customCert is the TLS certificate for the alternate UD server. // - cert is the TLS certificate for the UD server this call will connect with.
// - customContactFile is the data within a marshalled contact.Contact. // - contactFile is the data within a marshalled contact.Contact. This represents the
// - customAddress is the IP address of the alternate UD server. // contact file of the server this call will connect with.
// - address is the IP address of the UD server this call will connect with.
// //
// Returns // Returns
// - A Manager object which is registered to the specified alternate UD service. // - A Manager object which is registered to the specified UD service.
func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus, func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus,
username string, networkValidationSig, username string, networkValidationSig,
customCert, customContactFile []byte, customAddress string) (*Manager, error) { cert, contactFile []byte, address string) (*Manager, error) {
jww.INFO.Println("ud.NewOrLoad()") jww.INFO.Println("ud.NewOrLoad()")
...@@ -76,7 +77,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus, ...@@ -76,7 +77,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus,
} }
// Set alternative user discovery // Set alternative user discovery
err = m.setAlternateUserDiscovery(customCert, customContactFile, customAddress) err = m.setUserDiscovery(cert, contactFile, address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -187,18 +188,18 @@ func (m *Manager) GetContact() (contact.Contact, error) { ...@@ -187,18 +188,18 @@ func (m *Manager) GetContact() (contact.Contact, error) {
return contact.Contact{}, err return contact.Contact{}, err
} }
// Return alternative User discovery contact if set // Return alternative User discovery contact if set
if m.alternativeUd != nil { if m.ud != nil {
// Unmarshal UD DH public key // Unmarshal UD DH public key
alternativeDhPubKey := grp.NewInt(1) alternativeDhPubKey := grp.NewInt(1)
if err := alternativeDhPubKey. if err := alternativeDhPubKey.
UnmarshalJSON(m.alternativeUd.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 contact.Contact{ return contact.Contact{
ID: m.alternativeUd.host.GetId(), ID: m.ud.host.GetId(),
DhPubKey: alternativeDhPubKey, DhPubKey: alternativeDhPubKey,
OwnershipProof: nil, OwnershipProof: nil,
Facts: nil, Facts: nil,
...@@ -234,8 +235,8 @@ func (m *Manager) GetContact() (contact.Contact, error) { ...@@ -234,8 +235,8 @@ func (m *Manager) GetContact() (contact.Contact, error) {
// If the host does not exist, then it is added and returned. // If the host does not exist, then it is added and returned.
func (m *Manager) getOrAddUdHost() (*connect.Host, error) { func (m *Manager) getOrAddUdHost() (*connect.Host, error) {
// Return alternative User discovery service if it has been set // Return alternative User discovery service if it has been set
if m.alternativeUd != nil { if m.ud != nil {
return m.alternativeUd.host, nil return m.ud.host, nil
} }
netDef := m.getCmix().GetInstance().GetPartialNdf().Get() netDef := m.getCmix().GetInstance().GetPartialNdf().Get()
......
...@@ -53,8 +53,8 @@ func TestManager_SetAlternativeUserDiscovery(t *testing.T) { ...@@ -53,8 +53,8 @@ func TestManager_SetAlternativeUserDiscovery(t *testing.T) {
m, _ := newTestManager(t) m, _ := newTestManager(t)
altAddr := "0.0.0.0:11420" altAddr := "0.0.0.0:11420"
err := m.setAlternateUserDiscovery([]byte(testCert), []byte(testContact), string([]byte(altAddr))) err := m.setUserDiscovery([]byte(testCert), []byte(testContact), string([]byte(altAddr)))
if err != nil { if err != nil {
t.Fatalf("Unexpected error in setAlternateUserDiscovery: %v", err) t.Fatalf("Unexpected error in setUserDiscovery: %v", err)
} }
} }
...@@ -7,21 +7,16 @@ import ( ...@@ -7,21 +7,16 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
// alternateUd is an alternative user discovery service. // userDiscovery is the user discovery's contact information.
// This is used for testing, so client can avoid contacting type userDiscovery struct {
// the production server. This requires an alternative,
// deployed UD service.
type alternateUd struct {
host *connect.Host host *connect.Host
dhPubKey []byte dhPubKey []byte
} }
// setAlternateUserDiscovery sets the alternativeUd object within manager. // setUserDiscovery sets the ud object within Manager.
// Once set, any user discovery operation will go through the alternative // The specified the contact information will be used for
// user discovery service. // all further Manager operations which contact the UD server.
// func (m *Manager) setUserDiscovery(altCert,
// To undo this operation, use UnsetAlternativeUserDiscovery.
func (m *Manager) setAlternateUserDiscovery(altCert,
contactFile []byte, altAddress string) error { contactFile []byte, altAddress string) error {
params := connect.GetDefaultHostParams() params := connect.GetDefaultHostParams()
params.AuthEnabled = false params.AuthEnabled = false
...@@ -44,7 +39,7 @@ func (m *Manager) setAlternateUserDiscovery(altCert, ...@@ -44,7 +39,7 @@ func (m *Manager) setAlternateUserDiscovery(altCert,
"not be constructed.") "not be constructed.")
} }
m.alternativeUd = &alternateUd{ m.ud = &userDiscovery{
host: host, host: host,
dhPubKey: dhPubKey, dhPubKey: dhPubKey,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment