Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename ziti_net_session to ziti_session #618

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions inc_internal/internal_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions inc_internal/ziti_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions inc_internal/zt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -279,7 +279,7 @@ struct ziti_ctx {
bool services_loaded;
// map<name,ziti_service>
model_map services;
// map<service_id,ziti_net_session>
// map<service_id,ziti_session>
model_map sessions;

// map<service_id,*bool>
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions library/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
32 changes: 11 additions & 21 deletions library/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
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;

Expand Down Expand Up @@ -142,22 +142,13 @@
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);
}

Expand Down Expand Up @@ -393,7 +384,7 @@
}
}

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);
Expand Down Expand Up @@ -466,7 +457,7 @@
}
}

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;
Expand All @@ -486,11 +477,11 @@
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 {
Expand All @@ -506,8 +497,7 @@
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
Expand Down Expand Up @@ -895,7 +885,7 @@
}
}

CATCH(crypto) {

Check warning on line 888 in library/connect.c

View workflow job for this annotation

GitHub Actions / Windows x86_64

unreachable code [D:\a\ziti-sdk-c\ziti-sdk-c\build\library\ziti.vcxproj]

Check warning on line 888 in library/connect.c

View workflow job for this annotation

GitHub Actions / Windows ARM64

unreachable code [D:\a\ziti-sdk-c\ziti-sdk-c\build\library\ziti.vcxproj]
FREE(plain_text);
conn_set_state(conn, Disconnected);
conn->data_cb(conn, NULL, ZITI_CRYPTO_FAIL);
Expand Down Expand Up @@ -954,7 +944,7 @@
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
Expand All @@ -963,7 +953,7 @@
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);
Expand Down Expand Up @@ -1011,7 +1001,7 @@

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) {
Expand All @@ -1029,7 +1019,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion library/internal_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

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)

Expand Down Expand Up @@ -269,7 +269,7 @@

addr->type = ziti_address_cidr;
if (inet_pton(AF_INET, ip, (struct in_addr *) &addr->addr.cidr.ip) == 1) {
if ((bits = slash ? bits : 32) > 32)

Check warning on line 272 in library/internal_model.c

View workflow job for this annotation

GitHub Actions / Windows x86_64

potentially uninitialized local variable 'bits' used [D:\a\ziti-sdk-c\ziti-sdk-c\build\library\ziti.vcxproj]

Check warning on line 272 in library/internal_model.c

View workflow job for this annotation

GitHub Actions / Windows ARM64

potentially uninitialized local variable 'bits' used [D:\a\ziti-sdk-c\ziti-sdk-c\build\library\ziti.vcxproj]
goto invalid_cidr;
addr->addr.cidr.af = AF_INET;
addr->addr.cidr.bits = bits;
Expand Down
26 changes: 13 additions & 13 deletions library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@
ziti_context ctx = NULL;
PREPF(ziti, ziti_errorstr);

if (options->config == NULL) {

Check warning on line 210 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux ARM64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]

Check warning on line 210 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux x86_64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]
ZITI_LOG(ERROR, "config or controller/tls has to be set");
return ZITI_INVALID_CONFIG;
}
ctx = calloc(1, sizeof(*ctx));

if (options->config != NULL) {

Check warning on line 216 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux ARM64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]

Check warning on line 216 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux x86_64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]
TRY(ziti, ziti_load_config(&ctx->config, options->config));

Check warning on line 217 in library/ziti.c

View workflow job for this annotation

GitHub Actions / Linux x86_64

'config' is deprecated: ignored, will be removed [-Wdeprecated-declarations]
}

if (ctx->config.id.ca && strncmp(ctx->config.id.ca, "file://", strlen("file://")) == 0) {
Expand Down Expand Up @@ -338,7 +338,7 @@

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) {
Expand Down Expand Up @@ -381,9 +381,9 @@

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);
Expand Down Expand Up @@ -546,7 +546,7 @@
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);
Expand Down Expand Up @@ -675,7 +675,7 @@
}

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);
}
Expand Down Expand Up @@ -953,7 +953,7 @@
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);
Expand Down Expand Up @@ -1172,9 +1172,9 @@
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);
Expand Down Expand Up @@ -1677,22 +1677,22 @@
}
}

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
Expand All @@ -1702,7 +1702,7 @@
}
}

free_ziti_net_session(session);
free_ziti_session(session);
FREE(session);
}

Expand Down
Loading
Loading