diff --git a/library/model_support.c b/library/model_support.c index 4b94a838..fd3d62d5 100644 --- a/library/model_support.c +++ b/library/model_support.c @@ -55,8 +55,8 @@ jsmntok_t* parse_tokens(jsmn_parser *parser, const char *json, size_t len, size_ int rc = jsmn_parse(parser, json, len, toks, tok_cap); while (rc == JSMN_ERROR_NOMEM) { - toks = realloc(toks,(tok_cap *= 2) * sizeof(jsmntok_t)); - ZITI_LOG(VERBOSE, "reallocating token array, new size = %zd", tok_cap); + toks = realloc(toks, (tok_cap *= 2) * sizeof(jsmntok_t)); + ZITI_LOG(TRACE, "reallocating token array, new size = %zd", tok_cap); rc = jsmn_parse(parser, json, len, toks, tok_cap); } diff --git a/library/ziti.c b/library/ziti.c index 6a08a42d..03908c26 100644 --- a/library/ziti.c +++ b/library/ziti.c @@ -56,6 +56,8 @@ struct ziti_init_req { int code_to_error(const char *code); +static void services_refresh(uv_timer_t *t); + static void version_cb(ziti_version *v, ziti_error *err, void *ctx); static void session_cb(ziti_session *session, ziti_error *err, void *ctx); @@ -502,8 +504,14 @@ static void session_refresh(uv_timer_t *t) { struct ziti_init_req *req = calloc(1, sizeof(struct ziti_init_req)); req->ztx = ztx; - ZITI_LOG(DEBUG, "refreshing API session"); - ziti_ctrl_current_api_session(&ztx->controller, session_cb, req); + if (ztx->session) { + ZITI_LOG(DEBUG, "refreshing API session"); + ziti_ctrl_current_api_session(&ztx->controller, session_cb, req); + } + else { + ZITI_LOG(DEBUG, "requesting new API session"); + ziti_ctrl_login(&ztx->controller, ztx->opts->config_types, session_cb, req); + } } void ziti_force_session_refresh(ziti_context ztx) { @@ -538,6 +546,11 @@ static void update_services(ziti_service_array services, ziti_error *error, ziti return; } + // schedule next refresh + if (ztx->opts->refresh_interval > 0) { + ZITI_LOG(VERBOSE, "scheduling service refresh %ld seconds from now", ztx->opts->refresh_interval); + uv_timer_start(&ztx->refresh_timer, services_refresh, ztx->opts->refresh_interval * 1000, 0); + } ZITI_LOG(VERBOSE, "processing service updates"); model_map updates = {0}; @@ -644,7 +657,7 @@ static void session_cb(ziti_session *session, ziti_error *err, void *ctx) { if (ztx->opts->refresh_interval > 0 && !uv_is_active((const uv_handle_t *) &ztx->refresh_timer)) { ZITI_LOG(DEBUG, "refresh_interval set to %ld seconds", ztx->opts->refresh_interval); - uv_timer_start(&ztx->refresh_timer, services_refresh, 0, ztx->opts->refresh_interval * 1000); + services_refresh(&ztx->refresh_timer); } else if (ztx->opts->refresh_interval == 0) { ZITI_LOG(DEBUG, "refresh_interval not specified");