Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bug-- and a bit less brain overload
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Mar 2017 12:29:24 +0000 (13:29 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Mar 2017 12:29:24 +0000 (13:29 +0100)
examples/msg/dht-kademlia/answer.c
examples/msg/dht-kademlia/dht-kademlia.c

index ce1d586..1cd48a0 100644 (file)
@@ -144,7 +144,7 @@ unsigned int answer_contains(answer_t answer, unsigned int id)
   */
 unsigned int answer_destination_found(answer_t answer)
 {
-  if (xbt_dynar_length(answer->nodes) < 1) {
+  if (xbt_dynar_is_empty(answer->nodes)) {
     return 0;
   }
   node_contact_t contact_tail = xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
index c718db4..463fd01 100644 (file)
@@ -280,7 +280,6 @@ unsigned int ping(node_t node, unsigned int id_to_ping)
   char mailbox[MAILBOX_NAME_SIZE];
   snprintf(mailbox,MAILBOX_NAME_SIZE, "%d", id_to_ping);
 
-  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()));
@@ -307,24 +306,21 @@ unsigned int ping(node_t node, unsigned int id_to_ping)
       if (data->type == TASK_PING_ANSWER && id_to_ping == data->sender_id) {
         XBT_VERB("Ping to %s succeeded", mailbox);
         node_routing_table_update(node, data->sender_id);
-        destination_found = 1;
         task_free(task_received);
+        return 1; // Destination found, ping succeeded!
       } else {
         //If it's not our answer, we answer the query anyway.
         handle_task(node, task_received);
       }
     }
-  } while (destination_found == 0 && MSG_get_clock() < timeout);
+  } while (MSG_get_clock() < timeout);
 
   if (MSG_get_clock() >= timeout) {
     XBT_DEBUG("Ping to %s has timeout.", mailbox);
     return 0;
   }
-  if (destination_found == -1) {
-    XBT_DEBUG("It seems that %s is offline...", mailbox);
-    return 0;
-  }
-  return 1;
+  XBT_DEBUG("It seems that %s is offline...", mailbox);
+  return -1;
 }
 
 /** @brief Does a pseudo-random lookup for someone in the system