aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/testbed/testbed_api_testbed.c93
1 files changed, 64 insertions, 29 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index 6e3a83b6f..5e90b9045 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -50,6 +50,11 @@
50#define DEFAULT_SETUP_TIMEOUT 300 50#define DEFAULT_SETUP_TIMEOUT 300
51 51
52/** 52/**
53 * Testbed Run Handle
54 */
55struct RunContext;
56
57/**
53 * Context information for the operation we start 58 * Context information for the operation we start
54 */ 59 */
55struct RunContextOperation 60struct RunContextOperation
@@ -117,6 +122,28 @@ enum State
117 122
118 123
119/** 124/**
125 * Context for host compability checks
126 */
127struct CompatibilityCheckContext
128{
129 /**
130 * The run context
131 */
132 struct RunContext *rc;
133
134 /**
135 * Handle for the compability check
136 */
137 struct GNUNET_TESTBED_HostHabitableCheckHandle *h;
138
139 /**
140 * Index of the host in the run context's hosts array
141 */
142 unsigned int index;
143};
144
145
146/**
120 * Testbed Run Handle 147 * Testbed Run Handle
121 */ 148 */
122struct RunContext 149struct RunContext
@@ -179,9 +206,9 @@ struct RunContext
179 struct GNUNET_TESTBED_Host **hosts; 206 struct GNUNET_TESTBED_Host **hosts;
180 207
181 /** 208 /**
182 * The handle for whether a host is habitable or not 209 * Array of compatibility check contexts
183 */ 210 */
184 struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles; 211 struct CompatibilityCheckContext *hclist;
185 212
186 /** 213 /**
187 * Array of peers which we create 214 * Array of peers which we create
@@ -424,7 +451,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
424 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rc->register_hosts_task); 451 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rc->register_hosts_task);
425 GNUNET_assert (NULL == rc->reg_handle); 452 GNUNET_assert (NULL == rc->reg_handle);
426 GNUNET_assert (NULL == rc->peers); 453 GNUNET_assert (NULL == rc->peers);
427 GNUNET_assert (NULL == rc->hc_handles); 454 GNUNET_assert (NULL == rc->hclist);
428 GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); 455 GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state);
429 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map)); 456 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map));
430 GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map); 457 GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map);
@@ -476,15 +503,19 @@ rcop_cleanup_iterator (void *cls, uint32_t key, void *value)
476static void 503static void
477cleanup (struct RunContext *rc) 504cleanup (struct RunContext *rc)
478{ 505{
506 struct CompatibilityCheckContext *hc;
479 unsigned int nhost; 507 unsigned int nhost;
480 508
481 if (NULL != rc->hc_handles) 509 if (NULL != rc->hclist)
482 { 510 {
483 for (nhost = 0; nhost < rc->num_hosts; nhost++) 511 for (nhost = 0; nhost < rc->num_hosts; nhost++)
484 if (NULL != rc->hc_handles[nhost]) 512 {
485 GNUNET_TESTBED_is_host_habitable_cancel (rc->hc_handles[nhost]); 513 hc = &rc->hclist[nhost];
486 GNUNET_free (rc->hc_handles); 514 if (NULL != hc->h)
487 rc->hc_handles = NULL; 515 GNUNET_TESTBED_is_host_habitable_cancel (hc->h);
516 }
517 GNUNET_free (rc->hclist);
518 rc->hclist = NULL;
488 } 519 }
489 /* Stop register hosts task if it is running */ 520 /* Stop register hosts task if it is running */
490 if (GNUNET_SCHEDULER_NO_TASK != rc->register_hosts_task) 521 if (GNUNET_SCHEDULER_NO_TASK != rc->register_hosts_task)
@@ -1064,17 +1095,16 @@ static void
1064host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, 1095host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host,
1065 int status) 1096 int status)
1066{ 1097{
1067 struct RunContext *rc = cls; 1098 struct CompatibilityCheckContext *hc = cls;
1099 struct RunContext *rc;
1068 struct GNUNET_TESTBED_Host **old_hosts; 1100 struct GNUNET_TESTBED_Host **old_hosts;
1069 unsigned int nhost; 1101 unsigned int nhost;
1070 1102
1071 for (nhost = 0; nhost < rc->num_hosts; nhost++) 1103 GNUNET_assert (NULL != (rc = hc->rc));
1072 { 1104 nhost = hc->index;
1073 if (host == rc->hosts[nhost]) 1105 GNUNET_assert (nhost <= rc->num_hosts);
1074 break; 1106 GNUNET_assert (host == rc->hosts[nhost]);
1075 } 1107 hc->h = NULL;
1076 GNUNET_assert (nhost != rc->num_hosts);
1077 rc->hc_handles[nhost] = NULL;
1078 if (GNUNET_NO == status) 1108 if (GNUNET_NO == status)
1079 { 1109 {
1080 if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host))) 1110 if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host)))
@@ -1089,8 +1119,8 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host,
1089 rc->reg_hosts++; 1119 rc->reg_hosts++;
1090 if (rc->reg_hosts < rc->num_hosts) 1120 if (rc->reg_hosts < rc->num_hosts)
1091 return; 1121 return;
1092 GNUNET_free (rc->hc_handles); 1122 GNUNET_free (rc->hclist);
1093 rc->hc_handles = NULL; 1123 rc->hclist = NULL;
1094 rc->h = rc->hosts[0]; 1124 rc->h = rc->hosts[0];
1095 rc->num_hosts--; 1125 rc->num_hosts--;
1096 if (0 < rc->num_hosts) 1126 if (0 < rc->num_hosts)
@@ -1180,6 +1210,7 @@ GNUNET_TESTBED_run (const char *host_filename,
1180{ 1210{
1181 struct RunContext *rc; 1211 struct RunContext *rc;
1182 char *topology; 1212 char *topology;
1213 struct CompatibilityCheckContext *hc;
1183 struct GNUNET_TIME_Relative timeout; 1214 struct GNUNET_TIME_Relative timeout;
1184 unsigned long long random_links; 1215 unsigned long long random_links;
1185 unsigned int hid; 1216 unsigned int hid;
@@ -1278,22 +1309,26 @@ GNUNET_TESTBED_run (const char *host_filename,
1278 } 1309 }
1279 if (0 != rc->num_hosts) 1310 if (0 != rc->num_hosts)
1280 { 1311 {
1281 rc->hc_handles = 1312 rc->hclist = GNUNET_malloc (sizeof (struct CompatibilityCheckContext)
1282 GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostHabitableCheckHandle *) 1313 * rc->num_hosts);
1283 * rc->num_hosts);
1284 for (nhost = 0; nhost < rc->num_hosts; nhost++) 1314 for (nhost = 0; nhost < rc->num_hosts; nhost++)
1285 { 1315 {
1286 if (NULL == 1316 hc = &rc->hclist[nhost];
1287 (rc->hc_handles[nhost] = 1317 hc->index = nhost;
1288 GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg, 1318 hc->rc = rc;
1289 &host_habitable_cb, rc))) 1319 hc->h = GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg,
1320 &host_habitable_cb, hc);
1321 if (NULL == hc->h)
1290 { 1322 {
1291 GNUNET_break (0); 1323 GNUNET_break (0);
1292 for (nhost = 0; nhost < rc->num_hosts; nhost++) 1324 for (nhost = 0; nhost < rc->num_hosts; nhost++)
1293 if (NULL != rc->hc_handles[nhost]) 1325 {
1294 GNUNET_TESTBED_is_host_habitable_cancel (rc->hc_handles[nhost]); 1326 hc = &rc->hclist[nhost];
1295 GNUNET_free (rc->hc_handles); 1327 if (NULL != hc->h)
1296 rc->hc_handles = NULL; 1328 GNUNET_TESTBED_is_host_habitable_cancel (hc->h);
1329 }
1330 GNUNET_free (rc->hclist);
1331 rc->hclist = NULL;
1297 goto error_cleanup; 1332 goto error_cleanup;
1298 } 1333 }
1299 } 1334 }