From 46eec81fc6ea45b511e120f4c3a29134ad55a22d Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Tue, 30 Aug 2022 15:07:03 -0700 Subject: [PATCH] Remove GetServices from interface --- cmix/interface.go | 3 --- cmix/message/handler.go | 1 - cmix/message/serviceTracker.go | 27 ++++++--------------------- cmix/message/serviceTracker_test.go | 4 +++- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/cmix/interface.go b/cmix/interface.go index ef7afecce..a5db8b3cf 100644 --- a/cmix/interface.go +++ b/cmix/interface.go @@ -176,9 +176,6 @@ type Client interface { // running. Multiple trackTriggers can be registered. TrackServices(tracker message.ServicesTracker) - // GetServices retrieves the message.ServiceList. - GetServices() message.ServiceList - /* === In inProcess ===================================================== */ /* It is possible to receive a message over cMix before the fingerprints or triggers are registered. As a result, when handling fails, messages are diff --git a/cmix/message/handler.go b/cmix/message/handler.go index 510122ffb..6a5baf554 100644 --- a/cmix/message/handler.go +++ b/cmix/message/handler.go @@ -43,7 +43,6 @@ type Handler interface { DeleteService(clientID *id.ID, toDelete Service, response Processor) DeleteClientService(clientID *id.ID) TrackServices(triggerTracker ServicesTracker) - GetServices() ServiceList } type handler struct { diff --git a/cmix/message/serviceTracker.go b/cmix/message/serviceTracker.go index 972646e42..777c510f5 100644 --- a/cmix/message/serviceTracker.go +++ b/cmix/message/serviceTracker.go @@ -20,17 +20,13 @@ func (sm *ServicesManager) TrackServices(tracker ServicesTracker) { sm.trackers = append(sm.trackers, tracker) } -// GetServices retrieves the ServiceList from the ServicesManager. -// This is effectively a serializing of the -// ServicesManager's internal tmap. -func (sm *ServicesManager) GetServices() ServiceList { +// triggerServiceTracking triggers the tracking of services. Is it called when a +// service is added or removed. +func (sm *ServicesManager) triggerServiceTracking() { sm.Mutex.Lock() - defer sm.Mutex.Unlock() - return sm.getServices() -} - -// getServices is the non-thread-safe version of GetServices. -func (sm *ServicesManager) getServices() ServiceList { + if len(sm.trackers) == 0 { + return + } services := make(ServiceList) for uid, tmap := range sm.tmap { tList := make([]Service, 0, len(tmap)) @@ -39,17 +35,6 @@ func (sm *ServicesManager) getServices() ServiceList { } services[uid] = tList } - return services -} - -// triggerServiceTracking triggers the tracking of services. Is it called when a -// service is added or removed. -func (sm *ServicesManager) triggerServiceTracking() { - sm.Mutex.Lock() - if len(sm.trackers) == 0 { - return - } - services := sm.GetServices() sm.Mutex.Unlock() for _, callback := range sm.trackers { diff --git a/cmix/message/serviceTracker_test.go b/cmix/message/serviceTracker_test.go index c7b06b46a..a1a487762 100644 --- a/cmix/message/serviceTracker_test.go +++ b/cmix/message/serviceTracker_test.go @@ -13,7 +13,7 @@ import ( func TestServiceList_Marshal_UnmarshalJSON(t *testing.T) { var sl ServiceList = make(map[id.ID][]Service) - numServices := 10 + numServices := 3 testString := "test" for i := 0; i < numServices; i++ { uid := id.NewIdFromUInt(uint64(i), id.User, t) @@ -24,6 +24,8 @@ func TestServiceList_Marshal_UnmarshalJSON(t *testing.T) { t.Errorf(err.Error()) } + t.Logf("%s", jsonResult) + sl = make(map[id.ID][]Service) err = sl.UnmarshalJSON(jsonResult) if err != nil { -- GitLab