pnoltes commented on code in PR #710: URL: https://github.com/apache/celix/pull/710#discussion_r1481926778
########## bundles/remote_services/topology_manager/src/topology_manager.c: ########## @@ -183,16 +253,318 @@ celix_status_t topologyManager_rsaAdding(void * handle, service_reference_pt ref return status; } -celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt unusedRef CELIX_UNUSED, void * service) { +static celix_array_list_t* topologyManager_getNetworkInterfacesForPort(topology_manager_t* tm, unsigned int port) { + celix_status_t status = CELIX_SUCCESS; + celix_array_list_t* ifNames = celix_longHashMap_get(tm->networkIfNames, port); + if (ifNames == NULL) { + char ifNamesKey[64]; + CELIX_BUILD_ASSERT(sizeof(ifNamesKey) >= (sizeof(CELIX_RSA_INTERFACES_OF_PORT_PREFIX) + 10));//10 is max int len + (void)snprintf(ifNamesKey, sizeof(ifNamesKey), "%s%u", CELIX_RSA_INTERFACES_OF_PORT_PREFIX, port); + const char* ifNamesStr = celix_bundleContext_getProperty(tm->context, ifNamesKey, NULL); + if (ifNamesStr == NULL) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error getting interface names from config properties."); + return NULL; + } + celix_autoptr(celix_array_list_t) _ifNames = celix_arrayList_create(); + if (_ifNames == NULL) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error creating array list for interface names."); + return NULL; + } + celix_autofree char* ifNamesStrCopy = celix_utils_strdup(ifNamesStr); + if (ifNamesStrCopy == NULL) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error copying interface names string."); + return NULL; + } + char* savePtr = NULL; + char* token = strtok_r(ifNamesStrCopy, ",", &savePtr); + while (token != NULL && status == CELIX_SUCCESS) { + celix_autofree char* ifname = celix_utils_strdup(token); + if (ifname == NULL) { + status = CELIX_ENOMEM; + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error copying interface name."); + continue; + } + status = celix_arrayList_add(_ifNames, ifname); + if (status != CELIX_SUCCESS) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error adding interface name to array list."); + continue; + } + celix_steal_ptr(ifname); + token = strtok_r(NULL, ",", &savePtr); + } + + CELIX_DO_IF(status, status = celix_longHashMap_put(tm->networkIfNames, port, _ifNames)); + + if (status != CELIX_SUCCESS) { + for (int i = 0; i < celix_arrayList_size(_ifNames); ++i) { + free(celix_arrayList_get(_ifNames, i)); + } + return NULL; + } + ifNames = celix_steal_ptr(_ifNames); + } + return ifNames; +} + +static endpoint_description_t* topologyManager_createEndpointWithNetworkInterface(topology_manager_t* tm, const char* ifname, + endpoint_description_t* exportedRegEndpoint) { + celix_autoptr(endpoint_description_t) endpoint = endpointDescription_clone(exportedRegEndpoint); + if (endpoint == NULL) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error cloning endpoint description."); + return NULL; + } + celix_status_t status = celix_properties_set(endpoint->properties, CELIX_RSA_EXPORTED_ENDPOINT_EXPOSURE_INTERFACE, ifname); + if (status != CELIX_SUCCESS) { + celix_logHelper_logTssErrors(tm->loghelper, CELIX_LOG_LEVEL_ERROR); + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error setting property %s.", CELIX_RSA_EXPORTED_ENDPOINT_EXPOSURE_INTERFACE); + return NULL; + } + uuid_t endpointUuid; + uuid_generate(endpointUuid); + char endpointUuidStr[37]; + uuid_unparse_lower(endpointUuid, endpointUuidStr); + status = celix_properties_set(endpoint->properties, CELIX_RSA_ENDPOINT_ID, endpointUuidStr); + if (status != CELIX_SUCCESS) { + celix_logHelper_logTssErrors(tm->loghelper, CELIX_LOG_LEVEL_ERROR); + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error setting property %s.", CELIX_RSA_ENDPOINT_ID); + return NULL; + } + endpoint->id = celix_properties_get(endpoint->properties, CELIX_RSA_ENDPOINT_ID, ""); + status = celix_properties_set(endpoint->properties, CELIX_RSA_IP_ADDRESSES, "");//need to be filled in by discovery implementation + if (status) { + celix_logHelper_logTssErrors(tm->loghelper, CELIX_LOG_LEVEL_ERROR); + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error setting property %s.", CELIX_RSA_IP_ADDRESSES); + return NULL; + } + return celix_steal_ptr(endpoint); +} + +static celix_status_t topologyManager_generateEndpointsForDynamicIpExportedRegistration(topology_manager_t* tm, endpoint_description_t* exportedRegEndpoint, + celix_array_list_t* endpoints) { + celix_status_t status = CELIX_SUCCESS; + int port = celix_properties_getAsLong(exportedRegEndpoint->properties, CELIX_RSA_PORT, -1); + if (port < 0) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error getting port from dynamic ip endpoint description."); + return CELIX_ILLEGAL_ARGUMENT; + } + celix_array_list_t* ifNames = topologyManager_getNetworkInterfacesForPort(tm, port); + if (ifNames == NULL) { + celix_logHelper_error(tm->loghelper, "TOPOLOGY_MANAGER: Error getting network interface names for port %d.", port); + return CELIX_ILLEGAL_STATE; + } + + int size = celix_arrayList_size(ifNames); + for (int i = 0; i < size; ++i) { Review Comment: :+1: , indeed multiple endpoints based on dynamic intf resolution -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org