From 83f0b36c689a1dab6d8069a97ffebbf4274778ff Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 20 Jan 2021 16:37:15 -0500 Subject: [PATCH] use callback to process status change --- service/cziti/sdk.go | 14 ++++++-------- service/ziti-tunnel/service/state.go | 13 ++++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 324237d4..4e8a78bf 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -107,14 +107,14 @@ type ZIdentity struct { Services sync.Map Fingerprint string Active bool - StatusChanges chan int + StatusChanges func(int) } -func NewZid() *ZIdentity { +func NewZid(statusChange func(int)) *ZIdentity { zid := &ZIdentity{} zid.Services = sync.Map{} zid.Options = (*C.ziti_options)(C.calloc(1, C.sizeof_ziti_options)) - zid.StatusChanges = make(chan int) + zid.StatusChanges = statusChange return zid } @@ -390,7 +390,7 @@ func zitiContextEvent(nf C.ziti_context, status C.int, data unsafe.Pointer) { } else { log.Errorf("zitiContextEvent failed to connect[%s] to controller for %s", zid.statusErr, cfg) } - zid.StatusChanges <- int(status) + zid.StatusChanges(int(status)) } func zitiError(code C.int) error { @@ -400,8 +400,8 @@ func zitiError(code C.int) error { return nil } -func LoadZiti(cfg string, isActive bool) *ZIdentity { - zid := NewZid() +func LoadZiti(zid *ZIdentity, cfg string, isActive bool) { + //zid := NewZid() zid.Active = isActive @@ -428,8 +428,6 @@ func LoadZiti(cfg string, isActive bool) *ZIdentity { log.Debugf("successfully loaded identity from config file: %s", cfg) } }() - - return zid } //export free_async diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index c0788c28..9ecae7d4 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -239,10 +239,9 @@ func (t *RuntimeState) LoadIdentity(id *Id) { } log.Infof("loading identity %s[%s]", id.Name, id.FingerPrint) - id.CId = cziti.LoadZiti(id.Path(), id.Active) - go func(){ - statusChange := <- id.CId.StatusChanges //wait for the response - log.Infof("status change! %d", statusChange) + + sc := func(status int){ + log.Infof("status change! %d", status) id.ControllerVersion = id.CId.Version id.CId.Fingerprint = id.FingerPrint @@ -267,7 +266,11 @@ func (t *RuntimeState) LoadIdentity(id *Id) { Id: id.Identity, } log.Infof("connecting identity completed: %s[%s]", id.Name, id.FingerPrint) - }() + } + + id.CId = cziti.NewZid(sc) + + cziti.LoadZiti(id.CId, id.Path(), id.Active) } func (t *RuntimeState) LoadConfig() {