diff --git a/inc_internal/zt_internal.h b/inc_internal/zt_internal.h index a014ae05..da18ce75 100644 --- a/inc_internal/zt_internal.h +++ b/inc_internal/zt_internal.h @@ -180,7 +180,6 @@ struct ziti_ctx { model_map channels; LIST_HEAD(conns, ziti_conn) connections; - uv_async_t connect_async; uint32_t conn_seq; /* options */ @@ -198,8 +197,6 @@ struct ziti_ctx { extern "C" { #endif -int ziti_process_connect_reqs(ziti_context ztx); - int ziti_close_channels(ziti_context ztx); int ziti_channel_connect(ziti_context ztx, const char *name, const char *url, ch_connect_cb, void *ctx); diff --git a/library/connect.c b/library/connect.c index 87fed9d2..20eb9ffd 100644 --- a/library/connect.c +++ b/library/connect.c @@ -1025,12 +1025,6 @@ int ziti_accept(ziti_connection conn, ziti_conn_cb cb, ziti_data_cb data_cb) { return ZITI_OK; } -int ziti_process_connect_reqs(ziti_context ztx) { - ZITI_LOG(WARN, "TODO"); - - return ZITI_OK; -} - static int send_fin_message(ziti_connection conn) { ziti_channel_t *ch = conn->channel; int32_t conn_id = htole32(conn->conn_id); diff --git a/library/ziti.c b/library/ziti.c index a17ef21a..ee000747 100644 --- a/library/ziti.c +++ b/library/ziti.c @@ -59,6 +59,8 @@ static void version_cb(ziti_version *v, ziti_error *err, void *ctx); static void session_cb(ziti_session *session, ziti_error *err, void *ctx); +static void ziti_init_async(uv_async_t *ar); + static void grim_reaper(uv_prepare_t *p); #define CONN_STATES(XX) \ @@ -130,7 +132,6 @@ static int parse_getopt(const char *q, const char *opt, char *out, size_t maxout static void async_connects(uv_async_t *ar) { ziti_context ztx = ar->data; - ziti_process_connect_reqs(ztx); } int load_tls(ziti_config *cfg, tls_context **ctx) { @@ -179,16 +180,6 @@ int ziti_init_opts(ziti_options *options, uv_loop_t *loop, void *init_ctx) { ziti_log_init(loop, ZITI_LOG_DEFAULT_LEVEL, NULL); metrics_init(loop, 5); - uv_timeval64_t start_time; - uv_gettimeofday(&start_time); - - char time_str[32]; - ziti_fmt_time(time_str, sizeof(time_str), &start_time); - - ZITI_LOG(INFO, "Ziti C SDK version %s @%s(%s) starting at (%s.%03d)", - ziti_get_build_version(false), ziti_git_commit(), ziti_git_branch(), - time_str, start_time.tv_usec / 1000); - PREP(ziti); if (options->config == NULL && (options->controller == NULL || options->tls == NULL)) { @@ -216,10 +207,44 @@ int ziti_init_opts(ziti_options *options, uv_loop_t *loop, void *init_ctx) { ctx->loop = loop; ctx->ziti_timeout = ZITI_DEFAULT_TIMEOUT; - uv_async_init(loop, &ctx->connect_async, async_connects); - uv_unref((uv_handle_t *) &ctx->connect_async); + NEWP(init_req, struct ziti_init_req); + init_req->init_cb = options->init_cb; + init_req->init_ctx = init_ctx; + init_req->ztx = ctx; + + NEWP(async_init_req, uv_async_t); + uv_async_init(loop, async_init_req, ziti_init_async); + async_init_req->data = init_req; + + uv_async_send(async_init_req); + + CATCH(ziti) { + return ERR(ziti); + } + + return ZITI_OK; +} + +static void ziti_init_async(uv_async_t *ar) { + struct ziti_init_req *init_req = ar->data; + + ziti_context ctx = init_req->ztx; + uv_loop_t *loop = ar->loop; + + uv_close((uv_handle_t *) ar, (uv_close_cb) free); + + uv_timeval64_t start_time; + uv_gettimeofday(&start_time); + + char time_str[32]; + ziti_fmt_time(time_str, sizeof(time_str), &start_time); + + ZITI_LOG(INFO, "Ziti C SDK version %s @%s(%s) starting at (%s.%03d)", + ziti_get_build_version(false), ziti_git_commit(), ziti_git_branch(), + time_str, start_time.tv_usec / 1000); + - ziti_ctrl_init(loop, &ctx->controller, options->controller, ctx->tlsCtx); + ziti_ctrl_init(loop, &ctx->controller, ctx->opts->controller, ctx->tlsCtx); ziti_ctrl_get_version(&ctx->controller, version_cb, ctx); uv_timer_init(loop, &ctx->session_timer); @@ -237,17 +262,7 @@ int ziti_init_opts(ziti_options *options, uv_loop_t *loop, void *init_ctx) { uv_unref((uv_handle_t *) &ctx->reaper); uv_prepare_start(&ctx->reaper, grim_reaper); - NEWP(init_req, struct ziti_init_req); - init_req->init_cb = options->init_cb; - init_req->init_ctx = init_ctx; - init_req->ztx = ctx; ziti_ctrl_login(&ctx->controller, ctx->opts->config_types, session_cb, init_req); - - CATCH(ziti) { - return ERR(ziti); - } - - return ZITI_OK; } int ziti_init(const char *config, uv_loop_t *loop, ziti_init_cb init_cb, void *init_ctx) { @@ -290,6 +305,7 @@ int ziti_shutdown(ziti_context ztx) { ZITI_LOG(INFO, "Ziti is shutting down"); free_ziti_session(ztx->session); + free(ztx->session); ztx->session = NULL; uv_timer_stop(&ztx->refresh_timer); diff --git a/library/ziti_enroll.c b/library/ziti_enroll.c index 93335f6f..e389a5dc 100644 --- a/library/ziti_enroll.c +++ b/library/ziti_enroll.c @@ -37,11 +37,6 @@ static void well_known_certs_cb(char *base64_encoded_pkcs7, ziti_error *err, voi static void enroll_cb(ziti_enrollment_resp *er, ziti_error *err, void *ctx); -static void async_connects(uv_async_t *ar) { - ziti_context ztx = ar->data; - ziti_process_connect_reqs(ztx); -} - int verify_controller_jwt(tls_cert cert, void *ctx) { ZITI_LOG(INFO, "verifying JWT signature");