aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-regex-simulation-profiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/gnunet-regex-simulation-profiler.c')
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c634
1 files changed, 316 insertions, 318 deletions
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index d82b7800a..aa297d2ea 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21 21
22/** 22/**
@@ -38,22 +38,21 @@
38/** 38/**
39 * MySQL statement to insert an edge. 39 * MySQL statement to insert an edge.
40 */ 40 */
41#define INSERT_EDGE_STMT "INSERT IGNORE INTO `%s` "\ 41#define INSERT_EDGE_STMT "INSERT IGNORE INTO `%s` " \
42 "(`key`, `label`, `to_key`, `accepting`) "\ 42 "(`key`, `label`, `to_key`, `accepting`) " \
43 "VALUES (?, ?, ?, ?);" 43 "VALUES (?, ?, ?, ?);"
44 44
45/** 45/**
46 * MySQL statement to select a key count. 46 * MySQL statement to select a key count.
47 */ 47 */
48#define SELECT_KEY_STMT "SELECT COUNT(*) FROM `%s` "\ 48#define SELECT_KEY_STMT "SELECT COUNT(*) FROM `%s` " \
49 "WHERE `key` = ? AND `label` = ?;" 49 "WHERE `key` = ? AND `label` = ?;"
50 50
51/** 51/**
52 * Simple struct to keep track of progress, and print a 52 * Simple struct to keep track of progress, and print a
53 * nice little percentage meter for long running tasks. 53 * nice little percentage meter for long running tasks.
54 */ 54 */
55struct ProgressMeter 55struct ProgressMeter {
56{
57 /** 56 /**
58 * Total number of elements. 57 * Total number of elements.
59 */ 58 */
@@ -168,11 +167,11 @@ static char *regex_prefix;
168 * @return the progress meter 167 * @return the progress meter
169 */ 168 */
170static struct ProgressMeter * 169static struct ProgressMeter *
171create_meter (unsigned int total, char *start_string, int print) 170create_meter(unsigned int total, char *start_string, int print)
172{ 171{
173 struct ProgressMeter *ret; 172 struct ProgressMeter *ret;
174 173
175 ret = GNUNET_new (struct ProgressMeter); 174 ret = GNUNET_new(struct ProgressMeter);
176 ret->print = print; 175 ret->print = print;
177 ret->total = total; 176 ret->total = total;
178 ret->modnum = total / 4; 177 ret->modnum = total / 4;
@@ -180,9 +179,9 @@ create_meter (unsigned int total, char *start_string, int print)
180 ret->modnum = 1; 179 ret->modnum = 1;
181 ret->dotnum = (total / 50) + 1; 180 ret->dotnum = (total / 50) + 1;
182 if (start_string != NULL) 181 if (start_string != NULL)
183 ret->startup_string = GNUNET_strdup (start_string); 182 ret->startup_string = GNUNET_strdup(start_string);
184 else 183 else
185 ret->startup_string = GNUNET_strdup (""); 184 ret->startup_string = GNUNET_strdup("");
186 185
187 return ret; 186 return ret;
188} 187}
@@ -197,33 +196,33 @@ create_meter (unsigned int total, char *start_string, int print)
197 * GNUNET_NO if more items expected 196 * GNUNET_NO if more items expected
198 */ 197 */
199static int 198static int
200update_meter (struct ProgressMeter *meter) 199update_meter(struct ProgressMeter *meter)
201{ 200{
202 if (meter->print == GNUNET_YES) 201 if (meter->print == GNUNET_YES)
203 {
204 if (meter->completed % meter->modnum == 0)
205 { 202 {
206 if (meter->completed == 0) 203 if (meter->completed % meter->modnum == 0)
207 { 204 {
208 fprintf (stdout, "%sProgress: [0%%", meter->startup_string); 205 if (meter->completed == 0)
209 } 206 {
210 else 207 fprintf(stdout, "%sProgress: [0%%", meter->startup_string);
211 fprintf (stdout, "%d%%", 208 }
212 (int) (((float) meter->completed / meter->total) * 100)); 209 else
210 fprintf(stdout, "%d%%",
211 (int)(((float)meter->completed / meter->total) * 100));
212 }
213 else if (meter->completed % meter->dotnum == 0)
214 fprintf(stdout, "%s", ".");
215
216 if (meter->completed + 1 == meter->total)
217 fprintf(stdout, "%d%%]\n", 100);
218 fflush(stdout);
213 } 219 }
214 else if (meter->completed % meter->dotnum == 0)
215 fprintf (stdout, "%s", ".");
216
217 if (meter->completed + 1 == meter->total)
218 fprintf (stdout, "%d%%]\n", 100);
219 fflush (stdout);
220 }
221 meter->completed++; 220 meter->completed++;
222 221
223 if (meter->completed == meter->total) 222 if (meter->completed == meter->total)
224 return GNUNET_YES; 223 return GNUNET_YES;
225 if (meter->completed > meter->total) 224 if (meter->completed > meter->total)
226 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n"); 225 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
227 return GNUNET_NO; 226 return GNUNET_NO;
228} 227}
229 228
@@ -237,7 +236,7 @@ update_meter (struct ProgressMeter *meter)
237 * #GNUNET_SYSERR on error 236 * #GNUNET_SYSERR on error
238 */ 237 */
239static int 238static int
240reset_meter (struct ProgressMeter *meter) 239reset_meter(struct ProgressMeter *meter)
241{ 240{
242 if (meter == NULL) 241 if (meter == NULL)
243 return GNUNET_SYSERR; 242 return GNUNET_SYSERR;
@@ -253,10 +252,10 @@ reset_meter (struct ProgressMeter *meter)
253 * @param meter the meter to free 252 * @param meter the meter to free
254 */ 253 */
255static void 254static void
256free_meter (struct ProgressMeter *meter) 255free_meter(struct ProgressMeter *meter)
257{ 256{
258 GNUNET_free_non_null (meter->startup_string); 257 GNUNET_free_non_null(meter->startup_string);
259 GNUNET_free (meter); 258 GNUNET_free(meter);
260} 259}
261 260
262 261
@@ -266,18 +265,18 @@ free_meter (struct ProgressMeter *meter)
266 * @param cls NULL 265 * @param cls NULL
267 */ 266 */
268static void 267static void
269do_shutdown (void *cls) 268do_shutdown(void *cls)
270{ 269{
271 if (NULL != mysql_ctx) 270 if (NULL != mysql_ctx)
272 { 271 {
273 GNUNET_MYSQL_context_destroy (mysql_ctx); 272 GNUNET_MYSQL_context_destroy(mysql_ctx);
274 mysql_ctx = NULL; 273 mysql_ctx = NULL;
275 } 274 }
276 if (NULL != meter) 275 if (NULL != meter)
277 { 276 {
278 free_meter (meter); 277 free_meter(meter);
279 meter = NULL; 278 meter = NULL;
280 } 279 }
281} 280}
282 281
283 282
@@ -293,16 +292,16 @@ do_shutdown (void *cls)
293 * @param cls NULL 292 * @param cls NULL
294 */ 293 */
295static void 294static void
296do_abort (void *cls) 295do_abort(void *cls)
297{ 296{
298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); 297 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
299 if (NULL != scan_task) 298 if (NULL != scan_task)
300 { 299 {
301 GNUNET_SCHEDULER_cancel (scan_task); 300 GNUNET_SCHEDULER_cancel(scan_task);
302 scan_task = NULL; 301 scan_task = NULL;
303 } 302 }
304 result = GNUNET_SYSERR; 303 result = GNUNET_SYSERR;
305 GNUNET_SCHEDULER_shutdown (); 304 GNUNET_SCHEDULER_shutdown();
306} 305}
307 306
308/** 307/**
@@ -316,12 +315,12 @@ do_abort (void *cls)
316 * @param edges edges leaving current state. 315 * @param edges edges leaving current state.
317 */ 316 */
318static void 317static void
319regex_iterator (void *cls, 318regex_iterator(void *cls,
320 const struct GNUNET_HashCode *key, 319 const struct GNUNET_HashCode *key,
321 const char *proof, 320 const char *proof,
322 int accepting, 321 int accepting,
323 unsigned int num_edges, 322 unsigned int num_edges,
324 const struct REGEX_BLOCK_Edge *edges) 323 const struct REGEX_BLOCK_Edge *edges)
325{ 324{
326 unsigned int i; 325 unsigned int i;
327 int result; 326 int result;
@@ -329,118 +328,118 @@ regex_iterator (void *cls,
329 uint32_t iaccepting = (uint32_t)accepting; 328 uint32_t iaccepting = (uint32_t)accepting;
330 uint64_t total; 329 uint64_t total;
331 330
332 GNUNET_assert (NULL != mysql_ctx); 331 GNUNET_assert(NULL != mysql_ctx);
333 332
334 for (i = 0; i < num_edges; i++) 333 for (i = 0; i < num_edges; i++)
335 {
336 struct GNUNET_MY_QueryParam params_select[] = {
337 GNUNET_MY_query_param_auto_from_type (key),
338 GNUNET_MY_query_param_string (edges[i].label),
339 GNUNET_MY_query_param_end
340 };
341
342 struct GNUNET_MY_ResultSpec results_select[] = {
343 GNUNET_MY_result_spec_uint64 (&total),
344 GNUNET_MY_result_spec_end
345 };
346
347 result =
348 GNUNET_MY_exec_prepared (mysql_ctx,
349 select_stmt_handle,
350 params_select);
351
352 if (GNUNET_SYSERR == result)
353 {
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
355 "Error executing prepared mysql select statement\n");
356 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
357 return;
358 }
359
360 result =
361 GNUNET_MY_extract_result (select_stmt_handle,
362 results_select);
363
364 if (GNUNET_SYSERR == result)
365 {
366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
367 "Error extracting result mysql select statement\n");
368 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
369 return;
370 }
371
372 if (-1 != total && total > 0)
373 {
374 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
375 (unsigned long long)total,
376 GNUNET_h2s (key), edges[i].label);
377 }
378
379 struct GNUNET_MY_QueryParam params_stmt[] = {
380 GNUNET_MY_query_param_auto_from_type (&key),
381 GNUNET_MY_query_param_string (edges[i].label),
382 GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
383 GNUNET_MY_query_param_uint32 (&iaccepting),
384 GNUNET_MY_query_param_end
385 };
386
387 result =
388 GNUNET_MY_exec_prepared (mysql_ctx,
389 stmt_handle,
390 params_stmt);
391
392 if (0 == result)
393 {
394 char *key_str = GNUNET_strdup (GNUNET_h2s (key));
395 char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination));
396
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
398 key_str,
399 edges[i].label,
400 to_key_str,
401 accepting);
402
403 GNUNET_free (key_str);
404 GNUNET_free (to_key_str);
405 num_merged_transitions++;
406 }
407 else if (-1 != total)
408 {
409 num_merged_states++;
410 }
411
412 if (GNUNET_SYSERR == result || (1 != result && 0 != result))
413 { 334 {
414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 335 struct GNUNET_MY_QueryParam params_select[] = {
415 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n", 336 GNUNET_MY_query_param_auto_from_type(key),
416 result); 337 GNUNET_MY_query_param_string(edges[i].label),
417 GNUNET_SCHEDULER_add_now (&do_abort, NULL); 338 GNUNET_MY_query_param_end
339 };
340
341 struct GNUNET_MY_ResultSpec results_select[] = {
342 GNUNET_MY_result_spec_uint64(&total),
343 GNUNET_MY_result_spec_end
344 };
345
346 result =
347 GNUNET_MY_exec_prepared(mysql_ctx,
348 select_stmt_handle,
349 params_select);
350
351 if (GNUNET_SYSERR == result)
352 {
353 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
354 "Error executing prepared mysql select statement\n");
355 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
356 return;
357 }
358
359 result =
360 GNUNET_MY_extract_result(select_stmt_handle,
361 results_select);
362
363 if (GNUNET_SYSERR == result)
364 {
365 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
366 "Error extracting result mysql select statement\n");
367 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
368 return;
369 }
370
371 if (-1 != total && total > 0)
372 {
373 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
374 (unsigned long long)total,
375 GNUNET_h2s(key), edges[i].label);
376 }
377
378 struct GNUNET_MY_QueryParam params_stmt[] = {
379 GNUNET_MY_query_param_auto_from_type(&key),
380 GNUNET_MY_query_param_string(edges[i].label),
381 GNUNET_MY_query_param_auto_from_type(&edges[i].destination),
382 GNUNET_MY_query_param_uint32(&iaccepting),
383 GNUNET_MY_query_param_end
384 };
385
386 result =
387 GNUNET_MY_exec_prepared(mysql_ctx,
388 stmt_handle,
389 params_stmt);
390
391 if (0 == result)
392 {
393 char *key_str = GNUNET_strdup(GNUNET_h2s(key));
394 char *to_key_str = GNUNET_strdup(GNUNET_h2s(&edges[i].destination));
395
396 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
397 key_str,
398 edges[i].label,
399 to_key_str,
400 accepting);
401
402 GNUNET_free(key_str);
403 GNUNET_free(to_key_str);
404 num_merged_transitions++;
405 }
406 else if (-1 != total)
407 {
408 num_merged_states++;
409 }
410
411 if (GNUNET_SYSERR == result || (1 != result && 0 != result))
412 {
413 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
414 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
415 result);
416 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
417 }
418 } 418 }
419 }
420 419
421 if (0 == num_edges) 420 if (0 == num_edges)
422 {
423 struct GNUNET_MY_QueryParam params_stmt[] = {
424 GNUNET_MY_query_param_auto_from_type (key),
425 GNUNET_MY_query_param_string (""),
426 GNUNET_MY_query_param_fixed_size (NULL, 0),
427 GNUNET_MY_query_param_uint32 (&iaccepting),
428 GNUNET_MY_query_param_end
429 };
430
431 result =
432 GNUNET_MY_exec_prepared (mysql_ctx,
433 stmt_handle,
434 params_stmt);
435
436 if (1 != result && 0 != result)
437 { 421 {
438 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 422 struct GNUNET_MY_QueryParam params_stmt[] = {
439 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n", 423 GNUNET_MY_query_param_auto_from_type(key),
440 result); 424 GNUNET_MY_query_param_string(""),
441 GNUNET_SCHEDULER_add_now (&do_abort, NULL); 425 GNUNET_MY_query_param_fixed_size(NULL, 0),
426 GNUNET_MY_query_param_uint32(&iaccepting),
427 GNUNET_MY_query_param_end
428 };
429
430 result =
431 GNUNET_MY_exec_prepared(mysql_ctx,
432 stmt_handle,
433 params_stmt);
434
435 if (1 != result && 0 != result)
436 {
437 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
438 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
439 result);
440 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
441 }
442 } 442 }
443 }
444} 443}
445 444
446 445
@@ -452,26 +451,26 @@ regex_iterator (void *cls,
452 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure. 451 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
453 */ 452 */
454static int 453static int
455announce_regex (const char *regex) 454announce_regex(const char *regex)
456{ 455{
457 struct REGEX_INTERNAL_Automaton *dfa; 456 struct REGEX_INTERNAL_Automaton *dfa;
458 457
459 dfa = 458 dfa =
460 REGEX_INTERNAL_construct_dfa (regex, 459 REGEX_INTERNAL_construct_dfa(regex,
461 strlen (regex), 460 strlen(regex),
462 max_path_compression); 461 max_path_compression);
463 462
464 if (NULL == dfa) 463 if (NULL == dfa)
465 { 464 {
466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 465 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
467 "Failed to create DFA for regex %s\n", 466 "Failed to create DFA for regex %s\n",
468 regex); 467 regex);
469 GNUNET_SCHEDULER_add_now (&do_abort, NULL); 468 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
470 return GNUNET_SYSERR; 469 return GNUNET_SYSERR;
471 } 470 }
472 REGEX_INTERNAL_iterate_all_edges (dfa, 471 REGEX_INTERNAL_iterate_all_edges(dfa,
473 &regex_iterator, NULL); 472 &regex_iterator, NULL);
474 REGEX_INTERNAL_automaton_destroy (dfa); 473 REGEX_INTERNAL_automaton_destroy(dfa);
475 474
476 return GNUNET_OK; 475 return GNUNET_OK;
477} 476}
@@ -486,7 +485,7 @@ announce_regex (const char *regex)
486 * #GNUNET_SYSERR to abort iteration with error! 485 * #GNUNET_SYSERR to abort iteration with error!
487 */ 486 */
488static int 487static int
489policy_filename_cb (void *cls, const char *filename) 488policy_filename_cb(void *cls, const char *filename)
490{ 489{
491 char *regex; 490 char *regex;
492 char *data; 491 char *data;
@@ -494,70 +493,70 @@ policy_filename_cb (void *cls, const char *filename)
494 uint64_t filesize; 493 uint64_t filesize;
495 unsigned int offset; 494 unsigned int offset;
496 495
497 GNUNET_assert (NULL != filename); 496 GNUNET_assert(NULL != filename);
498 497
499 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 498 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
500 "Announcing regexes from file %s\n", 499 "Announcing regexes from file %s\n",
501 filename); 500 filename);
502 501
503 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 502 if (GNUNET_YES != GNUNET_DISK_file_test(filename))
504 { 503 {
505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 504 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
506 "Could not find policy file %s\n", 505 "Could not find policy file %s\n",
507 filename); 506 filename);
508 return GNUNET_OK; 507 return GNUNET_OK;
509 } 508 }
510 if (GNUNET_OK != 509 if (GNUNET_OK !=
511 GNUNET_DISK_file_size (filename, &filesize, 510 GNUNET_DISK_file_size(filename, &filesize,
512 GNUNET_YES, GNUNET_YES)) 511 GNUNET_YES, GNUNET_YES))
513 filesize = 0; 512 filesize = 0;
514 if (0 == filesize) 513 if (0 == filesize)
515 { 514 {
516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", 515 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n",
517 filename); 516 filename);
518 return GNUNET_OK; 517 return GNUNET_OK;
519 } 518 }
520 data = GNUNET_malloc (filesize); 519 data = GNUNET_malloc(filesize);
521 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize)) 520 if (filesize != GNUNET_DISK_fn_read(filename, data, filesize))
522 { 521 {
523 GNUNET_free (data); 522 GNUNET_free(data);
524 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 523 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
525 "Could not read policy file %s.\n", 524 "Could not read policy file %s.\n",
526 filename); 525 filename);
527 return GNUNET_OK; 526 return GNUNET_OK;
528 } 527 }
529 528
530 update_meter (meter); 529 update_meter(meter);
531 530
532 buf = data; 531 buf = data;
533 offset = 0; 532 offset = 0;
534 regex = NULL; 533 regex = NULL;
535 while (offset < (filesize - 1)) 534 while (offset < (filesize - 1))
536 {
537 offset++;
538 if (((data[offset] == '\n')) && (buf != &data[offset]))
539 { 535 {
540 data[offset] = '|'; 536 offset++;
541 num_policies++; 537 if (((data[offset] == '\n')) && (buf != &data[offset]))
542 buf = &data[offset + 1]; 538 {
539 data[offset] = '|';
540 num_policies++;
541 buf = &data[offset + 1];
542 }
543 else if ((data[offset] == '\n') || (data[offset] == '\0'))
544 buf = &data[offset + 1];
543 } 545 }
544 else if ((data[offset] == '\n') || (data[offset] == '\0'))
545 buf = &data[offset + 1];
546 }
547 data[offset] = '\0'; 546 data[offset] = '\0';
548 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data); 547 GNUNET_asprintf(&regex, "%s(%s)", regex_prefix, data);
549 GNUNET_assert (NULL != regex); 548 GNUNET_assert(NULL != regex);
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
551 "Announcing regex: %s\n", regex); 550 "Announcing regex: %s\n", regex);
552 551
553 if (GNUNET_OK != announce_regex (regex)) 552 if (GNUNET_OK != announce_regex(regex))
554 { 553 {
555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 554 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
556 "Could not announce regex %s\n", 555 "Could not announce regex %s\n",
557 regex); 556 regex);
558 } 557 }
559 GNUNET_free (regex); 558 GNUNET_free(regex);
560 GNUNET_free (data); 559 GNUNET_free(data);
561 return GNUNET_OK; 560 return GNUNET_OK;
562} 561}
563 562
@@ -568,7 +567,7 @@ policy_filename_cb (void *cls, const char *filename)
568 * @param cls NULL 567 * @param cls NULL
569 */ 568 */
570static void 569static void
571do_directory_scan (void *cls) 570do_directory_scan(void *cls)
572{ 571{
573 struct GNUNET_TIME_Absolute start_time; 572 struct GNUNET_TIME_Absolute start_time;
574 struct GNUNET_TIME_Relative duration; 573 struct GNUNET_TIME_Relative duration;
@@ -576,37 +575,37 @@ do_directory_scan (void *cls)
576 575
577 /* Create an MySQL prepared statement for the inserts */ 576 /* Create an MySQL prepared statement for the inserts */
578 scan_task = NULL; 577 scan_task = NULL;
579 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name); 578 GNUNET_asprintf(&stmt, INSERT_EDGE_STMT, table_name);
580 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt); 579 stmt_handle = GNUNET_MYSQL_statement_prepare(mysql_ctx, stmt);
581 GNUNET_free (stmt); 580 GNUNET_free(stmt);
582 581
583 GNUNET_asprintf (&stmt, SELECT_KEY_STMT, table_name); 582 GNUNET_asprintf(&stmt, SELECT_KEY_STMT, table_name);
584 select_stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt); 583 select_stmt_handle = GNUNET_MYSQL_statement_prepare(mysql_ctx, stmt);
585 GNUNET_free (stmt); 584 GNUNET_free(stmt);
586 585
587 GNUNET_assert (NULL != stmt_handle); 586 GNUNET_assert(NULL != stmt_handle);
588 587
589 meter = create_meter (num_policy_files, 588 meter = create_meter(num_policy_files,
590 "Announcing policy files\n", 589 "Announcing policy files\n",
591 GNUNET_YES); 590 GNUNET_YES);
592 start_time = GNUNET_TIME_absolute_get (); 591 start_time = GNUNET_TIME_absolute_get();
593 GNUNET_DISK_directory_scan (policy_dir, 592 GNUNET_DISK_directory_scan(policy_dir,
594 &policy_filename_cb, 593 &policy_filename_cb,
595 stmt_handle); 594 stmt_handle);
596 duration = GNUNET_TIME_absolute_get_duration (start_time); 595 duration = GNUNET_TIME_absolute_get_duration(start_time);
597 reset_meter (meter); 596 reset_meter(meter);
598 free_meter (meter); 597 free_meter(meter);
599 meter = NULL; 598 meter = NULL;
600 599
601 printf ("Announced %u files containing %u policies in %s\n" 600 printf("Announced %u files containing %u policies in %s\n"
602 "Duplicate transitions: %llu\nMerged states: %llu\n", 601 "Duplicate transitions: %llu\nMerged states: %llu\n",
603 num_policy_files, 602 num_policy_files,
604 num_policies, 603 num_policies,
605 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO), 604 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_NO),
606 num_merged_transitions, 605 num_merged_transitions,
607 num_merged_states); 606 num_merged_states);
608 result = GNUNET_OK; 607 result = GNUNET_OK;
609 GNUNET_SCHEDULER_shutdown (); 608 GNUNET_SCHEDULER_shutdown();
610} 609}
611 610
612 611
@@ -619,65 +618,65 @@ do_directory_scan (void *cls)
619 * @param config configuration 618 * @param config configuration
620 */ 619 */
621static void 620static void
622run (void *cls, 621run(void *cls,
623 char *const *args, 622 char *const *args,
624 const char *cfgfile, 623 const char *cfgfile,
625 const struct GNUNET_CONFIGURATION_Handle *config) 624 const struct GNUNET_CONFIGURATION_Handle *config)
626{ 625{
627 if (NULL == args[0]) 626 if (NULL == args[0])
628 { 627 {
629 fprintf (stderr, 628 fprintf(stderr,
630 _("No policy directory specified on command line. Exiting.\n")); 629 _("No policy directory specified on command line. Exiting.\n"));
631 result = GNUNET_SYSERR; 630 result = GNUNET_SYSERR;
632 return; 631 return;
633 } 632 }
634 if (GNUNET_YES != 633 if (GNUNET_YES !=
635 GNUNET_DISK_directory_test (args[0], GNUNET_YES)) 634 GNUNET_DISK_directory_test(args[0], GNUNET_YES))
636 { 635 {
637 fprintf (stderr, 636 fprintf(stderr,
638 _("Specified policies directory does not exist. Exiting.\n")); 637 _("Specified policies directory does not exist. Exiting.\n"));
639 result = GNUNET_SYSERR; 638 result = GNUNET_SYSERR;
640 return; 639 return;
641 } 640 }
642 policy_dir = args[0]; 641 policy_dir = args[0];
643 642
644 num_policy_files = GNUNET_DISK_directory_scan (policy_dir, 643 num_policy_files = GNUNET_DISK_directory_scan(policy_dir,
645 NULL, NULL); 644 NULL, NULL);
646 meter = NULL; 645 meter = NULL;
647 646
648 if (NULL == table_name) 647 if (NULL == table_name)
649 { 648 {
650 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 649 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
651 "No table name specified, using default \"NFA\".\n"); 650 "No table name specified, using default \"NFA\".\n");
652 table_name = "NFA"; 651 table_name = "NFA";
653 } 652 }
654 653
655 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql"); 654 mysql_ctx = GNUNET_MYSQL_context_create(config, "regex-mysql");
656 if (NULL == mysql_ctx) 655 if (NULL == mysql_ctx)
657 { 656 {
658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 657 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
659 "Failed to create mysql context\n"); 658 "Failed to create mysql context\n");
660 result = GNUNET_SYSERR; 659 result = GNUNET_SYSERR;
661 return; 660 return;
662 } 661 }
663 662
664 if (GNUNET_OK != 663 if (GNUNET_OK !=
665 GNUNET_CONFIGURATION_get_value_string (config, 664 GNUNET_CONFIGURATION_get_value_string(config,
666 "regex-mysql", 665 "regex-mysql",
667 "REGEX_PREFIX", 666 "REGEX_PREFIX",
668 &regex_prefix)) 667 &regex_prefix))
669 { 668 {
670 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 669 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
671 "regex-mysql", 670 "regex-mysql",
672 "REGEX_PREFIX"); 671 "REGEX_PREFIX");
673 result = GNUNET_SYSERR; 672 result = GNUNET_SYSERR;
674 return; 673 return;
675 } 674 }
676 675
677 result = GNUNET_OK; 676 result = GNUNET_OK;
678 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 677 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
679 NULL); 678 NULL);
680 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL); 679 scan_task = GNUNET_SCHEDULER_add_now(&do_directory_scan, NULL);
681} 680}
682 681
683 682
@@ -689,34 +688,33 @@ run (void *cls,
689 * @return 0 on success 688 * @return 0 on success
690 */ 689 */
691int 690int
692main (int argc, char *const *argv) 691main(int argc, char *const *argv)
693{ 692{
694 struct GNUNET_GETOPT_CommandLineOption options[] = { 693 struct GNUNET_GETOPT_CommandLineOption options[] = {
695 694 GNUNET_GETOPT_option_string('t',
696 GNUNET_GETOPT_option_string ('t', 695 "table",
697 "table", 696 "TABLENAME",
698 "TABLENAME", 697 gettext_noop("name of the table to write DFAs"),
699 gettext_noop ("name of the table to write DFAs"), 698 &table_name),
700 &table_name), 699
701 700 GNUNET_GETOPT_option_uint('p',
702 GNUNET_GETOPT_option_uint ('p', 701 "max-path-compression",
703 "max-path-compression", 702 "MAX_PATH_COMPRESSION",
704 "MAX_PATH_COMPRESSION", 703 gettext_noop("maximum path compression length"),
705 gettext_noop ("maximum path compression length"), 704 &max_path_compression),
706 &max_path_compression),
707 705
708 GNUNET_GETOPT_OPTION_END 706 GNUNET_GETOPT_OPTION_END
709 }; 707 };
710 int ret; 708 int ret;
711 709
712 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 710 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
713 return 2; 711 return 2;
714 712
715 result = GNUNET_SYSERR; 713 result = GNUNET_SYSERR;
716 ret = 714 ret =
717 GNUNET_PROGRAM_run (argc, argv, 715 GNUNET_PROGRAM_run(argc, argv,
718 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir", 716 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir",
719 _("Profiler for regex library"), options, &run, NULL); 717 _("Profiler for regex library"), options, &run, NULL);
720 if (GNUNET_OK != ret) 718 if (GNUNET_OK != ret)
721 return ret; 719 return ret;
722 if (GNUNET_OK != result) 720 if (GNUNET_OK != result)