From 7401d3bfb5eabc3f730b4f6e56d174796a141d30 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 12 Oct 2012 13:40:16 +0000 Subject: [PATCH] host registrations in profiler --- src/testbed/gnunet-testbed-profiler.c | 206 ++++++++++++++++++++++---- src/testbed/testbed_api.c | 2 + 2 files changed, 180 insertions(+), 28 deletions(-) diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index 56b06a501..4247bbebf 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c @@ -29,6 +29,38 @@ #include "gnunet_testbed_service.h" #include "testbed_api_hosts.h" +/** + * Generic loggins shorthand + */ +#define LOG(kind,...) \ + GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__) + +/** + * DLL of operations + */ +struct DLLOperation +{ + /** + * The testbed operation handle + */ + struct GNUNET_TESTBED_Operation *op; + + /** + * Closure + */ + void *cls; + + /** + * The next pointer for DLL + */ + struct DLLOperation *next; + + /** + * The prev pointer for DLL + */ + struct DLLOperation *prev; +}; + /** * An array of hosts loaded from the hostkeys file @@ -45,11 +77,41 @@ static struct GNUNET_TESTBED_Peer **peers; */ static struct GNUNET_TESTBED_Operation *op; +/** + * Host registration handle + */ +static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle; + +/** + * Handle to the master controller process + */ +struct GNUNET_TESTBED_ControllerProc *mc_proc; + +/** + * Handle to the master controller + */ +struct GNUNET_TESTBED_Controller *mc; + +/** + * Handle to global configuration + */ +struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Abort task identifier */ static GNUNET_SCHEDULER_TaskIdentifier abort_task; +/** + * Host registration task identifier + */ +static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task; + +/** + * Global event mask for all testbed events + */ +uint64_t event_mask; + /** * Current peer id */ @@ -84,12 +146,20 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (GNUNET_SCHEDULER_NO_TASK != abort_task) GNUNET_SCHEDULER_cancel (abort_task); + if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) + GNUNET_SCHEDULER_cancel (register_hosts_task); GNUNET_free_non_null (peers); + if (NULL != reg_handle) + GNUNET_TESTBED_cancel_registration (reg_handle); for (nhost = 0; nhost < num_hosts; nhost++) if (NULL != hosts[nhost]) GNUNET_TESTBED_host_destroy (hosts[nhost]); GNUNET_free_non_null (hosts); - GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ + if (NULL != mc_proc) + GNUNET_TESTBED_controller_stop (mc_proc); + if (NULL != cfg) + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ } @@ -102,28 +172,13 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Profiling timedout -- Aborting\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); abort_task = GNUNET_SCHEDULER_NO_TASK; + result = GNUNET_SYSERR; GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); } -/** - * Task to be executed when peers are ready - * - * @param cls NULL - * @param tc the task context - */ -static void -master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - result = GNUNET_OK; - GNUNET_assert (NULL != peers[0]); - op = GNUNET_TESTBED_peer_stop (peers[0], NULL, NULL); - GNUNET_assert (NULL != op); -} - - /** * Controller event callback * @@ -154,6 +209,101 @@ controller_event_cb (void *cls, } +/** + * Task to register all hosts available in the global host list + * + * @param cls NULL + * @param tc the scheduler task context + */ +static void +register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); + + +/** + * Callback which will be called to after a host registration succeeded or failed + * + * @param cls the closure + * @param emsg the error message; NULL if host registration is successful + */ +static void +host_registration_completion (void *cls, const char *emsg) +{ + reg_handle = NULL; + if (NULL != emsg) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Host registration failed for a host. Error: %s\n"), emsg); + GNUNET_SCHEDULER_cancel (abort_task); + abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); + return; + } + register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); +} + + +/** + * Task to register all hosts available in the global host list + * + * @param cls NULL + * @param tc the scheduler task context + */ +static void +register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + static unsigned int reg_host; + + register_hosts_task = GNUNET_SCHEDULER_NO_TASK; + if (reg_host == num_hosts) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "All hosts successfully registered\n"); + /* Start peer create task */ + } + reg_handle = GNUNET_TESTBED_register_host (mc, hosts[reg_host++], + host_registration_completion, + NULL); +} + + +/** + * Callback to signal successfull startup of the controller process + * + * @param cls the closure from GNUNET_TESTBED_controller_start() + * @param cfg the configuration with which the controller has been started; + * NULL if status is not GNUNET_OK + * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, + * GNUNET_TESTBED_controller_stop() shouldn't be called in this case + */ +static void +status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status) +{ + GNUNET_SCHEDULER_cancel (abort_task); + if (GNUNET_OK != status) + { + mc_proc = NULL; + abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); + return; + } + event_mask = 0; + event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); + event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); + event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); + event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); + mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask, + &controller_event_cb, NULL); + if (NULL == mc) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Unable to connect to master controller -- Check config\n")); + abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); + return; + } + register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); + abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &do_abort, NULL); +} + + /** * Main function that will be run by the scheduler. * @@ -166,7 +316,6 @@ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) { - uint64_t event_mask; unsigned int nhost; if (NULL == args[0]) @@ -182,7 +331,7 @@ run (void *cls, char *const *args, const char *cfgfile, num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts); if (0 == num_hosts) { - fprintf (stderr, _("No hosts loaded\n")); + fprintf (stderr, _("No hosts loaded. Need atleast one host\n")); return; } for (nhost = 0; nhost < num_hosts; nhost++) @@ -196,17 +345,18 @@ run (void *cls, char *const *args, const char *cfgfile, } if (num_hosts != nhost) { + fprintf (stderr, _("Exiting\n")); GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); return; } - peers = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Peer *)); - event_mask = 0; - event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); - event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); - event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); - event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); - GNUNET_TESTBED_run (NULL, config, num_peers, event_mask, &controller_event_cb, - NULL, &master_task, NULL); + cfg = GNUNET_CONFIGURATION_dup (config); + mc_proc = + GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_ + (hosts[0]), + hosts[0], + cfg, + status_cb, + NULL); abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 1c5d01342..7cd536497 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -1683,6 +1683,8 @@ GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller memcpy (&msg[1], service_name, service_name_size); GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg); + GNUNET_break (0); /* This function is not yet implemented on the + testbed service */ } -- 2.25.1