int netloc_lookup_table_append(struct netloc_dt_lookup_table *ht, const char *key, void *value) { unsigned long hashed_key; // JJH : Add hash function hashed_key = 0; return netloc_lookup_table_append_with_int(ht, key, hashed_key, value); }
int netloc_dc_append_edge_to_node(netloc_data_collection_handle_t *handle, netloc_node_t *node, netloc_edge_t *edge) { char *key = NULL; netloc_edge_t *found_edge = NULL; netloc_node_t *found_node = NULL; unsigned long key_int; bool is_cached = false; /* * Setup the table for the first edge */ if( NULL == handle->edges ) { handle->edges = calloc(1, sizeof(*handle->edges)); netloc_lookup_table_init(handle->edges, 1, 0); } /* * Setup the table for the first node */ if(NULL == handle->node_list) { handle->node_list = calloc(1, sizeof(*handle->node_list)); netloc_lookup_table_init(handle->node_list, 1, 0); } /* * Check to see if we have seen this edge before */ asprintf(&key, "%d", edge->edge_uid); found_edge = (netloc_edge_t*)netloc_lookup_table_access(handle->edges, key); free(key); key = NULL; // JJH: Should we be checking the contents of the edge, not just the key? /* * If not add it to the edges lookup table */ if( NULL == found_edge ) { found_edge = netloc_dt_edge_t_dup(edge); asprintf(&key, "%d", found_edge->edge_uid); netloc_lookup_table_append(handle->edges, key, found_edge); free(key); key = NULL; } /* * Update the edge links * if the node endpoint is not in the list, then add a stub */ if( NULL == edge->src_node_id ) { return NETLOC_ERROR_NOT_FOUND; } SUPPORT_CONVERT_ADDR_TO_INT(edge->src_node_id, handle->network->network_type, key_int); asprintf(&key, "%s", edge->src_node_id); found_node = netloc_lookup_table_access_with_int(handle->node_list, key, key_int); if( NULL == found_node ) { found_node = netloc_dt_node_t_construct(); found_node->physical_id = strdup(edge->src_node_id); found_node->physical_id_int = key_int; found_node->node_type = NETLOC_NODE_TYPE_INVALID; netloc_lookup_table_append_with_int(handle->node_list, key, key_int, found_node); } else { is_cached = true; } found_edge->src_node = found_node; free(key); key = NULL; if( NULL == edge->dest_node_id ) { return NETLOC_ERROR_NOT_FOUND; } asprintf(&key, "%s", edge->dest_node_id); SUPPORT_CONVERT_ADDR_TO_INT(edge->dest_node_id, handle->network->network_type, key_int); found_node = netloc_lookup_table_access_with_int(handle->node_list, key, key_int); if( NULL == found_node ) { found_node = netloc_dt_node_t_construct(); found_node->physical_id = strdup(edge->dest_node_id); found_node->physical_id_int = key_int; found_node->node_type = NETLOC_NODE_TYPE_INVALID; netloc_lookup_table_append_with_int(handle->node_list, key, key_int, found_node); } found_edge->dest_node = found_node; free(key); key = NULL; /* * Add the edge index to the node passed to us */ node->num_edge_ids++; node->edge_ids = (int*)realloc(node->edge_ids, sizeof(int) * node->num_edge_ids); node->edge_ids[node->num_edge_ids -1] = found_edge->edge_uid; node->num_edges++; node->edges = (netloc_edge_t**)realloc(node->edges, sizeof(netloc_edge_t*) * node->num_edges); node->edges[node->num_edges -1] = found_edge; /* * Update the cached version of this node */ if( is_cached ) { json_object_del(handle->node_data_acc, node->physical_id); json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); } return NETLOC_SUCCESS; }
int netloc_dc_append_node(netloc_data_collection_handle_t *handle, netloc_node_t *node) { char *key = NULL; netloc_node_t *cur_node = NULL; unsigned long key_int; /* * Setup the table for the first node */ if(NULL == handle->node_list) { handle->node_list = calloc(1, sizeof(*handle->node_list)); netloc_lookup_table_init(handle->node_list, 1, 0); } /* * Check to see if we have seen this node before */ SUPPORT_CONVERT_ADDR_TO_INT(node->physical_id, handle->network->network_type, key_int); asprintf(&key, "%s", node->physical_id); cur_node = netloc_lookup_table_access_with_int(handle->node_list, key, key_int); if( NULL != cur_node ) { if( NETLOC_NODE_TYPE_INVALID == cur_node->node_type ) { // JJH: We should be able to use 'replace' instead of 'remove' and 'append' // Need to double check ordering. netloc_lookup_table_remove_with_int(handle->node_list, key, key_int); } else { fprintf(stderr, "Warning: A version of this node has already been added to the data set!\n"); fprintf(stderr, "Warning: Support for updating nodes is not yet available\n"); // JJH: Delete the old cached version ? replace it? //json_object_del(handle->node_data_acc, node->physical_id); } } free(key); key = NULL; /* * Add the node to our list */ if( NULL == cur_node ) { cur_node = netloc_dt_node_t_dup(node); cur_node->__uid__ = 0; cur_node->physical_id_int = key_int; asprintf(&key, "%s", node->physical_id); netloc_lookup_table_append_with_int(handle->node_list, key, key_int, cur_node); /* * Encode the data: Physical ID is the key */ json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); } else if( NETLOC_NODE_TYPE_INVALID == cur_node->node_type ) { netloc_dt_node_t_copy(node, cur_node); cur_node->__uid__ = 0; cur_node->physical_id_int = key_int; asprintf(&key, "%s", node->physical_id); netloc_lookup_table_append_with_int(handle->node_list, key, key_int, cur_node); /* * Encode the data: Physical ID is the key */ json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); } else { /* * Replace the node? * The code below will fix the cache (node_data_acc), but the handle->node_list needs to also be updated. */ //json_object_del(handle->node_data_acc, node->physical_id); //json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); return NETLOC_ERROR_NOT_IMPL; } return NETLOC_SUCCESS; }