From 8f8c920e2ca62ecb903e5fdaa134cd7524faaefb Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Tue, 9 Aug 2022 10:22:53 -0700 Subject: [PATCH] Fix documentation --- bindings/ud.go | 2 +- ud/manager.go | 29 +++++++++++++++-------------- ud/manager_test.go | 4 ++-- ud/{alternate.go => ud.go} | 19 +++++++------------ 4 files changed, 25 insertions(+), 29 deletions(-) rename ud/{alternate.go => ud.go} (59%) diff --git a/bindings/ud.go b/bindings/ud.go index 2603a6287..e8af64ae0 100644 --- a/bindings/ud.go +++ b/bindings/ud.go @@ -129,7 +129,7 @@ type UdNetworkStatus interface { // You may use the UD server run by the xx network team by using E2e.GetUdAddressFromNdf. // // 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, username string, registrationValidationSignature, cert, contactFile []byte, address string) ( diff --git a/ud/manager.go b/ud/manager.go index f6aa78e9b..1b0ee3578 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -38,9 +38,9 @@ type Manager struct { // may cause unexpected behaviour. factMux sync.Mutex - // alternativeUd is an alternate User discovery service to circumvent - // production. This is for testing with a separately deployed UD service. - alternativeUd *alternateUd + // ud is the tracker for the contact information of the specified UD server. + // This information is specified in NewOrLoad. + ud *userDiscovery } // NewOrLoad loads an existing Manager from storage or creates a @@ -57,15 +57,16 @@ type Manager struct { // provides if through the bindings. // - 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). -// - customCert is the TLS certificate for the alternate UD server. -// - customContactFile is the data within a marshalled contact.Contact. -// - customAddress is the IP address of the alternate UD server. +// - cert is the TLS certificate for the UD server this call will connect with. +// - contactFile is the data within a marshalled contact.Contact. This represents the +// 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 -// - 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, username string, networkValidationSig, - customCert, customContactFile []byte, customAddress string) (*Manager, error) { + cert, contactFile []byte, address string) (*Manager, error) { jww.INFO.Println("ud.NewOrLoad()") @@ -76,7 +77,7 @@ func NewOrLoad(user udE2e, comms Comms, follower udNetworkStatus, } // Set alternative user discovery - err = m.setAlternateUserDiscovery(customCert, customContactFile, customAddress) + err = m.setUserDiscovery(cert, contactFile, address) if err != nil { return nil, err } @@ -187,18 +188,18 @@ func (m *Manager) GetContact() (contact.Contact, error) { return contact.Contact{}, err } // Return alternative User discovery contact if set - if m.alternativeUd != nil { + if m.ud != nil { // Unmarshal UD DH public key alternativeDhPubKey := grp.NewInt(1) if err := alternativeDhPubKey. - UnmarshalJSON(m.alternativeUd.dhPubKey); err != nil { + UnmarshalJSON(m.ud.dhPubKey); err != nil { return contact.Contact{}, errors.WithMessage(err, "Failed to unmarshal UD "+ "DH public key.") } return contact.Contact{ - ID: m.alternativeUd.host.GetId(), + ID: m.ud.host.GetId(), DhPubKey: alternativeDhPubKey, OwnershipProof: nil, Facts: nil, @@ -234,8 +235,8 @@ func (m *Manager) GetContact() (contact.Contact, error) { // 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.alternativeUd != nil { - return m.alternativeUd.host, nil + if m.ud != nil { + return m.ud.host, nil } netDef := m.getCmix().GetInstance().GetPartialNdf().Get() diff --git a/ud/manager_test.go b/ud/manager_test.go index ae984bc44..e6a1018ba 100644 --- a/ud/manager_test.go +++ b/ud/manager_test.go @@ -53,8 +53,8 @@ func TestManager_SetAlternativeUserDiscovery(t *testing.T) { m, _ := newTestManager(t) 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 { - t.Fatalf("Unexpected error in setAlternateUserDiscovery: %v", err) + t.Fatalf("Unexpected error in setUserDiscovery: %v", err) } } diff --git a/ud/alternate.go b/ud/ud.go similarity index 59% rename from ud/alternate.go rename to ud/ud.go index 26ba501e4..431c193c0 100644 --- a/ud/alternate.go +++ b/ud/ud.go @@ -7,21 +7,16 @@ import ( "gitlab.com/xx_network/primitives/id" ) -// alternateUd is an alternative user discovery service. -// This is used for testing, so client can avoid contacting -// the production server. This requires an alternative, -// deployed UD service. -type alternateUd struct { +// userDiscovery is the user discovery's contact information. +type userDiscovery struct { host *connect.Host dhPubKey []byte } -// setAlternateUserDiscovery 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) setAlternateUserDiscovery(altCert, +// setUserDiscovery sets the ud object within Manager. +// The specified the contact information will be used for +// all further Manager operations which contact the UD server. +func (m *Manager) setUserDiscovery(altCert, contactFile []byte, altAddress string) error { params := connect.GetDefaultHostParams() params.AuthEnabled = false @@ -44,7 +39,7 @@ func (m *Manager) setAlternateUserDiscovery(altCert, "not be constructed.") } - m.alternativeUd = &alternateUd{ + m.ud = &userDiscovery{ host: host, dhPubKey: dhPubKey, } -- GitLab