Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Example cleaning
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 10 Feb 2016 13:56:14 +0000 (14:56 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 10 Feb 2016 13:56:14 +0000 (14:56 +0100)
 - replace deployment by something closer to what the provided
   generator produces
 - Stop using the ugly platform.xml file
 - revalidate tesh
 - reindent to 120 character width
 - use proper dynar function when possible
 - more uniform comments

13 files changed:
examples/msg/kademlia/answer.c
examples/msg/kademlia/answer.h
examples/msg/kademlia/generate.py
examples/msg/kademlia/kademlia.c
examples/msg/kademlia/kademlia.h
examples/msg/kademlia/kademlia.tesh
examples/msg/kademlia/kademlia.xml
examples/msg/kademlia/node.c
examples/msg/kademlia/node.h
examples/msg/kademlia/routing_table.c
examples/msg/kademlia/routing_table.h
examples/msg/kademlia/task.c
examples/msg/kademlia/task.h

index ee1082b..5aa893f 100644 (file)
@@ -8,9 +8,7 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg_kademlia_node);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg_kademlia_node);
 
-/**
-  * Initialize a node answer object.
-  */
+/** Initialize a node answer object. */
 answer_t answer_init(unsigned int destination_id)
 {
   answer_t answer = xbt_new(s_answer_t, 1);
 answer_t answer_init(unsigned int destination_id)
 {
   answer_t answer = xbt_new(s_answer_t, 1);
@@ -21,9 +19,7 @@ answer_t answer_init(unsigned int destination_id)
   return answer;
 }
 
   return answer;
 }
 
-/**
-  * Destroys a node answer object.
-  */
+/** Destroys a node answer object. */
 void answer_free(answer_t answer)
 {
   unsigned int i;
 void answer_free(answer_t answer)
 {
   unsigned int i;
@@ -34,22 +30,18 @@ void answer_free(answer_t answer)
   xbt_free(answer);
 }
 
   xbt_free(answer);
 }
 
-/**
-  * @brief Prints a answer_t, for debugging purposes
-  */
+/** @brief Prints a answer_t, for debugging purposes */
 void answer_print(answer_t answer)
 {
   unsigned int cpt;
   node_contact_t contact;
   XBT_INFO("Searching %08x, size %d", answer->destination_id, answer->size);
   xbt_dynar_foreach(answer->nodes, cpt, contact) {
 void answer_print(answer_t answer)
 {
   unsigned int cpt;
   node_contact_t contact;
   XBT_INFO("Searching %08x, size %d", answer->destination_id, answer->size);
   xbt_dynar_foreach(answer->nodes, cpt, contact) {
-    XBT_INFO("Node %08x: %08x is at distance %d", cpt, contact->id,
-             contact->distance);
+    XBT_INFO("Node %08x: %08x is at distance %d", cpt, contact->id, contact->distance);
   }
 }
 
   }
 }
 
-/**
-  * @brief Merge two answer_t together, only keeping the best nodes
+/** @brief Merge two answer_t together, only keeping the best nodes
   * @param destination the destination in which the nodes will be put
   * @param source the source of the nodes to add
   */
   * @param destination the destination in which the nodes will be put
   * @param source the source of the nodes to add
   */
@@ -72,9 +64,7 @@ unsigned int answer_merge(answer_t destination, answer_t source)
   return nb_added;
 }
 
   return nb_added;
 }
 
-/**
-  * Helper to sort answer_t objects
-  */
+/** Helper to sort answer_t objects */
 static int _answer_sort_function(const void *e1, const void *e2)
 {
   node_contact_t c1 = *(void **) e1;
 static int _answer_sort_function(const void *e1, const void *e2)
 {
   node_contact_t c1 = *(void **) e1;
@@ -88,8 +78,7 @@ static int _answer_sort_function(const void *e1, const void *e2)
       return 1;
 }
 
       return 1;
 }
 
-/**
-  * Sorts a answer_t, by node distance.
+/** @brief Sorts a answer_t, by node distance.
   * @param answer the answer to sort
   * @param destination_id the id of the guy we are trying to find
   */
   * @param answer the answer to sort
   * @param destination_id the id of the guy we are trying to find
   */
@@ -98,9 +87,7 @@ void answer_sort(answer_t answer)
   xbt_dynar_sort(answer->nodes, &_answer_sort_function);
 }
 
   xbt_dynar_sort(answer->nodes, &_answer_sort_function);
 }
 
-/**
-  * Trims a answer_t, in order for it to have a size of less or equal
-  * to "bucket_size"
+/** @brief Trims a answer_t, in order for it to have a size of less or equal to "bucket_size"
   * @param answer the answer_t to trim
   */
 void answer_trim(answer_t answer)
   * @param answer the answer_t to trim
   */
 void answer_trim(answer_t answer)
@@ -111,12 +98,10 @@ void answer_trim(answer_t answer)
     answer->size--;
     node_contact_free(value);
   }
     answer->size--;
     node_contact_free(value);
   }
-  xbt_assert(xbt_dynar_length(answer->nodes) == answer->size,
-             "Wrong size for the answer");
+  xbt_assert(xbt_dynar_length(answer->nodes) == answer->size, "Wrong size for the answer");
 }
 
 }
 
-/**
-  * Adds the content of a bucket unsigned into a answer object.
+/** @brief Adds the content of a bucket unsigned into a answer object.
   * @param bucket the bucket we have to had unsigned into
   * @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.
   * @param bucket the bucket we have to had unsigned into
   * @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.
@@ -136,16 +121,14 @@ void answer_add_bucket(bucket_t bucket, answer_t answer)
   }
 }
 
   }
 }
 
-/**
-  * Returns if the id supplied is in the answer.
+/** @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)
 {
   * @param id : id we're looking for
   */
 unsigned int answer_contains(answer_t answer, unsigned int id)
 {
-  unsigned int i = 0, size = xbt_dynar_length(answer->nodes);
+  unsigned int i = 0;
   node_contact_t contact;
   node_contact_t contact;
-  for (i = 0; i < size; i++) {
-    contact = xbt_dynar_get_as(answer->nodes, i, node_contact_t);
+  xbt_dynar_foreach(answer->nodes, i, contact){
     if (id == contact->id) {
       return 1;
     }
     if (id == contact->id) {
       return 1;
     }
@@ -153,8 +136,7 @@ unsigned int answer_contains(answer_t answer, unsigned int id)
   return 0;
 }
 
   return 0;
 }
 
-/**
-  * Returns if the destination we are trying to find is found
+/** @brief Returns if the destination we are trying to find is found
   * @param answer the answer
   * @return if the destination is found.
   */
   * @param answer the answer
   * @return if the destination is found.
   */
@@ -163,7 +145,6 @@ unsigned int answer_destination_found(answer_t answer)
   if (xbt_dynar_length(answer->nodes) < 1) {
     return 0;
   }
   if (xbt_dynar_length(answer->nodes) < 1) {
     return 0;
   }
-  node_contact_t contact_tail =
-      xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
+  node_contact_t contact_tail = xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
   return contact_tail->distance == 0;
 }
   return contact_tail->distance == 0;
 }
