1 /* Copyright (c) 2012-2019. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task, "Messages specific for this msg example");
11 /** @brief Creates a new "find node" task
12 * @param sender_id the id of the node who sends the task
13 * @param destination_id the id the sender is trying to find
14 * @param hostname the hostname of the node, for logging purposes
16 msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname)
18 task_data_t data = xbt_new(s_task_data_t, 1);
20 data->type = TASK_FIND_NODE;
21 data->sender_id = sender_id;
22 data->destination_id = destination_id;
24 data->answer_to = mailbox;
25 data->issuer_host_name = hostname;
27 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
32 /** @brief Creates a new "answer to find node" task
33 * @param sender_id the node who sent the task
34 * @param destination_id the node that should be found
35 * @param answer the answer to send
36 * @param mailbox The mailbox of the sender
37 * @param hostname sender hostname
39 msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destination_id, answer_t answer,
40 char *mailbox, const char *hostname)
42 task_data_t data = xbt_new(s_task_data_t, 1);
44 data->type = TASK_FIND_NODE_ANSWER;
45 data->sender_id = sender_id;
46 data->destination_id = destination_id;
47 data->answer = answer;
48 data->answer_to = mailbox;
49 data->issuer_host_name = hostname;
51 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
56 /** @brief Destroys a task and its data
57 * @param task the task that'll be destroyed
59 void task_free(msg_task_t task)
61 xbt_assert((task != NULL), "Tried to free a NULL task");
63 task_data_t data = MSG_task_get_data(task);
66 answer_free(data->answer);
70 MSG_task_destroy(task);
73 /** @brief Destroys a task and its data (taking a void* pointer
74 * @param task The task that'll be destroyed
76 void task_free_v(void *task)