From abc57b7293a39f5e7519118a09e05e1691b4538a Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Mon, 8 Aug 2022 13:42:59 -0700 Subject: [PATCH] Fix contact marshal mismatch bug --- bindings/ud.go | 10 +++++----- ud/alternate.go | 21 +++++++++++---------- ud/manager.go | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/bindings/ud.go b/bindings/ud.go index da1b196a2..d3652056f 100644 --- a/bindings/ud.go +++ b/bindings/ud.go @@ -125,13 +125,13 @@ func LoadOrNewUserDiscovery(e2eID int, follower UdNetworkStatus, } // Construct callback - UdNetworkStatusFn := func() xxdk.Status { + udNetworkStatusFn := func() xxdk.Status { return xxdk.Status(follower.UdNetworkStatus()) } // Build manager u, err := ud.LoadOrNewManager(user.api, user.api.GetComms(), - UdNetworkStatusFn, username, registrationValidationSignature) + udNetworkStatusFn, username, registrationValidationSignature) if err != nil { return nil, err } @@ -156,7 +156,7 @@ func LoadOrNewUserDiscovery(e2eID int, follower UdNetworkStatus, // be nil, however UD may return an error in some cases (e.g. in a production level environment). // - altCert is the TLS certificate for the alternate UD server. // - altAddress is the IP address of the alternate UD server. -// - marshalledContact is the data within a marshalled contact.Contact. +// - marshalledContact is a JSON marshalled contact.Contact. // // Returns // - A Manager object which is registered to the specified alternate UD service. @@ -172,13 +172,13 @@ func LoadOrNewAlternateUserDiscovery(e2eID int, follower UdNetworkStatus, } // Construct callback - UdNetworkStatusFn := func() xxdk.Status { + udNetworkStatusFn := func() xxdk.Status { return xxdk.Status(follower.UdNetworkStatus()) } // Build manager u, err := ud.LoadOrNewAlternateUserDiscovery(user.api, user.api.GetComms(), - UdNetworkStatusFn, username, registrationValidationSignature, + udNetworkStatusFn, username, registrationValidationSignature, altCert, altAddress, marshalledContact) if err != nil { return nil, err diff --git a/ud/alternate.go b/ud/alternate.go index 4f0013bfc..f0f1a50e6 100644 --- a/ud/alternate.go +++ b/ud/alternate.go @@ -1,10 +1,10 @@ package ud import ( + "encoding/json" "github.com/pkg/errors" "gitlab.com/elixxir/crypto/contact" "gitlab.com/xx_network/comms/connect" - "gitlab.com/xx_network/primitives/id" ) // alternateUd is an alternative user discovery service. @@ -26,27 +26,28 @@ func (m *Manager) setAlternateUserDiscovery(altCert, altAddress, params := connect.GetDefaultHostParams() params.AuthEnabled = false - udIdBytes, dhPubKey, err := contact.ReadContactFromFile(contactFile) + c := &contact.Contact{} + err := json.Unmarshal(contactFile, c) if err != nil { - return err - } - - udID, err := id.Unmarshal(udIdBytes) - if err != nil { - return err + return errors.Errorf("Failed to unmarshal contact file: %v", err) } // Add a new host and return it if it does not already exist - host, err := m.comms.AddHost(udID, string(altAddress), + host, err := m.comms.AddHost(c.ID, string(altAddress), altCert, params) if err != nil { return errors.WithMessage(err, "User Discovery host object could "+ "not be constructed.") } + dhPubJson, err := c.DhPubKey.MarshalJSON() + if err != nil { + return errors.Errorf("Failed to marshal Diffie-Helman public key: %v", err) + } + m.alternativeUd = &alternateUd{ host: host, - dhPubKey: dhPubKey, + dhPubKey: dhPubJson, } return nil diff --git a/ud/manager.go b/ud/manager.go index c1d51d002..9545ed748 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -140,7 +140,7 @@ func NewManagerFromBackup(user udE2e, comms Comms, follower udNetworkStatus, // be nil, however UD may return an error in some cases (e.g. in a production level environment). // - altCert is the TLS certificate for the alternate UD server. // - altAddress is the IP address of the alternate UD server. -// - marshalledContact is the data within a marshalled contact.Contact. +// - marshalledContact is a JSON marshalled contact.Contact. // // Returns // - A Manager object which is registered to the specified alternate UD service. -- GitLab