diff options
Diffstat (limited to 'src/regex/gnunet-regex-profiler.c')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 122 |
1 files changed, 68 insertions, 54 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index 5938c99b1..db5432845 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -214,11 +214,6 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; | |||
214 | static struct GNUNET_SCHEDULER_Task * abort_task; | 214 | static struct GNUNET_SCHEDULER_Task * abort_task; |
215 | 215 | ||
216 | /** | 216 | /** |
217 | * Shutdown task identifier | ||
218 | */ | ||
219 | static struct GNUNET_SCHEDULER_Task * shutdown_task; | ||
220 | |||
221 | /** | ||
222 | * Host registration task identifier | 217 | * Host registration task identifier |
223 | */ | 218 | */ |
224 | static struct GNUNET_SCHEDULER_Task * register_hosts_task; | 219 | static struct GNUNET_SCHEDULER_Task * register_hosts_task; |
@@ -408,12 +403,16 @@ do_shutdown (void *cls) | |||
408 | char output_buffer[512]; | 403 | char output_buffer[512]; |
409 | size_t size; | 404 | size_t size; |
410 | 405 | ||
411 | shutdown_task = NULL; | ||
412 | if (NULL != abort_task) | 406 | if (NULL != abort_task) |
407 | { | ||
413 | GNUNET_SCHEDULER_cancel (abort_task); | 408 | GNUNET_SCHEDULER_cancel (abort_task); |
409 | abort_task = NULL; | ||
410 | } | ||
414 | if (NULL != register_hosts_task) | 411 | if (NULL != register_hosts_task) |
412 | { | ||
415 | GNUNET_SCHEDULER_cancel (register_hosts_task); | 413 | GNUNET_SCHEDULER_cancel (register_hosts_task); |
416 | 414 | register_hosts_task = NULL; | |
415 | } | ||
417 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | 416 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) |
418 | { | 417 | { |
419 | peer = &peers[peer_cnt]; | 418 | peer = &peers[peer_cnt]; |
@@ -441,8 +440,10 @@ do_shutdown (void *cls) | |||
441 | } | 440 | } |
442 | 441 | ||
443 | if (NULL != data_file) | 442 | if (NULL != data_file) |
443 | { | ||
444 | GNUNET_DISK_file_close (data_file); | 444 | GNUNET_DISK_file_close (data_file); |
445 | 445 | data_file = NULL; | |
446 | } | ||
446 | for (search_str_cnt = 0; | 447 | for (search_str_cnt = 0; |
447 | search_str_cnt < num_peers && NULL != search_strings; | 448 | search_str_cnt < num_peers && NULL != search_strings; |
448 | search_str_cnt++) | 449 | search_str_cnt++) |
@@ -450,18 +451,28 @@ do_shutdown (void *cls) | |||
450 | GNUNET_free_non_null (search_strings[search_str_cnt]); | 451 | GNUNET_free_non_null (search_strings[search_str_cnt]); |
451 | } | 452 | } |
452 | GNUNET_free_non_null (search_strings); | 453 | GNUNET_free_non_null (search_strings); |
454 | search_strings = NULL; | ||
453 | 455 | ||
454 | if (NULL != reg_handle) | 456 | if (NULL != reg_handle) |
457 | { | ||
455 | GNUNET_TESTBED_cancel_registration (reg_handle); | 458 | GNUNET_TESTBED_cancel_registration (reg_handle); |
456 | 459 | reg_handle = NULL; | |
460 | } | ||
457 | if (NULL != mc) | 461 | if (NULL != mc) |
462 | { | ||
458 | GNUNET_TESTBED_controller_disconnect (mc); | 463 | GNUNET_TESTBED_controller_disconnect (mc); |
464 | mc = NULL; | ||
465 | } | ||
459 | if (NULL != mc_proc) | 466 | if (NULL != mc_proc) |
467 | { | ||
460 | GNUNET_TESTBED_controller_stop (mc_proc); | 468 | GNUNET_TESTBED_controller_stop (mc_proc); |
469 | mc_proc = NULL; | ||
470 | } | ||
461 | if (NULL != cfg) | 471 | if (NULL != cfg) |
472 | { | ||
462 | GNUNET_CONFIGURATION_destroy (cfg); | 473 | GNUNET_CONFIGURATION_destroy (cfg); |
463 | 474 | cfg = NULL; | |
464 | GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ | 475 | } |
465 | } | 476 | } |
466 | 477 | ||
467 | 478 | ||
@@ -475,12 +486,11 @@ do_abort (void *cls) | |||
475 | { | 486 | { |
476 | unsigned long i = (unsigned long) cls; | 487 | unsigned long i = (unsigned long) cls; |
477 | 488 | ||
478 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting from line %lu...\n", i); | 489 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
490 | "Aborting from line %lu...\n", i); | ||
479 | abort_task = NULL; | 491 | abort_task = NULL; |
480 | result = GNUNET_SYSERR; | 492 | result = GNUNET_SYSERR; |
481 | if (NULL != shutdown_task) | 493 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
482 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
483 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
484 | } | 494 | } |
485 | 495 | ||
486 | 496 | ||
@@ -499,7 +509,8 @@ do_abort (void *cls) | |||
499 | * @return service handle to return in 'op_result', NULL on error | 509 | * @return service handle to return in 'op_result', NULL on error |
500 | */ | 510 | */ |
501 | static void * | 511 | static void * |
502 | stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 512 | stats_ca (void *cls, |
513 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
503 | { | 514 | { |
504 | return GNUNET_STATISTICS_create ("<driver>", cfg); | 515 | return GNUNET_STATISTICS_create ("<driver>", cfg); |
505 | } | 516 | } |
@@ -532,10 +543,12 @@ stats_da (void *cls, void *op_result) | |||
532 | * @param name the name of the datum | 543 | * @param name the name of the datum |
533 | * @param value the current value | 544 | * @param value the current value |
534 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | 545 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not |
535 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 546 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
536 | */ | 547 | */ |
537 | static int | 548 | static int |
538 | stats_iterator (void *cls, const char *subsystem, const char *name, | 549 | stats_iterator (void *cls, |
550 | const char *subsystem, | ||
551 | const char *name, | ||
539 | uint64_t value, int is_persistent) | 552 | uint64_t value, int is_persistent) |
540 | { | 553 | { |
541 | struct RegexPeer *peer = cls; | 554 | struct RegexPeer *peer = cls; |
@@ -596,9 +609,9 @@ stats_cb (void *cls, | |||
596 | fprintf (stderr, "s"); | 609 | fprintf (stderr, "s"); |
597 | if (peer_cnt == num_peers) | 610 | if (peer_cnt == num_peers) |
598 | { | 611 | { |
599 | struct GNUNET_TIME_Relative delay = { 100 }; | 612 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
600 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\nCollecting stats finished. Shutting down.\n"); | 613 | "\nCollecting stats finished. Shutting down.\n"); |
601 | shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL); | 614 | GNUNET_SCHEDULER_shutdown (); |
602 | result = GNUNET_OK; | 615 | result = GNUNET_OK; |
603 | } | 616 | } |
604 | else | 617 | else |
@@ -845,12 +858,8 @@ static void | |||
845 | find_timed_out (void *cls) | 858 | find_timed_out (void *cls) |
846 | { | 859 | { |
847 | struct RegexPeer *p = cls; | 860 | struct RegexPeer *p = cls; |
848 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
849 | 861 | ||
850 | p->timeout = NULL; | 862 | p->timeout = NULL; |
851 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
852 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
853 | return; | ||
854 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
855 | "Searching for string \"%s\" on peer %d timed out.\n", | 864 | "Searching for string \"%s\" on peer %d timed out.\n", |
856 | p->search_str, | 865 | p->search_str, |
@@ -869,12 +878,9 @@ static void | |||
869 | find_string (void *cls) | 878 | find_string (void *cls) |
870 | { | 879 | { |
871 | unsigned int search_peer = (unsigned int) (long) cls; | 880 | unsigned int search_peer = (unsigned int) (long) cls; |
872 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
873 | 881 | ||
874 | tc = GNUNET_SCHEDULER_get_task_context (); | 882 | if ( (search_peer >= num_peers) || |
875 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || | 883 | (GNUNET_YES == in_shutdown) ) |
876 | search_peer >= num_peers || | ||
877 | GNUNET_YES == in_shutdown) | ||
878 | return; | 884 | return; |
879 | 885 | ||
880 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 886 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -893,14 +899,13 @@ find_string (void *cls) | |||
893 | &dht_da, | 899 | &dht_da, |
894 | &peers[search_peer]); | 900 | &peers[search_peer]); |
895 | GNUNET_assert (NULL != peers[search_peer].op_handle); | 901 | GNUNET_assert (NULL != peers[search_peer].op_handle); |
896 | peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT, | 902 | peers[search_peer].timeout |
897 | &find_timed_out, | 903 | = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT, |
898 | &peers[search_peer]); | 904 | &find_timed_out, |
905 | &peers[search_peer]); | ||
899 | } | 906 | } |
900 | 907 | ||
901 | 908 | ||
902 | |||
903 | |||
904 | /** | 909 | /** |
905 | * Callback called when testbed has started the daemon we asked for. | 910 | * Callback called when testbed has started the daemon we asked for. |
906 | * | 911 | * |
@@ -909,7 +914,8 @@ find_string (void *cls) | |||
909 | * @param emsg NULL on success; otherwise an error description | 914 | * @param emsg NULL on success; otherwise an error description |
910 | */ | 915 | */ |
911 | static void | 916 | static void |
912 | daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op, | 917 | daemon_started (void *cls, |
918 | struct GNUNET_TESTBED_Operation *op, | ||
913 | const char *emsg) | 919 | const char *emsg) |
914 | { | 920 | { |
915 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 921 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
@@ -961,8 +967,10 @@ do_announce (void *cls) | |||
961 | { | 967 | { |
962 | unsigned int i; | 968 | unsigned int i; |
963 | 969 | ||
964 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting announce.\n"); | 970 | if (GNUNET_YES == in_shutdown) |
965 | 971 | return; | |
972 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
973 | "Starting announce.\n"); | ||
966 | for (i = 0; i < init_parallel_searches; i++) | 974 | for (i = 0; i < init_parallel_searches; i++) |
967 | { | 975 | { |
968 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 976 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -982,10 +990,8 @@ static void | |||
982 | announce_next_regex (void *cls) | 990 | announce_next_regex (void *cls) |
983 | { | 991 | { |
984 | struct RegexPeer *peer; | 992 | struct RegexPeer *peer; |
985 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
986 | 993 | ||
987 | tc = GNUNET_SCHEDULER_get_task_context (); | 994 | if (GNUNET_YES == in_shutdown) |
988 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
989 | return; | 995 | return; |
990 | if (next_search >= num_peers) | 996 | if (next_search >= num_peers) |
991 | { | 997 | { |
@@ -1015,6 +1021,7 @@ announce_next_regex (void *cls) | |||
1015 | parallel_searches++; | 1021 | parallel_searches++; |
1016 | } | 1022 | } |
1017 | 1023 | ||
1024 | |||
1018 | /** | 1025 | /** |
1019 | * DHT connect callback. Called when we are connected to the dht service for | 1026 | * DHT connect callback. Called when we are connected to the dht service for |
1020 | * the peer in 'cls'. If successfull we connect to the stats service of this | 1027 | * the peer in 'cls'. If successfull we connect to the stats service of this |
@@ -1026,8 +1033,10 @@ announce_next_regex (void *cls) | |||
1026 | * @param emsg error message. | 1033 | * @param emsg error message. |
1027 | */ | 1034 | */ |
1028 | static void | 1035 | static void |
1029 | dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 1036 | dht_connect_cb (void *cls, |
1030 | void *ca_result, const char *emsg) | 1037 | struct GNUNET_TESTBED_Operation *op, |
1038 | void *ca_result, | ||
1039 | const char *emsg) | ||
1031 | { | 1040 | { |
1032 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1041 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
1033 | 1042 | ||
@@ -1194,10 +1203,12 @@ master_controller_cb (void *cls, | |||
1194 | * @param strings set of strings loaded from file. Caller needs to free this | 1203 | * @param strings set of strings loaded from file. Caller needs to free this |
1195 | * if number returned is greater than zero. | 1204 | * if number returned is greater than zero. |
1196 | * @param limit upper limit on the number of strings read from the file | 1205 | * @param limit upper limit on the number of strings read from the file |
1197 | * @return number of strings found in the file. GNUNET_SYSERR on error. | 1206 | * @return number of strings found in the file. #GNUNET_SYSERR on error. |
1198 | */ | 1207 | */ |
1199 | static int | 1208 | static int |
1200 | load_search_strings (const char *filename, char ***strings, unsigned int limit) | 1209 | load_search_strings (const char *filename, |
1210 | char ***strings, | ||
1211 | unsigned int limit) | ||
1201 | { | 1212 | { |
1202 | char *data; | 1213 | char *data; |
1203 | char *buf; | 1214 | char *buf; |
@@ -1268,7 +1279,9 @@ load_search_strings (const char *filename, char ***strings, unsigned int limit) | |||
1268 | * @param config configuration | 1279 | * @param config configuration |
1269 | */ | 1280 | */ |
1270 | static void | 1281 | static void |
1271 | run (void *cls, char *const *args, const char *cfgfile, | 1282 | run (void *cls, |
1283 | char *const *args, | ||
1284 | const char *cfgfile, | ||
1272 | const struct GNUNET_CONFIGURATION_Handle *config) | 1285 | const struct GNUNET_CONFIGURATION_Handle *config) |
1273 | { | 1286 | { |
1274 | unsigned int nsearchstrs; | 1287 | unsigned int nsearchstrs; |
@@ -1282,7 +1295,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1282 | { | 1295 | { |
1283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1284 | _("No configuration file given. Exiting\n")); | 1297 | _("No configuration file given. Exiting\n")); |
1285 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1298 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1286 | return; | 1299 | return; |
1287 | } | 1300 | } |
1288 | cfg = GNUNET_CONFIGURATION_dup (config); | 1301 | cfg = GNUNET_CONFIGURATION_dup (config); |
@@ -1291,9 +1304,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1291 | "REGEX_PREFIX", | 1304 | "REGEX_PREFIX", |
1292 | ®ex_prefix)) | 1305 | ®ex_prefix)) |
1293 | { | 1306 | { |
1294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1307 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1295 | _("Configuration option \"regex_prefix\" missing. Exiting\n")); | 1308 | "regexprofiler", |
1296 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1309 | "regex_prefix"); |
1310 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1297 | return; | 1311 | return; |
1298 | } | 1312 | } |
1299 | if (GNUNET_OK != | 1313 | if (GNUNET_OK != |
@@ -1328,7 +1342,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1328 | { | 1342 | { |
1329 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1330 | _("Specified policies directory does not exist. Exiting.\n")); | 1344 | _("Specified policies directory does not exist. Exiting.\n")); |
1331 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1345 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1332 | return; | 1346 | return; |
1333 | } | 1347 | } |
1334 | if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL))) | 1348 | if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL))) |
@@ -1344,7 +1358,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1344 | { | 1358 | { |
1345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1359 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1346 | _("No search strings file given. Exiting.\n")); | 1360 | _("No search strings file given. Exiting.\n")); |
1347 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1361 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1348 | return; | 1362 | return; |
1349 | } | 1363 | } |
1350 | nsearchstrs = load_search_strings (strings_file, | 1364 | nsearchstrs = load_search_strings (strings_file, |
@@ -1357,14 +1371,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1358 | "File (%s) does not contain enough strings (%u/%u).\n", | 1372 | "File (%s) does not contain enough strings (%u/%u).\n", |
1359 | strings_file, nsearchstrs, num_peers); | 1373 | strings_file, nsearchstrs, num_peers); |
1360 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1374 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1361 | return; | 1375 | return; |
1362 | } | 1376 | } |
1363 | if ( (0 == num_peers) || (NULL == search_strings)) | 1377 | if ( (0 == num_peers) || (NULL == search_strings)) |
1364 | { | 1378 | { |
1365 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1366 | _("Error loading search strings. Exiting.\n")); | 1380 | _("Error loading search strings. Exiting.\n")); |
1367 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1381 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1368 | return; | 1382 | return; |
1369 | } | 1383 | } |
1370 | for (i = 0; i < num_peers; i++) | 1384 | for (i = 0; i < num_peers; i++) |