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 {
// 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) (
......
......@@ -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()
......
......@@ -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)
}
}
......@@ -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,
}
......
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