}
/** @brief Prints a answer_t, for debugging purposes */
-void answer_print(answer_t answer)
+void answer_print(const_answer_t answer)
{
unsigned int cpt;
node_contact_t contact;
* @param destination the destination in which the nodes will be put
* @param source the source of the nodes to add
*/
-unsigned int answer_merge(answer_t destination, answer_t source)
+unsigned int answer_merge(answer_t destination, const_answer_t source)
{
node_contact_t contact;
node_contact_t contact_copy;
* @param answer the answer to sort
* @param destination_id the id of the guy we are trying to find
*/
-void answer_sort(answer_t answer)
+void answer_sort(const_answer_t answer)
{
xbt_dynar_sort(answer->nodes, &_answer_sort_function);
}
* @param answer the answer object we're going to put the data in
* @param destination_id the id of the guy we are trying to find.
*/
-void answer_add_bucket(bucket_t bucket, answer_t answer)
+void answer_add_bucket(const_bucket_t bucket, answer_t answer)
{
xbt_assert((bucket != NULL), "Provided a NULL bucket");
xbt_assert((bucket->nodes != NULL), "Provided a bucket which nodes are NULL");
/** @brief Returns if the id supplied is in the answer.
* @param id : id we're looking for
*/
-unsigned int answer_contains(answer_t answer, unsigned int id)
+unsigned int answer_contains(const_answer_t answer, unsigned int id)
{
unsigned int i = 0;
node_contact_t contact;
* @param answer the answer
* @return if the destination is found.
*/
-unsigned int answer_destination_found(answer_t answer)
+unsigned int answer_destination_found(const_answer_t answer)
{
if (xbt_dynar_is_empty(answer->nodes)) {
return 0;
} s_answer_t;
typedef s_answer_t *answer_t;
+typedef const s_answer_t* const_answer_t;
answer_t answer_init(unsigned int destination_id);
void answer_free(answer_t answer);
-void answer_print(answer_t answer);
-unsigned int answer_merge(answer_t destination, answer_t source);
-void answer_sort(answer_t answer);
+void answer_print(const_answer_t answer);
+unsigned int answer_merge(answer_t destination, const_answer_t source);
+void answer_sort(const_answer_t answer);
void answer_trim(answer_t answer);
-void answer_add_bucket(bucket_t bucket, answer_t answer);
-unsigned int answer_contains(answer_t answer, unsigned int id);
-unsigned int answer_destination_found(answer_t answer);
+void answer_add_bucket(const_bucket_t bucket, answer_t answer);
+unsigned int answer_contains(const_answer_t answer, unsigned int id);
+unsigned int answer_destination_found(const_answer_t answer);
#endif /* _KADEMLIA_EXAMPLES_ANSWER_H_ */
* Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best
* nodes
*/
-unsigned int send_find_node_to_best(node_t node, answer_t node_list)
+unsigned int send_find_node_to_best(node_t node, const_answer_t node_list)
{
unsigned int i = 0;
unsigned int j = 0;
}
/** @brief Handles the answer to an incoming "find_node" task */
-void handle_find_node(node_t node, task_data_t data)
+void handle_find_node(node_t node, const_task_data_t data)
{
XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x",
data->answer_to, data->issuer_host_name, data->destination_id);
void random_lookup(node_t node);
void send_find_node(node_t node, unsigned int id, unsigned int destination);
-unsigned int send_find_node_to_best(node_t node, answer_t node_list);
+unsigned int send_find_node_to_best(node_t node, const_answer_t node_list);
void handle_task(node_t node, msg_task_t task);
-void handle_find_node(node_t node, task_data_t data);
+void handle_find_node(node_t node, const_task_data_t data);
#endif /* _MSG_EXAMPLES_KADEMLIA_H */
* @param node Our node data
* @param id The id of the node we need to add unsigned into our routing table
*/
-void node_routing_table_update(node_t node, unsigned int id)
+void node_routing_table_update(const_node_t node, unsigned int id)
{
routing_table_t table = node->table;
//retrieval of the bucket in which the should be
* @param node : our node
* @param destination_id : the id of the guy we are trying to find
*/
-answer_t node_find_closest(node_t node, unsigned int destination_id)
+answer_t node_find_closest(const_node_t node, unsigned int destination_id)
{
int i;
answer_t answer = answer_init(destination_id);
}
/** Builds a contact information from a contact information */
-node_contact_t node_contact_copy(node_contact_t node_contact)
+node_contact_t node_contact_copy(const_node_contact_t node_contact)
{
node_contact_t contact = xbt_new(s_node_contact_t, 1);
} s_node_contact_t;
typedef s_node_contact_t *node_contact_t;
+typedef const s_node_contact_t* const_node_contact_t;
/* Node data */
typedef struct s_node {
} s_node_t;
typedef s_node_t *node_t;
+typedef const s_node_t* const_node_t;
// node functions
node_t node_init(unsigned int id);
void node_free(node_t node);
-void node_routing_table_update(node_t node, unsigned int id);
-answer_t node_find_closest(node_t node, unsigned int destination_id);
+void node_routing_table_update(const_node_t node, unsigned int id);
+answer_t node_find_closest(const_node_t node, unsigned int destination_id);
// identifier functions
unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix);
// node contact functions
node_contact_t node_contact_new(unsigned int id, unsigned int distance);
-node_contact_t node_contact_copy(node_contact_t node_contact);
+node_contact_t node_contact_copy(const_node_contact_t node_contact);
void node_contact_free(node_contact_t contact);
#endif /* _MSG_EXAMPLES_ROUTING_H */
}
/**@brief prints the routing table, to debug stuff. */
-void routing_table_print(routing_table_t table)
+void routing_table_print(const_routing_table_t table)
{
unsigned int j;
unsigned int value;
* @param bucket the bucket in which we try to find our identifier
* @param id the id
*/
-unsigned int bucket_find_id(bucket_t bucket, unsigned int id)
+unsigned int bucket_find_id(const_bucket_t bucket, unsigned int id)
{
unsigned int i;
unsigned int current_id;
}
/** Returns if the bucket contains an identifier. */
-unsigned int bucket_contains(bucket_t bucket, unsigned int id)
+unsigned int bucket_contains(const_bucket_t bucket, unsigned int id)
{
return xbt_dynar_member(bucket->nodes, &id);
}
* @param id the identifier
* @return the bucket in which the the identifier would be.
*/
-bucket_t routing_table_find_bucket(routing_table_t table, unsigned int id)
+bucket_t routing_table_find_bucket(const_routing_table_t table, unsigned int id)
{
unsigned int xor_number = table->id ^ id;
unsigned int prefix = get_node_prefix(xor_number, IDENTIFIER_SIZE);
} s_bucket_t;
typedef s_bucket_t *bucket_t;
+typedef const s_bucket_t* const_bucket_t;
/* Node routing table */
typedef struct s_routing_table {
} s_routing_table_t;
typedef s_routing_table_t *routing_table_t;
+typedef const s_routing_table_t* const_routing_table_t;
// bucket functions
-unsigned int bucket_find_id(bucket_t bucket, unsigned int id);
-unsigned int bucket_contains(bucket_t bucket, unsigned int id);
+unsigned int bucket_find_id(const_bucket_t bucket, unsigned int id);
+unsigned int bucket_contains(const_bucket_t bucket, unsigned int id);
// routing table functions
routing_table_t routing_table_init(unsigned int node_id);
void routing_table_free(routing_table_t table);
unsigned int routing_table_contains(routing_table_t table, unsigned int node_id);
-void routing_table_print(routing_table_t table);
-bucket_t routing_table_find_bucket(routing_table_t table, unsigned int id);
+void routing_table_print(const_routing_table_t table);
+bucket_t routing_table_find_bucket(const_routing_table_t table, unsigned int id);
#endif /* _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE */
} s_task_data_t;
typedef s_task_data_t *task_data_t;
+typedef const s_task_data_t* const_task_data_t;
//Task handling functions
msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname);
xbt_dynar_t pending_tasks;
} s_node_t;
typedef s_node_t* node_t;
+typedef const s_node_t* const_node_t;
typedef struct s_state {
int id;
} s_task_data_t;
typedef s_task_data_t* task_data_t;
-static int domain(unsigned int a, unsigned int level);
-static int shl(int a, int b);
-static int closest_in_namespace_set(node_t node, int dest);
-static int routing_next(node_t node, int dest);
-
/**
* @brief Gets the mailbox name of a host given its chord id.
* @param node_id id of a node
}
/* Get the closest id to the dest in the node namespace_set */
-static int closest_in_namespace_set(node_t node, int dest) {
+static int closest_in_namespace_set(const_node_t node, int dest)
+{
int res = -1;
if ((node->namespace_set[NAMESPACE_SIZE-1] <= dest) && (dest <= node->namespace_set[0])) {
int best_dist = abs(node->id - dest);
}
/* Get the corresponding state of a node */
-static state_t node_get_state(node_t node) {
+static state_t node_get_state(const_node_t node)
+{
state_t state = xbt_new0(s_state_t,1);
state->id = node->id;
for (int i=0; i<NEIGHBORHOOD_SIZE; i++)
return state;
}
-static void print_node_id(node_t node) {
+static void print_node_id(const_node_t node)
+{
XBT_INFO(" Id: %i '%08x' ", node->id, (unsigned)node->id);
}
-static void print_node_neighborood_set(node_t node) {
+static void print_node_neighborood_set(const_node_t node)
+{
XBT_INFO(" Neighborhood:");
for (int i=0; i<NEIGHBORHOOD_SIZE; i++)
XBT_INFO(" %08x", (unsigned)node->neighborhood_set[i]);
}
-static void print_node_routing_table(node_t node) {
+static void print_node_routing_table(const_node_t node)
+{
XBT_INFO(" Routing table:");
for (int i=0; i<LEVELS_COUNT; i++){
for (int j=0; j<LEVEL_SIZE; j++)
}
}
/* Print the node namespace set */
-static void print_node_namespace_set(node_t node) {
+static void print_node_namespace_set(const_node_t node)
+{
XBT_INFO(" Namespace:");
for (int i=0; i<NAMESPACE_SIZE; i++)
XBT_INFO(" %08x", (unsigned)node->namespace_set[i]);
}
/* Print the node information */
-static void print_node(node_t node) {
+static void print_node(const_node_t node)
+{
XBT_INFO("Node:");
print_node_id(node);
print_node_neighborood_set(node);
}
/* Join the ring */
-static int join(node_t node){
+static int join(const_node_t node)
+{
task_data_t req_data = xbt_new0(s_task_data_t,1);
req_data->type = TASK_JOIN;
req_data->sender_id = node->id;