Skip to content

Commit

Permalink
Merge pull request #208 from openziti/merge-0.18.7
Browse files Browse the repository at this point in the history
Merge 0.18.7
  • Loading branch information
ekoby authored Dec 23, 2020
2 parents 6ee97bd + ce49637 commit b9f84e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(FetchContent)

FetchContent_Declare(uv-mbed
GIT_REPOSITORY https://github.com/netfoundry/uv-mbed.git
GIT_TAG v0.11.0
GIT_TAG v0.11.1
)
set(ENABLE_UM_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(uv-mbed)
Expand Down
4 changes: 2 additions & 2 deletions library/model_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
20 changes: 17 additions & 3 deletions library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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);
Expand Down Expand Up @@ -461,8 +463,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) {
Expand Down Expand Up @@ -498,6 +506,11 @@ static void update_services(ziti_service_array services, ziti_error *error, void
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};
Expand Down Expand Up @@ -627,7 +640,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");
uv_timer_stop(&ztx->refresh_timer);
Expand Down Expand Up @@ -681,6 +694,7 @@ static void session_cb(ziti_session *session, ziti_error *err, void *ctx) {
} else {
uv_timer_start(&ztx->session_timer, session_refresh, 5 * 1000, 0);
}

} else {
ZITI_LOG(ERROR, "%s: no session or error received", ziti_errorstr(ZITI_WTF));
}
Expand Down

0 comments on commit b9f84e8

Please sign in to comment.