From f6940b14610d1ac8f34a2e35572c1db33920c0c4 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 24 Mar 2017 13:29:24 +0100 Subject: [PATCH 1/1] bug-- and a bit less brain overload --- examples/msg/dht-kademlia/answer.c | 2 +- examples/msg/dht-kademlia/dht-kademlia.c | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/examples/msg/dht-kademlia/answer.c b/examples/msg/dht-kademlia/answer.c index ce1d586604..1cd48a0cf9 100644 --- a/examples/msg/dht-kademlia/answer.c +++ b/examples/msg/dht-kademlia/answer.c @@ -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); diff --git a/examples/msg/dht-kademlia/dht-kademlia.c b/examples/msg/dht-kademlia/dht-kademlia.c index c718db420f..463fd01338 100644 --- a/examples/msg/dht-kademlia/dht-kademlia.c +++ b/examples/msg/dht-kademlia/dht-kademlia.c @@ -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 -- 2.20.1