XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chord,
"Messages specific for this msg example");
-#define NB_BITS 6
-#define NB_KEYS 64
+#define NB_BITS 16
+#define NB_KEYS 65536
#define COMM_SIZE 10
#define COMP_SIZE 0
+#define TIMEOUT 100
/**
* Finger element.
int request_id; // id paramater (used by some types of tasks)
int request_finger; // finger parameter (used by some types of tasks)
int answer_id; // answer (used by some types of tasks)
- const char* answer_to; // mailbox to send an answer to
+ char* answer_to; // mailbox to send an answer to (or NULL)
const char* issuer_host_name; // used for logging
} s_task_data_t, *task_data_t;
static int normalize(int id);
static int is_in_interval(int id, int start, int end);
static char* get_mailbox(int host_id);
+static void task_data_destroy(task_data_t task_data);
static void print_finger_table(node_t node);
static void set_finger(node_t node, int finger_index, int id);
static void set_predecessor(node_t node, int predecessor_id);
return bprintf("mailbox%d", node_id);
}
+/**
+ * \brief Frees the memory used by some task data.
+ * \param task_data the task data to destroy
+ */
+static void task_data_destroy(task_data_t task_data)
+{
+ xbt_free(task_data->answer_to);
+ xbt_free(task_data);
+}
+
/**
* \brief Displays the finger table of a node.
* \param node a node
// a transfer has occured
MSG_error_t status = MSG_comm_get_status(node.comm_receive);
- MSG_comm_destroy(node.comm_receive);
- node.comm_receive = NULL;
if (status != MSG_OK) {
DEBUG0("Failed to receive a task. Nevermind.");
+ node.comm_receive = NULL;
}
else {
// the task was successfully received
+ MSG_comm_destroy(node.comm_receive);
+ node.comm_receive = NULL;
handle_task(&node, task_received);
}
}
xbt_dynar_foreach(node.comms, cursor, comm_send) {
task = MSG_comm_get_task(comm_send);
MSG_task_cancel(task);
- xbt_free(MSG_task_get_data(task));
+ task_data_destroy(MSG_task_get_data(task));
MSG_task_destroy(task);
MSG_comm_destroy(comm_send);
// FIXME: the task is actually not destroyed because MSG thinks that the other side (whose process is dead) is still using it
if (is_in_interval(task_data->request_id, node->id + 1, node->fingers[0].id)) {
task_data->type = TASK_FIND_SUCCESSOR_ANSWER;
task_data->answer_id = node->fingers[0].id;
- comm = MSG_task_isend(task, task_data->answer_to);
- xbt_dynar_push(node->comms, &comm);
DEBUG3("Sending back a 'Find Successor Answer' to %s: the successor of %d is %d",
task_data->issuer_host_name,
task_data->request_id, task_data->answer_id);
+ comm = MSG_task_isend(task, task_data->answer_to);
+ xbt_dynar_push(node->comms, &comm);
}
else {
// otherwise, forward the request to the closest preceding finger in my table
DEBUG1("Receiving a 'Get Predecessor' request from %s", task_data->issuer_host_name);
task_data->type = TASK_GET_PREDECESSOR_ANSWER;
task_data->answer_id = node->pred_id;
- comm = MSG_task_isend(task, task_data->answer_to);
- xbt_dynar_push(node->comms, &comm);
DEBUG3("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d",
task_data->issuer_host_name,
task_data->answer_to, task_data->answer_id);
+ comm = MSG_task_isend(task, task_data->answer_to);
+ xbt_dynar_push(node->comms, &comm);
break;
case TASK_NOTIFY:
// someone is telling me that he may be my new predecessor
DEBUG1("Receiving a 'Notify' request from %s", task_data->issuer_host_name);
notify(node, task_data->request_id);
- xbt_free(task_data);
+ task_data_destroy(task_data);
MSG_task_destroy(task);
break;
DEBUG1("Receiving a 'Predecessor Leaving' message from %s", task_data->issuer_host_name);
// modify my predecessor
set_predecessor(node, task_data->request_id);
- xbt_free(task_data);
+ task_data_destroy(task_data);
MSG_task_destroy(task);
/*TODO :
>> notify my new predecessor
DEBUG1("Receiving a 'Successor Leaving' message from %s", task_data->issuer_host_name);
// modify my successor FIXME : this should be implicit ?
set_finger(node, 0, task_data->request_id);
- xbt_free(task_data);
+ task_data_destroy(task_data);
MSG_task_destroy(task);
/* TODO
>> notify my new successor
>> update my table & predecessors table */
break;
- default:
- CRITICAL1("Received an unexpected task: %d", type);
- //xbt_abort();
+ case TASK_FIND_SUCCESSOR_ANSWER:
+ case TASK_GET_PREDECESSOR_ANSWER:
+ DEBUG2("Ignoring unexpected task of type %d (%p)", type, task);
+ break;
}
}
req_data->successor_id = node->fingers[0].id;
req_data->pred_id = node->pred_id;
req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
+ req_data->answer_to = NULL;
const char* task_name = NULL;
const char* to_mailbox = NULL;
if (to == 1) { // notify my successor
task_data_t req_data = xbt_new0(s_task_data_t, 1);
req_data->type = TASK_FIND_SUCCESSOR;
req_data->request_id = id;
- req_data->answer_to = node->mailbox;
+ req_data->answer_to = xbt_strdup(node->mailbox);
req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
// send a "Find Successor" request to ask_to_id
- m_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
- DEBUG3("Sending a 'Find Successor' request (task %p) to %d for id %d", task, ask_to, id);
- MSG_error_t res = MSG_task_send_with_timeout(task, mailbox, 50);
+ m_task_t task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
+ DEBUG3("Sending a 'Find Successor' request (task %p) to %d for id %d", task_sent, ask_to, id);
+ MSG_error_t res = MSG_task_send_with_timeout(task_sent, mailbox, 50);
if (res != MSG_OK) {
- DEBUG2("Failed to send the 'Find Successor' request to %d for id %d", ask_to, id);
- MSG_task_destroy(task);
- xbt_free(req_data);
+ DEBUG3("Failed to send the 'Find Successor' request (task %p) to %d for id %d",
+ task_sent, ask_to, id);
+ MSG_task_destroy(task_sent);
+ task_data_destroy(req_data);
}
else {
// receive the answer
DEBUG3("Sent a 'Find Successor' request (task %p) to %d for key %d, waiting for the answer",
- task, ask_to, id);
+ task_sent, ask_to, id);
do {
if (node->comm_receive == NULL) {
- task = NULL;
- node->comm_receive = MSG_task_irecv(&task, node->mailbox);
+ m_task_t task_received = NULL;
+ node->comm_receive = MSG_task_irecv(&task_received, node->mailbox);
}
res = MSG_comm_wait(node->comm_receive, 50);
if (res != MSG_OK) {
- DEBUG2("Failed to receive the answer to my 'Find Successor' request (task %p): %d", task, res);
+ DEBUG2("Failed to receive the answer to my 'Find Successor' request (task %p): %d",
+ task_sent, res);
stop = 1;
-// MSG_comm_destroy(node->comm_receive);
+ //MSG_comm_destroy(node->comm_receive);
}
else {
- task = MSG_comm_get_task(node->comm_receive);
- task_data_t ans_data = MSG_task_get_data(task);
+ m_task_t task_received = MSG_comm_get_task(node->comm_receive);
+ DEBUG1("Received a task (%p)", task_received);
+ task_data_t ans_data = MSG_task_get_data(task_received);
- if (ans_data->type != TASK_FIND_SUCCESSOR_ANSWER) {
- handle_task(node, task);
+ if (task_received != task_sent) {
+ // this is not the expected answer
+ handle_task(node, task_received);
}
else {
- DEBUG3("Received the answer to my 'Find Successor' request (task %p): the successor of key %d is %d",
- task, id, successor);
+ // this is our answer
+ DEBUG4("Received the answer to my 'Find Successor' request for id %d (task %p): the successor of key %d is %d",
+ ans_data->request_id, task_received, id, ans_data->answer_id);
successor = ans_data->answer_id;
stop = 1;
- MSG_task_destroy(task);
- xbt_free(req_data);
+ MSG_task_destroy(task_received);
+ task_data_destroy(req_data);
}
}
node->comm_receive = NULL;
char* mailbox = get_mailbox(ask_to);
task_data_t req_data = xbt_new0(s_task_data_t, 1);
req_data->type = TASK_GET_PREDECESSOR;
- req_data->answer_to = node->mailbox;
+ req_data->answer_to = xbt_strdup(node->mailbox);
req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
// send a "Get Predecessor" request to ask_to_id
DEBUG1("Sending a 'Get Predecessor' request to %d", ask_to);
- m_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
- MSG_error_t res = MSG_task_send_with_timeout(task, mailbox, 50);
+ m_task_t task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
+ MSG_error_t res = MSG_task_send_with_timeout(task_sent, mailbox, 50);
if (res != MSG_OK) {
- DEBUG1("Failed to send the 'Get Predecessor' request to %d", ask_to);
- MSG_task_destroy(task);
- xbt_free(req_data);
+ DEBUG2("Failed to send the 'Get Predecessor' request (task %p) to %d",
+ task_sent, ask_to);
+ MSG_task_destroy(task_sent);
+ task_data_destroy(req_data);
}
else {
// receive the answer
- DEBUG2("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to, req_data->answer_to);
+ DEBUG3("Sent 'Get Predecessor' request (task %p) to %d, waiting for the answer on my mailbox '%s'",
+ task_sent, ask_to, req_data->answer_to);
do {
if (node->comm_receive == NULL) { // FIXME simplify this
- task = NULL;
- node->comm_receive = MSG_task_irecv(&task, node->mailbox);
+ m_task_t task_received = NULL;
+ node->comm_receive = MSG_task_irecv(&task_received, node->mailbox);
}
res = MSG_comm_wait(node->comm_receive, 50);
if (res != MSG_OK) {
- DEBUG1("Failed to receive the answer to my 'Get Predecessor' request: %d", res);
+ DEBUG2("Failed to receive the answer to my 'Get Predecessor' request (task %p): %d",
+ task_sent, res);
stop = 1;
-// MSG_comm_destroy(node->comm_receive);
+ //MSG_comm_destroy(node->comm_receive);
}
else {
- task = MSG_comm_get_task(node->comm_receive);
- task_data_t ans_data = MSG_task_get_data(task);
+ m_task_t task_received = MSG_comm_get_task(node->comm_receive);
+ task_data_t ans_data = MSG_task_get_data(task_received);
- if (ans_data->type != TASK_GET_PREDECESSOR_ANSWER) {
- handle_task(node, task);
+ if (task_received != task_sent) {
+ handle_task(node, task_received);
}
else {
- DEBUG2("Received the answer to my 'Get Predecessor' request: the predecessor of node %d is %d", ask_to, predecessor_id);
+ DEBUG3("Received the answer to my 'Get Predecessor' request (task %p): the predecessor of node %d is %d",
+ task_received, ask_to, ans_data->answer_id);
predecessor_id = ans_data->answer_id;
stop = 1;
- MSG_task_destroy(task);
- xbt_free(req_data);
+ MSG_task_destroy(task_received);
+ task_data_destroy(req_data);
}
}
node->comm_receive = NULL;
req_data->type = TASK_NOTIFY;
req_data->request_id = predecessor_candidate_id;
req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
+ req_data->answer_to = NULL;
// send a "Notify" request to notify_id
- DEBUG1("Sending a 'Notify' request to %d", notify_id);
m_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
+ DEBUG2("Sending a 'Notify' request (task %p) to %d", task, notify_id);
char* mailbox = get_mailbox(notify_id);
msg_comm_t comm = MSG_task_isend(task, mailbox);
xbt_dynar_push(node->comms, &comm);
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="3">
+
+ <process host="Jacquelin" function="node">
+ <argument value="42"/> <!-- my id -->
+ <argument value ="600"/> <!-- quit date -->
+ </process>
+
+ <process host="Boivin" function="node"><argument value="45743" /><argument value="42" /><argument value="10" /><argument value="10000" /></process>
+ <process host="Jean_Yves" function="node"><argument value="49540" /><argument value="45743" /><argument value="20" /><argument value="10000" /></process>
+ <process host="TeX" function="node"><argument value="42066" /><argument value="42" /><argument value="30" /><argument value="10000" /></process>
+ <process host="Geoff" function="node"><argument value="8641" /><argument value="49540" /><argument value="40" /><argument value="10000" /></process>
+ <process host="Disney" function="node"><argument value="47294" /><argument value="8641" /><argument value="50" /><argument value="10000" /></process>
+ <process host="iRMX" function="node"><argument value="4255" /><argument value="49540" /><argument value="60" /><argument value="10000" /></process>
+ <process host="McGee" function="node"><argument value="13460" /><argument value="45743" /><argument value="70" /><argument value="10000" /></process>
+ <process host="Gatien" function="node"><argument value="5974" /><argument value="42" /><argument value="80" /><argument value="10000" /></process>
+ <process host="Laroche" function="node"><argument value="38967" /><argument value="47294" /><argument value="90" /><argument value="10000" /></process>
+ <process host="Tanguay" function="node"><argument value="64924" /><argument value="47294" /><argument value="100" /><argument value="10000" /></process>
+ <process host="Morin" function="node"><argument value="8328" /><argument value="49540" /><argument value="110" /><argument value="10000" /></process>
+ <process host="Ethernet" function="node"><argument value="35288" /><argument value="45743" /><argument value="120" /><argument value="10000" /></process>
+ <process host="Bellemarre" function="node"><argument value="21612" /><argument value="35288" /><argument value="130" /><argument value="10000" /></process>
+ <process host="Kuenning" function="node"><argument value="42578" /><argument value="21612" /><argument value="140" /><argument value="10000" /></process>
+ <process host="Gaston" function="node"><argument value="62486" /><argument value="42578" /><argument value="150" /><argument value="10000" /></process>
+ <process host="Harry" function="node"><argument value="35280" /><argument value="42" /><argument value="160" /><argument value="10000" /></process>
+ <process host="Bousquet" function="node"><argument value="12812" /><argument value="42" /><argument value="170" /><argument value="10000" /></process>
+ <process host="Paul" function="node"><argument value="7629" /><argument value="42" /><argument value="180" /><argument value="10000" /></process>
+ <process host="St_Jean" function="node"><argument value="21882" /><argument value="42" /><argument value="190" /><argument value="10000" /></process>
+ <process host="Jill" function="node"><argument value="6345" /><argument value="42" /><argument value="200" /><argument value="10000" /></process>
+ <process host="Marcel" function="node"><argument value="34784" /><argument value="38967" /><argument value="210" /><argument value="10000" /></process>
+ <process host="Wright" function="node"><argument value="9686" /><argument value="4255" /><argument value="220" /><argument value="10000" /></process>
+ <process host="Jackson" function="node"><argument value="57934" /><argument value="4255" /><argument value="230" /><argument value="10000" /></process>
+ <process host="Fernand" function="node"><argument value="22592" /><argument value="62486" /><argument value="240" /><argument value="10000" /></process>
+ <process host="Soucy" function="node"><argument value="62311" /><argument value="57934" /><argument value="250" /><argument value="10000" /></process>
+ <process host="Ste_Julie" function="node"><argument value="7413" /><argument value="57934" /><argument value="260" /><argument value="10000" /></process>
+ <process host="Victoria" function="node"><argument value="58188" /><argument value="7413" /><argument value="270" /><argument value="10000" /></process>
+ <process host="Lessard" function="node"><argument value="45305" /><argument value="7413" /><argument value="280" /><argument value="10000" /></process>
+ <process host="Florient" function="node"><argument value="12202" /><argument value="7413" /><argument value="290" /><argument value="10000" /></process>
+ <process host="Marcoux" function="node"><argument value="24642" /><argument value="7413" /><argument value="300" /><argument value="10000" /></process>
+ <process host="Gavrel" function="node"><argument value="12412" /><argument value="7413" /><argument value="310" /><argument value="10000" /></process>
+ <process host="Bescherelle" function="node"><argument value="56041" /><argument value="7413" /><argument value="320" /><argument value="10000" /></process>
+ <process host="Pierre" function="node"><argument value="46691" /><argument value="7413" /><argument value="330" /><argument value="10000" /></process>
+ <process host="Jamie" function="node"><argument value="23457" /><argument value="7413" /><argument value="340" /><argument value="10000" /></process>
+ <process host="Rubin" function="node"><argument value="19096" /><argument value="7413" /><argument value="350" /><argument value="10000" /></process>
+ <process host="Olivier" function="node"><argument value="50820" /><argument value="42578" /><argument value="360" /><argument value="10000" /></process>
+ <process host="Boucherville" function="node"><argument value="55902" /><argument value="8328" /><argument value="370" /><argument value="10000" /></process>
+ <process host="Pointe_Claire" function="node"><argument value="28052" /><argument value="5974" /><argument value="380" /><argument value="10000" /></process>
+ <process host="Kansas" function="node"><argument value="31120" /><argument value="55902" /><argument value="390" /><argument value="10000" /></process>
+ <process host="King" function="node"><argument value="52051" /><argument value="58188" /><argument value="400" /><argument value="10000" /></process>
+ <process host="Lapointe" function="node"><argument value="58470" /><argument value="19096" /><argument value="410" /><argument value="10000" /></process>
+ <process host="Julian" function="node"><argument value="1280" /><argument value="7413" /><argument value="420" /><argument value="10000" /></process>
+ <process host="Lafontaine" function="node"><argument value="46920" /><argument value="47294" /><argument value="430" /><argument value="10000" /></process>
+ <process host="Gordon" function="node"><argument value="52974" /><argument value="4255" /><argument value="440" /><argument value="10000" /></process>
+ <process host="Drouin" function="node"><argument value="50233" /><argument value="8641" /><argument value="450" /><argument value="10000" /></process>
+ <process host="Robert" function="node"><argument value="48917" /><argument value="50820" /><argument value="460" /><argument value="10000" /></process>
+ <process host="Jocelyne" function="node"><argument value="5476" /><argument value="7629" /><argument value="470" /><argument value="10000" /></process>
+ <process host="Stephen" function="node"><argument value="38304" /><argument value="50820" /><argument value="480" /><argument value="10000" /></process>
+ <process host="Provost" function="node"><argument value="4181" /><argument value="7629" /><argument value="490" /><argument value="10000" /></process>
+ <process host="Juneau" function="node"><argument value="14672" /><argument value="8641" /><argument value="500" /><argument value="10000" /></process>
+ <process host="Casavant" function="node"><argument value="64444" /><argument value="62311" /><argument value="510" /><argument value="10000" /></process>
+ <process host="St_Antoine" function="node"><argument value="17176" /><argument value="4181" /><argument value="520" /><argument value="10000" /></process>
+ <process host="Louis" function="node"><argument value="56445" /><argument value="64444" /><argument value="530" /><argument value="10000" /></process>
+ <process host="Julien" function="node"><argument value="53326" /><argument value="52974" /><argument value="540" /><argument value="10000" /></process>
+ <process host="St_Paul" function="node"><argument value="44773" /><argument value="52974" /><argument value="550" /><argument value="10000" /></process>
+ <process host="Mathematica" function="node"><argument value="56062" /><argument value="31120" /><argument value="560" /><argument value="10000" /></process>
+ <process host="LaTeX" function="node"><argument value="17446" /><argument value="62311" /><argument value="570" /><argument value="10000" /></process>
+ <process host="Sirois" function="node"><argument value="8672" /><argument value="8641" /><argument value="580" /><argument value="10000" /></process>
+ <process host="Monique" function="node"><argument value="23543" /><argument value="45305" /><argument value="590" /><argument value="10000" /></process>
+ <process host="Audy" function="node"><argument value="12767" /><argument value="7629" /><argument value="600" /><argument value="10000" /></process>
+ <process host="Bourassa" function="node"><argument value="39639" /><argument value="23543" /><argument value="610" /><argument value="10000" /></process>
+ <process host="OHara" function="node"><argument value="11729" /><argument value="39639" /><argument value="620" /><argument value="10000" /></process>
+ <process host="Boston" function="node"><argument value="28853" /><argument value="50233" /><argument value="630" /><argument value="10000" /></process>
+ <process host="Papineau" function="node"><argument value="41870" /><argument value="31120" /><argument value="640" /><argument value="10000" /></process>
+ <process host="Fraser" function="node"><argument value="41142" /><argument value="45305" /><argument value="650" /><argument value="10000" /></process>
+ <process host="Browne" function="node"><argument value="52840" /><argument value="56062" /><argument value="660" /><argument value="10000" /></process>
+ <process host="SunOS" function="node"><argument value="14017" /><argument value="11729" /><argument value="670" /><argument value="10000" /></process>
+ <process host="Varennes" function="node"><argument value="16097" /><argument value="8672" /><argument value="680" /><argument value="10000" /></process>
+ <process host="Jacques" function="node"><argument value="61643" /><argument value="16097" /><argument value="690" /><argument value="10000" /></process>
+ <process host="Thierry" function="node"><argument value="48384" /><argument value="61643" /><argument value="700" /><argument value="10000" /></process>
+ <process host="Lachapelle" function="node"><argument value="49196" /><argument value="48384" /><argument value="710" /><argument value="10000" /></process>
+ <process host="kV" function="node"><argument value="3041" /><argument value="49196" /><argument value="720" /><argument value="10000" /></process>
+ <process host="Yolande" function="node"><argument value="57006" /><argument value="3041" /><argument value="730" /><argument value="10000" /></process>
+ <process host="Pronovost" function="node"><argument value="50752" /><argument value="57006" /><argument value="740" /><argument value="10000" /></process>
+ <process host="SPICE" function="node"><argument value="25862" /><argument value="39639" /><argument value="750" /><argument value="10000" /></process>
+ <process host="Europe" function="node"><argument value="9368" /><argument value="42" /><argument value="760" /><argument value="10000" /></process>
+ <process host="Roy" function="node"><argument value="21230" /><argument value="13460" /><argument value="770" /><argument value="10000" /></process>
+ <process host="Amadeus" function="node"><argument value="38231" /><argument value="50233" /><argument value="780" /><argument value="10000" /></process>
+ <process host="Intel" function="node"><argument value="16977" /><argument value="19096" /><argument value="790" /><argument value="10000" /></process>
+ <process host="Cambridge" function="node"><argument value="25608" /><argument value="14017" /><argument value="800" /><argument value="10000" /></process>
+ <process host="Tremblay" function="node"><argument value="34574" /><argument value="41142" /><argument value="810" /><argument value="10000" /></process>
+ <process host="UNIX" function="node"><argument value="594" /><argument value="44773" /><argument value="820" /><argument value="10000" /></process>
+ <process host="Domey" function="node"><argument value="20647" /><argument value="44773" /><argument value="830" /><argument value="10000" /></process>
+ <process host="St_Bruno" function="node"><argument value="14594" /><argument value="61643" /><argument value="840" /><argument value="10000" /></process>
+ <process host="Jean_Claude" function="node"><argument value="54654" /><argument value="3041" /><argument value="850" /><argument value="10000" /></process>
+ <process host="Doyon" function="node"><argument value="5384" /><argument value="3041" /><argument value="860" /><argument value="10000" /></process>
+ <process host="Fafard" function="node"><argument value="12482" /><argument value="57006" /><argument value="870" /><argument value="10000" /></process>
+ <process host="Croteau" function="node"><argument value="54647" /><argument value="16977" /><argument value="880" /><argument value="10000" /></process>
+ <process host="Dodge" function="node"><argument value="17524" /><argument value="594" /><argument value="890" /><argument value="10000" /></process>
+</platform>