From 8463e0b06b0943a7dbba9972f1cd036af844e1fd Mon Sep 17 00:00:00 2001 From: Jose Marcial Vieira Bisneto Date: Thu, 16 Mar 2017 21:18:03 -0300 Subject: [PATCH] Kademlia, better treatment when there is no result. --- routing/kademlia.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routing/kademlia.c b/routing/kademlia.c index 11051b4..ff83533 100644 --- a/routing/kademlia.c +++ b/routing/kademlia.c @@ -447,11 +447,13 @@ struct MultiAddress** search_kademlia(char* peer_id, int timeout) search_result->ipv4_count == 0 && search_result->ipv6_count == 0) { to = search_kademlia_internal (id, 0, to); // Repeat search to collect result. - if (to <= 0) return NULL; // time out. usleep(2000000); // Wait a few seconds for the result. to -= 2000000; } + if (search_result->ipv4_count == 0 || + search_result->ipv6_count == 0) return NULL; // no result. + ret = calloc(search_result->ipv4_count + search_result->ipv6_count + 1, // IPv4 + IPv6 itens and a NULL terminator. sizeof (struct MultiAddress*)); // array of pointer. if (!ret) {