From: Arnaud Giersch Date: Fri, 27 Dec 2019 16:30:51 +0000 (+0100) Subject: [sonar] Constify pointer and reference parameters in examples/deprecated/. X-Git-Tag: v3.25~206 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ee3f7ee4964754dfbdbb351279c08bff5a2d771a [sonar] Constify pointer and reference parameters in examples/deprecated/. --- diff --git a/examples/deprecated/msg/dht-kademlia/answer.c b/examples/deprecated/msg/dht-kademlia/answer.c index 681a0af129..5ad44a3825 100644 --- a/examples/deprecated/msg/dht-kademlia/answer.c +++ b/examples/deprecated/msg/dht-kademlia/answer.c @@ -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; diff --git a/examples/deprecated/msg/dht-kademlia/answer.h b/examples/deprecated/msg/dht-kademlia/answer.h index e67bd62c7e..c3f498b526 100644 --- a/examples/deprecated/msg/dht-kademlia/answer.h +++ b/examples/deprecated/msg/dht-kademlia/answer.h @@ -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_ */ diff --git a/examples/deprecated/msg/dht-kademlia/dht-kademlia.c b/examples/deprecated/msg/dht-kademlia/dht-kademlia.c index f33ba10088..f008973ba1 100644 --- a/examples/deprecated/msg/dht-kademlia/dht-kademlia.c +++ b/examples/deprecated/msg/dht-kademlia/dht-kademlia.c @@ -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); diff --git a/examples/deprecated/msg/dht-kademlia/dht-kademlia.h b/examples/deprecated/msg/dht-kademlia/dht-kademlia.h index 62f550c607..0ecce3bbc4 100644 --- a/examples/deprecated/msg/dht-kademlia/dht-kademlia.h +++ b/examples/deprecated/msg/dht-kademlia/dht-kademlia.h @@ -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 */ diff --git a/examples/deprecated/msg/dht-kademlia/node.c b/examples/deprecated/msg/dht-kademlia/node.c index 629f277f8b..5450a690ae 100644 --- a/examples/deprecated/msg/dht-kademlia/node.c +++ b/examples/deprecated/msg/dht-kademlia/node.c @@ -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); diff --git a/examples/deprecated/msg/dht-kademlia/node.h b/examples/deprecated/msg/dht-kademlia/node.h index e8f97c67a3..fb49c09873 100644 --- a/examples/deprecated/msg/dht-kademlia/node.h +++ b/examples/deprecated/msg/dht-kademlia/node.h @@ -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 */ diff --git a/examples/deprecated/msg/dht-kademlia/routing_table.c b/examples/deprecated/msg/dht-kademlia/routing_table.c index 5672b26a75..68d26611c9 100644 --- a/examples/deprecated/msg/dht-kademlia/routing_table.c +++ b/examples/deprecated/msg/dht-kademlia/routing_table.c @@ -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); diff --git a/examples/deprecated/msg/dht-kademlia/routing_table.h b/examples/deprecated/msg/dht-kademlia/routing_table.h index 1f0a677082..a192f2448d 100644 --- a/examples/deprecated/msg/dht-kademlia/routing_table.h +++ b/examples/deprecated/msg/dht-kademlia/routing_table.h @@ -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 */ diff --git a/examples/deprecated/msg/dht-kademlia/task.h b/examples/deprecated/msg/dht-kademlia/task.h index 849038887c..7879b48d69 100644 --- a/examples/deprecated/msg/dht-kademlia/task.h +++ b/examples/deprecated/msg/dht-kademlia/task.h @@ -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); diff --git a/examples/deprecated/msg/dht-pastry/dht-pastry.c b/examples/deprecated/msg/dht-pastry/dht-pastry.c index ba71a214e8..274e2ba8f7 100644 --- a/examples/deprecated/msg/dht-pastry/dht-pastry.c +++ b/examples/deprecated/msg/dht-pastry/dht-pastry.c @@ -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; iid, (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; ineighborhood_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; inamespace_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;