From 1b43aac9a5a18005a165dd8ea18ae0d74d0e5ae4 Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Tue, 6 Sep 2022 15:23:13 -0700 Subject: [PATCH] Fix lazy loading for UD name service --- ud/channelIDTracking.go | 29 +++++++++++++++-------------- ud/manager.go | 3 +++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ud/channelIDTracking.go b/ud/channelIDTracking.go index ee1938ec3..3eb25a4a3 100644 --- a/ud/channelIDTracking.go +++ b/ud/channelIDTracking.go @@ -25,7 +25,6 @@ const ( graceDuration time.Duration = time.Hour ) -var startChannelNameServiceOnce sync.Once var ErrChannelLeaseSignature = errors.New("failure to validate lease signature") // loadRegistrationDisk loads a registrationDisk from the kv @@ -356,24 +355,26 @@ func (c *clientIDTracker) requestChannelLease() (int64, []byte, error) { // StartChannelNameService creates a new clientIDTracker // and returns a reference to it's type as the NameService interface. -// However it's scheduler thread isn't started until it's Start +// However, it's scheduler thread isn't started until it's Start // method is called. -func (m *Manager) StartChannelNameService() channels.NameService { - udPubKeyBytes := m.user.GetCmix().GetInstance().GetPartialNdf().Get().UDB.DhPubKey - var service channels.NameService - username, err := m.store.GetUsername() - if err != nil { - jww.FATAL.Panic(err) - } - startChannelNameServiceOnce.Do(func() { - service = newclientIDTracker( +func (m *Manager) StartChannelNameService() (channels.NameService, error) { + + if m.nameService == nil { + udPubKeyBytes := m.user.GetCmix().GetInstance().GetPartialNdf().Get().UDB.DhPubKey + username, err := m.store.GetUsername() + if err != nil { + return nil, err + } + m.nameService = newclientIDTracker( m.comms, m.ud.host, username, m.getKv(), m.user.GetReceptionIdentity(), - ed25519.PublicKey(udPubKeyBytes), + udPubKeyBytes, m.getRng()) - }) - return service + + } + + return m.nameService, nil } diff --git a/ud/manager.go b/ud/manager.go index d431da78c..010b7d5aa 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -37,6 +37,9 @@ type Manager struct { // ud is the tracker for the contact information of the specified UD server. // This information is specified in Manager's constructors (NewOrLoad and NewManagerFromBackup). ud *userDiscovery + + // + nameService *clientIDTracker } // NewOrLoad loads an existing Manager from storage or creates a -- GitLab