index 24902dd..03fe765 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014. The SimGrid Team.
+/* Copyright (c) 2012, 2014, 2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -8,10 +8,8 @@
 #define _KADEMLIA_EXAMPLES_ANSWER_H_
 #include <xbt/dynar.h>
 #include "routing_table.h"
 #define _KADEMLIA_EXAMPLES_ANSWER_H_
 #include <xbt/dynar.h>
 #include "routing_table.h"
-/*
- * Node query anwser. contains the elements closest
- * to the id given.
- */
+
+/* Node query anwser. contains the elements closest to the id given. */
 typedef struct s_node_answer {
   unsigned int destination_id;
   xbt_dynar_t nodes;            //Dynar of node_contact_t
 typedef struct s_node_answer {
   unsigned int destination_id;
   xbt_dynar_t nodes;            //Dynar of node_contact_t
index 1b9526c..c1c7a72 100755 (executable)
@@ -20,9 +20,9 @@ max_id = 2 ** nb_bits - 1
 all_ids = [0]
 
 sys.stdout.write("<?xml version='1.0'?>\n"
 all_ids = [0]
 
 sys.stdout.write("<?xml version='1.0'?>\n"
-"<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"
-"<platform version=\"3\">\n"
-"  <process host=\"c-0.me\" function=\"node\"><argument value=\"0000000000000000000000000000000000000000\"/><argument value=\"%d\"/></process>\n" % end_date)
+"<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n"
+"<platform version=\"4\">\n  <process host=\"node-0.acme.org\" function=\"node\">\n"
+"     <argument value=\"0\"/>\n     <argument value=\"%d\"/>\n  </process>\n" % end_date)
 
 for i in range(1, nb_nodes):
        ok = False
 
 for i in range(1, nb_nodes):
        ok = False
@@ -31,7 +31,8 @@ for i in range(1, nb_nodes):
                ok = not my_id in all_ids
        known_id = all_ids[random.randint(0, len(all_ids) - 1)]
        start_date = i * 10
                ok = not my_id in all_ids
        known_id = all_ids[random.randint(0, len(all_ids) - 1)]
        start_date = i * 10
-       line = "  <process host=\"c-%d.me\" function=\"node\"><argument value=\"%s\" /><argument value=\"%s\" /><argument value=\"%d\" /></process>\n" % (i, my_id, known_id,end_date)
+       line = "  <process host=\"node-%d.acme.org\" function=\"node\">\n    <argument value=\"%s\"/>"\
+              "\n    <argument value=\"%s\"/>\n    <argument value=\"%d\"/>\n  </process>\n" % (i, my_id, known_id,end_date)
        sys.stdout.write(line)
        all_ids.append(my_id)
 
        sys.stdout.write(line)
        all_ids.append(my_id)
 
index 5ba1285..f7e2195 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014-2015. The SimGrid Team.
+/* Copyright (c) 2012, 2014-2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
   * <b>kademlia/kademlia.c: Kademlia protocol</b>
   * Implements the Kademlia protocol, using 32 bits identifiers.
   */
   * <b>kademlia/kademlia.c: Kademlia protocol</b>
   * Implements the Kademlia protocol, using 32 bits identifiers.
   */
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia,
-                             "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia, "Messages specific for this msg example");
 
 extern long unsigned int smx_total_comms;
 
 
 extern long unsigned int smx_total_comms;
 
-/**
-  * Main loop for the process
-  */
+/* Main loop for the process */
 static void main_loop(node_t node, double deadline)
 {
   double next_lookup_time = MSG_get_clock() + random_lookup_interval;
 static void main_loop(node_t node, double deadline)
 {
   double next_lookup_time = MSG_get_clock() + random_lookup_interval;
@@ -50,12 +47,10 @@ static void main_loop(node_t node, double deadline)
         node->receive_comm = NULL;
 
         if (status == MSG_OK) {
         node->receive_comm = NULL;
 
         if (status == MSG_OK) {
-          xbt_assert((node->task_received != NULL),
-                     "We received an incorrect task");
+          xbt_assert((node->task_received != NULL), "We received an incorrect task");
           handle_task(node, node->task_received);
         } else {
           handle_task(node, node->task_received);
         } else {
-          xbt_assert((MSG_comm_get_task(node->receive_comm) == NULL),
-                     "Comm failed but received a task.");
+          xbt_assert((MSG_comm_get_task(node->receive_comm) == NULL), "Comm failed but received a task.");
           XBT_DEBUG("Nevermind, the communication has failed.");
         }
       }
           XBT_DEBUG("Nevermind, the communication has failed.");
         }
       }
@@ -66,20 +61,17 @@ static void main_loop(node_t node, double deadline)
   }
   //Cleanup the receiving communication.
   if (node->receive_comm != NULL) {
   }
   //Cleanup the receiving communication.
   if (node->receive_comm != NULL) {
-    if (MSG_comm_test(node->receive_comm)
-        && MSG_comm_get_status(node->receive_comm) == MSG_OK) {
+    if (MSG_comm_test(node->receive_comm) && MSG_comm_get_status(node->receive_comm) == MSG_OK) {
       task_free(MSG_comm_get_task(node->receive_comm));
     }
     MSG_comm_destroy(node->receive_comm);
   }
 }
 
       task_free(MSG_comm_get_task(node->receive_comm));
     }
     MSG_comm_destroy(node->receive_comm);
   }
 }
 
-/**
-  * \brief Node function
-  * Arguments :
-  * - my node ID
-  * - the ID of the person I know in the system (or not)
-  * - Time before I leave the system because I'm bored
+/** @brief Node function
+  * @param my node ID
+  * @param the ID of the person I know in the system (or not)
+  * @param Time before I leave the system because I'm bored
   */
 static int node(int argc, char *argv[])
 {
   */
 static int node(int argc, char *argv[])
 {
@@ -108,15 +100,14 @@ static int node(int argc, char *argv[])
     XBT_INFO("I couldn't join the network :(");
   }
   XBT_DEBUG("I'm leaving the network");
     XBT_INFO("I couldn't join the network :(");
   }
   XBT_DEBUG("I'm leaving the network");
-  XBT_INFO("%d/%d FIND_NODE have succeeded", node->find_node_success,
-           node->find_node_success + node->find_node_failed);
+  XBT_INFO("%d/%d FIND_NODE have succeeded", node->find_node_success, node->find_node_success + node->find_node_failed);
   node_free(node);
 
   return 0;
 }
 
 /**
   node_free(node);
 
   return 0;
 }
 
 /**
-  * Tries to join the network
+  * @brief Tries to join the network
   * @param node node data
   * @param id_known id of the node I know in the network.
   */
   * @param node node data
   * @param id_known id of the node I know in the network.
   */
@@ -154,7 +145,6 @@ unsigned int join(node_t node, unsigned int id_known)
             node_list = data->answer;
             xbt_dynar_foreach(node_list->nodes, i, contact) {
               node_routing_table_update(node, contact->id);
             node_list = data->answer;
             xbt_dynar_foreach(node_list->nodes, i, contact) {
               node_routing_table_update(node, contact->id);
-              //ping(node,contact->id);
             }
             task_free(node->task_received);
           } else {
             }
             task_free(node->task_received);
           } else {
@@ -172,9 +162,7 @@ unsigned int join(node_t node, unsigned int id_known)
   } while (answer_got == 0 && trial < max_join_trials);
   /* Second step: Send a FIND_NODE to a a random node in buckets */
   unsigned int bucket_id = routing_table_find_bucket(node->table, id_known)->id;
   } while (answer_got == 0 && trial < max_join_trials);
   /* Second step: Send a FIND_NODE to a a random node in buckets */
   unsigned int bucket_id = routing_table_find_bucket(node->table, id_known)->id;
