diff --git a/inc_internal/zt_internal.h b/inc_internal/zt_internal.h index 14c1458b..745bc475 100644 --- a/inc_internal/zt_internal.h +++ b/inc_internal/zt_internal.h @@ -260,6 +260,7 @@ struct ziti_ctx { uv_timeval64_t session_received_at; ziti_identity_data *identity_data; + bool services_loaded; // map model_map services; // map diff --git a/library/ziti.c b/library/ziti.c index d7d2aff9..cad1250f 100644 --- a/library/ziti.c +++ b/library/ziti.c @@ -787,16 +787,16 @@ static void set_service_flags(ziti_service *s) { static void service_cb(ziti_service *s, const ziti_error *err, void *ctx) { struct service_req_s *req = ctx; - int rc = err ? err->err : ZITI_OK; + int rc = ZITI_SERVICE_UNAVAILABLE; if (s != NULL) { set_service_flags(s); ziti_service *old = model_map_set(&req->ztx->services, s->name, s); free_ziti_service_ptr(old); - } - else { - if (rc == ZITI_NOT_FOUND) { - rc = ZITI_SERVICE_UNAVAILABLE; + rc = ZITI_OK; + } else { + if (err) { + rc = err->err; } } @@ -1188,9 +1188,11 @@ static void update_services(ziti_service_array services, const ziti_error *error model_map_set(&ztx->services, s->name, s); } - if (addIdx > 0 || remIdx > 0 || chIdx > 0) { - ZTX_LOG(DEBUG, "sending service event %zd added, %zd removed, %zd changed", addIdx, remIdx, chIdx); + if (!ztx->services_loaded || (addIdx + remIdx + chIdx) > 0) { + ZTX_LOG(DEBUG, "sending service event initial[%s] %zd added, %zd removed, %zd changed", + ztx->services_loaded ? "false" : "true", addIdx, remIdx, chIdx); ziti_send_event(ztx, &ev); + ztx->services_loaded = true; } else { ZTX_LOG(VERBOSE, "no services added, changed, or removed"); } diff --git a/programs/sample-bridge/ziti-fd-client.c b/programs/sample-bridge/ziti-fd-client.c index e3075223..6a599db3 100644 --- a/programs/sample-bridge/ziti-fd-client.c +++ b/programs/sample-bridge/ziti-fd-client.c @@ -1,4 +1,4 @@ -// Copyright (c) 2022. NetFoundry Inc. +// Copyright (c) 2022-2023. NetFoundry Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) { long rc = service ? Ziti_connect(socket, ztx, service, "ziggy") : Ziti_connect_addr(socket, hostname, port); if (rc != 0) { - fprintf(stderr, "failed to connect: %ld(%s)\n", rc, ziti_errorstr(rc)); + fprintf(stderr, "failed to connect: %ld(%s)\n", rc, ziti_errorstr(Ziti_last_error())); goto DONE; }