/** * Shutdown nicely * * @param cls NULL * @param tc the task context */ static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct DLLOperation *dll_op; unsigned int nhost; shutdown_task = GNUNET_SCHEDULER_NO_TASK; 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); if (NULL != reg_handle) GNUNET_TESTBED_cancel_registration (reg_handle); if (NULL != topology_op) GNUNET_TESTBED_operation_done (topology_op); for (nhost = 0; nhost < num_hosts; nhost++) if (NULL != hosts[nhost]) GNUNET_TESTBED_host_destroy (hosts[nhost]); GNUNET_free_non_null (hosts); while (NULL != (dll_op = dll_op_head)) { GNUNET_TESTBED_operation_done (dll_op->op); GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); GNUNET_free (dll_op); } if (NULL != mc) GNUNET_TESTBED_controller_disconnect (mc); 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 */ }
/** * Assuming all peers have been destroyed cleanup run handle * * @param rc the run context */ static void cleanup (struct GNUNET_TESTBED_RunHandle *rc) { unsigned int hid; GNUNET_assert (NULL == rc->register_hosts_task); GNUNET_assert (NULL == rc->reg_handle); GNUNET_assert (NULL == rc->peers); GNUNET_assert (NULL == rc->hclist); GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map)); GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map); if (NULL != rc->c) GNUNET_TESTBED_controller_disconnect (rc->c); if (NULL != rc->cproc) GNUNET_TESTBED_controller_stop (rc->cproc); if (NULL != rc->h) GNUNET_TESTBED_host_destroy (rc->h); for (hid = 0; hid < rc->num_hosts; hid++) GNUNET_TESTBED_host_destroy (rc->hosts[hid]); GNUNET_free_non_null (rc->hosts); if (NULL != rc->cfg) GNUNET_CONFIGURATION_destroy (rc->cfg); GNUNET_free_non_null (rc->topo_file); GNUNET_free_non_null (rc->trusted_ip); GNUNET_free (rc); }
/** * Shutdown nicely * * @param cls NULL * @param tc the task context */ static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (NULL != abort_task) GNUNET_SCHEDULER_cancel (abort_task); if (NULL != delay_task_id) { GNUNET_SCHEDULER_cancel (delay_task_id); delay_task_id = NULL; } if (NULL != hc_handle) GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); if (NULL != mc) GNUNET_TESTBED_controller_disconnect (mc); if (NULL != cp) GNUNET_TESTBED_controller_stop (cp); if (NULL != slave3) GNUNET_TESTBED_host_destroy (slave3); if (NULL != slave2) GNUNET_TESTBED_host_destroy (slave2); if (NULL != slave) GNUNET_TESTBED_host_destroy (slave); if (NULL != host) GNUNET_TESTBED_host_destroy (host); if (NULL != cfg) GNUNET_CONFIGURATION_destroy (cfg); if (NULL != cfg3) GNUNET_CONFIGURATION_destroy (cfg3); if (NULL != rh) GNUNET_TESTBED_cancel_registration (rh); }
/** * Shutdown nicely * * @param cls NULL * @param tc the task context */ static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (NULL != abort_task) GNUNET_SCHEDULER_cancel (abort_task); if (NULL != hc_handle) GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); GNUNET_assert (NULL == delayed_connect_task); if (NULL != common_operation) GNUNET_TESTBED_operation_done (common_operation); if (NULL != reg_handle) GNUNET_TESTBED_cancel_registration (reg_handle); if (NULL != controller1) GNUNET_TESTBED_controller_disconnect (controller1); GNUNET_CONFIGURATION_destroy (cfg); if (NULL != cfg2) GNUNET_CONFIGURATION_destroy (cfg2); if (NULL != cp1) GNUNET_TESTBED_controller_stop (cp1); if (NULL != host) GNUNET_TESTBED_host_destroy (host); if (NULL != neighbour1) GNUNET_TESTBED_host_destroy (neighbour1); if (NULL != neighbour2) GNUNET_TESTBED_host_destroy (neighbour2); }
/** * Callback that will be called when the helper process dies. This is not called * when the helper process is stoped using GNUNET_HELPER_stop() * * @param cls the closure from GNUNET_HELPER_start() */ static void helper_exp_cb (void *cls) { struct GNUNET_TESTBED_ControllerProc *cp = cls; GNUNET_TESTBED_ControllerStatusCallback cb; void *cb_cls; cb = cp->cb; cb_cls = cp->cls; cp->helper = NULL; GNUNET_TESTBED_controller_stop (cp); if (NULL != cb) cb (cb_cls, NULL, GNUNET_SYSERR); }
/** * Shutdown nicely * * @param cls NULL * @param tc the task context */ static void do_shutdown (void *cls) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); if (NULL != abort_task) GNUNET_SCHEDULER_cancel (abort_task); if (NULL != reg_handle) GNUNET_TESTBED_cancel_registration (reg_handle); if (NULL != controller) GNUNET_TESTBED_controller_disconnect (controller); if (NULL != cfg) GNUNET_CONFIGURATION_destroy (cfg); if (NULL != cp) GNUNET_TESTBED_controller_stop (cp); if (NULL != neighbour) GNUNET_TESTBED_host_destroy (neighbour); if (NULL != host) GNUNET_TESTBED_host_destroy (host); }
/** * Shutdown nicely * * @param cls NULL * @param tc the task context */ static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (GNUNET_SCHEDULER_NO_TASK != abort_task) GNUNET_SCHEDULER_cancel (abort_task); if (NULL != slave3) GNUNET_TESTBED_host_destroy (slave3); if (NULL != slave2) GNUNET_TESTBED_host_destroy (slave2); if (NULL != slave) GNUNET_TESTBED_host_destroy (slave); if (NULL != host) GNUNET_TESTBED_host_destroy (host); if (NULL != mc) GNUNET_TESTBED_controller_disconnect (mc); if (NULL != cfg) GNUNET_CONFIGURATION_destroy (cfg); if (NULL != cfg3) GNUNET_CONFIGURATION_destroy (cfg3); if (NULL != cp) GNUNET_TESTBED_controller_stop (cp); if (NULL != rh) GNUNET_TESTBED_cancel_registration (rh); }
/** * Starts a controller process at the given host. The given host's configration * is used as a Template configuration to use for the remote controller; the * remote controller will be started with a slightly modified configuration * (port numbers, unix domain sockets and service home values are changed as per * TESTING library on the remote host). The modified configuration replaces the * host's existing configuration before signalling success through the * GNUNET_TESTBED_ControllerStatusCallback() * * @param trusted_ip the ip address of the controller which will be set as TRUSTED * HOST(all connections form this ip are permitted by the testbed) when * starting testbed controller at host. This can either be a single ip * address or a network address in CIDR notation. * @param host the host where the controller has to be started. CANNOT be NULL. * @param cb function called when the controller is successfully started or * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be * called if cb is called with GNUNET_SYSERR as status. Will never be * called in the same task as 'GNUNET_TESTBED_controller_start' * (synchronous errors will be signalled by returning NULL). This * parameter cannot be NULL. * @param cls closure for above callbacks * @return the controller process handle, NULL on errors */ struct GNUNET_TESTBED_ControllerProc * GNUNET_TESTBED_controller_start (const char *trusted_ip, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_ControllerStatusCallback cb, void *cls) { struct GNUNET_TESTBED_ControllerProc *cp; struct GNUNET_TESTBED_HelperInit *msg; const struct GNUNET_CONFIGURATION_Handle *cfg; const char *hostname; static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; GNUNET_assert (NULL != host); GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); hostname = NULL; API_VIOLATION (GNUNET_NO == host->locked, "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); host->locked = GNUNET_YES; API_VIOLATION (GNUNET_NO == host->controller_started, "Attempting to start a controller on a host which is already started a controller"); cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc); if (0 == GNUNET_TESTBED_host_get_id_ (host)) { cp->helper = GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv, &helper_mst, &helper_exp_cb, cp); } else { char *helper_binary_path_args[2]; char **rsh_args; char **rsh_suffix_args; const char *username; char *port; char *argstr; char *aux; unsigned int cnt; username = host->username; hostname = host->hostname; GNUNET_asprintf (&port, "%u", host->port); LOG_DEBUG ("Starting remote connection to destination %s\n", hostname); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed", "HELPER_BINARY_PATH", &helper_binary_path_args[0])) helper_binary_path_args[0] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); helper_binary_path_args[1] = NULL; rsh_args = gen_rsh_args (port, hostname, username); rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args); cp->helper_argv = join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); free_argv (rsh_args); free_argv (rsh_suffix_args); GNUNET_free (port); argstr = GNUNET_strdup (""); for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) { aux = argstr; GNUNET_assert (0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt])); GNUNET_free (aux); } LOG_DEBUG ("Helper cmd str: %s\n", argstr); GNUNET_free (argstr); cp->helper = GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst, &helper_exp_cb, cp); GNUNET_free (helper_binary_path_args[0]); } if (NULL == cp->helper) { if (NULL != cp->helper_argv) free_argv (cp->helper_argv); GNUNET_free (cp); return NULL; } cp->host = host; cp->cb = cb; cp->cls = cls; msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg); cp->msg = &msg->header; cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); if (NULL == cp->shandle) { GNUNET_free (msg); GNUNET_TESTBED_controller_stop (cp); return NULL; } return cp; }