diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-04-18 09:52:53 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-04-18 09:52:53 +0000 |
commit | 7e454dfc7e59450d4bfb68f1dd591cc687a7e221 (patch) | |
tree | 3fea234d08411ef71e2aa20feca63d2cd4492e16 /src/regex | |
parent | 6c4a5cf1b0ba02f99df557dd693af968ae65dcac (diff) | |
download | gnunet-7e454dfc7e59450d4bfb68f1dd591cc687a7e221.tar.gz gnunet-7e454dfc7e59450d4bfb68f1dd591cc687a7e221.zip |
- remove old internal testbed code
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 690 |
1 files changed, 21 insertions, 669 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index eb65b8995..9e7e85909 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -196,17 +196,6 @@ struct RegexPeer | |||
196 | 196 | ||
197 | 197 | ||
198 | /** | 198 | /** |
199 | * An array of hosts loaded from the hostkeys file | ||
200 | */ | ||
201 | static struct GNUNET_TESTBED_Host **hosts; | ||
202 | |||
203 | /** | ||
204 | * Array of peer handles used to pass to | ||
205 | * GNUNET_TESTBED_overlay_configure_topology | ||
206 | */ | ||
207 | static struct GNUNET_TESTBED_Peer **peer_handles; | ||
208 | |||
209 | /** | ||
210 | * The array of peers; we fill this as the peers are given to us by the testbed | 199 | * The array of peers; we fill this as the peers are given to us by the testbed |
211 | */ | 200 | */ |
212 | static struct RegexPeer *peers; | 201 | static struct RegexPeer *peers; |
@@ -232,26 +221,6 @@ static struct GNUNET_TESTBED_Controller *mc; | |||
232 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 221 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
233 | 222 | ||
234 | /** | 223 | /** |
235 | * Head of the operations list | ||
236 | */ | ||
237 | static struct DLLOperation *dll_op_head; | ||
238 | |||
239 | /** | ||
240 | * Tail of the operations list | ||
241 | */ | ||
242 | static struct DLLOperation *dll_op_tail; | ||
243 | |||
244 | /** | ||
245 | * Peer linking - topology operation | ||
246 | */ | ||
247 | static struct GNUNET_TESTBED_Operation *topology_op; | ||
248 | |||
249 | /** | ||
250 | * The handle for whether a host is habitable or not | ||
251 | */ | ||
252 | struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles; | ||
253 | |||
254 | /** | ||
255 | * Abort task identifier | 224 | * Abort task identifier |
256 | */ | 225 | */ |
257 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 226 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
@@ -287,26 +256,11 @@ static struct GNUNET_TIME_Relative prof_time; | |||
287 | static unsigned int num_peers; | 256 | static unsigned int num_peers; |
288 | 257 | ||
289 | /** | 258 | /** |
290 | * Number of hosts in the hosts array | ||
291 | */ | ||
292 | static unsigned int num_hosts; | ||
293 | |||
294 | /** | ||
295 | * Factor of number of links. num_links = num_peers * linking_factor. | 259 | * Factor of number of links. num_links = num_peers * linking_factor. |
296 | */ | 260 | */ |
297 | static unsigned int linking_factor; | 261 | static unsigned int linking_factor; |
298 | 262 | ||
299 | /** | 263 | /** |
300 | * Number of random links to be established between peers | ||
301 | */ | ||
302 | static unsigned int num_links; | ||
303 | |||
304 | /** | ||
305 | * Number of connect operations that have failed, candidates to retry | ||
306 | */ | ||
307 | static unsigned int retry_links; | ||
308 | |||
309 | /** | ||
310 | * Global testing status | 264 | * Global testing status |
311 | */ | 265 | */ |
312 | static int result; | 266 | static int result; |
@@ -347,11 +301,6 @@ static unsigned int peers_found; | |||
347 | static unsigned int next_search; | 301 | static unsigned int next_search; |
348 | 302 | ||
349 | /** | 303 | /** |
350 | * Search task identifier | ||
351 | */ | ||
352 | static GNUNET_SCHEDULER_TaskIdentifier search_task; | ||
353 | |||
354 | /** | ||
355 | * Search timeout task identifier. | 304 | * Search timeout task identifier. |
356 | */ | 305 | */ |
357 | static GNUNET_SCHEDULER_TaskIdentifier search_timeout_task; | 306 | static GNUNET_SCHEDULER_TaskIdentifier search_timeout_task; |
@@ -484,9 +433,7 @@ announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
484 | static void | 433 | static void |
485 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 434 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
486 | { | 435 | { |
487 | struct DLLOperation *dll_op; | ||
488 | struct RegexPeer *peer; | 436 | struct RegexPeer *peer; |
489 | unsigned int nhost; | ||
490 | unsigned int peer_cnt; | 437 | unsigned int peer_cnt; |
491 | unsigned int search_str_cnt; | 438 | unsigned int search_str_cnt; |
492 | char output_buffer[512]; | 439 | char output_buffer[512]; |
@@ -495,14 +442,6 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
495 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | 442 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; |
496 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | 443 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
497 | GNUNET_SCHEDULER_cancel (abort_task); | 444 | GNUNET_SCHEDULER_cancel (abort_task); |
498 | if (NULL != hc_handles) | ||
499 | { | ||
500 | for (nhost = 0; nhost < num_hosts; nhost++) | ||
501 | if (NULL != hc_handles[nhost]) | ||
502 | GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[nhost]); | ||
503 | GNUNET_free (hc_handles); | ||
504 | hc_handles = NULL; | ||
505 | } | ||
506 | if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) | 445 | if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) |
507 | GNUNET_SCHEDULER_cancel (register_hosts_task); | 446 | GNUNET_SCHEDULER_cancel (register_hosts_task); |
508 | 447 | ||
@@ -546,19 +485,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
546 | 485 | ||
547 | if (NULL != reg_handle) | 486 | if (NULL != reg_handle) |
548 | GNUNET_TESTBED_cancel_registration (reg_handle); | 487 | GNUNET_TESTBED_cancel_registration (reg_handle); |
549 | if (NULL != topology_op) | 488 | |
550 | GNUNET_TESTBED_operation_done (topology_op); | ||
551 | for (nhost = 0; nhost < num_hosts; nhost++) | ||
552 | if (NULL != hosts[nhost]) | ||
553 | GNUNET_TESTBED_host_destroy (hosts[nhost]); | ||
554 | GNUNET_free_non_null (hosts); | ||
555 | |||
556 | while (NULL != (dll_op = dll_op_head)) | ||
557 | { | ||
558 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
559 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
560 | GNUNET_free (dll_op); | ||
561 | } | ||
562 | if (NULL != mc) | 489 | if (NULL != mc) |
563 | GNUNET_TESTBED_controller_disconnect (mc); | 490 | GNUNET_TESTBED_controller_disconnect (mc); |
564 | if (NULL != mc_proc) | 491 | if (NULL != mc_proc) |
@@ -1179,527 +1106,35 @@ dht_da (void *cls, void *op_result) | |||
1179 | } | 1106 | } |
1180 | 1107 | ||
1181 | 1108 | ||
1182 | /******************************************************************************/ | ||
1183 | /*************************** TESTBED PEER SETUP *****************************/ | ||
1184 | /******************************************************************************/ | ||
1185 | |||
1186 | |||
1187 | /** | ||
1188 | * Configure the peer overlay topology. | ||
1189 | * | ||
1190 | * @param cls NULL | ||
1191 | * @param tc the task context | ||
1192 | */ | ||
1193 | static void | ||
1194 | do_configure_topology (void *cls, | ||
1195 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
1196 | { | ||
1197 | /* | ||
1198 | if (0 == linking_factor) | ||
1199 | linking_factor = 1; | ||
1200 | num_links = linking_factor * num_peers; | ||
1201 | */ | ||
1202 | /* num_links = num_peers - 1; */ | ||
1203 | num_links = linking_factor; | ||
1204 | |||
1205 | /* Do overlay connect */ | ||
1206 | prof_start_time = GNUNET_TIME_absolute_get (); | ||
1207 | topology_op = | ||
1208 | GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peer_handles, | ||
1209 | NULL, | ||
1210 | NULL, | ||
1211 | NULL, | ||
1212 | GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, | ||
1213 | num_links, | ||
1214 | GNUNET_TESTBED_TOPOLOGY_RETRY_CNT, | ||
1215 | (unsigned int) 0, | ||
1216 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | ||
1217 | if (NULL == topology_op) | ||
1218 | { | ||
1219 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1220 | "Cannot create topology, op handle was NULL\n"); | ||
1221 | GNUNET_assert (0); | ||
1222 | } | ||
1223 | } | ||
1224 | |||
1225 | |||
1226 | /** | ||
1227 | * Functions of this signature are called when a peer has been successfully | ||
1228 | * started or stopped. | ||
1229 | * | ||
1230 | * @param cls the closure from GNUNET_TESTBED_peer_start/stop() | ||
1231 | * @param emsg NULL on success; otherwise an error description | ||
1232 | */ | ||
1233 | static void | ||
1234 | peer_churn_cb (void *cls, const char *emsg) | ||
1235 | { | ||
1236 | struct DLLOperation *dll_op = cls; | ||
1237 | struct GNUNET_TESTBED_Operation *op; | ||
1238 | static unsigned int started_peers; | ||
1239 | unsigned int peer_cnt; | ||
1240 | |||
1241 | op = dll_op->op; | ||
1242 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
1243 | GNUNET_free (dll_op); | ||
1244 | if (NULL != emsg) | ||
1245 | { | ||
1246 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1247 | _("An operation has failed while starting peers: %s\n"), emsg); | ||
1248 | GNUNET_TESTBED_operation_done (op); | ||
1249 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
1250 | GNUNET_SCHEDULER_cancel (abort_task); | ||
1251 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1252 | return; | ||
1253 | } | ||
1254 | GNUNET_TESTBED_operation_done (op); | ||
1255 | if (++started_peers == num_peers) | ||
1256 | { | ||
1257 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
1258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1259 | "All peers started successfully in %s\n", | ||
1260 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); | ||
1261 | result = GNUNET_OK; | ||
1262 | |||
1263 | peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * num_peers); | ||
1264 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
1265 | peer_handles[peer_cnt] = peers[peer_cnt].peer_handle; | ||
1266 | |||
1267 | state = STATE_PEERS_LINKING; | ||
1268 | GNUNET_SCHEDULER_add_now (&do_configure_topology, NULL); | ||
1269 | } | ||
1270 | } | ||
1271 | |||
1272 | |||
1273 | /** | ||
1274 | * Functions of this signature are called when a peer has been successfully | ||
1275 | * created | ||
1276 | * | ||
1277 | * @param cls the closure from GNUNET_TESTBED_peer_create() | ||
1278 | * @param peer the handle for the created peer; NULL on any error during | ||
1279 | * creation | ||
1280 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | ||
1281 | */ | ||
1282 | static void | ||
1283 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | ||
1284 | { | ||
1285 | struct DLLOperation *dll_op = cls; | ||
1286 | struct RegexPeer *peer_ptr; | ||
1287 | static unsigned int created_peers; | ||
1288 | unsigned int peer_cnt; | ||
1289 | |||
1290 | if (NULL != emsg) | ||
1291 | { | ||
1292 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1293 | _("Creating a peer failed. Error: %s\n"), emsg); | ||
1294 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
1295 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
1296 | GNUNET_free (dll_op); | ||
1297 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
1298 | GNUNET_SCHEDULER_cancel (abort_task); | ||
1299 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1300 | return; | ||
1301 | } | ||
1302 | |||
1303 | peer_ptr = dll_op->cls; | ||
1304 | GNUNET_assert (NULL == peer_ptr->peer_handle); | ||
1305 | GNUNET_CONFIGURATION_destroy (peer_ptr->cfg); | ||
1306 | peer_ptr->cfg = NULL; | ||
1307 | peer_ptr->peer_handle = peer; | ||
1308 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
1309 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
1310 | GNUNET_free (dll_op); | ||
1311 | |||
1312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n", | ||
1313 | peer_ptr->id, | ||
1314 | GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle)); | ||
1315 | |||
1316 | if (++created_peers == num_peers) | ||
1317 | { | ||
1318 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
1319 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1320 | "All peers created successfully in %s\n", | ||
1321 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); | ||
1322 | /* Now peers are to be started */ | ||
1323 | state = STATE_PEERS_STARTING; | ||
1324 | prof_start_time = GNUNET_TIME_absolute_get (); | ||
1325 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
1326 | { | ||
1327 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
1328 | dll_op->op = GNUNET_TESTBED_peer_start (dll_op, | ||
1329 | peers[peer_cnt].peer_handle, | ||
1330 | &peer_churn_cb, dll_op); | ||
1331 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
1332 | } | ||
1333 | } | ||
1334 | } | ||
1335 | |||
1336 | |||
1337 | /** | ||
1338 | * Function called with a filename for each file in the policy directory. Create | ||
1339 | * a peer for each filename and update the peer's configuration to include the | ||
1340 | * max_path_compression specified as a command line argument as well as the | ||
1341 | * policy_file for this peer. The gnunet-service-regexprofiler service is | ||
1342 | * automatically started on this peer. The service reads the configurration and | ||
1343 | * announces the regexes stored in the policy file 'filename'. | ||
1344 | * | ||
1345 | * @param cls closure | ||
1346 | * @param filename complete filename (absolute path) | ||
1347 | * @return GNUNET_OK to continue to iterate, | ||
1348 | * GNUNET_SYSERR to abort iteration with error! | ||
1349 | */ | ||
1350 | static int | ||
1351 | policy_filename_cb (void *cls, const char *filename) | ||
1352 | { | ||
1353 | static unsigned int peer_cnt; | ||
1354 | struct DLLOperation *dll_op; | ||
1355 | struct RegexPeer *peer = &peers[peer_cnt]; | ||
1356 | |||
1357 | GNUNET_assert (NULL != peer); | ||
1358 | |||
1359 | peer->policy_file = GNUNET_strdup (filename); | ||
1360 | |||
1361 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1362 | "Creating peer %i on host %s for policy file %s\n", | ||
1363 | peer->id, GNUNET_TESTBED_host_get_hostname (peer->host_handle), | ||
1364 | filename); | ||
1365 | |||
1366 | /* Set configuration options specific for this peer | ||
1367 | (max_path_compression and policy_file */ | ||
1368 | peer->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
1369 | GNUNET_CONFIGURATION_set_value_number (peer->cfg, "REGEXPROFILER", | ||
1370 | "MAX_PATH_COMPRESSION", | ||
1371 | (unsigned long long) | ||
1372 | max_path_compression); | ||
1373 | GNUNET_CONFIGURATION_set_value_string (peer->cfg, "REGEXPROFILER", | ||
1374 | "POLICY_FILE", filename); | ||
1375 | |||
1376 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
1377 | dll_op->cls = &peers[peer_cnt]; | ||
1378 | dll_op->op = GNUNET_TESTBED_peer_create (mc, | ||
1379 | peer->host_handle, | ||
1380 | peer->cfg, | ||
1381 | &peer_create_cb, | ||
1382 | dll_op); | ||
1383 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
1384 | |||
1385 | peer_cnt++; | ||
1386 | |||
1387 | return GNUNET_OK; | ||
1388 | } | ||
1389 | |||
1390 | |||
1391 | /** | ||
1392 | * Controller event callback. | ||
1393 | * | ||
1394 | * @param cls NULL | ||
1395 | * @param event the controller event | ||
1396 | */ | ||
1397 | static void | ||
1398 | controller_event_cb (void *cls, | ||
1399 | const struct GNUNET_TESTBED_EventInformation *event) | ||
1400 | { | ||
1401 | struct DLLOperation *dll_op; | ||
1402 | struct GNUNET_TESTBED_Operation *op; | ||
1403 | int ret; | ||
1404 | |||
1405 | switch (state) | ||
1406 | { | ||
1407 | case STATE_SLAVES_STARTING: | ||
1408 | switch (event->type) | ||
1409 | { | ||
1410 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
1411 | { | ||
1412 | static unsigned int slaves_started; | ||
1413 | unsigned int peer_cnt; | ||
1414 | |||
1415 | dll_op = event->op_cls; | ||
1416 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
1417 | GNUNET_free (dll_op); | ||
1418 | op = event->op; | ||
1419 | if (NULL != event->details.operation_finished.emsg) | ||
1420 | { | ||
1421 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1422 | _("An operation has failed while starting slaves\n")); | ||
1423 | GNUNET_TESTBED_operation_done (op); | ||
1424 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
1425 | GNUNET_SCHEDULER_cancel (abort_task); | ||
1426 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1427 | return; | ||
1428 | } | ||
1429 | GNUNET_TESTBED_operation_done (op); | ||
1430 | /* Proceed to start peers */ | ||
1431 | if (++slaves_started == num_hosts - 1) | ||
1432 | { | ||
1433 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1434 | "All slaves started successfully\n"); | ||
1435 | |||
1436 | state = STATE_PEERS_CREATING; | ||
1437 | prof_start_time = GNUNET_TIME_absolute_get (); | ||
1438 | |||
1439 | if (-1 == (ret = GNUNET_DISK_directory_scan (policy_dir, | ||
1440 | NULL, | ||
1441 | NULL))) | ||
1442 | { | ||
1443 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1444 | _("No files found in `%s'\n"), | ||
1445 | policy_dir); | ||
1446 | GNUNET_SCHEDULER_shutdown (); | ||
1447 | return; | ||
1448 | } | ||
1449 | num_peers = (unsigned int) ret; | ||
1450 | peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers); | ||
1451 | |||
1452 | /* Initialize peers */ | ||
1453 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
1454 | { | ||
1455 | struct RegexPeer *peer = &peers[peer_cnt]; | ||
1456 | peer->id = peer_cnt; | ||
1457 | peer->policy_file = NULL; | ||
1458 | /* Do not start peers on hosts[0] (master controller) */ | ||
1459 | peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))]; | ||
1460 | peer->dht_handle = NULL; | ||
1461 | peer->search_handle = NULL; | ||
1462 | peer->stats_handle = NULL; | ||
1463 | peer->stats_op_handle = NULL; | ||
1464 | peer->search_str = NULL; | ||
1465 | peer->search_str_matched = GNUNET_NO; | ||
1466 | } | ||
1467 | |||
1468 | GNUNET_DISK_directory_scan (policy_dir, | ||
1469 | &policy_filename_cb, | ||
1470 | NULL); | ||
1471 | } | ||
1472 | } | ||
1473 | break; | ||
1474 | default: | ||
1475 | GNUNET_assert (0); | ||
1476 | } | ||
1477 | break; | ||
1478 | case STATE_PEERS_STARTING: | ||
1479 | switch (event->type) | ||
1480 | { | ||
1481 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
1482 | /* Control reaches here when peer start fails */ | ||
1483 | case GNUNET_TESTBED_ET_PEER_START: | ||
1484 | /* we handle peer starts in peer_churn_cb */ | ||
1485 | break; | ||
1486 | default: | ||
1487 | GNUNET_assert (0); | ||
1488 | } | ||
1489 | break; | ||
1490 | case STATE_PEERS_LINKING: | ||
1491 | switch (event->type) | ||
1492 | { | ||
1493 | static unsigned int established_links; | ||
1494 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
1495 | /* Control reaches here when a peer linking operation fails */ | ||
1496 | if (NULL != event->details.operation_finished.emsg) | ||
1497 | { | ||
1498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1499 | _("An operation has failed while linking\n")); | ||
1500 | printf ("F%u/%u(%s)", | ||
1501 | retry_links + 1, established_links + 1, | ||
1502 | event->details.operation_finished.emsg); | ||
1503 | fflush (stdout); | ||
1504 | retry_links++; | ||
1505 | } | ||
1506 | /* We do no retries, consider this link as established */ | ||
1507 | /* break; */ | ||
1508 | case GNUNET_TESTBED_ET_CONNECT: | ||
1509 | { | ||
1510 | char output_buffer[1024]; | ||
1511 | size_t size; | ||
1512 | |||
1513 | if (0 == established_links) | ||
1514 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Establishing links ."); | ||
1515 | else | ||
1516 | { | ||
1517 | printf (".");fflush (stdout); | ||
1518 | } | ||
1519 | if (++established_links == num_links) | ||
1520 | { | ||
1521 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
1522 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1523 | "%u links established in %s\n", | ||
1524 | num_links, | ||
1525 | GNUNET_STRINGS_relative_time_to_string (prof_time, | ||
1526 | GNUNET_NO)); | ||
1527 | prof_time = GNUNET_TIME_relative_divide(prof_time, num_links); | ||
1528 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1529 | "Average of %s per connection\n", | ||
1530 | GNUNET_STRINGS_relative_time_to_string (prof_time, | ||
1531 | GNUNET_NO)); | ||
1532 | result = GNUNET_OK; | ||
1533 | GNUNET_free (peer_handles); | ||
1534 | |||
1535 | if (NULL != data_file) | ||
1536 | { | ||
1537 | size = | ||
1538 | GNUNET_snprintf (output_buffer, | ||
1539 | sizeof (output_buffer), | ||
1540 | "# of peers: %u\n# of links established: %u\n" | ||
1541 | "Time to establish links: %s\n" | ||
1542 | "Linking failures: %u\n" | ||
1543 | "path compression length: %u\n" | ||
1544 | "# of search strings: %u\n", | ||
1545 | num_peers, | ||
1546 | (established_links - retry_links), | ||
1547 | GNUNET_STRINGS_relative_time_to_string (prof_time, | ||
1548 | GNUNET_NO), | ||
1549 | retry_links, | ||
1550 | max_path_compression, | ||
1551 | num_search_strings); | ||
1552 | |||
1553 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) | ||
1554 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | ||
1555 | } | ||
1556 | |||
1557 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1558 | "\nWaiting %s before starting to announce.\n", | ||
1559 | GNUNET_STRINGS_relative_time_to_string (search_delay, | ||
1560 | GNUNET_NO)); | ||
1561 | state = STATE_SEARCH_REGEX; | ||
1562 | search_task = GNUNET_SCHEDULER_add_delayed (search_delay, | ||
1563 | &do_announce, NULL); | ||
1564 | } | ||
1565 | } | ||
1566 | break; | ||
1567 | default: | ||
1568 | GNUNET_assert (0); | ||
1569 | } | ||
1570 | break; | ||
1571 | case STATE_SEARCH_REGEX: | ||
1572 | { | ||
1573 | /* Handled in service connect callback */ | ||
1574 | break; | ||
1575 | } | ||
1576 | default: | ||
1577 | switch (state) | ||
1578 | { | ||
1579 | case STATE_PEERS_CREATING: | ||
1580 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create peer\n"); | ||
1581 | break; | ||
1582 | default: | ||
1583 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1584 | "Unexpected controller_cb with state %i!\n", state); | ||
1585 | } | ||
1586 | GNUNET_assert (0); | ||
1587 | } | ||
1588 | } | ||
1589 | |||
1590 | |||
1591 | /** | 1109 | /** |
1592 | * Task to register all hosts available in the global host list. | 1110 | * Signature of a main function for a testcase. |
1593 | * | 1111 | * |
1594 | * @param cls NULL | 1112 | * @param cls NULL |
1595 | * @param tc the scheduler task context | 1113 | * @param num_peers_ number of peers in 'peers' |
1596 | */ | 1114 | * @param peers handle to peers run in the testbed. NULL upon timeout (see |
1597 | static void | 1115 | * GNUNET_TESTBED_test_run()). |
1598 | register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 1116 | * @param links_succeeded the number of overlay link connection attempts that |
1599 | 1117 | * succeeded | |
1600 | 1118 | * @param links_failed the number of overlay link connection attempts that | |
1601 | /** | 1119 | * failed |
1602 | * Callback which will be called to after a host registration succeeded or failed | ||
1603 | * | ||
1604 | * @param cls the closure | ||
1605 | * @param emsg the error message; NULL if host registration is successful | ||
1606 | */ | 1120 | */ |
1607 | static void | 1121 | static void |
1608 | host_registration_completion (void *cls, const char *emsg) | 1122 | test_master (void *cls, |
1609 | { | 1123 | unsigned int num_peers_, |
1610 | reg_handle = NULL; | 1124 | struct GNUNET_TESTBED_Peer **testbed_peers, |
1611 | if (NULL != emsg) | 1125 | unsigned int links_succeeded, |
1612 | { | 1126 | unsigned int links_failed) |
1613 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1614 | _("Host registration failed for a host. Error: %s\n"), emsg); | ||
1615 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
1616 | GNUNET_SCHEDULER_cancel (abort_task); | ||
1617 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1618 | return; | ||
1619 | } | ||
1620 | register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); | ||
1621 | } | ||
1622 | |||
1623 | |||
1624 | /** | ||
1625 | * Task to register all hosts available in the global host list. | ||
1626 | * | ||
1627 | * @param cls NULL | ||
1628 | * @param tc the scheduler task context | ||
1629 | */ | ||
1630 | static void | ||
1631 | register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1632 | { | 1127 | { |
1633 | struct DLLOperation *dll_op; | 1128 | unsigned int i; |
1634 | static unsigned int reg_host; | ||
1635 | unsigned int slave; | ||
1636 | 1129 | ||
1637 | register_hosts_task = GNUNET_SCHEDULER_NO_TASK; | 1130 | for (i = 0; i < num_peers; i++) |
1638 | if (reg_host == num_hosts - 1) | 1131 | GNUNET_SCHEDULER_add_now (&do_announce, NULL); |
1639 | { | ||
1640 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1641 | "All hosts successfully registered\n"); | ||
1642 | /* Start slaves */ | ||
1643 | state = STATE_SLAVES_STARTING; | ||
1644 | for (slave = 1; slave < num_hosts; slave++) | ||
1645 | { | ||
1646 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
1647 | dll_op->op = GNUNET_TESTBED_controller_link (dll_op, | ||
1648 | mc, | ||
1649 | hosts[slave], | ||
1650 | hosts[0], | ||
1651 | cfg, | ||
1652 | GNUNET_YES); | ||
1653 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
1654 | } | ||
1655 | return; | ||
1656 | } | ||
1657 | reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host], | ||
1658 | host_registration_completion, | ||
1659 | NULL); | ||
1660 | } | 1132 | } |
1661 | 1133 | ||
1662 | 1134 | ||
1663 | /** | 1135 | /******************************************************************************/ |
1664 | * Callback to signal successfull startup of the controller process. | 1136 | /*************************** TESTBED PEER SETUP *****************************/ |
1665 | * | 1137 | /******************************************************************************/ |
1666 | * @param cls the closure from GNUNET_TESTBED_controller_start() | ||
1667 | * @param config the configuration with which the controller has been started; | ||
1668 | * NULL if status is not GNUNET_OK | ||
1669 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | ||
1670 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | ||
1671 | */ | ||
1672 | static void | ||
1673 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status) | ||
1674 | { | ||
1675 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
1676 | GNUNET_SCHEDULER_cancel (abort_task); | ||
1677 | if (GNUNET_OK != status) | ||
1678 | { | ||
1679 | mc_proc = NULL; | ||
1680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Oh, dear!\n"); | ||
1681 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1682 | return; | ||
1683 | } | ||
1684 | event_mask = 0; | ||
1685 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | ||
1686 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | ||
1687 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
1688 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | ||
1689 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
1690 | mc = GNUNET_TESTBED_controller_connect (hosts[0], event_mask, | ||
1691 | &controller_event_cb, NULL); | ||
1692 | if (NULL == mc) | ||
1693 | { | ||
1694 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1695 | _("Unable to connect to master controller -- Check config\n")); | ||
1696 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1697 | return; | ||
1698 | } | ||
1699 | register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); | ||
1700 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1701 | &do_abort, (void*) __LINE__); | ||
1702 | } | ||
1703 | 1138 | ||
1704 | 1139 | ||
1705 | /** | 1140 | /** |
@@ -1775,51 +1210,6 @@ load_search_strings (const char *filename, char ***strings, unsigned int limit) | |||
1775 | 1210 | ||
1776 | 1211 | ||
1777 | /** | 1212 | /** |
1778 | * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to | ||
1779 | * inform whether the given host is habitable or not. The Handle returned by | ||
1780 | * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called | ||
1781 | * | ||
1782 | * @param cls NULL | ||
1783 | * @param host the host whose status is being reported; will be NULL if the host | ||
1784 | * given to GNUNET_TESTBED_is_host_habitable() is NULL | ||
1785 | * @param status GNUNET_YES if it is habitable; GNUNET_NO if not | ||
1786 | */ | ||
1787 | static void | ||
1788 | host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status) | ||
1789 | { | ||
1790 | struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handle = cls; | ||
1791 | static unsigned int hosts_checked; | ||
1792 | |||
1793 | *hc_handle = NULL; | ||
1794 | if (GNUNET_NO == status) | ||
1795 | { | ||
1796 | if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host))) | ||
1797 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), | ||
1798 | GNUNET_TESTBED_host_get_hostname (host)); | ||
1799 | else | ||
1800 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Testbed cannot be started on localhost\n")); | ||
1801 | GNUNET_SCHEDULER_cancel (abort_task); | ||
1802 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__); | ||
1803 | return; | ||
1804 | } | ||
1805 | hosts_checked++; | ||
1806 | /* printf (_("\rChecked %u hosts"), hosts_checked); */ | ||
1807 | /* fflush (stdout); */ | ||
1808 | if (hosts_checked < num_hosts) | ||
1809 | return; | ||
1810 | /* printf (_("\nAll hosts can start testbed. Creating peers\n")); */ | ||
1811 | GNUNET_free (hc_handles); | ||
1812 | hc_handles = NULL; | ||
1813 | mc_proc = | ||
1814 | GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname | ||
1815 | (hosts[0]), | ||
1816 | hosts[0], | ||
1817 | status_cb, | ||
1818 | NULL); | ||
1819 | } | ||
1820 | |||
1821 | |||
1822 | /** | ||
1823 | * Main function that will be run by the scheduler. | 1213 | * Main function that will be run by the scheduler. |
1824 | * | 1214 | * |
1825 | * @param cls closure | 1215 | * @param cls closure |
@@ -1831,7 +1221,6 @@ static void | |||
1831 | run (void *cls, char *const *args, const char *cfgfile, | 1221 | run (void *cls, char *const *args, const char *cfgfile, |
1832 | const struct GNUNET_CONFIGURATION_Handle *config) | 1222 | const struct GNUNET_CONFIGURATION_Handle *config) |
1833 | { | 1223 | { |
1834 | unsigned int nhost; | ||
1835 | unsigned int nsearchstrs; | 1224 | unsigned int nsearchstrs; |
1836 | 1225 | ||
1837 | if (NULL == args[0]) | 1226 | if (NULL == args[0]) |
@@ -1846,43 +1235,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1846 | _("No policy directory specified on command line. Exiting.\n")); | 1235 | _("No policy directory specified on command line. Exiting.\n")); |
1847 | return; | 1236 | return; |
1848 | } | 1237 | } |
1849 | num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], config, &hosts); | ||
1850 | if (0 == num_hosts) | ||
1851 | { | ||
1852 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1853 | _("No hosts loaded. Need at least one host\n")); | ||
1854 | return; | ||
1855 | } | ||
1856 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1857 | _("Checking whether given hosts can start testbed." | ||
1858 | "Please wait\n")); | ||
1859 | hc_handles = GNUNET_malloc (sizeof (struct | ||
1860 | GNUNET_TESTBED_HostHabitableCheckHandle *) | ||
1861 | * num_hosts); | ||
1862 | for (nhost = 0; nhost < num_hosts; nhost++) | ||
1863 | { | ||
1864 | hc_handles[nhost] = GNUNET_TESTBED_is_host_habitable (hosts[nhost], config, | ||
1865 | &host_habitable_cb, | ||
1866 | &hc_handles[nhost]); | ||
1867 | if (NULL == hc_handles[nhost]) | ||
1868 | { | ||
1869 | int i; | ||
1870 | |||
1871 | GNUNET_break (0); | ||
1872 | for (i = 0; i <= nhost; i++) | ||
1873 | if (NULL != hc_handles[i]) | ||
1874 | GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[i]); | ||
1875 | GNUNET_free (hc_handles); | ||
1876 | hc_handles = NULL; | ||
1877 | break; | ||
1878 | } | ||
1879 | } | ||
1880 | if (num_hosts != nhost) | ||
1881 | { | ||
1882 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Exiting\n")); | ||
1883 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1884 | return; | ||
1885 | } | ||
1886 | if (NULL == config) | 1238 | if (NULL == config) |
1887 | { | 1239 | { |
1888 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |