| 1072 | } |
| 1073 | |
| 1074 | clusterer_node_t *api_get_next_hop(int cluster_id, int node_id) |
| 1075 | { |
| 1076 | clusterer_node_t *ret = NULL; |
| 1077 | node_info_t *dest_node; |
| 1078 | cluster_info_t *cluster; |
| 1079 | |
| 1080 | lock_start_read(cl_list_lock); |
| 1081 | |
| 1082 | cluster = get_cluster_by_id(cluster_id); |
| 1083 | if (!cluster) { |
| 1084 | LM_DBG("Cluster id: %d not found!\n", cluster_id); |
| 1085 | goto error; |
| 1086 | } |
| 1087 | dest_node = get_node_by_id(cluster, node_id); |
| 1088 | if (!dest_node) { |
| 1089 | LM_DBG("Node id: %d no found!\n", node_id); |
| 1090 | goto error; |
| 1091 | } |
| 1092 | |
| 1093 | if (get_next_hop(dest_node) == 0) { |
| 1094 | LM_DBG("No other path to node: %d\n", node_id); |
| 1095 | goto error; |
| 1096 | } |
| 1097 | |
| 1098 | lock_get(dest_node->lock); |
| 1099 | |
| 1100 | if (add_clusterer_node(&ret, dest_node->next_hop) < 0) { |
| 1101 | lock_release(dest_node->lock); |
| 1102 | LM_ERR("Failed to allocate next hop\n"); |
| 1103 | goto error; |
| 1104 | } |
| 1105 | |
| 1106 | lock_release(dest_node->lock); |
| 1107 | |
| 1108 | lock_stop_read(cl_list_lock); |
| 1109 | |
| 1110 | return ret; |
| 1111 | error: |
| 1112 | lock_stop_read(cl_list_lock); |
| 1113 | return NULL; |
| 1114 | } |
| 1115 | |
| 1116 | void api_free_next_hop(clusterer_node_t *next_hop) |
| 1117 | { |
nothing calls this directly
no test coverage detected