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)
downloadgnunet-91443f0b2069987845c458ab70eee8f0600f5939.tar.gz
gnunet-91443f0b2069987845c458ab70eee8f0600f5939.zip
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 083926cbf..9eaf702a3 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -153,6 +153,11 @@ struct DLLOperation *dll_op_tail;
153struct GNUNET_TESTBED_Operation *topology_op; 153struct GNUNET_TESTBED_Operation *topology_op;
154 154
155/** 155/**
156 * The handle for whether a host is habitable or not
157 */
158struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles;
159
160/**
156 * Abort task identifier 161 * Abort task identifier
157 */ 162 */
158static GNUNET_SCHEDULER_TaskIdentifier abort_task; 163static GNUNET_SCHEDULER_TaskIdentifier abort_task;
@@ -253,6 +258,14 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
253 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 258 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
254 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 259 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
255 GNUNET_SCHEDULER_cancel (abort_task); 260 GNUNET_SCHEDULER_cancel (abort_task);
261 if (NULL != hc_handles)
262 {
263 for (nhost = 0; nhost < num_hosts; nhost++)
264 if (NULL != hc_handles[num_hosts])
265 GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[num_hosts]);
266 GNUNET_free (hc_handles);
267 hc_handles = NULL;
268 }
256 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) 269 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
257 GNUNET_SCHEDULER_cancel (register_hosts_task); 270 GNUNET_SCHEDULER_cancel (register_hosts_task);
258 if (NULL != reg_handle) 271 if (NULL != reg_handle)
@@ -688,6 +701,35 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int stat
688 701
689 702
690/** 703/**
704 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
705 * inform whether the given host is habitable or not. The Handle returned by
706 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
707 *
708 * @param cls NULL
709 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
710 */
711static void
712host_habitable_cb (void *cls, int status)
713{
714 struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handle = cls;
715 static unsigned int hosts_checked;
716
717 *hc_handle = NULL;
718 if (++hosts_checked < num_hosts)
719 return;
720 GNUNET_free (hc_handles);
721 hc_handles = NULL;
722 mc_proc =
723 GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_
724 (hosts[0]),
725 hosts[0],
726 cfg,
727 status_cb,
728 NULL);
729}
730
731
732/**
691 * Main function that will be run by the scheduler. 733 * Main function that will be run by the scheduler.
692 * 734 *
693 * @param cls closure 735 * @param cls closure
@@ -717,12 +759,22 @@ run (void *cls, char *const *args, const char *cfgfile,
717 fprintf (stderr, _("No hosts loaded. Need at least one host\n")); 759 fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
718 return; 760 return;
719 } 761 }
762 hc_handles = GNUNET_malloc (sizeof (struct
763 GNUNET_TESTBED_HostHabitableCheckHandle *)
764 * num_hosts);
720 for (nhost = 0; nhost < num_hosts; nhost++) 765 for (nhost = 0; nhost < num_hosts; nhost++)
721 { 766 {
722 if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost], config)) 767 if (NULL == (hc_handles[nhost] = GNUNET_TESTBED_is_host_habitable (hosts[nhost], config,
768 &host_habitable_cb,
769 &hc_handles[nhost])))
723 { 770 {
724 fprintf (stderr, _("Host %s cannot start testbed\n"), 771 fprintf (stderr, _("Host %s cannot start testbed\n"),
725 GNUNET_TESTBED_host_get_hostname_ (hosts[nhost])); 772 GNUNET_TESTBED_host_get_hostname_ (hosts[nhost]));
773 for (nhost = 0; nhost < num_hosts; nhost++)
774 if (NULL != hc_handles[num_hosts])
775 GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[num_hosts]);
776 GNUNET_free (hc_handles);
777 hc_handles = NULL;
726 break; 778 break;
727 } 779 }
728 } 780 }
@@ -733,13 +785,6 @@ run (void *cls, char *const *args, const char *cfgfile,
733 return; 785 return;
734 } 786 }
735 cfg = GNUNET_CONFIGURATION_dup (config); 787 cfg = GNUNET_CONFIGURATION_dup (config);
736 mc_proc =
737 GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_
738 (hosts[0]),
739 hosts[0],
740 cfg,
741 status_cb,
742 NULL);
743 abort_task = 788 abort_task =
744 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 789 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
745 (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, 790 (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,