use callback to process status change

This commit is contained in:
dovholuknf
2021-01-20 16:37:15 -05:00
parent aaa7334a0d
commit 83f0b36c68
2 changed files with 14 additions and 13 deletions
+6 -8
View File
@@ -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
+8 -5
View File
@@ -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() {