Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
yet another cleaning pass
[simgrid.git] / examples / msg / kademlia / node.c
index 49c9345..08aa37c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010, 2012-2014. 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
@@ -6,16 +6,13 @@
 
 #include "node.h"
 #include "routing_table.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)
 {
@@ -33,17 +30,14 @@ node_t node_init(unsigned int node_id)
   return node;
 }
 
-/*
- * \brief Node destructor
- */
+/* @brief Node destructor  */
 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
   */
@@ -57,27 +51,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) {
-    /* 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 {
-      /* 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.
-    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);
   }
 }
 
-/**
-  * 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
   */
@@ -88,19 +80,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;
-  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);
 
-  /* 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];
@@ -120,10 +107,9 @@ answer_t node_find_closest(node_t node, unsigned int destination_id)
   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)
 {
@@ -134,8 +120,7 @@ unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
   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
@@ -151,17 +136,14 @@ unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
   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);
 }
 
-/**
-  * 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);
@@ -172,9 +154,7 @@ node_contact_t node_contact_new(unsigned int id, unsigned int distance)
   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);
@@ -185,10 +165,7 @@ node_contact_t node_contact_copy(node_contact_t node_contact)
   return contact;
 }
 
-/**
-  * Destructor
-  * @param contact the node_contact to kill.
-  */
+/** Destructor */
 void node_contact_free(node_contact_t contact)
 {
   xbt_free(contact);