-  for (i = 0;
-       ((bucket_id - i) > 0 || (bucket_id + i) <= identifier_size)
-       && i < JOIN_BUCKETS_QUERIES; i++) {
+  for (i = 0; ((bucket_id - i) > 0 || (bucket_id + i) <= identifier_size) && i < JOIN_BUCKETS_QUERIES; i++) {
     if (bucket_id - i > 0) {
       unsigned int id_in_bucket = get_id_in_prefix(node->id, bucket_id - i);
       find_node(node, id_in_bucket, 0);
     if (bucket_id - i > 0) {
       unsigned int id_in_bucket = get_id_in_prefix(node->id, bucket_id - i);
       find_node(node, id_in_bucket, 0);
@@ -187,15 +175,12 @@ unsigned int join(node_t node, unsigned int id_known)
   return answer_got;
 }
 
   return answer_got;
 }
 
-/**
-  * Send a request to find a node in the node routing table.
-  * @brief node our node data
-  * @brief id_to_find the id of the node we are trying to find
+/** @brief Send a request to find a node in the node routing table.
+  * @param node our node data
+  * @param id_to_find the id of the node we are trying to find
   */
   */
-unsigned int find_node(node_t node, unsigned int id_to_find,
-                       unsigned int count_in_stats)
+unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_in_stats)
 {
 {
-
   unsigned int i = 0;
   unsigned int queries, answers;
   unsigned int destination_found = 0;
   unsigned int i = 0;
   unsigned int queries, answers;
   unsigned int destination_found = 0;
@@ -214,9 +199,7 @@ unsigned int find_node(node_t node, unsigned int id_to_find,
 
   msg_error_t status;
 
 
   msg_error_t status;
 
-  /* Ask the nodes on our list if they   have information about
-   * the node we are trying to find */
-
+  /* Ask the nodes on our list if they   have information about the node we are trying to find */
   do {
     answers = 0;
     queries = send_find_node_to_best(node, node_list);
   do {
     answers = 0;
     queries = send_find_node_to_best(node, node_list);
@@ -227,8 +210,7 @@ unsigned int find_node(node_t node, unsigned int id_to_find,
     do {
       if (node->receive_comm == NULL) {
         node->task_received = NULL;
     do {
       if (node->receive_comm == NULL) {
         node->task_received = NULL;
-        node->receive_comm =
-            MSG_task_irecv(&node->task_received, node->mailbox);
+        node->receive_comm = MSG_task_irecv(&node->task_received, node->mailbox);
       }
       if (node->receive_comm) {
         if (MSG_comm_test(node->receive_comm)) {
       }
       if (node->receive_comm) {
         if (MSG_comm_test(node->receive_comm)) {
@@ -242,8 +224,7 @@ unsigned int find_node(node_t node, unsigned int id_to_find,
             xbt_assert((data != NULL), "No data in the task");
 
             //Check if what we have received is what we are looking for.
             xbt_assert((data != NULL), "No data in the task");
 
             //Check if what we have received is what we are looking for.
-            if (data->type == TASK_FIND_NODE_ANSWER
-                && data->answer->destination_id == id_to_find) {
+            if (data->type == TASK_FIND_NODE_ANSWER && data->answer->destination_id == id_to_find) {
               //Handle the answer
               node_routing_table_update(node, data->sender_id);
               node_contact_t contact;
               //Handle the answer
               node_routing_table_update(node, data->sender_id);
               node_contact_t contact;
@@ -254,8 +235,7 @@ unsigned int find_node(node_t node, unsigned int id_to_find,
 
               nodes_added = answer_merge(node_list, data->answer);
               XBT_DEBUG("Received an answer from %s (%s) with %ld nodes on it",
 
               nodes_added = answer_merge(node_list, data->answer);
               XBT_DEBUG("Received an answer from %s (%s) with %ld nodes on it",
-                        data->answer_to, data->issuer_host_name,
-                        xbt_dynar_length(data->answer->nodes));
+                        data->answer_to, data->issuer_host_name, xbt_dynar_length(data->answer->nodes));
 
               task_free(node->task_received);
             } else {
 
               task_free(node->task_received);
             } else {
@@ -273,8 +253,8 @@ unsigned int find_node(node_t node, unsigned int id_to_find,
       }
     } while (MSG_get_clock() < timeout && answers < queries);
     destination_found = answer_destination_found(node_list);
       }
     } while (MSG_get_clock() < timeout && answers < queries);
     destination_found = answer_destination_found(node_list);
-  } while (!destination_found && (nodes_added > 0 || answers == 0)
-           && MSG_get_clock() < global_timeout && steps < MAX_STEPS);
+  } while (!destination_found && (nodes_added > 0 || answers == 0) && MSG_get_clock() < global_timeout
+            && steps < MAX_STEPS);
   if (destination_found) {
     if (count_in_stats)
       node->find_node_success++;
   if (destination_found) {
     if (count_in_stats)
       node->find_node_success++;
@@ -291,8 +271,7 @@ unsigned int find_node(node_t node, unsigned int id_to_find,
   return destination_found;
 }
 
   return destination_found;
 }
 
-/**
-  * Pings a node in the system to see if it is online.
+/** @brief Pings a node in the system to see if it is online.
   * @param node Our node data
   * @param id_to_ping the id of a node we want to see if it is online.
   * @return if the ping succeded or not.
   * @param node Our node data
   * @param id_to_ping the id of a node we want to see if it is online.
   * @return if the ping succeded or not.
@@ -305,9 +284,7 @@ unsigned int ping(node_t node, unsigned int id_to_ping)
   unsigned int destination_found = 0;
   double timeout = MSG_get_clock() + ping_timeout;
 
   unsigned int destination_found = 0;
   double timeout = MSG_get_clock() + ping_timeout;
 
-  msg_task_t ping_task =
-      task_new_ping(node->id, node->mailbox,
-                    MSG_host_get_name(MSG_host_self()));
+  msg_task_t ping_task = task_new_ping(node->id, node->mailbox, MSG_host_get_name(MSG_host_self()));
   msg_task_t task_received = NULL;
 
   XBT_VERB("PING %08x", id_to_ping);
   msg_task_t task_received = NULL;
 
   XBT_VERB("PING %08x", id_to_ping);
@@ -322,8 +299,7 @@ unsigned int ping(node_t node, unsigned int id_to_ping)
   do {
     task_received = NULL;
     msg_error_t status =
   do {
     task_received = NULL;
     msg_error_t status =
-        MSG_task_receive_with_timeout(&task_received, node->mailbox,
-                                      ping_timeout);
+        MSG_task_receive_with_timeout(&task_received, node->mailbox, ping_timeout);
     if (status == MSG_OK) {
       xbt_assert((task_received != NULL), "Invalid task received");
       //Checking if it's what we are waiting for or not.
     if (status == MSG_OK) {
       xbt_assert((task_received != NULL), "Invalid task received");
       //Checking if it's what we are waiting for or not.
@@ -352,8 +328,7 @@ unsigned int ping(node_t node, unsigned int id_to_ping)
   return 1;
 }
 
   return 1;
 }
 
-/**
-  * Does a pseudo-random lookup for someone in the system
+/** @brief Does a pseudo-random lookup for someone in the system
   * @param node caller node data
   */
 void random_lookup(node_t node)
   * @param node caller node data
   */
 void random_lookup(node_t node)
@@ -364,8 +339,7 @@ void random_lookup(node_t node)
   find_node(node, id_to_look, 1);
 }
 
   find_node(node, id_to_look, 1);
 }
 
-/**
-  * @brief Send a "FIND_NODE" to a node
+/** @brief Send a "FIND_NODE" to a node
   * @param node sender node data
   * @param id node we are querying
   * @param destination node we are trying to find.
   * @param node sender node data
   * @param id node we are querying
   * @param destination node we are trying to find.
@@ -376,9 +350,7 @@ void send_find_node(node_t node, unsigned int id, unsigned int destination)
   /* Gets the mailbox to send to */
   get_node_mailbox(id, mailbox);
   /* Build the task */
   /* Gets the mailbox to send to */
   get_node_mailbox(id, mailbox);
   /* Build the task */
-  msg_task_t task =
-      task_new_find_node(node->id, destination, node->mailbox,
-                         MSG_host_get_name(MSG_host_self()));
+  msg_task_t task = task_new_find_node(node->id, destination, node->mailbox, MSG_host_get_name(MSG_host_self()));
   /* Send the task */
   xbt_assert((task != NULL), "Trying to send a NULL task.");
   MSG_task_dsend(task, mailbox, task_free_v);
   /* Send the task */
   xbt_assert((task != NULL), "Trying to send a NULL task.");
   MSG_task_dsend(task, mailbox, task_free_v);
@@ -393,7 +365,8 @@ unsigned int send_find_node_to_best(node_t node, answer_t node_list)
   unsigned int i = 0, j = 0;
   unsigned int destination = node_list->destination_id;
   node_contact_t node_to_query;
   unsigned int i = 0, j = 0;
   unsigned int destination = node_list->destination_id;
   node_contact_t node_to_query;
-  while (j < kademlia_alpha && i < node_list->size) {   /* We need to have at most "kademlia_alpha" requets each time, according to the protocol */
+  while (j < kademlia_alpha && i < node_list->size) {
+    /* We need to have at most "kademlia_alpha" requests each time, according to the protocol */
     /* Gets the node we want to send the query to */
     node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t);
     if (node_to_query->id != node->id) {        /* No need to query ourselves */
     /* Gets the node we want to send the query to */
     node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t);
     if (node_to_query->id != node->id) {        /* No need to query ourselves */
@@ -405,9 +378,7 @@ unsigned int send_find_node_to_best(node_t node, answer_t node_list)
   return i;
 }
 
   return i;
 }
 
-/**
-  * \brief Handles an incomming received task
-  */
+/** @brief Handles an incoming received task */
 void handle_task(node_t node, msg_task_t task)
 {
   task_data_t data = MSG_task_get_data(task);
 void handle_task(node_t node, msg_task_t task)
 {
   task_data_t data = MSG_task_get_data(task);
@@ -425,15 +396,12 @@ void handle_task(node_t node, msg_task_t task)
     handle_ping(node, data);
     break;
   default:
     handle_ping(node, data);
     break;
   default:
-
     break;
   }
   task_free(task);
 }
 
     break;
   }
   task_free(task);
 }
 
-/**
-  * \brief Handles the answer to an incomming "find_node" task
-  */
+/** @brief Handles the answer to an incoming "find_node" task */
 void handle_find_node(node_t node, task_data_t data)
 {
   XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x",
 void handle_find_node(node_t node, task_data_t data)
 {
   XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x",
@@ -441,47 +409,35 @@ void handle_find_node(node_t node, task_data_t data)
   //Building the answer to the request
   answer_t answer = node_find_closest(node, data->destination_id);
   //Building the task to send
   //Building the answer to the request
   answer_t answer = node_find_closest(node, data->destination_id);
   //Building the task to send
-  msg_task_t task =
-      task_new_find_node_answer(node->id, data->destination_id, answer,
-                                node->mailbox,
-                                MSG_host_get_name(MSG_host_self()));
+  msg_task_t task = task_new_find_node_answer(node->id, data->destination_id, answer, node->mailbox,
+                                              MSG_host_get_name(MSG_host_self()));
   //Sending the task
   MSG_task_dsend(task, data->answer_to, task_free_v);
 }
 
   //Sending the task
   MSG_task_dsend(task, data->answer_to, task_free_v);
 }
 
-/**
-  * \brief handles the answer to a ping
-  */
+/** @brief handles the answer to a ping */
 void handle_ping(node_t node, task_data_t data)
 {
 void handle_ping(node_t node, task_data_t data)
 {
-  XBT_VERB("Received a PING request from %s (%s)", data->answer_to,
-           data->issuer_host_name);
+  XBT_VERB("Received a PING request from %s (%s)", data->answer_to, data->issuer_host_name);
   //Building the answer to the request
   //Building the answer to the request
-  msg_task_t task =
-      task_new_ping_answer(node->id, data->answer_to,
-                           MSG_host_get_name(MSG_host_self()));
+  msg_task_t task = task_new_ping_answer(node->id, data->answer_to, MSG_host_get_name(MSG_host_self()));
 
   MSG_task_dsend(task, data->answer_to, task_free_v);
 }
 
 
   MSG_task_dsend(task, data->answer_to, task_free_v);
 }
 
-/**
-  * \brief Main function
-  */
+/** @brief Main function */
 int main(int argc, char *argv[])
 {
 int main(int argc, char *argv[])
 {
-
   MSG_init(&argc, argv);
 
   /* Check the arguments */
   MSG_init(&argc, argv);
 
   /* Check the arguments */
-  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
-       "\tExample: %s msg_platform.xml msg_deployment.xml\n", 
-       argv[0], argv[0]);
+  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n\tExample: %s msg_platform.xml msg_deployment.xml\n",
+             argv[0], argv[0]);
 
   const char *platform_file = argv[1];
   const char *deployment_file = argv[2];
 
   MSG_create_environment(platform_file);
 
   const char *platform_file = argv[1];
   const char *deployment_file = argv[2];
 
   MSG_create_environment(platform_file);
-
   MSG_function_register("node", node);
   MSG_launch_application(deployment_file);
 
   MSG_function_register("node", node);
   MSG_launch_application(deployment_file);
 
index 1fce788..b0990ac 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014. The SimGrid Team.
+/* Copyright (c) 2012, 2014, 2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -11,8 +11,7 @@
 
 //core kademlia functions
 unsigned int join(node_t node, unsigned int id_known);
 
 //core kademlia functions
 unsigned int join(node_t node, unsigned int id_known);
-unsigned int find_node(node_t node, unsigned int id_to_find,
-                       unsigned int count_in_stats);
+unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_in_stats);
 unsigned int ping(node_t node, unsigned int id_to_ping);
 void random_lookup(node_t node);
 
 unsigned int ping(node_t node, unsigned int id_to_ping);
 void random_lookup(node_t node);
 
@@ -23,5 +22,4 @@ void handle_task(node_t node, msg_task_t task);
 void handle_find_node(node_t node, task_data_t data);
 void handle_ping(node_t node, task_data_t data);
 
 void handle_find_node(node_t node, task_data_t data);
 void handle_ping(node_t node, task_data_t data);
 
-
 #endif                          /* _MSG_EXAMPLES_KADEMLIA_H */
 #endif                          /* _MSG_EXAMPLES_KADEMLIA_H */
index 2dfb2f0..ef3212a 100644 (file)
@@ -3,32 +3,32 @@
 p Testing the Kademlia implementation with MSG
 
 ! output sort 19
 p Testing the Kademlia implementation with MSG
 
 ! output sort 19
-$ $SG_TEST_EXENV ${bindir:=.}/kademlia ${srcdir:=.}/../../platforms/platform.xml ${srcdir:=.}/kademlia.xml "--log=root.fmt:[%10.6r]%e(%02i:%P@%h)%e%m%n"
-> [  0.000000] ( 1:node@Jacquelin) Hi, I'm going to create the network with id 00000000
-> [  0.000000] ( 2:node@Boivin) Hi, I'm going to join the network with id 00000001
-> [  0.000000] ( 3:node@Jean_Yves) Hi, I'm going to join the network with id 00000003
-> [  0.000000] ( 4:node@TeX) Hi, I'm going to join the network with id 00000007
-> [  0.000000] ( 5:node@Geoff) Hi, I'm going to join the network with id 0000000f
-> [  0.000000] ( 6:node@Disney) Hi, I'm going to join the network with id 0000001f
-> [  0.000000] ( 7:node@iRMX) Hi, I'm going to join the network with id 0000003f
-> [  0.000000] ( 8:node@McGee) Hi, I'm going to join the network with id 0000007f
-> [  0.000000] ( 9:node@Gatien) Hi, I'm going to join the network with id 000000ff
-> [  0.000000] (10:node@Laroche) Hi, I'm going to join the network with id 000001ff
-> [  0.000000] (11:node@Tanguay) Hi, I'm going to join the network with id 000003ff
-> [  0.000000] (12:node@Morin) Hi, I'm going to join the network with id 000007ff
-> [  0.000000] (13:node@Ethernet) Hi, I'm going to join the network with id 00000fff
-> [900.000000] ( 0:maestro@) Messages created: 1277
-> [900.000000] ( 0:maestro@) Simulated time: 900
-> [900.000000] ( 1:node@Jacquelin) 8/8 FIND_NODE have succeeded
-> [900.000000] ( 2:node@Boivin) 7/7 FIND_NODE have succeeded
-> [900.000000] ( 3:node@Jean_Yves) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 4:node@TeX) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 5:node@Geoff) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 6:node@Disney) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 7:node@iRMX) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 8:node@McGee) 7/7 FIND_NODE have succeeded
-> [900.000000] ( 9:node@Gatien) 6/6 FIND_NODE have succeeded
-> [900.000000] (10:node@Laroche) 6/6 FIND_NODE have succeeded
-> [900.000000] (11:node@Tanguay) 6/6 FIND_NODE have succeeded
-> [900.000000] (12:node@Morin) 7/7 FIND_NODE have succeeded
-> [900.000000] (13:node@Ethernet) 7/7 FIND_NODE have succeeded
+$ $SG_TEST_EXENV ${bindir:=.}/kademlia ${srcdir:=.}/../../platforms/cluster.xml ${srcdir:=.}/kademlia.xml "--log=root.fmt:[%10.6r]%e(%02i:%P@%h)%e%m%n"
+> [  0.000000] ( 1:node@node-0.acme.org) Hi, I'm going to create the network with id 00000000
+> [  0.000000] ( 2:node@node-1.acme.org) Hi, I'm going to join the network with id 00000001
+> [  0.000000] ( 3:node@node-2.acme.org) Hi, I'm going to join the network with id 00000003
+> [  0.000000] ( 4:node@node-3.acme.org) Hi, I'm going to join the network with id 00000007
+> [  0.000000] ( 5:node@node-4.acme.org) Hi, I'm going to join the network with id 0000000f
+> [  0.000000] ( 6:node@node-5.acme.org) Hi, I'm going to join the network with id 0000001f
+> [  0.000000] ( 7:node@node-6.acme.org) Hi, I'm going to join the network with id 0000003f
+> [  0.000000] ( 8:node@node-7.acme.org) Hi, I'm going to join the network with id 0000007f
+> [  0.000000] ( 9:node@node-8.acme.org) Hi, I'm going to join the network with id 000000ff
+> [  0.000000] (10:node@node-9.acme.org) Hi, I'm going to join the network with id 000001ff
+> [  0.000000] (11:node@node-10.acme.org) Hi, I'm going to join the network with id 000003ff
+> [  0.000000] (12:node@node-11.acme.org) Hi, I'm going to join the network with id 000007ff
+> [  0.000000] (13:node@node-12.acme.org) Hi, I'm going to join the network with id 00000fff
+> [780.000000] ( 7:node@node-6.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 9:node@node-8.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 3:node@node-2.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 2:node@node-1.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] (11:node@node-10.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 1:node@node-0.acme.org) 7/7 FIND_NODE have succeeded
+> [780.000000] ( 5:node@node-4.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] (13:node@node-12.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 8:node@node-7.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 6:node@node-5.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] (10:node@node-9.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] (12:node@node-11.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 4:node@node-3.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 0:maestro@) Messages created: 1179
+> [780.000000] ( 0:maestro@) Simulated time: 780
index 28a0b77..0627834 100644 (file)
@@ -2,71 +2,71 @@
 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
 <platform version="4">
 
 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
 <platform version="4">
 
-  <process host="Jacquelin" function="node">
+  <process host="node-0.acme.org" function="node">
     <argument value="0x0000"/>          <!-- my id -->
     <argument value="0x0000"/>          <!-- my id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
 
   </process>
 
-  <process host="Boivin" function="node">
+  <process host="node-1.acme.org" function="node">
     <argument value="0x0001"/>          <!-- my id -->
     <argument value="0"/>               <!-- known id -->
     <argument value="0x0001"/>          <!-- my id -->
     <argument value="0"/>               <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
 
   </process>
 
-  <process host="Jean_Yves" function="node">
+  <process host="node-2.acme.org" function="node">
     <argument value="0x0003"/>          <!-- my id -->
     <argument value="0x0001"/>          <!-- known id -->
     <argument value="0x0003"/>          <!-- my id -->
     <argument value="0x0001"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
 
   </process>
 
-  <process host="TeX" function="node">
+  <process host="node-3.acme.org" function="node">
     <argument value="0x0007"/>          <!-- my id -->
     <argument value="0x0003"/>          <!-- known id -->
     <argument value="0x0007"/>          <!-- my id -->
     <argument value="0x0003"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="Geoff" function="node">
+  <process host="node-4.acme.org" function="node">
     <argument value="0x000f"/>          <!-- my id -->
     <argument value="0x0007"/>          <!-- known id -->
     <argument value="0x000f"/>          <!-- my id -->
     <argument value="0x0007"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="Disney" function="node">
+  <process host="node-5.acme.org" function="node">
     <argument value="0x001f"/>          <!-- my id -->
     <argument value="0x000f"/>          <!-- known id -->
     <argument value="0x001f"/>          <!-- my id -->
     <argument value="0x000f"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="iRMX" function="node">
+  <process host="node-6.acme.org" function="node">
     <argument value="0x003f"/>          <!-- my id -->
     <argument value="0x001f"/>          <!-- known id -->
     <argument value="0x003f"/>          <!-- my id -->
     <argument value="0x001f"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="McGee" function="node">
+  <process host="node-7.acme.org" function="node">
     <argument value="0x007f"/>          <!-- my id -->
     <argument value="0x003f"/>          <!-- known id -->
     <argument value="0x007f"/>          <!-- my id -->
     <argument value="0x003f"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="Gatien" function="node">
+  <process host="node-8.acme.org" function="node">
     <argument value="0x00ff"/>          <!-- my id -->
     <argument value="0x007f"/>          <!-- known id -->
     <argument value="0x00ff"/>          <!-- my id -->
     <argument value="0x007f"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="Laroche" function="node">
+  <process host="node-9.acme.org" function="node">
     <argument value="0x01ff"/>          <!-- my id -->
     <argument value="0x00ff"/>          <!-- known id -->
     <argument value="0x01ff"/>          <!-- my id -->
     <argument value="0x00ff"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-  <process host="Tanguay" function="node">
+  <process host="node-10.acme.org" function="node">
     <argument value="0x03ff"/>          <!-- my id -->
     <argument value="0x01ff"/>          <!-- known id -->
     <argument value="0x03ff"/>          <!-- my id -->
     <argument value="0x01ff"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-   <process host="Morin" function="node">
+   <process host="node-11.acme.org" function="node">
     <argument value="0x07ff"/>          <!-- my id -->
     <argument value="0x03ff"/>          <!-- known id -->
     <argument value="0x07ff"/>          <!-- my id -->
     <argument value="0x03ff"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
   </process>
-   <process host="Ethernet" function="node">
+   <process host="node-12.acme.org" function="node">
     <argument value="0x0fff"/>          <!-- my id -->
     <argument value="0x0000"/>          <!-- known id -->
     <argument value="0x0fff"/>          <!-- my id -->
     <argument value="0x0000"/>          <!-- known id -->
-    <argument value ="900"/>            <!-- deadline -->
+    <argument value ="780"/>            <!-- deadline -->
   </process>
 </platform>
   </process>
 </platform>
index a01c9c4..bc0c9e5 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010, 2012-2015. The SimGrid Team.
+/* Copyright (c) 2010, 2012-2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 #include "simgrid/msg.h"
 #include "xbt/log.h"
 #include "xbt/asserts.h"
 #include "simgrid/msg.h"
 #include "xbt/log.h"
 #include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_node,
-                             "Messages specific for this msg example");
-/**
-  * \brief Initialization of a node
-  * \param node_id the id of the node
-  * \return the node created
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_node, "Messages specific for this msg example");
+
+/** @brief Initialization of a node
+  * @param node_id the id of the node
+  * @return the node created
   */
 node_t node_init(unsigned int node_id)
 {
   */
 node_t node_init(unsigned int node_id)
 {
@@ -33,17 +32,14 @@ node_t node_init(unsigned int node_id)
   return node;
 }
 
   return node;
 }
 
-/*
- * \brief Node destructor
- */
+/* @brief Node destructor  */
 void node_free(node_t node)
 {
   routing_table_free(node->table);
   xbt_free(node);
 }
 
 void node_free(node_t node)
 {
   routing_table_free(node->table);
   xbt_free(node);
 }
 
-/**
-  * @brief Updates/Puts the node id unsigned into our routing table
+/** @brief Updates/Puts the node id unsigned into our routing table
   * @param node Our node data
   * @param id The id of the node we need to add unsigned into our routing table
   */
   * @param node Our node data
   * @param id The id of the node we need to add unsigned into our routing table
   */
@@ -57,27 +53,25 @@ void node_routing_table_update(node_t node, unsigned int id)
   unsigned int id_pos = bucket_find_id(bucket, id);
 
   if (id_pos == -1) {
   unsigned int id_pos = bucket_find_id(bucket, id);
 
   if (id_pos == -1) {
-    /* We check if the bucket is full or not. If it is, we evict
-     * old offline elements */
+    /* We check if the bucket is full or not. If it is, we evict old offline elements */
     if (xbt_dynar_length(bucket->nodes) < bucket_size) {
       //TODO: this is not really very efficient. Maybe we should use something else than dynars ?
       xbt_dynar_unshift(bucket->nodes, &id);
       XBT_VERB("I'm adding to my routing table %08x", id);
     } else {
     if (xbt_dynar_length(bucket->nodes) < bucket_size) {
       //TODO: this is not really very efficient. Maybe we should use something else than dynars ?
       xbt_dynar_unshift(bucket->nodes, &id);
       XBT_VERB("I'm adding to my routing table %08x", id);
     } else {
-      /* TODO: we need to evict the old elements: that's why this function is in "node" instead of "routing table". This is not implemented yet. */
+      /* TODO: we need to evict the old elements: that's why this function is in "node" instead of "routing table".
+       * This is not implemented yet. */
     }
   } else {
     //We push to the front of the dynar the element.
     }
   } else {
     //We push to the front of the dynar the element.
-    unsigned int element =
-        xbt_dynar_get_as(bucket->nodes, id_pos, unsigned int);
+    unsigned int element = xbt_dynar_get_as(bucket->nodes, id_pos, unsigned int);
     xbt_dynar_remove_at(bucket->nodes, id_pos, NULL);
     xbt_dynar_unshift(bucket->nodes, &element);
     XBT_VERB("I'm updating %08x", element);
   }
 }
 
     xbt_dynar_remove_at(bucket->nodes, id_pos, NULL);
     xbt_dynar_unshift(bucket->nodes, &element);
     XBT_VERB("I'm updating %08x", element);
   }
 }
 
-/**
-  * Finds the closest nodes to the node given.
+/** @brief Finds the closest nodes to the node given.
   * @param node : our node
   * @param destination_id : the id of the guy we are trying to find
   */
   * @param node : our node
   * @param destination_id : the id of the guy we are trying to find
   */
@@ -88,19 +82,14 @@ answer_t node_find_closest(node_t node, unsigned int destination_id)
   /* We find the corresponding bucket for the id */
   bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
   int bucket_id = bucket->id;
   /* We find the corresponding bucket for the id */
   bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
   int bucket_id = bucket->id;
-  xbt_assert((bucket_id <= identifier_size),
-             "Bucket found has a wrong identifier");
+  xbt_assert((bucket_id <= identifier_size), "Bucket found has a wrong identifier");
   /* So, we copy the contents of the bucket unsigned into our result dynar */
   answer_add_bucket(bucket, answer);
 
   /* So, we copy the contents of the bucket unsigned into our result dynar */
   answer_add_bucket(bucket, answer);
 
-  /* However, if we don't have enough elements in our bucket, we NEED to
-     include at least
-     * "bucket_size" elements (if, of course, we know at least "bucket_size" elements. So we're going to look unsigned into the other buckets.
+  /* However, if we don't have enough elements in our bucket, we NEED to include at least "bucket_size" elements
+   * (if, of course, we know at least "bucket_size" elements. So we're going to look unsigned into the other buckets.
    */
    */
-  for (i = 1;
-       answer->size < bucket_size && ((bucket_id - i > 0)
-                                      || (bucket_id + i < identifier_size));
-       i++) {
+  for (i = 1; answer->size < bucket_size && ((bucket_id - i > 0) || (bucket_id + i < identifier_size)); i++) {
     /* We check the previous buckets */
     if (bucket_id - i >= 0) {
       bucket_t bucket_p = &node->table->buckets[bucket_id - i];
     /* We check the previous buckets */
     if (bucket_id - i >= 0) {
       bucket_t bucket_p = &node->table->buckets[bucket_id - i];
@@ -120,10 +109,9 @@ answer_t node_find_closest(node_t node, unsigned int destination_id)
   return answer;
 }
 
   return answer;
 }
 
-/**
- * Returns an identifier which is in a specific bucket of a routing table
- * @brief id id of the routing table owner
- * @brief prefix id of the bucket where we want that identifier to be
+/**@brief Returns an identifier which is in a specific bucket of a routing table
+ * @param id id of the routing table owner
+ * @param prefix id of the bucket where we want that identifier to be
  */
 unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
 {
  */
 unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
 {
@@ -134,8 +122,7 @@ unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
   return n ^ id;
 }
 
   return n ^ id;
 }
 
-/**
-  * \brief Returns the prefix of an identifier.
+/** @brief Returns the prefix of an identifier.
   * The prefix is the id of the bucket in which the remote identifier xor our identifier should be stored.
   * @param id : bigunsigned int id to test
   * @param nb_bits : key size
   * The prefix is the id of the bucket in which the remote identifier xor our identifier should be stored.
   * @param id : bigunsigned int id to test
   * @param nb_bits : key size
@@ -151,17 +138,14 @@ unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
   return 0;
 }
 
   return 0;
 }
 
-/**
-  * \brief Gets the mailbox name of a host given its identifier
+/** @brief Gets the mailbox name of a host given its identifier
   */
 void get_node_mailbox(unsigned int id, char *mailbox)
 {
   sprintf(mailbox, "%0*x", MAILBOX_NAME_SIZE, id);
 }
 
   */
 void get_node_mailbox(unsigned int id, char *mailbox)
 {
   sprintf(mailbox, "%0*x", MAILBOX_NAME_SIZE, id);
 }
 
-/**
-  * Constructor, build a new contact information.
-  */
+/** Constructor, build a new contact information. */
 node_contact_t node_contact_new(unsigned int id, unsigned int distance)
 {
   node_contact_t contact = xbt_new(s_node_contact_t, 1);
 node_contact_t node_contact_new(unsigned int id, unsigned int distance)
 {
   node_contact_t contact = xbt_new(s_node_contact_t, 1);
@@ -172,9 +156,7 @@ node_contact_t node_contact_new(unsigned int id, unsigned int distance)
   return contact;
 }
 
   return contact;
 }
 
-/**
-  * Builds a contact information from a contact information
-  */
+/** Builds a contact information from a contact information */
 node_contact_t node_contact_copy(node_contact_t node_contact)
 {
   node_contact_t contact = xbt_new(s_node_contact_t, 1);
 node_contact_t node_contact_copy(node_contact_t node_contact)
 {
   node_contact_t contact = xbt_new(s_node_contact_t, 1);
@@ -185,10 +167,7 @@ node_contact_t node_contact_copy(node_contact_t node_contact)
   return contact;
 }
 
   return contact;
 }
 
-/**
-  * Destructor
-  * @param contact the node_contact to kill.
-  */
+/** Destructor */
 void node_contact_free(node_contact_t contact)
 {
   xbt_free(contact);
 void node_contact_free(node_contact_t contact)
 {
   xbt_free(contact);
index 06b9a47..9a5eab2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014-2015. The SimGrid Team.
+/* Copyright (c) 2012, 2014-2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 #include "simgrid/msg.h"
 
 #include "common.h"
 #include "simgrid/msg.h"
 
 #include "common.h"
-
 #include "answer.h"
 #include "routing_table.h"
 #include "answer.h"
 #include "routing_table.h"
-/**
-  * Information about a foreign node
-  */
+
+/* Information about a foreign node */
 typedef struct s_node_contact {
   unsigned int id;              //The node identifier
   unsigned int distance;        //The distance from the node
 } s_node_contact_t, *node_contact_t;
 
 typedef struct s_node_contact {
   unsigned int id;              //The node identifier
   unsigned int distance;        //The distance from the node
 } s_node_contact_t, *node_contact_t;
 
-/*
- * Node data
- */
+/* Node data */
 typedef struct s_node {
   unsigned int id;              //node id - 160 bits
   routing_table_t table;        //node routing table
 typedef struct s_node {
   unsigned int id;              //node id - 160 bits
   routing_table_t table;        //node routing table
@@ -39,11 +35,9 @@ typedef struct s_node {
 // node functions
 node_t node_init(unsigned int id);
 void node_free(node_t node);
 // 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(node_t node, unsigned int id);
 answer_t node_find_closest(node_t node, unsigned int destination_id);
 
-
 // identifier functions
 unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix);
 unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits);
 // identifier functions
 unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix);
 unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits);
index 3501868..dae7c95 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2015. The SimGrid Team.
+/* Copyright (c) 2012-2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -9,11 +9,9 @@
 #include "simgrid/msg.h"
 #include "xbt/log.h"
 #include "xbt/asserts.h"
 #include "simgrid/msg.h"
 #include "xbt/log.h"
 #include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_routing_table,
-                             "Messages specific for this msg example");
-/**
-  * \brief Initialization of a node routing table.
-  */
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_routing_table, "Messages specific for this msg example");
+
+/** @brief Initialization of a node routing table.  */
 routing_table_t routing_table_init(unsigned int node_id)
 {
   unsigned int i;
 routing_table_t routing_table_init(unsigned int node_id)
 {
   unsigned int i;
@@ -27,9 +25,7 @@ routing_table_t routing_table_init(unsigned int node_id)
   return table;
 }
 
   return table;
 }
 
-/**
-  * \brief Frees the routing table
-  */
+/** @brief Frees the routing table */
 void routing_table_free(routing_table_t table)
 {
   unsigned int i;
 void routing_table_free(routing_table_t table)
 {
   unsigned int i;
@@ -41,18 +37,14 @@ void routing_table_free(routing_table_t table)
   xbt_free(table);
 }
 
   xbt_free(table);
 }
 
-/**
-  * Returns if the routing table contains the id.
-  */
+/** Returns if the routing table contains the id. */
 unsigned int routing_table_contains(routing_table_t table, unsigned int node_id)
 {
   bucket_t bucket = routing_table_find_bucket(table, node_id);
   return bucket_contains(bucket, node_id);
 }
 
 unsigned int routing_table_contains(routing_table_t table, unsigned int node_id)
 {
   bucket_t bucket = routing_table_find_bucket(table, node_id);
   return bucket_contains(bucket, node_id);
 }
 
-/**
-  * @brief prints the routing table, to debug stuff.
-  */
+/**@brief prints the routing table, to debug stuff. */
 void routing_table_print(routing_table_t table)
 {
   unsigned int i, j, value;
 void routing_table_print(routing_table_t table)
 {
   unsigned int i, j, value;
@@ -68,39 +60,28 @@ void routing_table_print(routing_table_t table)
   }
 }
 
   }
 }
 
-/**
-  * Finds an identifier in a bucket and returns its position
-  * or returns -1 if it doesn't exists
+/** @brief Finds an identifier in a bucket and returns its position or returns -1 if it doesn't exists
   * @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)
 {
   * @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 i, length = xbt_dynar_length(bucket->nodes);
-  for (i = 0; i < length; i++) {        //TODO: Use foreach maybe ?
-    if (id == xbt_dynar_get_as(bucket->nodes, i, unsigned int)) {
+  unsigned int i, current_id;
+  xbt_dynar_foreach(bucket->nodes, i, current_id){
+    if (id == current_id){
       return i;
     }
   }
   return -1;
 }
 
       return i;
     }
   }
   return -1;
 }
 
-/**
-  * Returns if the bucket contains an identifier.
-  */
+/** Returns if the bucket contains an identifier.  */
 unsigned int bucket_contains(bucket_t bucket, unsigned int id)
 {
 unsigned int bucket_contains(bucket_t bucket, unsigned int id)
 {
-  unsigned int length = xbt_dynar_length(bucket->nodes), i = 0;
-  for (i = 0; i < length; i++) {
-    if (id == xbt_dynar_get_as(bucket->nodes, i, unsigned int)) {
-      return 1;
-    }
-  }
-  return 0;
+  return xbt_dynar_member(bucket->nodes, &id);
 }
 
 }
 
-/**
-  * Fins the corresponding bucket in a routing table for a given identifier
+/** @brief Finds the corresponding bucket in a routing table for a given identifier
   * @param table the routing table
   * @param id the identifier
   * @return the bucket in which the the identifier would be.
   * @param table the routing table
   * @param id the identifier
   * @return the bucket in which the the identifier would be.
@@ -109,9 +90,7 @@ bucket_t routing_table_find_bucket(routing_table_t table, unsigned int id)
 {
   unsigned int xor_number = table->id ^ id;
   unsigned int prefix = get_node_prefix(xor_number, identifier_size);
 {
   unsigned int xor_number = table->id ^ id;
   unsigned int prefix = get_node_prefix(xor_number, identifier_size);
-  xbt_assert(prefix >= 0
-             && prefix <= identifier_size,
-             "Tried to return a  bucket that doesn't exist.");
+  xbt_assert(prefix >= 0 && prefix <= identifier_size, "Tried to return a  bucket that doesn't exist.");
   bucket_t bucket = &table->buckets[prefix];
   return bucket;
 }
   bucket_t bucket = &table->buckets[prefix];
   return bucket;
 }
index 6baa1cf..63ae7b5 100644 (file)
@@ -8,31 +8,28 @@
 #define _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE
 #include "common.h"
 #include <xbt/dynar.h>
 #define _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE
 #include "common.h"
 #include <xbt/dynar.h>
-/*
- * Routing table bucket
- */
+
+/* Routing table bucket */
 typedef struct s_bucket {
   xbt_dynar_t nodes;            //Nodes in the bucket.
   unsigned int id;              //bucket id
 } s_bucket_t, *bucket_t;
 
 typedef struct s_bucket {
   xbt_dynar_t nodes;            //Nodes in the bucket.
   unsigned int id;              //bucket id
 } s_bucket_t, *bucket_t;
 
-/*
- * Node routing table
- */
+/* Node routing table */
 typedef struct s_routing_table {
   unsigned int id;              //node id of the client's routing table
   s_bucket_t *buckets;          //Node bucket list - 160 sized.
 } s_routing_table_t, *routing_table_t;
 typedef struct s_routing_table {
   unsigned int id;              //node id of the client's routing table
   s_bucket_t *buckets;          //Node bucket list - 160 sized.
 } s_routing_table_t, *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);
 // bucket functions
 unsigned int bucket_find_id(bucket_t bucket, unsigned int id);
 unsigned int bucket_contains(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);
 // 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);
+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(routing_table_t table);
 bucket_t routing_table_find_bucket(routing_table_t table, unsigned int id);
 
-
 #endif                          /* _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE */
 #endif                          /* _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE */
index 5268482..790a2e6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014. The SimGrid Team.
+/* Copyright (c) 2012, 2014, 2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -6,19 +6,15 @@
 
 #include "task.h"
 #include "answer.h"
 
 #include "task.h"
 #include "answer.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task,
-                             "Messages specific for this msg example");
-/**
-  * Creates a new "find node" task
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task, "Messages specific for this msg example");
+
+/** @brief Creates a new "find node" task
   * @param sender_id the id of the node who sends the task
   * @param destination_id the id the sender is trying to find
   * @param hostname the hostname of the node, for logging purposes
   */
   * @param sender_id the id of the node who sends the task
   * @param destination_id the id the sender is trying to find
   * @param hostname the hostname of the node, for logging purposes
   */
-msg_task_t task_new_find_node(unsigned int sender_id,
-                              unsigned int destination_id, char *mailbox,
-                              const char *hostname)
+msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname)
 {
 {
-
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_FIND_NODE;
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_FIND_NODE;
@@ -28,26 +24,21 @@ msg_task_t task_new_find_node(unsigned int sender_id,
   data->answer_to = mailbox;
   data->issuer_host_name = hostname;
 
   data->answer_to = mailbox;
   data->issuer_host_name = hostname;
 
-
   msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
 
   return task;
 }
 
   msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
 
   return task;
 }
 
-/**
-  * Creates a new "answer to find node" task
+/** @brief Creates a new "answer to find node" task
   *  @param sender_id the node who sent the task
   *  @param destination_id the node that should be found
   *  @param answer the answer to send
   *  @param mailbox The mailbox of the sender
   *  @param hostname sender hostname
   */
   *  @param sender_id the node who sent the task
   *  @param destination_id the node that should be found
   *  @param answer the answer to send
   *  @param mailbox The mailbox of the sender
   *  @param hostname sender hostname
   */
-msg_task_t task_new_find_node_answer(unsigned int sender_id,
-                                     unsigned int destination_id,
-                                     answer_t answer, char *mailbox,
-                                     const char *hostname)
+msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destination_id, answer_t answer,
+                                     char *mailbox, const char *hostname)
 {
 {
-
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_FIND_NODE_ANSWER;
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_FIND_NODE_ANSWER;
@@ -62,16 +53,13 @@ msg_task_t task_new_find_node_answer(unsigned int sender_id,
   return task;
 }
 
   return task;
 }
 
-/**
-  * Creates a new "ping" task
+/** @brief Creates a new "ping" task
   * @param sender_id : sender node identifier
   * @param mailbox : mailbox where we should respond
   * @param hostname : hostname of the sender, for debugging purposes
   */
   * @param sender_id : sender node identifier
   * @param mailbox : mailbox where we should respond
   * @param hostname : hostname of the sender, for debugging purposes
   */
-msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
-                         const char *hostname)
+msg_task_t task_new_ping(unsigned int sender_id, char *mailbox, const char *hostname)
 {
 {
-
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_PING;
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_PING;
@@ -86,16 +74,13 @@ msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
   return task;
 }
 
   return task;
 }
 
