- const char* task_name = MSG_task_get_name(task);
- task_data_t task_data = (task_data_t) MSG_task_get_data(task);
-
- if (!strcmp(task_name, "Find Successor")) {
- INFO2("Receiving a 'Find Successor' request from %s for id %d",
- task_data->issuer_host_name, task_data->request_id);
- // is my successor the successor?
- if (is_in_interval(task_data->request_id, node.id + 1, node.fingers[0].id)) {
- task_data->answer_id = node.fingers[0].id;
- MSG_task_set_name(task, "Find Successor Answer");
- INFO3("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_send = MSG_task_isend(task, task_data->answer_to);
- xbt_dynar_push(node.comms, &comm_send);
- }
- else {
- // otherwise, forward the request to the closest preceding finger in my table
- int closest = closest_preceding_node(&node, task_data->request_id);
- INFO2("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d",
- task_data->request_id, closest);
- mailbox = get_mailbox(closest);
- comm_send = MSG_task_isend(task, mailbox);
- xbt_dynar_push(node.comms, &comm_send);
- xbt_free(mailbox);
- }
- }
-
- else if (!strcmp(task_name, "Get Predecessor")) {
- INFO1("Receiving a 'Get Predecessor' request from %s", task_data->issuer_host_name);
- task_data->answer_id = node.pred_id;
- MSG_task_set_name(task, "Get Predecessor Answer");
- INFO2("Sending back a 'Get Predecessor Answer' to %s: my predecessor is %d",
- task_data->issuer_host_name, task_data->answer_id);
- comm_send = MSG_task_isend(task, task_data->answer_to);
- xbt_dynar_push(node.comms, &comm_send);
- }
- /*
- else if (!strcmp(task_name, "Find Predecessor")) {
- INFO2("Receiving a 'Find Predecessor' Request from %s for id %d", task_data->issuer_host_name, task_data->request_id);
- // am I the predecessor?
- if (is_in_interval(task_data->request_id, node.id + 1, node.fingers[0].id)) {
- task_data->answer_id = node.id;
- MSG_task_set_name(task, "Find Predecessor Answer");
- INFO3("Sending back a 'Find Predecessor' Answer to %s: the predecessor 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
- int closest = closest_preceding_node(&node, task_data->request_id);
- INFO2("Forwarding 'Find Predecessor' request for id %d to my closest preceding finger %d", task_data->request_id, closest);
- mailbox = get_mailbox(closest);
- comm = MSG_task_isend(task, mailbox);
- xbt_dynar_push(node.comms, &comm);
- xbt_free(mailbox);
- }
- }
- */
-
- /*
- else if (!strcmp(task_name, "Notify Node Joined")) {
- // someone may be my new neighboor
- INFO1("Receiving a 'Notify Node Joine' request from %s", task_data->issuer_host_name);
- notify_node_joined(&node, task_data->request_id);
- }
- else if (!strcmp(task_name, "Update Finger")) {
- // someone is telling me that he may be my new finger
- INFO1("Receiving an 'Update Finger' request from %s", task_data->issuer_host_name);
- update_finger_table(&node, task_data->request_id, task_data->request_finger);
- }
- */
- else if (!strcmp(task_name, "Notify")) {
- // someone is telling me that he may be my new predecessor
- INFO1("Receiving a 'Notify' request from %s", task_data->issuer_host_name);
- notify(&node, task_data->request_id);
- }
- else if (!strcmp(task_name, "Predecessor Leaving")) {
- // my predecessor is about to quit
- INFO1("Receiving a 'Predecessor Leaving' message from %s", task_data->issuer_host_name);
- // modify my predecessor
- set_predecessor(&node, task_data->pred_id);
- /*TODO :
- >> notify my new predecessor
- >> send a notify_predecessors !!
- */
- }
- else if (!strcmp(task_name, "Successor Leaving")) {
- // my successor is about to quit
- INFO1("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->successor_id);
- /* TODO
- >> notify my new successor
- >> update my table & predecessors table */
- }