#include <simgrid/msg.h>
#include <xbt/RngStream.h>
-static void task_free(void *data);
+static void task_free(void* data);
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_tracker, "Messages specific for the tracker");
/**
* @param argc number of arguments
* @param argv arguments
*/
-int tracker(int argc, char *argv[])
+int tracker(int argc, char* argv[])
{
- //Checking arguments
+ // Checking arguments
xbt_assert(argc == 2, "Wrong number of arguments for the tracker.");
- //Retrieving end time
- double deadline = xbt_str_parse_double(argv[1],"Invalid deadline: %s");
+ // Retrieving end time
+ double deadline = xbt_str_parse_double(argv[1], "Invalid deadline: %s");
xbt_assert(deadline > 0, "Wrong deadline supplied");
- RngStream stream = (RngStream) MSG_host_get_data(MSG_host_self());
- //Building peers array
+ RngStream stream = (RngStream)MSG_host_get_data(MSG_host_self());
+ // Building peers array
xbt_dynar_t peers_list = xbt_dynar_new(sizeof(int), NULL);
XBT_INFO("Tracker launched.");
comm_received = MSG_task_irecv(&task_received, TRACKER_MAILBOX);
}
if (MSG_comm_test(comm_received)) {
- //Check for correct status
+ // Check for correct status
if (MSG_comm_get_status(comm_received) == MSG_OK) {
- //Retrieve the data sent by the peer.
+ // Retrieve the data sent by the peer.
tracker_task_data_t data = MSG_task_get_data(task_received);
- //Add the peer to our peer list.
+ // Add the peer to our peer list.
if (is_in_list(peers_list, data->peer_id) == 0) {
xbt_dynar_push_as(peers_list, int, data->peer_id);
}
- //Sending peers to the peer
+ // Sending peers to the peer
int next_peer;
int peers_length = xbt_dynar_length(peers_list);
for (int i = 0; i < MAXIMUM_PEERS && i < peers_length; i++) {
} while (is_in_list(data->peers, next_peer));
xbt_dynar_push_as(data->peers, int, next_peer);
}
- //setting the interval
+ // setting the interval
data->interval = TRACKER_QUERY_INTERVAL;
- //sending the task back to the peer.
+ // sending the task back to the peer.
MSG_task_dsend(task_received, data->mailbox, task_free);
- //destroy the communication.
+ // destroy the communication.
}
MSG_comm_destroy(comm_received);
comm_received = NULL;
MSG_process_sleep(1);
}
}
- //Free the remaining communication if any
+ // Free the remaining communication if any
if (comm_received) {
MSG_comm_destroy(comm_received);
}
- //Free the peers list
+ // Free the peers list
xbt_dynar_free(&peers_list);
XBT_INFO("Tracker is leaving");
* Build a new task for the tracker.
* @param issuer_host_name Hostname of the issuer. For debugging purposes
*/
-tracker_task_data_t tracker_task_data_new(const char *issuer_host_name, const char *mailbox, int peer_id,
- int uploaded, int downloaded, int left)
+tracker_task_data_t tracker_task_data_new(const char* issuer_host_name, const char* mailbox, int peer_id, int uploaded,
+ int downloaded, int left)
{
tracker_task_data_t task = xbt_new(s_tracker_task_data_t, 1);
- task->type = TRACKER_TASK_QUERY;
+ task->type = TRACKER_TASK_QUERY;
task->issuer_host_name = issuer_host_name;
- task->mailbox = mailbox;
- task->peer_id = peer_id;
- task->uploaded = uploaded;
- task->downloaded = downloaded;
- task->left = left;
+ task->mailbox = mailbox;
+ task->peer_id = peer_id;
+ task->uploaded = uploaded;
+ task->downloaded = downloaded;
+ task->left = left;
task->peers = xbt_dynar_new(sizeof(int), NULL);
* Free a tracker task that has not successfully been sent.
* @param data Task to free
*/
-static void task_free(void *data)
+static void task_free(void* data)
{
tracker_task_data_t task_data = MSG_task_get_data(data);
tracker_task_data_free(task_data);