int citrusleaf_info_auth(as_cluster *cluster, char *hostname, short port, char *names, char **values, int timeout_ms) { int rv = -1; as_vector sockaddr_in_v; as_vector_inita(&sockaddr_in_v, sizeof(struct sockaddr_in), 5); if (! as_lookup(NULL, hostname, port, true, &sockaddr_in_v)) { goto Done; } for (uint32_t i = 0; i < sockaddr_in_v.size; i++) { struct sockaddr_in* sa_in = as_vector_get(&sockaddr_in_v, i); if (0 == citrusleaf_info_host_auth(cluster, sa_in, names, values, timeout_ms, true, /* check bounds */ true)) { rv = 0; goto Done; } } Done: as_vector_destroy(&sockaddr_in_v); return(rv); }
/** * Send an info request to a specific host. The response must be freed by the caller on success. * * ~~~~~~~~~~{.c} * char * res = NULL; * if ( aerospike_info_host(&as, &err, NULL, "127.0.0.1", 3000, "info", &res) != AEROSPIKE_OK ) { * // handle error * } * else { * // handle response * free(res); * res = NULL; * } * ~~~~~~~~~~ * * @param as The aerospike instance to use for this operation. * @param err The as_error to be populated if an error occurs. * @param policy The policy to use for this operation. If NULL, then the default policy will be used. * @param addr The IP address or hostname to send the request to. * @param port The port to send the request to. * @param req The info request to send. * @param res The response from the node. The response will be a NULL terminated string, allocated by the function, and must be freed by the caller. * * @return AEROSPIKE_OK on success. Otherwise an error. * * @ingroup info_operations */ as_status aerospike_info_host( aerospike * as, as_error * err, const as_policy_info * policy, const char * addr, uint16_t port, const char * req, char ** res) { as_error_reset(err); if (! policy) { policy = &as->config.policies.info; } as_vector sockaddr_in_v; as_vector_inita(&sockaddr_in_v, sizeof(struct sockaddr_in), 5); as_status status = as_lookup(NULL, err, (char*)addr, port, &sockaddr_in_v); if (status) { as_vector_destroy(&sockaddr_in_v); return status; } uint64_t deadline = as_socket_deadline(policy->timeout); as_cluster* cluster = as->cluster; status = AEROSPIKE_ERR_CLUSTER; bool loop = true; for (uint32_t i = 0; i < sockaddr_in_v.size && loop; i++) { struct sockaddr_in* sa_in = as_vector_get(&sockaddr_in_v, i); status = as_info_command_host(cluster, err, sa_in, (char*)req, policy->send_as_is, deadline, res); switch (status) { case AEROSPIKE_OK: case AEROSPIKE_ERR_TIMEOUT: case AEROSPIKE_ERR_INDEX_FOUND: case AEROSPIKE_ERR_INDEX_NOT_FOUND: loop = false; break; default: break; } } as_vector_destroy(&sockaddr_in_v); return status; }
static as_status as_cluster_seed_nodes(as_cluster* cluster, as_error* err, bool enable_warnings) { // Add all nodes at once to avoid copying entire array multiple times. as_vector nodes_to_add; as_vector_inita(&nodes_to_add, sizeof(as_node*), 64); as_vector addresses; as_vector_inita(&addresses, sizeof(struct sockaddr_in), 5); as_node_info node_info; as_error error_local; as_error_init(&error_local); // AEROSPIKE_ERR_TIMEOUT doesn't come with a message; make sure it's initialized. as_status status = AEROSPIKE_OK; as_seeds* seeds = as_seeds_reserve(cluster); for (uint32_t i = 0; i < seeds->size; i++) { as_seed* seed = &seeds->array[i]; as_vector_clear(&addresses); status = as_lookup(&error_local, seed->name, seed->port, &addresses); if (status != AEROSPIKE_OK) { if (enable_warnings) { as_log_warn("Failed to lookup %s:%d. %s %s", seed->name, seed->port, as_error_string(status), error_local.message); } continue; } for (uint32_t i = 0; i < addresses.size; i++) { struct sockaddr_in* addr = as_vector_get(&addresses, i); status = as_lookup_node(cluster, &error_local, addr, &node_info); if (status == AEROSPIKE_OK) { as_host host; if (as_strncpy(host.name, seed->name, sizeof(host.name))) { as_log_warn("Hostname has been truncated: %s", host.name); } host.port = seed->port; as_node* node = as_cluster_find_node_in_vector(&nodes_to_add, node_info.name); if (node) { as_close(node_info.fd); as_node_add_address(node, &host, addr); } else { node = as_node_create(cluster, &host, addr, &node_info); as_address* a = as_node_get_address_full(node); as_log_info("Add node %s %s:%d", node->name, a->name, (int)cf_swap_from_be16(a->addr.sin_port)); as_vector_append(&nodes_to_add, &node); } } else { if (enable_warnings) { as_log_warn("Failed to connect to seed %s:%d. %s %s", seed->name, seed->port, as_error_string(status), error_local.message); } } } } as_seeds_release(seeds); if (nodes_to_add.size > 0) { as_cluster_add_nodes(cluster, &nodes_to_add); status = AEROSPIKE_OK; } else { status = as_error_set_message(err, AEROSPIKE_ERR_CLIENT, "Failed to seed cluster"); } as_vector_destroy(&nodes_to_add); as_vector_destroy(&addresses); return status; }