+/**
+ * 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)
+{
+ struct DLLOperation *dll_op;
+ static unsigned int reg_host;
+ unsigned int slave;
+
+ register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
+ if (reg_host == num_hosts - 1)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "All hosts successfully registered\n");
+ /* Start slaves */
+ state = STATE_SLAVES_STARTING;
+ for (slave = 1; slave < num_hosts; slave++)
+ {
+ dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+ dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
+ mc,
+ hosts[slave],
+ hosts[0],
+ cfg,
+ GNUNET_YES);
+ GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
+ }
+ return;
+ }
+ 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 config 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)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ 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);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
+ 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;
+ }
+ if (num_hosts > 1)
+ register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
+ else
+ start_peers ();
+ abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &do_abort, NULL);
+}
+
+