diff --git a/inc_internal/internal_model.h b/inc_internal/internal_model.h index b9141963..78e754b8 100644 --- a/inc_internal/internal_model.h +++ b/inc_internal/internal_model.h @@ -32,10 +32,9 @@ XX(name, string, none, name, __VA_ARGS__)\ XX(hostname, string, none, hostname, __VA_ARGS__) \ XX(protocols, string, map, supportedProtocols, __VA_ARGS__) -#define ZITI_NET_SESSION_MODEL(XX, ...) \ +#define ZITI_SESSION_MODEL(XX, ...) \ XX(token, string, none, token, __VA_ARGS__)\ XX(id, string, none, id, __VA_ARGS__) \ -XX(session_type, string, none, type, __VA_ARGS__) \ XX(edge_routers, ziti_edge_router, list, edgeRouters, __VA_ARGS__) \ XX(service_id, string, none, NULL, __VA_ARGS__) @@ -190,7 +189,7 @@ DECLARE_MODEL(ziti_identity_data, ZITI_IDENTITY_DATA_MODEL) DECLARE_MODEL(ziti_edge_router, ZITI_EDGE_ROUTER_MODEL) -DECLARE_MODEL(ziti_net_session, ZITI_NET_SESSION_MODEL) +DECLARE_MODEL(ziti_session, ZITI_SESSION_MODEL) DECLARE_MODEL(ziti_api_session, ZITI_API_SESSION_MODEL) diff --git a/inc_internal/ziti_ctrl.h b/inc_internal/ziti_ctrl.h index a3b9fb78..fb3f684d 100644 --- a/inc_internal/ziti_ctrl.h +++ b/inc_internal/ziti_ctrl.h @@ -90,14 +90,14 @@ void ziti_ctrl_get_service(ziti_controller *ctrl, const char *service_name, void ziti_ctrl_create_session( ziti_controller *ctrl, const char *service_id, ziti_session_type type, - void (*cb)(ziti_net_session *, const ziti_error *, void *), void *ctx); + void (*cb)(ziti_session *, const ziti_error *, void *), void *ctx); void ziti_ctrl_get_session( ziti_controller *ctrl, const char *session_id, - void (*cb)(ziti_net_session *, const ziti_error *, void *), void *ctx); + void (*cb)(ziti_session *, const ziti_error *, void *), void *ctx); void ziti_ctrl_get_sessions( - ziti_controller *ctrl, void (*cb)(ziti_net_session **, const ziti_error *, void *), void *ctx); + ziti_controller *ctrl, void (*cb)(ziti_session **, const ziti_error *, void *), void *ctx); void ziti_ctrl_get_well_known_certs(ziti_controller *ctrl, void (*cb)(char *, const ziti_error *, void *), void *ctx); diff --git a/inc_internal/zt_internal.h b/inc_internal/zt_internal.h index 51f90aa0..6a225f3d 100644 --- a/inc_internal/zt_internal.h +++ b/inc_internal/zt_internal.h @@ -184,7 +184,7 @@ struct ziti_conn { ziti_listen_cb listen_cb; ziti_client_cb client_cb; - ziti_net_session *session; + ziti_session *session; model_map bindings; model_map children; uv_timer_t *timer; @@ -279,7 +279,7 @@ struct ziti_ctx { bool services_loaded; // map model_map services; - // map + // map model_map sessions; // map @@ -320,10 +320,10 @@ struct ziti_ctx { extern "C" { #endif -bool ziti_is_session_valid(ziti_context ztx, ziti_net_session *session, const char *service_id, ziti_session_type type); +bool ziti_is_session_valid(ziti_context ztx, ziti_session *session, const char *service_id, ziti_session_type type); void -ziti_invalidate_session(ziti_context ztx, ziti_net_session *session, const char *service_id, ziti_session_type type); +ziti_invalidate_session(ziti_context ztx, ziti_session *session, const char *service_id, ziti_session_type type); void ziti_on_channel_event(ziti_channel_t *ch, ziti_router_status status, ziti_context ztx); diff --git a/library/bind.c b/library/bind.c index ae64093f..dae514e4 100644 --- a/library/bind.c +++ b/library/bind.c @@ -51,7 +51,7 @@ static void stop_binding(struct binding_s *b); static void schedule_rebind(struct ziti_conn *conn, bool now); -static void session_cb(ziti_net_session *session, const ziti_error *err, void *ctx); +static void session_cb(ziti_session *session, const ziti_error *err, void *ctx); static void notify_status(struct ziti_conn *conn, int err); @@ -109,7 +109,7 @@ static struct binding_s* new_binding(struct ziti_conn *conn) { } static void process_bindings(struct ziti_conn *conn) { - ziti_net_session *ns = conn->server.session; + ziti_session *ns = conn->server.session; struct ziti_ctx *ztx = conn->ziti_ctx; size_t target = MIN(conn->server.max_bindings, model_map_size(&ztx->channels)); @@ -172,16 +172,16 @@ static void schedule_rebind(struct ziti_conn *conn, bool now) { } -static void session_cb(ziti_net_session *session, const ziti_error *err, void *ctx) { +static void session_cb(ziti_session *session, const ziti_error *err, void *ctx) { struct ziti_conn *conn = ctx; int e = err ? err->err : ZITI_OK; switch (e) { case ZITI_OK: { - ziti_net_session *old = conn->server.session; + ziti_session *old = conn->server.session; conn->server.session = session; notify_status(conn, ZITI_OK); - free_ziti_net_session_ptr(old); + free_ziti_session_ptr(old); process_bindings(conn); break; @@ -197,7 +197,7 @@ static void session_cb(ziti_net_session *session, const ziti_error *err, void *c // our session is stale if (conn->server.session) { - free_ziti_net_session_ptr(conn->server.session); + free_ziti_session_ptr(conn->server.session); conn->server.session = NULL; schedule_rebind(conn, true); } else { @@ -290,7 +290,7 @@ static int dispose(ziti_connection server) { server->server.timer = NULL; } - free_ziti_net_session_ptr(server->server.session); + free_ziti_session_ptr(server->server.session); free(server->service); free(server); return 1; @@ -421,7 +421,7 @@ static void bind_reply_cb(void *ctx, message *msg, int code) { void start_binding(struct binding_s *b, ziti_channel_t *ch) { struct ziti_conn *conn = b->conn; - ziti_net_session *s = conn->server.session; + ziti_session *s = conn->server.session; CONN_LOG(TRACE, "ch[%d] => Edge Bind request token[%s]", ch->id, s->token); b->ch = ch; @@ -553,7 +553,7 @@ static void stop_binding(struct binding_s *b) { return; } - ziti_net_session *s = b->conn->server.session; + ziti_session *s = b->conn->server.session; if (s == NULL) { return; } diff --git a/library/connect.c b/library/connect.c index 6f771b0f..bb3839e1 100644 --- a/library/connect.c +++ b/library/connect.c @@ -65,7 +65,7 @@ struct local_hash { struct ziti_conn_req { ziti_session_type session_type; char *service_id; - ziti_net_session *session; + ziti_session *session; ziti_conn_cb cb; ziti_dial_opts dial_opts; @@ -142,22 +142,13 @@ static ziti_listen_opts *clone_ziti_listen_opts(const ziti_listen_opts *ln_opts) return c; } -static void free_ziti_listen_opts(ziti_listen_opts *ln_opts) { - if (ln_opts == NULL) { - ZITI_LOG(TRACE, "refuse to free NULL listen_opts"); - return; - } - FREE(ln_opts->identity); - free(ln_opts); -} - static void free_conn_req(struct ziti_conn_req *r) { if (r->conn_timeout != NULL) { uv_close((uv_handle_t *) r->conn_timeout, free_handle); } if (r->session_type == ziti_session_types.Bind && r->session) { - free_ziti_net_session(r->session); + free_ziti_session(r->session); FREE(r->session); } @@ -393,7 +384,7 @@ static void connect_timeout(uv_timer_t *timer) { } } -static int ziti_connect(struct ziti_ctx *ztx, ziti_net_session *session, struct ziti_conn *conn) { +static int ziti_connect(struct ziti_ctx *ztx, ziti_session *session, struct ziti_conn *conn) { // verify ziti context is still authorized if (ztx->api_session == NULL) { CONN_LOG(ERROR, "ziti context is not authenticated, cannot connect to service[%s]", conn->service); @@ -466,7 +457,7 @@ static void connect_get_service_cb(ziti_context ztx, ziti_service *s, int status } } -static void connect_get_net_session_cb(ziti_net_session *s, const ziti_error *err, void *ctx) { +static void connect_get_net_session_cb(ziti_session *s, const ziti_error *err, void *ctx) { struct ziti_conn *conn = ctx; struct ziti_conn_req *req = conn->conn_req; struct ziti_ctx *ztx = conn->ziti_ctx; @@ -486,11 +477,11 @@ static void connect_get_net_session_cb(ziti_net_session *s, const ziti_error *er req->session = s; s->service_id = strdup(req->service_id); if (req->session_type == ziti_session_types.Dial) { - ziti_net_session *existing = model_map_get(&ztx->sessions, req->service_id); + ziti_session *existing = model_map_get(&ztx->sessions, req->service_id); // this happens with concurrent connection requests for the same service (common with browsers) if (existing) { CONN_LOG(DEBUG, "found session[%s] for service[%s]", existing->id, conn->service); - free_ziti_net_session(s); + free_ziti_session(s); free(s); req->session = existing; } else { @@ -506,8 +497,7 @@ static void process_connect(struct ziti_conn *conn) { struct ziti_conn_req *req = conn->conn_req; struct ziti_ctx *ztx = conn->ziti_ctx; uv_loop_t *loop = ztx->loop; - - + // find service if (req->service_id == NULL) { // connect_get_service_cb will re-enter process_connect() if service is already cached in the context @@ -954,7 +944,7 @@ void connect_reply_cb(void *ctx, message *msg, int err) { if (strncmp(INVALID_SESSION, (const char *) msg->body, msg->header.body_len) == 0) { CONN_LOG(WARN, "session for service[%s] became invalid", conn->service); if (conn->conn_req->session_type == ziti_session_types.Dial) { - ziti_net_session *s = model_map_get(&conn->ziti_ctx->sessions, req->service_id); + ziti_session *s = model_map_get(&conn->ziti_ctx->sessions, req->service_id); if (s != req->session) { // already removed or different one // req reference is no longer valid @@ -963,7 +953,7 @@ void connect_reply_cb(void *ctx, message *msg, int err) { model_map_remove(&conn->ziti_ctx->sessions, req->service_id); } } - free_ziti_net_session(req->session); + free_ziti_session(req->session); FREE(req->session); ziti_channel_rem_receiver(conn->channel, conn->conn_id); @@ -1011,7 +1001,7 @@ void connect_reply_cb(void *ctx, message *msg, int err) { static int ziti_channel_start_connection(struct ziti_conn *conn, ziti_channel_t *ch) { struct ziti_conn_req *req = conn->conn_req; - ziti_net_session *s = req->session; + ziti_session *s = req->session; uint32_t content_type; switch (conn->state) { @@ -1029,7 +1019,7 @@ static int ziti_channel_start_connection(struct ziti_conn *conn, ziti_channel_t if (!ziti_is_session_valid(conn->ziti_ctx, s, req->service_id, req->session_type)) { CONN_LOG(DEBUG, "session is no longer valid"); if (req->session_type == ziti_session_types.Bind) { - free_ziti_net_session(req->session); + free_ziti_session(req->session); FREE(req->session); } req->session = NULL; diff --git a/library/internal_model.c b/library/internal_model.c index 6fc9bbe4..cfa49efe 100644 --- a/library/internal_model.c +++ b/library/internal_model.c @@ -71,7 +71,7 @@ IMPL_MODEL(ziti_config, ZITI_CONFIG_MODEL) IMPL_MODEL(ziti_edge_router, ZITI_EDGE_ROUTER_MODEL) -IMPL_MODEL(ziti_net_session, ZITI_NET_SESSION_MODEL) +IMPL_MODEL(ziti_session, ZITI_SESSION_MODEL) IMPL_MODEL(api_path, ZITI_API_PATH_MODEL) diff --git a/library/ziti.c b/library/ziti.c index 1a809273..284890d4 100644 --- a/library/ziti.c +++ b/library/ziti.c @@ -338,7 +338,7 @@ static void logout_cb(void *resp, const ziti_error *err, void *ctx) { ziti_close_channels(ztx, ZITI_DISABLED); - model_map_clear(&ztx->sessions, (_free_f) free_ziti_net_session_ptr); + model_map_clear(&ztx->sessions, (_free_f) free_ziti_session_ptr); model_map_clear(&ztx->services, (_free_f) free_ziti_service_ptr); if (ztx->closing) { @@ -381,9 +381,9 @@ static void ziti_stop_internal(ziti_context ztx, void *data) { model_map_iter it = model_map_iterator(&ztx->sessions); while (it) { - ziti_net_session *ns = model_map_it_value(it); + ziti_session *ns = model_map_it_value(it); it = model_map_it_remove(it); - free_ziti_net_session_ptr(ns); + free_ziti_session_ptr(ns); } // close all channels ziti_close_channels(ztx, ZITI_DISABLED); @@ -546,7 +546,7 @@ static void free_ztx(uv_handle_t *h) { ziti_auth_query_free(ztx->auth_queries); ziti_posture_checks_free(ztx->posture_checks); model_map_clear(&ztx->services, (_free_f) free_ziti_service_ptr); - model_map_clear(&ztx->sessions, (_free_f) free_ziti_net_session_ptr); + model_map_clear(&ztx->sessions, (_free_f) free_ziti_session_ptr); ziti_set_unauthenticated(ztx); free_ziti_identity_data(ztx->identity_data); FREE(ztx->identity_data); @@ -675,7 +675,7 @@ void ziti_dump(ziti_context ztx, int (*printer)(void *arg, const char *fmt, ...) } printer(ctx, "\n==================\nSessions:\n"); - ziti_net_session *sess; + ziti_session *sess; MODEL_MAP_FOREACH(name, sess, &ztx->sessions) { printer(ctx, "%s: service_id[%s]\n", sess->id, name); } @@ -953,7 +953,7 @@ void ziti_re_auth_with_cb(ziti_context ztx, void(*cb)(ziti_api_session *, const uv_timer_stop(ztx->posture_checks->timer); } - model_map_clear(&ztx->sessions, (_free_f) free_ziti_net_session_ptr); + model_map_clear(&ztx->sessions, (_free_f) free_ziti_session_ptr); FREE(ztx->last_update); model_list cfgs = {0}; model_list_append(&cfgs, ZITI_INTERCEPT_CFG_V1); @@ -1172,9 +1172,9 @@ static void update_services(ziti_service_array services, const ziti_error *error s = model_map_it_value(it); ev.event.service.removed[remIdx++] = s; - ziti_net_session *session = model_map_remove(&ztx->sessions, s->id); + ziti_session *session = model_map_remove(&ztx->sessions, s->id); if (session) { - free_ziti_net_session(session); + free_ziti_session(session); free(session); } it = model_map_it_remove(it); @@ -1677,22 +1677,22 @@ static void version_cb(ziti_version *v, const ziti_error *err, void *ctx) { } } -bool ziti_is_session_valid(ziti_context ztx, ziti_net_session *session, const char *service_id, ziti_session_type type) { +bool ziti_is_session_valid(ziti_context ztx, ziti_session *session, const char *service_id, ziti_session_type type) { if (session == NULL) return false; if (type == ziti_session_types.Bind) return true; - ziti_net_session *s = model_map_get(&ztx->sessions, service_id); + ziti_session *s = model_map_get(&ztx->sessions, service_id); return s == session; } -void ziti_invalidate_session(ziti_context ztx, ziti_net_session *session, const char *service_id, ziti_session_type type) { +void ziti_invalidate_session(ziti_context ztx, ziti_session *session, const char *service_id, ziti_session_type type) { if (session == NULL) { return; } if (type == ziti_session_types.Dial) { - ziti_net_session *s = model_map_get(&ztx->sessions, service_id); + ziti_session *s = model_map_get(&ztx->sessions, service_id); if (s != session) { // already removed or different one // passed reference is no longer valid @@ -1702,7 +1702,7 @@ void ziti_invalidate_session(ziti_context ztx, ziti_net_session *session, const } } - free_ziti_net_session(session); + free_ziti_session(session); FREE(session); } diff --git a/library/ziti_ctrl.c b/library/ziti_ctrl.c index 246e435c..12d65137 100644 --- a/library/ziti_ctrl.c +++ b/library/ziti_ctrl.c @@ -565,21 +565,21 @@ ziti_ctrl_get_service(ziti_controller *ctrl, const char *service_name, void (*cb void ziti_ctrl_get_session( ziti_controller *ctrl, const char *session_id, - void (*cb)(ziti_net_session *, const ziti_error *, void *), void *ctx) { + void (*cb)(ziti_session *, const ziti_error *, void *), void *ctx) { if (!verify_api_session(ctrl, (void (*)(void *, const ziti_error *, void *)) cb, ctx)) return; char req_path[128]; snprintf(req_path, sizeof(req_path), "/sessions/%s", session_id); - struct ctrl_resp *resp = MAKE_RESP(ctrl, cb, parse_ziti_net_session_ptr, ctx); + struct ctrl_resp *resp = MAKE_RESP(ctrl, cb, parse_ziti_session_ptr, ctx); tlsuv_http_req_t *req = start_request(ctrl->client, "GET", req_path, ctrl_resp_cb, resp); tlsuv_http_req_header(req, "Content-Type", "application/json"); } void ziti_ctrl_create_session( ziti_controller *ctrl, const char *service_id, ziti_session_type type, - void (*cb)(ziti_net_session *, const ziti_error *, void *), void *ctx) { + void (*cb)(ziti_session *, const ziti_error *, void *), void *ctx) { if (!verify_api_session(ctrl, (void (*)(void *, const ziti_error *, void *)) cb, ctx)) return; @@ -588,17 +588,17 @@ void ziti_ctrl_create_session( "{\"serviceId\": \"%s\", \"type\": \"%s\"}", service_id, ziti_session_types.name(type)); - struct ctrl_resp *resp = MAKE_RESP(ctrl, cb, parse_ziti_net_session_ptr, ctx); + struct ctrl_resp *resp = MAKE_RESP(ctrl, cb, parse_ziti_session_ptr, ctx); tlsuv_http_req_t *req = start_request(ctrl->client, "POST", "/sessions", ctrl_resp_cb, resp); tlsuv_http_req_header(req, "Content-Type", "application/json"); tlsuv_http_req_data(req, content, len, free_body_cb); } void ziti_ctrl_get_sessions( - ziti_controller *ctrl, void (*cb)(ziti_net_session **, const ziti_error *, void *), void *ctx) { + ziti_controller *ctrl, void (*cb)(ziti_session **, const ziti_error *, void *), void *ctx) { if(!verify_api_session(ctrl, (ctrl_resp_cb_t)cb, ctx)) return; - struct ctrl_resp *resp = MAKE_RESP(ctrl, cb, parse_ziti_net_session_array, ctx); + struct ctrl_resp *resp = MAKE_RESP(ctrl, cb, parse_ziti_session_array, ctx); resp->paging = true; resp->base_path = "/sessions"; ctrl_paging_req(resp); diff --git a/tests/ctrl_tests.cpp b/tests/ctrl_tests.cpp index 98adf0dd..2c943b6c 100644 --- a/tests/ctrl_tests.cpp +++ b/tests/ctrl_tests.cpp @@ -181,7 +181,7 @@ TEST_CASE("controller_test","[integ]") { auto ns = do_get2(ctrl, ziti_ctrl_create_session, (const char *) s->id, *s->permissions[0]); REQUIRE(ns != nullptr); REQUIRE(ns->token != nullptr); - free_ziti_net_session_ptr(ns); + free_ziti_session_ptr(ns); free_ziti_service_array(&services); } AND_THEN("logout should succeed") { diff --git a/tests/test_ziti_model.cpp b/tests/test_ziti_model.cpp index 92ecb2e3..77f0b0bc 100644 --- a/tests/test_ziti_model.cpp +++ b/tests/test_ziti_model.cpp @@ -165,8 +165,8 @@ TEST_CASE("multi-edge-router session", "[model]") { "token": "f49bbb5c-4623-4ae0-9e88-b6ea226434dc", "type": "Dial" })"; - ziti_net_session *s; - REQUIRE(parse_ziti_net_session_ptr(&s, session_json, (int) strlen(session_json)) == strlen(session_json)); + ziti_session *s; + REQUIRE(parse_ziti_session_ptr(&s, session_json, (int) strlen(session_json)) == strlen(session_json)); REQUIRE(model_list_size(&s->edge_routers) == 3); @@ -180,7 +180,7 @@ TEST_CASE("multi-edge-router session", "[model]") { tls = (const char *) model_map_get(&er->protocols, "tls"); REQUIRE_THAT(tls, Catch::Matchers::Matches("tls://cd938be5-bd0b-48b3-8db8-67e4bf62eb10.production.netfoundry.io:443")); - free_ziti_net_session(s); + free_ziti_session(s); free(s); }