diff --git a/service/build.bat b/service/build.bat index ce595fe8..35349264 100644 --- a/service/build.bat +++ b/service/build.bat @@ -14,7 +14,7 @@ REM See the License for the specific language governing permissions and REM limitations under the License. REM SET REPO_URL=https://github.com/openziti/ziti-tunnel-sdk-c.git -SET ZITI_TUNNEL_REPO_BRANCH=v0.7.34 +SET ZITI_TUNNEL_REPO_BRANCH=v0.8.3 REM override the c sdk used in the build - leave blank for the same as specified in the tunneler sdk SET ZITI_SDK_C_BRANCH= REM the number of TCP connections the tunneler sdk can have at any one time diff --git a/service/cziti/dns.go b/service/cziti/dns.go index b7ce7a0a..9a4f6292 100644 --- a/service/cziti/dns.go +++ b/service/cziti/dns.go @@ -186,7 +186,6 @@ func (dns *dnsImpl) RegisterService(svcId string, dnsNameToReg string, port uint ip: ip, ctx: zid, network: currentNetwork, - dnsEnabled: zid.Active, refCount: 1, } log.Infof("mapping hostname %s to ip %s as dns %s", dnsNameToReg, ip.String(), icept.AsDnsName()) diff --git a/service/cziti/sdk.c b/service/cziti/sdk.c index d376131a..3b63d5c0 100644 --- a/service/cziti/sdk.c +++ b/service/cziti/sdk.c @@ -93,5 +93,5 @@ struct ziti_service_event* ziti_event_service_event(ziti_event_t *ev) { } ziti_service* ziti_service_array_get(ziti_service_array arr, int idx) { - return arr[idx]; + return arr ? arr[idx] : NULL; } diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 95217125..49dcc99a 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -106,7 +106,6 @@ type ZIdentity struct { Version string Services sync.Map Fingerprint string - Active bool StatusChanges func(int) } @@ -123,7 +122,7 @@ func (c *ZIdentity) GetMetrics() (int64, int64, bool) { return 0, 0, false } if C.is_null(unsafe.Pointer(c.czctx)) { - log.Debugf("ziti context is C.NULL? is the identity initialized? %s", c.Fingerprint) + log.Debugf("ziti context is still null. the identity is probably not initialized yet: %s", c.Fingerprint) return 0, 0, false } var up, down C.double @@ -316,7 +315,7 @@ func serviceUnavailable(ctx *ZIdentity, svcId string, name string) { //export eventCB func eventCB(ztx C.ziti_context, event *C.ziti_event_t) { appCtx := C.ziti_app_ctx(ztx) - log.Debugf("events received. type: %d for ztx(%p)", event._type, ztx) + log.Tracef("events received. type: %d for ztx(%p)", event._type, ztx) switch event._type { case C.ZitiContextEvent: @@ -348,7 +347,7 @@ func eventCB(ztx C.ziti_context, event *C.ziti_event_t) { log.Info("service removed ", C.GoString(s.name)) } for i := 0; true ; i++ { - s := C.ziti_service_array_get(srvEvent.changed, C.int(i)) + s := C.ziti_service_array_get(srvEvent.changed, C.int(i)) if unsafe.Pointer(s) == C.NULL { break } @@ -356,7 +355,7 @@ func eventCB(ztx C.ziti_context, event *C.ziti_event_t) { serviceCB(ztx, s, C.ZITI_OK, appCtx) } for i := 0; true ; i++ { - s := C.ziti_service_array_get(srvEvent.added, C.int(i)) + s := C.ziti_service_array_get(srvEvent.added, C.int(i)) if unsafe.Pointer(s) == C.NULL { break } @@ -400,13 +399,9 @@ func zitiError(code C.int) error { return nil } -func LoadZiti(zid *ZIdentity, cfg string, isActive bool) { - //zid := NewZid() - - zid.Active = isActive - +func LoadZiti(zid *ZIdentity, cfg string, refreshInterval int) { zid.Options.config = C.CString(cfg) - zid.Options.refresh_interval = C.long(300) + zid.Options.refresh_interval = C.long(refreshInterval) zid.Options.metrics_type = C.INSTANT zid.Options.config_types = C.all_configs zid.Options.pq_domain_cb = C.ziti_pq_domain_cb(C.ziti_pq_domain_go) @@ -419,15 +414,13 @@ func LoadZiti(zid *ZIdentity, cfg string, isActive bool) { ptr := unsafe.Pointer(zid) zid.Options.app_ctx = ptr - go func() { - rc := C.ziti_init_opts(zid.Options, _impl.libuvCtx.l) - if rc != C.ZITI_OK { - zid.status, zid.statusErr = int(rc), zitiError(rc) - log.Errorf("FAILED to load identity from config file: %s due to: %s", cfg, zid.statusErr) - } else { - log.Debugf("successfully loaded identity from config file: %s", cfg) - } - }() + rc := C.ziti_init_opts(zid.Options, _impl.libuvCtx.l) + if rc != C.ZITI_OK { + zid.status, zid.statusErr = int(rc), zitiError(rc) + log.Errorf("FAILED to load identity from config file: %s due to: %s", cfg, zid.statusErr) + } else { + log.Debugf("successfully loaded identity from config file: %s", cfg) + } } //export free_async diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 73eac1a4..07f948cf 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -738,6 +738,8 @@ func newIdentity(newId dto.AddIdentity, out *json.Encoder) { }, } + rts.ids[id.FingerPrint] = id + connectIdentity(id) state := rts.state @@ -764,7 +766,7 @@ func connectIdentity(id *Id) { log.Infof("connecting identity: %s[%s]", id.Name, id.FingerPrint) if id.CId == nil || !id.CId.Loaded { - rts.LoadIdentity(id) + rts.LoadIdentity(id, DEFAULT_REFRESH_INTERVAL) } else { log.Debugf("%s[%s] is already loaded", id.Name, id.FingerPrint) diff --git a/service/ziti-tunnel/service/pkg-vars.go b/service/ziti-tunnel/service/pkg-vars.go index fcb54571..b867f5c6 100644 --- a/service/ziti-tunnel/service/pkg-vars.go +++ b/service/ziti-tunnel/service/pkg-vars.go @@ -55,6 +55,8 @@ const ( ERROR_DISCONNECTING_ID = 50 IDENTITY_NOT_FOUND = 1000 + DEFAULT_REFRESH_INTERVAL = 300 + cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue InformationEvent = 0 //1 diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index 9ecae7d4..189fefb9 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -226,7 +226,7 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) (net.IP, *tun.Device return ip, t.tun, nil } -func (t *RuntimeState) LoadIdentity(id *Id) { +func (t *RuntimeState) LoadIdentity(id *Id, refreshInterval int) { if id.CId != nil && id.CId.Loaded { log.Warnf("id %s[%s] already connected", id.Name, id.FingerPrint) return @@ -270,7 +270,7 @@ func (t *RuntimeState) LoadIdentity(id *Id) { id.CId = cziti.NewZid(sc) - cziti.LoadZiti(id.CId, id.Path(), id.Active) + cziti.LoadZiti(id.CId, id.Path(), refreshInterval) } func (t *RuntimeState) LoadConfig() { @@ -278,7 +278,10 @@ func (t *RuntimeState) LoadConfig() { if err != nil { err = readConfig(t, config.BackupFile()) if err != nil { - log.Panicf("config file is not valid nor is backup file!") + //this means BOTH files are unusable. that's really bad... :( delete both files and then panic... + os.Remove(config.File()) + os.Remove(config.BackupFile()) + log.Panicf("config file is not valid nor is backup file! both files have been deleted.") } }