-/**
-  * Creates a new "ping answer" task
+/** @brief Creates a new "ping answer" task
   * @param sender_id : sender node identifier
   * @param mailbox : mailbox of the sender
   * @param hostname : hostname of the sender, for debugging purposes
   */
   * @param sender_id : sender node identifier
   * @param mailbox : mailbox of the sender
   * @param hostname : hostname of the sender, for debugging purposes
   */
-msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
-                                const char *hostname)
+msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox, const char *hostname)
 {
 {
-
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_PING_ANSWER;
   task_data_t data = xbt_new(s_task_data_t, 1);
 
   data->type = TASK_PING_ANSWER;
@@ -110,8 +95,7 @@ msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
   return task;
 }
 
   return task;
 }
 
-/**
-  * Destroys a task and its data
+/** @brief Destroys a task and its data
   * @param task the task that'll be destroyed
   */
 void task_free(msg_task_t task)
   * @param task the task that'll be destroyed
   */
 void task_free(msg_task_t task)
@@ -126,11 +110,9 @@ void task_free(msg_task_t task)
   xbt_free(data);
 
   MSG_task_destroy(task);
   xbt_free(data);
 
   MSG_task_destroy(task);
-
 }
 
 }
 
-/**
-  * Destroys a task and its data (taking a void* pointer
+/** @brief Destroys a task and its data (taking a void* pointer
   * @param task The task that'll be destroyed
   */
 void task_free_v(void *task)
   * @param task The task that'll be destroyed
   */
 void task_free_v(void *task)
