From 8ce489adfdd6e6b2b1aa46256d0e0f960e4b4ff9 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 29 Jan 2019 13:34:27 +0100 Subject: [PATCH] Kill dead code in kademlia examples. --- examples/deprecated/java/CMakeLists.txt | 2 +- .../deprecated/java/dht/kademlia/Common.java | 2 - .../deprecated/java/dht/kademlia/Node.java | 41 ------------ .../java/dht/kademlia/PingAnswerTask.java | 13 ---- .../java/dht/kademlia/PingTask.java | 13 ---- examples/deprecated/msg/dht-kademlia/common.h | 1 - .../msg/dht-kademlia/dht-kademlia.c | 66 ------------------- .../msg/dht-kademlia/dht-kademlia.h | 2 - examples/deprecated/msg/dht-kademlia/task.c | 42 ------------ examples/deprecated/msg/dht-kademlia/task.h | 4 -- .../s4u/dht-kademlia/s4u-dht-kademlia.hpp | 2 - 11 files changed, 1 insertion(+), 187 deletions(-) delete mode 100644 examples/deprecated/java/dht/kademlia/PingAnswerTask.java delete mode 100644 examples/deprecated/java/dht/kademlia/PingTask.java diff --git a/examples/deprecated/java/CMakeLists.txt b/examples/deprecated/java/CMakeLists.txt index 676d85d5fc..c5a61b97b4 100644 --- a/examples/deprecated/java/CMakeLists.txt +++ b/examples/deprecated/java/CMakeLists.txt @@ -11,7 +11,7 @@ set(cloud-migration_files Main Daemon Test XVM) set(dht-chord_files Main ChordTask Common FindSuccessorAnswerTask FindSuccessorTask GetPredecessorAnswerTask GetPredecessorTask Node NotifyTask) set(dht-kademlia_files Main Answer Bucket Common Contact FindNodeAnswerTask FindNodeTask - KademliaTask Node PingAnswerTask PingTask RoutingTable) + KademliaTask Node RoutingTable) set(trace-pingpong_files Main PingPongTask Receiver Sender) set(energy-consumption_files Main EnergyConsumer) set(energy-pstate_files Main PstateRunner) diff --git a/examples/deprecated/java/dht/kademlia/Common.java b/examples/deprecated/java/dht/kademlia/Common.java index df5a30df6d..6f5a72bd99 100644 --- a/examples/deprecated/java/dht/kademlia/Common.java +++ b/examples/deprecated/java/dht/kademlia/Common.java @@ -24,8 +24,6 @@ public class Common { public static final int FIND_NODE_TIMEOUT = 10; /* Global timeout for a FIND_NODE request */ public static final int FIND_NODE_GLOBAL_TIMEOUT = 50; - /* Timeout for a "PING" request */ - public static final int PING_TIMEOUT = 35; public static final int MAX_STEPS = 10; public static final int JOIN_BUCKETS_QUERIES = 1; diff --git a/examples/deprecated/java/dht/kademlia/Node.java b/examples/deprecated/java/dht/kademlia/Node.java index 5ce801cca7..ebc43a73f6 100644 --- a/examples/deprecated/java/dht/kademlia/Node.java +++ b/examples/deprecated/java/dht/kademlia/Node.java @@ -230,38 +230,6 @@ public class Node extends Process { return destinationFound; } - /** - * @brief Sends a "PING" request to a node - * @param destination Ping destination id. - */ - public void ping(int destination) { - boolean destinationFound = false; - double timeout = Msg.getClock() + Common.PING_TIMEOUT; - PingTask pingTask = new PingTask(this.id); - /* Sending the ping task */ - pingTask.dsend(Integer.toString(destination)); - do { - try { - Task task = Task.receive(Integer.toString(this.id),Common.PING_TIMEOUT); - if (task instanceof PingAnswerTask) { - PingAnswerTask answerTask = (PingAnswerTask)task; - if (answerTask.getSenderId() == destination) { - this.table.update(destination); - destinationFound = true; - } else { - handleTask(task); - } - } else { - handleTask(task); - } - waitFor(1); - } - catch (Exception ex) { - Msg.debug("Caught exception: " + ex); - } - } while (Msg.getClock() < timeout && !destinationFound); - } - /** * @brief Sends a "FIND_NODE" request (task) to a node we know. * @param id Id of the node we are querying @@ -300,9 +268,6 @@ public class Node extends Process { if (task instanceof FindNodeTask) { handleFindNode((FindNodeTask)task); } - else if (task instanceof PingTask) { - handlePing((PingTask)task); - } } } @@ -312,10 +277,4 @@ public class Node extends Process { FindNodeAnswerTask taskToSend = new FindNodeAnswerTask(this.id,task.getDestination(),answer); taskToSend.dsend(Integer.toString(task.getSenderId())); } - - public void handlePing(PingTask task) { - Msg.debug("Received a PING from " + task.getSenderId()); - PingAnswerTask taskToSend = new PingAnswerTask(this.id); - taskToSend.dsend(Integer.toString(task.getSenderId())); - } } diff --git a/examples/deprecated/java/dht/kademlia/PingAnswerTask.java b/examples/deprecated/java/dht/kademlia/PingAnswerTask.java deleted file mode 100644 index ea6ed88211..0000000000 --- a/examples/deprecated/java/dht/kademlia/PingAnswerTask.java +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) 2012-2019. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -package dht.kademlia; - -public class PingAnswerTask extends KademliaTask { - public PingAnswerTask(int senderId) { - super(senderId); - } -} diff --git a/examples/deprecated/java/dht/kademlia/PingTask.java b/examples/deprecated/java/dht/kademlia/PingTask.java deleted file mode 100644 index 8deaf2765f..0000000000 --- a/examples/deprecated/java/dht/kademlia/PingTask.java +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) 2012-2019. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -package dht.kademlia; - -public class PingTask extends KademliaTask { - public PingTask(int senderId) { - super(senderId); - } -} diff --git a/examples/deprecated/msg/dht-kademlia/common.h b/examples/deprecated/msg/dht-kademlia/common.h index 870a412769..bb101f67d1 100644 --- a/examples/deprecated/msg/dht-kademlia/common.h +++ b/examples/deprecated/msg/dht-kademlia/common.h @@ -10,7 +10,6 @@ #define RECEIVE_TIMEOUT 1 -#define ping_timeout 55 #define find_node_timeout 10 #define find_node_global_timeout 50 diff --git a/examples/deprecated/msg/dht-kademlia/dht-kademlia.c b/examples/deprecated/msg/dht-kademlia/dht-kademlia.c index 09afc14301..49e4ffd007 100644 --- a/examples/deprecated/msg/dht-kademlia/dht-kademlia.c +++ b/examples/deprecated/msg/dht-kademlia/dht-kademlia.c @@ -268,59 +268,6 @@ unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_ return destination_found; } -/** @brief Pings a node in the system to see if it is online. - * @param node Our node data - * @param id_to_ping the id of a node we want to see if it is online. - * @return if the ping succeded or not. - */ -unsigned int ping(node_t node, unsigned int id_to_ping) -{ - char mailbox[MAILBOX_NAME_SIZE]; - snprintf(mailbox, MAILBOX_NAME_SIZE, "%u", id_to_ping); - - 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())); - msg_task_t task_received = NULL; - - XBT_VERB("PING %08x", id_to_ping); - - //Check that we aren't trying to ping ourselves - if (id_to_ping == node->id) { - return 1; - } - - /* Sending the ping task */ - MSG_task_dsend(ping_task, mailbox, task_free_v); - do { - task_received = NULL; - msg_error_t status = - MSG_task_receive_with_timeout(&task_received, node->mailbox, ping_timeout); - if (status == MSG_OK) { - xbt_assert((task_received != NULL), "Invalid task received"); - //Checking if it's what we are waiting for or not. - task_data_t data = MSG_task_get_data(task_received); - xbt_assert((data != NULL), "didn't receive any data..."); - 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); - 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 (MSG_get_clock() < timeout); - - if (MSG_get_clock() >= timeout) { - XBT_DEBUG("Ping to %s has timeout.", mailbox); - return 0; - } - XBT_DEBUG("It seems that %s is offline...", mailbox); - return -1; -} - /** @brief Does a pseudo-random lookup for someone in the system * @param node caller node data */ @@ -385,9 +332,6 @@ void handle_task(node_t node, msg_task_t task) case TASK_FIND_NODE_ANSWER: XBT_DEBUG("Received a wrong answer for a FIND_NODE"); break; - case TASK_PING: - handle_ping(node, data); - break; default: break; } @@ -408,16 +352,6 @@ void handle_find_node(node_t node, task_data_t data) MSG_task_dsend(task, data->answer_to, task_free_v); } -/** @brief handles the answer to a ping */ -void handle_ping(node_t node, task_data_t data) -{ - XBT_VERB("Received a PING request from %s (%s)", data->answer_to, data->issuer_host_name); - //Building the answer to the request - msg_task_t task = task_new_ping_answer(node->id, data->answer_to, MSG_host_get_name(MSG_host_self())); - - MSG_task_dsend(task, data->answer_to, task_free_v); -} - /** @brief Main function */ int main(int argc, char *argv[]) { diff --git a/examples/deprecated/msg/dht-kademlia/dht-kademlia.h b/examples/deprecated/msg/dht-kademlia/dht-kademlia.h index 2992314fad..62f550c607 100644 --- a/examples/deprecated/msg/dht-kademlia/dht-kademlia.h +++ b/examples/deprecated/msg/dht-kademlia/dht-kademlia.h @@ -12,7 +12,6 @@ //core kademlia functions unsigned int join(node_t node, unsigned int id_known); unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_in_stats); -unsigned int ping(node_t node, unsigned int id_to_ping); void random_lookup(node_t node); void send_find_node(node_t node, unsigned int id, unsigned int destination); @@ -20,6 +19,5 @@ unsigned int send_find_node_to_best(node_t node, 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_ping(node_t node, task_data_t data); #endif /* _MSG_EXAMPLES_KADEMLIA_H */ diff --git a/examples/deprecated/msg/dht-kademlia/task.c b/examples/deprecated/msg/dht-kademlia/task.c index a1e39b1d1d..126a15d4e1 100644 --- a/examples/deprecated/msg/dht-kademlia/task.c +++ b/examples/deprecated/msg/dht-kademlia/task.c @@ -53,48 +53,6 @@ msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destin return task; } -/** @brief Creates a new "ping" task - * @param sender_id : sender node identifier - * @param mailbox : mailbox where we should respond - * @param hostname : hostname of the sender, for debugging purposes - */ -msg_task_t task_new_ping(unsigned int sender_id, char *mailbox, const char *hostname) -{ - task_data_t data = xbt_new(s_task_data_t, 1); - - data->type = TASK_PING; - data->sender_id = sender_id; - data->destination_id = 0; - data->answer = NULL; - data->answer_to = mailbox; - data->issuer_host_name = hostname; - - msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data); - - return task; -} - -/** @brief Creates a new "ping answer" task - * @param sender_id : sender node identifier - * @param mailbox : mailbox of the sender - * @param hostname : hostname of the sender, for debugging purposes - */ -msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox, const char *hostname) -{ - task_data_t data = xbt_new(s_task_data_t, 1); - - data->type = TASK_PING_ANSWER; - data->sender_id = sender_id; - data->destination_id = 0; - data->answer = NULL; - data->answer_to = mailbox; - data->issuer_host_name = hostname; - - msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data); - - return task; -} - /** @brief Destroys a task and its data * @param task the task that'll be destroyed */ diff --git a/examples/deprecated/msg/dht-kademlia/task.h b/examples/deprecated/msg/dht-kademlia/task.h index a5aac157cd..849038887c 100644 --- a/examples/deprecated/msg/dht-kademlia/task.h +++ b/examples/deprecated/msg/dht-kademlia/task.h @@ -16,8 +16,6 @@ typedef enum { TASK_FIND_NODE_ANSWER, TASK_FIND_VALUE, TASK_FIND_VALUE_ANSWER, - TASK_PING, - TASK_PING_ANSWER, TASK_LEAVING } e_task_type_t; @@ -37,8 +35,6 @@ typedef s_task_data_t *task_data_t; msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname); msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destination_id, answer_t answer, char *mailbox, const char *hostname); -msg_task_t task_new_ping(unsigned int sender_id, char *mailbox, const char *hostname); -msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox, const char *hostname); void task_free(msg_task_t task); void task_free_v(void *task); #endif /* _MSG_KADEMLIA_EXAMPLES_TASK */ diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp index 5e9f8857a8..e1fedb717d 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp @@ -12,14 +12,12 @@ namespace kademlia { class Answer; class Message; -class Ping; } #define max_join_trials 4 #define RECEIVE_TIMEOUT 1 -#define ping_timeout 55 #define find_node_timeout 10 #define find_node_global_timeout 50 -- 2.20.1