aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-testbed-profiler.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-12-03 13:58:54 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-12-03 13:58:54 +0000
commit91443f0b2069987845c458ab70eee8f0600f5939 (patch)
tree2ad1d5cb676f2146cccc009bf2a9209c56012ef2 /src/testbed/gnunet-testbed-profiler.c
parent020a5d9860368e63c997fb5dd82b2498b85f0584 (diff)
making GNUNET_TESTBED_is_host_compatible() asynchronous
Diffstat (limited to 'src/testbed/gnunet-testbed-profiler.c')
-rw-r--r--src/testbed/gnunet-testbed-profiler.c63
1 files changed, 54 insertions, 9 deletions
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
index 083926cbf5..9eaf702a33 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -153,6 +153,11 @@ struct DLLOperation *dll_op_tail;
struct GNUNET_TESTBED_Operation *topology_op;
/**
+ * The handle for whether a host is habitable or not
+ */
+struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles;
+
+/**
* Abort task identifier
*/
static GNUNET_SCHEDULER_TaskIdentifier abort_task;
@@ -253,6 +258,14 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
shutdown_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_SCHEDULER_NO_TASK != abort_task)
GNUNET_SCHEDULER_cancel (abort_task);
+ if (NULL != hc_handles)
+ {
+ for (nhost = 0; nhost < num_hosts; nhost++)
+ if (NULL != hc_handles[num_hosts])
+ GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[num_hosts]);
+ GNUNET_free (hc_handles);
+ hc_handles = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
GNUNET_SCHEDULER_cancel (register_hosts_task);
if (NULL != reg_handle)
@@ -688,6 +701,35 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int stat
/**
+ * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
+ * inform whether the given host is habitable or not. The Handle returned by
+ * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
+ *
+ * @param cls NULL
+ * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
+ */
+static void
+host_habitable_cb (void *cls, int status)
+{
+ struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handle = cls;
+ static unsigned int hosts_checked;
+
+ *hc_handle = NULL;
+ if (++hosts_checked < num_hosts)
+ return;
+ GNUNET_free (hc_handles);
+ hc_handles = NULL;
+ mc_proc =
+ GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_
+ (hosts[0]),
+ hosts[0],
+ cfg,
+ status_cb,
+ NULL);
+}
+
+
+/**
* Main function that will be run by the scheduler.
*
* @param cls closure
@@ -717,12 +759,22 @@ run (void *cls, char *const *args, const char *cfgfile,
fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
return;
}
+ hc_handles = GNUNET_malloc (sizeof (struct
+ GNUNET_TESTBED_HostHabitableCheckHandle *)
+ * num_hosts);
for (nhost = 0; nhost < num_hosts; nhost++)
- {
- if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost], config))
+ {
+ if (NULL == (hc_handles[nhost] = GNUNET_TESTBED_is_host_habitable (hosts[nhost], config,
+ &host_habitable_cb,
+ &hc_handles[nhost])))
{
fprintf (stderr, _("Host %s cannot start testbed\n"),
GNUNET_TESTBED_host_get_hostname_ (hosts[nhost]));
+ for (nhost = 0; nhost < num_hosts; nhost++)
+ if (NULL != hc_handles[num_hosts])
+ GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[num_hosts]);
+ GNUNET_free (hc_handles);
+ hc_handles = NULL;
break;
}
}
@@ -733,13 +785,6 @@ run (void *cls, char *const *args, const char *cfgfile,
return;
}
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,