Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in examples/deprecated/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Dec 2019 16:30:51 +0000 (17:30 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Dec 2019 17:24:04 +0000 (18:24 +0100)
examples/deprecated/msg/dht-kademlia/answer.c
examples/deprecated/msg/dht-kademlia/answer.h
examples/deprecated/msg/dht-kademlia/dht-kademlia.c
examples/deprecated/msg/dht-kademlia/dht-kademlia.h
examples/deprecated/msg/dht-kademlia/node.c
examples/deprecated/msg/dht-kademlia/node.h
examples/deprecated/msg/dht-kademlia/routing_table.c
examples/deprecated/msg/dht-kademlia/routing_table.h
examples/deprecated/msg/dht-kademlia/task.h
examples/deprecated/msg/dht-pastry/dht-pastry.c

index 681a0af..5ad44a3 100644 (file)
@@ -32,7 +32,7 @@ void answer_free(answer_t answer)
 }
 
 /** @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;
@@ -46,7 +46,7 @@ void answer_print(answer_t answer)
   * @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;
@@ -84,7 +84,7 @@ static int _answer_sort_function(const void *e1, const void *e2)
   * @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);
 }
@@ -108,7 +108,7 @@ void answer_trim(answer_t answer)
   * @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");
@@ -126,7 +126,7 @@ void answer_add_bucket(bucket_t bucket, answer_t 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)
+unsigned int answer_contains(const_answer_t answer, unsigned int id)
 {
   unsigned int i = 0;
   node_contact_t contact;
@@ -142,7 +142,7 @@ unsigned int answer_contains(answer_t answer, unsigned int id)
   * @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;
index e67bd62..c3f498b 100644 (file)
@@ -17,15 +17,16 @@ typedef struct s_node_answer {
 } 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_ */
index f33ba10..f008973 100644 (file)
@@ -301,7 +301,7 @@ void send_find_node(node_t node, unsigned int id, unsigned int destination)
   * 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;
@@ -340,7 +340,7 @@ void handle_task(node_t node, msg_task_t task)
 }
 
 /** @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);
index 62f550c..0ecce3b 100644 (file)
@@ -15,9 +15,9 @@ unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_
 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 */
index 629f277..5450a69 100644 (file)
@@ -42,7 +42,7 @@ void node_free(node_t node)
   * @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
@@ -74,7 +74,7 @@ void node_routing_table_update(node_t node, unsigned int id)
   * @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);
@@ -155,7 +155,7 @@ node_contact_t node_contact_new(unsigned int id, unsigned int distance)
 }
 
 /** 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);
 
index e8f97c6..fb49c09 100644 (file)
@@ -20,6 +20,7 @@ typedef struct s_node_contact {
 } 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 {
@@ -35,12 +36,13 @@ 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);
@@ -49,6 +51,6 @@ void get_node_mailbox(unsigned int id, char *mailbox);
 
 // 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 */
index 5672b26..68d2661 100644 (file)
@@ -43,7 +43,7 @@ unsigned int routing_table_contains(routing_table_t table, unsigned int node_id)
 }
 
 /**@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;
@@ -63,7 +63,7 @@ void routing_table_print(routing_table_t table)
   * @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;
@@ -76,7 +76,7 @@ unsigned int bucket_find_id(bucket_t bucket, unsigned int 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);
 }
@@ -86,7 +86,7 @@ unsigned int bucket_contains(bucket_t bucket, unsigned int 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);
index 1f0a677..a192f24 100644 (file)
@@ -16,6 +16,7 @@ typedef struct s_bucket {
 } 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 {
@@ -24,16 +25,17 @@ 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 */
index 8490388..7879b48 100644 (file)
@@ -30,6 +30,7 @@ typedef struct s_task_data {
 } 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);
index ba71a21..274e2ba 100644 (file)
@@ -43,6 +43,7 @@ typedef struct s_node {
   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;
@@ -72,11 +73,6 @@ typedef struct s_task_data {
 } 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
@@ -118,7 +114,8 @@ static void task_free(void* task)
 }
 
 /* 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);
@@ -173,7 +170,8 @@ static int routing_next(node_t node, int 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++)
@@ -189,17 +187,20 @@ static state_t node_get_state(node_t node) {
   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++)
@@ -207,14 +208,16 @@ static void print_node_routing_table(node_t node) {
   }
 }
 /* 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);
@@ -427,7 +430,8 @@ static void handle_task(node_t node, msg_task_t task) {
 }
 
 /* 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;