index 251a1e1..a7cd143 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014-2015. The SimGrid Team.
+/* Copyright (c) 2012, 2014-2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -9,9 +9,8 @@
 #include "common.h"
 #include "node.h"
 #include "simgrid/msg.h"
 #include "common.h"
 #include "node.h"
 #include "simgrid/msg.h"
-/**
-  * Types of tasks exchanged
-  */
+
+/* Types of tasks exchanged */
 typedef enum {
   TASK_FIND_NODE,
   TASK_FIND_NODE_ANSWER,
 typedef enum {
   TASK_FIND_NODE,
   TASK_FIND_NODE_ANSWER,
@@ -21,9 +20,8 @@ typedef enum {
   TASK_PING_ANSWER,
   TASK_LEAVING
 } e_task_type_t;
   TASK_PING_ANSWER,
   TASK_LEAVING
 } e_task_type_t;
-/**
-  * Data attached with the tasks
-  */
+
+/* Data attached with the tasks */
 typedef struct s_task_data {
   e_task_type_t type;
   unsigned int sender_id;       //Id of the guy who sent the task
 typedef struct s_task_data {
   e_task_type_t type;
   unsigned int sender_id;       //Id of the guy who sent the task
@@ -34,19 +32,11 @@ typedef struct s_task_data {
 } s_task_data_t, *task_data_t;
 
 //Task handling functions
 } s_task_data_t, *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);
-
-msg_task_t task_new_find_node_answer(unsigned int sender_id,
-                                     unsigned int destination_id,
-                                     answer_t answer, char *mailbox,
-                                     const char *hostname);
-
-msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
-                         const char *hostname);
-msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
-                                const char *hostname);
+msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname);
+msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destination_id, answer_t answer,
+                                     char *mailbox, const char *hostname);
+msg_task_t task_new_ping(unsigned int sender_id, char *mailbox, const char *hostname);
+msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox, const char *hostname);
 void task_free(msg_task_t task);
 void task_free_v(void *task);
 #endif                          /* _MSG_KADEMLIA_EXAMPLES_TASK */
 void task_free(msg_task_t task);
 void task_free_v(void *task);
 #endif                          /* _MSG_KADEMLIA_EXAMPLES_TASK */