aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/regex
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/gnunet-daemon-regexprofiler.c28
-rw-r--r--src/regex/gnunet-regex-profiler.c122
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c156
-rw-r--r--src/regex/gnunet-service-regex.c5
4 files changed, 171 insertions, 140 deletions
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c
index 1ff3b55e3..42fc8ace0 100644
--- a/src/regex/gnunet-daemon-regexprofiler.c
+++ b/src/regex/gnunet-daemon-regexprofiler.c
@@ -117,7 +117,11 @@ shutdown_task (void *cls)
117 REGEX_INTERNAL_announce_cancel (announce_handle); 117 REGEX_INTERNAL_announce_cancel (announce_handle);
118 announce_handle = NULL; 118 announce_handle = NULL;
119 } 119 }
120 120 if (NULL != reannounce_task)
121 {
122 GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task));
123 reannounce_task = NULL;
124 }
121 if (NULL != dht_handle) 125 if (NULL != dht_handle)
122 { 126 {
123 GNUNET_DHT_disconnect (dht_handle); 127 GNUNET_DHT_disconnect (dht_handle);
@@ -142,16 +146,8 @@ reannounce_regex (void *cls)
142{ 146{
143 char *regex = cls; 147 char *regex = cls;
144 struct GNUNET_TIME_Relative random_delay; 148 struct GNUNET_TIME_Relative random_delay;
145 const struct GNUNET_SCHEDULER_TaskContext *tc;
146 149
147 reannounce_task = NULL; 150 reannounce_task = NULL;
148 tc = GNUNET_SCHEDULER_get_task_context ();
149 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
150 {
151 GNUNET_free (regex);
152 return;
153 }
154
155 if (0 == rounds--) 151 if (0 == rounds--)
156 { 152 {
157 global_ret = 0; 153 global_ret = 0;
@@ -195,7 +191,7 @@ reannounce_regex (void *cls)
195 * @param regex regular expression to announce on this peer's cadet. 191 * @param regex regular expression to announce on this peer's cadet.
196 */ 192 */
197static void 193static void
198announce_regex (const char * regex) 194announce_regex (const char *regex)
199{ 195{
200 char *copy; 196 char *copy;
201 197
@@ -210,7 +206,8 @@ announce_regex (const char * regex)
210 policy_filename); 206 policy_filename);
211 GNUNET_assert (NULL == reannounce_task); 207 GNUNET_assert (NULL == reannounce_task);
212 copy = GNUNET_strdup (regex); 208 copy = GNUNET_strdup (regex);
213 reannounce_task = GNUNET_SCHEDULER_add_now (reannounce_regex, (void *) copy); 209 reannounce_task = GNUNET_SCHEDULER_add_now (&reannounce_regex,
210 (void *) copy);
214} 211}
215 212
216 213
@@ -347,14 +344,17 @@ run (void *cls, char *const *args GNUNET_UNUSED,
347 REGEX_TEST_free_from_file (components); 344 REGEX_TEST_free_from_file (components);
348 345
349 /* Announcing regexes from policy_filename */ 346 /* Announcing regexes from policy_filename */
350 GNUNET_asprintf (&rx_with_pfx, "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*", regex_prefix, regex); 347 GNUNET_asprintf (&rx_with_pfx,
348 "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
349 regex_prefix,
350 regex);
351 announce_regex (rx_with_pfx); 351 announce_regex (rx_with_pfx);
352 GNUNET_free (regex); 352 GNUNET_free (regex);
353 GNUNET_free (rx_with_pfx); 353 GNUNET_free (rx_with_pfx);
354 354
355 /* Scheduled the task to clean up when shutdown is called */ 355 /* Scheduled the task to clean up when shutdown is called */
356 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
357 NULL); 357 NULL);
358} 358}
359 359
360 360
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;
214static struct GNUNET_SCHEDULER_Task * abort_task; 214static struct GNUNET_SCHEDULER_Task * abort_task;
215 215
216/** 216/**
217 * Shutdown task identifier
218 */
219static struct GNUNET_SCHEDULER_Task * shutdown_task;
220
221/**
222 * Host registration task identifier 217 * Host registration task identifier
223 */ 218 */
224static struct GNUNET_SCHEDULER_Task * register_hosts_task; 219static 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 */
501static void * 511static void *
502stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 512stats_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 */
537static int 548static int
538stats_iterator (void *cls, const char *subsystem, const char *name, 549stats_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
845find_timed_out (void *cls) 858find_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
869find_string (void *cls) 878find_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 */
911static void 916static void
912daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op, 917daemon_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
982announce_next_regex (void *cls) 990announce_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 */
1028static void 1035static void
1029dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 1036dht_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 */
1199static int 1208static int
1200load_search_strings (const char *filename, char ***strings, unsigned int limit) 1209load_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 */
1270static void 1281static void
1271run (void *cls, char *const *args, const char *cfgfile, 1282run (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 &regex_prefix)) 1305 &regex_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++)
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index 27dfa773d..0f955f7b5 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -89,19 +89,9 @@ struct ProgressMeter
89static struct ProgressMeter *meter; 89static struct ProgressMeter *meter;
90 90
91/** 91/**
92 * Abort task identifier.
93 */
94static struct GNUNET_SCHEDULER_Task * abort_task;
95
96/**
97 * Shutdown task identifier.
98 */
99static struct GNUNET_SCHEDULER_Task * shutdown_task;
100
101/**
102 * Scan task identifier; 92 * Scan task identifier;
103 */ 93 */
104static struct GNUNET_SCHEDULER_Task * scan_task; 94static struct GNUNET_SCHEDULER_Task *scan_task;
105 95
106/** 96/**
107 * Global testing status. 97 * Global testing status.
@@ -240,8 +230,8 @@ update_meter (struct ProgressMeter *meter)
240 * 230 *
241 * @param meter the meter to reset 231 * @param meter the meter to reset
242 * 232 *
243 * @return GNUNET_YES if meter reset, 233 * @return #GNUNET_YES if meter reset,
244 * GNUNET_SYSERR on error 234 * #GNUNET_SYSERR on error
245 */ 235 */
246static int 236static int
247reset_meter (struct ProgressMeter *meter) 237reset_meter (struct ProgressMeter *meter)
@@ -274,21 +264,28 @@ free_meter (struct ProgressMeter *meter)
274 */ 264 */
275static void 265static void
276do_shutdown (void *cls) 266do_shutdown (void *cls)
277{ 267{
278 shutdown_task = NULL;
279 if (NULL != abort_task)
280 GNUNET_SCHEDULER_cancel (abort_task);
281 if (NULL != mysql_ctx) 268 if (NULL != mysql_ctx)
269 {
282 GNUNET_MYSQL_context_destroy (mysql_ctx); 270 GNUNET_MYSQL_context_destroy (mysql_ctx);
271 mysql_ctx = NULL;
272 }
283 if (NULL != meter) 273 if (NULL != meter)
274 {
284 free_meter (meter); 275 free_meter (meter);
285 276 meter = NULL;
286 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ 277 }
287} 278}
288 279
289 280
290/** 281/**
291 * abort task to run on test timed out 282 * Abort task to run on test timed out.
283 *
284 * FIXME: this doesn't actually work, it used to cancel
285 * the already running 'scan_task', but now that should
286 * always be NULL and do nothing. We instead need to set
287 * a global variable and abort scan_task internally, not
288 * via scheduler.
292 * 289 *
293 * @param cls NULL 290 * @param cls NULL
294 */ 291 */
@@ -296,25 +293,29 @@ static void
296do_abort (void *cls) 293do_abort (void *cls)
297{ 294{
298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); 295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
299 abort_task = NULL; 296 if (NULL != scan_task)
300 GNUNET_SCHEDULER_cancel (scan_task); 297 {
301 scan_task = NULL; 298 GNUNET_SCHEDULER_cancel (scan_task);
299 scan_task = NULL;
300 }
302 result = GNUNET_SYSERR; 301 result = GNUNET_SYSERR;
303 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 302 GNUNET_SCHEDULER_shutdown ();
304} 303}
305 304
306 305
307/** 306/**
308 * Dummy function for prepared select. Always return GNUNET_OK. 307 * Dummy function for prepared select. Always returns #GNUNET_OK.
309 * 308 *
310 * @param cls closure 309 * @param cls closure
311 * @param num_values number of values. 310 * @param num_values number of values.
312 * @param values returned values from select stmt. 311 * @param values returned values from select stmt.
313 * 312 *
314 * @return GNUNET_OK 313 * @return #GNUNET_OK
315 */ 314 */
316static int 315static int
317return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values) 316return_ok (void *cls,
317 unsigned int num_values,
318 MYSQL_BIND * values)
318{ 319{
319 return GNUNET_OK; 320 return GNUNET_OK;
320} 321}
@@ -326,13 +327,16 @@ return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
326 * @param cls closure. 327 * @param cls closure.
327 * @param key hash for current state. 328 * @param key hash for current state.
328 * @param proof proof for current state. 329 * @param proof proof for current state.
329 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. 330 * @param accepting #GNUNET_YES if this is an accepting state, #GNUNET_NO if not.
330 * @param num_edges number of edges leaving current state. 331 * @param num_edges number of edges leaving current state.
331 * @param edges edges leaving current state. 332 * @param edges edges leaving current state.
332 */ 333 */
333static void 334static void
334regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, 335regex_iterator (void *cls,
335 int accepting, unsigned int num_edges, 336 const struct GNUNET_HashCode *key,
337 const char *proof,
338 int accepting,
339 unsigned int num_edges,
336 const struct REGEX_BLOCK_Edge *edges) 340 const struct REGEX_BLOCK_Edge *edges)
337{ 341{
338 unsigned int i; 342 unsigned int i;
@@ -453,7 +457,7 @@ regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
453 * each state into a MySQL database. 457 * each state into a MySQL database.
454 * 458 *
455 * @param regex regular expression. 459 * @param regex regular expression.
456 * @return GNUNET_OK on success, GNUNET_SYSERR on failure. 460 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
457 */ 461 */
458static int 462static int
459announce_regex (const char *regex) 463announce_regex (const char *regex)
@@ -461,18 +465,20 @@ announce_regex (const char *regex)
461 struct REGEX_INTERNAL_Automaton *dfa; 465 struct REGEX_INTERNAL_Automaton *dfa;
462 466
463 dfa = 467 dfa =
464 REGEX_INTERNAL_construct_dfa (regex, strlen (regex), max_path_compression); 468 REGEX_INTERNAL_construct_dfa (regex,
469 strlen (regex),
470 max_path_compression);
465 471
466 if (NULL == dfa) 472 if (NULL == dfa)
467 { 473 {
468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create DFA for regex %s\n", 474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
475 "Failed to create DFA for regex %s\n",
469 regex); 476 regex);
470 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); 477 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
471 return GNUNET_SYSERR; 478 return GNUNET_SYSERR;
472 } 479 }
473 480 REGEX_INTERNAL_iterate_all_edges (dfa,
474 REGEX_INTERNAL_iterate_all_edges (dfa, &regex_iterator, NULL); 481 &regex_iterator, NULL);
475
476 REGEX_INTERNAL_automaton_destroy (dfa); 482 REGEX_INTERNAL_automaton_destroy (dfa);
477 483
478 return GNUNET_OK; 484 return GNUNET_OK;
@@ -484,8 +490,8 @@ announce_regex (const char *regex)
484 * 490 *
485 * @param cls closure 491 * @param cls closure
486 * @param filename complete filename (absolute path) 492 * @param filename complete filename (absolute path)
487 * @return GNUNET_OK to continue to iterate, 493 * @return #GNUNET_OK to continue to iterate,
488 * GNUNET_SYSERR to abort iteration with error! 494 * #GNUNET_SYSERR to abort iteration with error!
489 */ 495 */
490static int 496static int
491policy_filename_cb (void *cls, const char *filename) 497policy_filename_cb (void *cls, const char *filename)
@@ -498,17 +504,20 @@ policy_filename_cb (void *cls, const char *filename)
498 504
499 GNUNET_assert (NULL != filename); 505 GNUNET_assert (NULL != filename);
500 506
501 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Announcing regexes from file %s\n", 507 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
508 "Announcing regexes from file %s\n",
502 filename); 509 filename);
503 510
504 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 511 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
505 { 512 {
506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not find policy file %s\n", 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
514 "Could not find policy file %s\n",
507 filename); 515 filename);
508 return GNUNET_OK; 516 return GNUNET_OK;
509 } 517 }
510 if (GNUNET_OK != 518 if (GNUNET_OK !=
511 GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES)) 519 GNUNET_DISK_file_size (filename, &filesize,
520 GNUNET_YES, GNUNET_YES))
512 filesize = 0; 521 filesize = 0;
513 if (0 == filesize) 522 if (0 == filesize)
514 { 523 {
@@ -520,7 +529,8 @@ policy_filename_cb (void *cls, const char *filename)
520 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize)) 529 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
521 { 530 {
522 GNUNET_free (data); 531 GNUNET_free (data);
523 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n", 532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
533 "Could not read policy file %s.\n",
524 filename); 534 filename);
525 return GNUNET_OK; 535 return GNUNET_OK;
526 } 536 }
@@ -545,11 +555,13 @@ policy_filename_cb (void *cls, const char *filename)
545 data[offset] = '\0'; 555 data[offset] = '\0';
546 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data); 556 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
547 GNUNET_assert (NULL != regex); 557 GNUNET_assert (NULL != regex);
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex); 558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
559 "Announcing regex: %s\n", regex);
549 560
550 if (GNUNET_OK != announce_regex (regex)) 561 if (GNUNET_OK != announce_regex (regex))
551 { 562 {
552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not announce regex %s\n", 563 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
564 "Could not announce regex %s\n",
553 regex); 565 regex);
554 } 566 }
555 GNUNET_free (regex); 567 GNUNET_free (regex);
@@ -571,6 +583,7 @@ do_directory_scan (void *cls)
571 char *stmt; 583 char *stmt;
572 584
573 /* Create an MySQL prepared statement for the inserts */ 585 /* Create an MySQL prepared statement for the inserts */
586 scan_task = NULL;
574 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name); 587 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
575 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt); 588 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
576 GNUNET_free (stmt); 589 GNUNET_free (stmt);
@@ -581,10 +594,13 @@ do_directory_scan (void *cls)
581 594
582 GNUNET_assert (NULL != stmt_handle); 595 GNUNET_assert (NULL != stmt_handle);
583 596
584 meter = 597 meter = create_meter (num_policy_files,
585 create_meter (num_policy_files, "Announcing policy files\n", GNUNET_YES); 598 "Announcing policy files\n",
599 GNUNET_YES);
586 start_time = GNUNET_TIME_absolute_get (); 600 start_time = GNUNET_TIME_absolute_get ();
587 GNUNET_DISK_directory_scan (policy_dir, &policy_filename_cb, stmt_handle); 601 GNUNET_DISK_directory_scan (policy_dir,
602 &policy_filename_cb,
603 stmt_handle);
588 duration = GNUNET_TIME_absolute_get_duration (start_time); 604 duration = GNUNET_TIME_absolute_get_duration (start_time);
589 reset_meter (meter); 605 reset_meter (meter);
590 free_meter (meter); 606 free_meter (meter);
@@ -592,12 +608,13 @@ do_directory_scan (void *cls)
592 608
593 printf ("Announced %u files containing %u policies in %s\n" 609 printf ("Announced %u files containing %u policies in %s\n"
594 "Duplicate transitions: %llu\nMerged states: %llu\n", 610 "Duplicate transitions: %llu\nMerged states: %llu\n",
595 num_policy_files, num_policies, 611 num_policy_files,
612 num_policies,
596 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO), 613 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO),
597 num_merged_transitions, num_merged_states); 614 num_merged_transitions,
598 615 num_merged_states);
599 result = GNUNET_OK; 616 result = GNUNET_OK;
600 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 617 GNUNET_SCHEDULER_shutdown ();
601} 618}
602 619
603 620
@@ -610,7 +627,9 @@ do_directory_scan (void *cls)
610 * @param config configuration 627 * @param config configuration
611 */ 628 */
612static void 629static void
613run (void *cls, char *const *args, const char *cfgfile, 630run (void *cls,
631 char *const *args,
632 const char *cfgfile,
614 const struct GNUNET_CONFIGURATION_Handle *config) 633 const struct GNUNET_CONFIGURATION_Handle *config)
615{ 634{
616 if (NULL == args[0]) 635 if (NULL == args[0])
@@ -620,7 +639,8 @@ run (void *cls, char *const *args, const char *cfgfile,
620 result = GNUNET_SYSERR; 639 result = GNUNET_SYSERR;
621 return; 640 return;
622 } 641 }
623 if (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES)) 642 if (GNUNET_YES !=
643 GNUNET_DISK_directory_test (args[0], GNUNET_YES))
624 { 644 {
625 fprintf (stderr, 645 fprintf (stderr,
626 _("Specified policies directory does not exist. Exiting.\n")); 646 _("Specified policies directory does not exist. Exiting.\n"));
@@ -629,7 +649,8 @@ run (void *cls, char *const *args, const char *cfgfile,
629 } 649 }
630 policy_dir = args[0]; 650 policy_dir = args[0];
631 651
632 num_policy_files = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL); 652 num_policy_files = GNUNET_DISK_directory_scan (policy_dir,
653 NULL, NULL);
633 meter = NULL; 654 meter = NULL;
634 655
635 if (NULL == table_name) 656 if (NULL == table_name)
@@ -642,32 +663,29 @@ run (void *cls, char *const *args, const char *cfgfile,
642 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql"); 663 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
643 if (NULL == mysql_ctx) 664 if (NULL == mysql_ctx)
644 { 665 {
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create mysql context\n"); 666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
667 "Failed to create mysql context\n");
646 result = GNUNET_SYSERR; 668 result = GNUNET_SYSERR;
647 return; 669 return;
648 } 670 }
649 671
650 if (GNUNET_OK != 672 if (GNUNET_OK !=
651 GNUNET_CONFIGURATION_get_value_string (config, "regex-mysql", 673 GNUNET_CONFIGURATION_get_value_string (config,
652 "REGEX_PREFIX", &regex_prefix)) 674 "regex-mysql",
675 "REGEX_PREFIX",
676 &regex_prefix))
653 { 677 {
654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 678 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
655 _ 679 "regex-mysql",
656 ("%s service is lacking key configuration settings (%s). Exiting.\n"), 680 "REGEX_PREFIX");
657 "regexprofiler", "regex_prefix");
658 result = GNUNET_SYSERR; 681 result = GNUNET_SYSERR;
659 return; 682 return;
660 } 683 }
661 684
662
663 result = GNUNET_OK; 685 result = GNUNET_OK;
664 686 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
687 NULL);
665 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL); 688 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL);
666
667 /* Scheduled the task to clean up when shutdown is called */
668 shutdown_task =
669 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
670 NULL);
671} 689}
672 690
673 691
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index a70876534..530e4f358 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -384,9 +384,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
384 GNUNET_SCHEDULER_shutdown (); 384 GNUNET_SCHEDULER_shutdown ();
385 return; 385 return;
386 } 386 }
387 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 387 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
388 &cleanup_task, 388 NULL);
389 NULL);
390 nc = GNUNET_SERVER_notification_context_create (server, 1); 389 nc = GNUNET_SERVER_notification_context_create (server, 1);
391 stats = GNUNET_STATISTICS_create ("regex", cfg); 390 stats = GNUNET_STATISTICS_create ("regex", cfg);
392 GNUNET_SERVER_add_handlers (server, handlers); 391 GNUNET_SERVER_add_handlers (server, handlers);