summaryrefslogtreecommitdiff
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.c622
1 files changed, 312 insertions, 310 deletions
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index aa297d2ea..6637bafed 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -52,7 +52,8 @@
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{
56 /** 57 /**
57 * Total number of elements. 58 * Total number of elements.
58 */ 59 */
@@ -167,11 +168,11 @@ static char *regex_prefix;
167 * @return the progress meter 168 * @return the progress meter
168 */ 169 */
169static struct ProgressMeter * 170static struct ProgressMeter *
170create_meter(unsigned int total, char *start_string, int print) 171create_meter (unsigned int total, char *start_string, int print)
171{ 172{
172 struct ProgressMeter *ret; 173 struct ProgressMeter *ret;
173 174
174 ret = GNUNET_new(struct ProgressMeter); 175 ret = GNUNET_new (struct ProgressMeter);
175 ret->print = print; 176 ret->print = print;
176 ret->total = total; 177 ret->total = total;
177 ret->modnum = total / 4; 178 ret->modnum = total / 4;
@@ -179,9 +180,9 @@ create_meter(unsigned int total, char *start_string, int print)
179 ret->modnum = 1; 180 ret->modnum = 1;
180 ret->dotnum = (total / 50) + 1; 181 ret->dotnum = (total / 50) + 1;
181 if (start_string != NULL) 182 if (start_string != NULL)
182 ret->startup_string = GNUNET_strdup(start_string); 183 ret->startup_string = GNUNET_strdup (start_string);
183 else 184 else
184 ret->startup_string = GNUNET_strdup(""); 185 ret->startup_string = GNUNET_strdup ("");
185 186
186 return ret; 187 return ret;
187} 188}
@@ -196,33 +197,33 @@ create_meter(unsigned int total, char *start_string, int print)
196 * GNUNET_NO if more items expected 197 * GNUNET_NO if more items expected
197 */ 198 */
198static int 199static int
199update_meter(struct ProgressMeter *meter) 200update_meter (struct ProgressMeter *meter)
200{ 201{
201 if (meter->print == GNUNET_YES) 202 if (meter->print == GNUNET_YES)
203 {
204 if (meter->completed % meter->modnum == 0)
202 { 205 {
203 if (meter->completed % meter->modnum == 0) 206 if (meter->completed == 0)
204 { 207 {
205 if (meter->completed == 0) 208 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
206 { 209 }
207 fprintf(stdout, "%sProgress: [0%%", meter->startup_string); 210 else
208 } 211 fprintf (stdout, "%d%%",
209 else 212 (int) (((float) meter->completed / meter->total) * 100));
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);
219 } 213 }
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 }
220 meter->completed++; 221 meter->completed++;
221 222
222 if (meter->completed == meter->total) 223 if (meter->completed == meter->total)
223 return GNUNET_YES; 224 return GNUNET_YES;
224 if (meter->completed > meter->total) 225 if (meter->completed > meter->total)
225 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n"); 226 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
226 return GNUNET_NO; 227 return GNUNET_NO;
227} 228}
228 229
@@ -236,7 +237,7 @@ update_meter(struct ProgressMeter *meter)
236 * #GNUNET_SYSERR on error 237 * #GNUNET_SYSERR on error
237 */ 238 */
238static int 239static int
239reset_meter(struct ProgressMeter *meter) 240reset_meter (struct ProgressMeter *meter)
240{ 241{
241 if (meter == NULL) 242 if (meter == NULL)
242 return GNUNET_SYSERR; 243 return GNUNET_SYSERR;
@@ -252,10 +253,10 @@ reset_meter(struct ProgressMeter *meter)
252 * @param meter the meter to free 253 * @param meter the meter to free
253 */ 254 */
254static void 255static void
255free_meter(struct ProgressMeter *meter) 256free_meter (struct ProgressMeter *meter)
256{ 257{
257 GNUNET_free_non_null(meter->startup_string); 258 GNUNET_free_non_null (meter->startup_string);
258 GNUNET_free(meter); 259 GNUNET_free (meter);
259} 260}
260 261
261 262
@@ -265,18 +266,18 @@ free_meter(struct ProgressMeter *meter)
265 * @param cls NULL 266 * @param cls NULL
266 */ 267 */
267static void 268static void
268do_shutdown(void *cls) 269do_shutdown (void *cls)
269{ 270{
270 if (NULL != mysql_ctx) 271 if (NULL != mysql_ctx)
271 { 272 {
272 GNUNET_MYSQL_context_destroy(mysql_ctx); 273 GNUNET_MYSQL_context_destroy (mysql_ctx);
273 mysql_ctx = NULL; 274 mysql_ctx = NULL;
274 } 275 }
275 if (NULL != meter) 276 if (NULL != meter)
276 { 277 {
277 free_meter(meter); 278 free_meter (meter);
278 meter = NULL; 279 meter = NULL;
279 } 280 }
280} 281}
281 282
282 283
@@ -292,16 +293,16 @@ do_shutdown(void *cls)
292 * @param cls NULL 293 * @param cls NULL
293 */ 294 */
294static void 295static void
295do_abort(void *cls) 296do_abort (void *cls)
296{ 297{
297 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); 298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
298 if (NULL != scan_task) 299 if (NULL != scan_task)
299 { 300 {
300 GNUNET_SCHEDULER_cancel(scan_task); 301 GNUNET_SCHEDULER_cancel (scan_task);
301 scan_task = NULL; 302 scan_task = NULL;
302 } 303 }
303 result = GNUNET_SYSERR; 304 result = GNUNET_SYSERR;
304 GNUNET_SCHEDULER_shutdown(); 305 GNUNET_SCHEDULER_shutdown ();
305} 306}
306 307
307/** 308/**
@@ -315,131 +316,131 @@ do_abort(void *cls)
315 * @param edges edges leaving current state. 316 * @param edges edges leaving current state.
316 */ 317 */
317static void 318static void
318regex_iterator(void *cls, 319regex_iterator (void *cls,
319 const struct GNUNET_HashCode *key, 320 const struct GNUNET_HashCode *key,
320 const char *proof, 321 const char *proof,
321 int accepting, 322 int accepting,
322 unsigned int num_edges, 323 unsigned int num_edges,
323 const struct REGEX_BLOCK_Edge *edges) 324 const struct REGEX_BLOCK_Edge *edges)
324{ 325{
325 unsigned int i; 326 unsigned int i;
326 int result; 327 int result;
327 328
328 uint32_t iaccepting = (uint32_t)accepting; 329 uint32_t iaccepting = (uint32_t) accepting;
329 uint64_t total; 330 uint64_t total;
330 331
331 GNUNET_assert(NULL != mysql_ctx); 332 GNUNET_assert (NULL != mysql_ctx);
332 333
333 for (i = 0; i < num_edges; i++) 334 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) ))
334 { 413 {
335 struct GNUNET_MY_QueryParam params_select[] = { 414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
336 GNUNET_MY_query_param_auto_from_type(key), 415 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
337 GNUNET_MY_query_param_string(edges[i].label), 416 result);
338 GNUNET_MY_query_param_end 417 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
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 }
419 420
420 if (0 == num_edges) 421 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) )
421 { 437 {
422 struct GNUNET_MY_QueryParam params_stmt[] = { 438 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
423 GNUNET_MY_query_param_auto_from_type(key), 439 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
424 GNUNET_MY_query_param_string(""), 440 result);
425 GNUNET_MY_query_param_fixed_size(NULL, 0), 441 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
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 }
443} 444}
444 445
445 446
@@ -451,26 +452,26 @@ regex_iterator(void *cls,
451 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure. 452 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
452 */ 453 */
453static int 454static int
454announce_regex(const char *regex) 455announce_regex (const char *regex)
455{ 456{
456 struct REGEX_INTERNAL_Automaton *dfa; 457 struct REGEX_INTERNAL_Automaton *dfa;
457 458
458 dfa = 459 dfa =
459 REGEX_INTERNAL_construct_dfa(regex, 460 REGEX_INTERNAL_construct_dfa (regex,
460 strlen(regex), 461 strlen (regex),
461 max_path_compression); 462 max_path_compression);
462 463
463 if (NULL == dfa) 464 if (NULL == dfa)
464 { 465 {
465 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
466 "Failed to create DFA for regex %s\n", 467 "Failed to create DFA for regex %s\n",
467 regex); 468 regex);
468 GNUNET_SCHEDULER_add_now(&do_abort, NULL); 469 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
469 return GNUNET_SYSERR; 470 return GNUNET_SYSERR;
470 } 471 }
471 REGEX_INTERNAL_iterate_all_edges(dfa, 472 REGEX_INTERNAL_iterate_all_edges (dfa,
472 &regex_iterator, NULL); 473 &regex_iterator, NULL);
473 REGEX_INTERNAL_automaton_destroy(dfa); 474 REGEX_INTERNAL_automaton_destroy (dfa);
474 475
475 return GNUNET_OK; 476 return GNUNET_OK;
476} 477}
@@ -485,7 +486,7 @@ announce_regex(const char *regex)
485 * #GNUNET_SYSERR to abort iteration with error! 486 * #GNUNET_SYSERR to abort iteration with error!
486 */ 487 */
487static int 488static int
488policy_filename_cb(void *cls, const char *filename) 489policy_filename_cb (void *cls, const char *filename)
489{ 490{
490 char *regex; 491 char *regex;
491 char *data; 492 char *data;
@@ -493,70 +494,70 @@ policy_filename_cb(void *cls, const char *filename)
493 uint64_t filesize; 494 uint64_t filesize;
494 unsigned int offset; 495 unsigned int offset;
495 496
496 GNUNET_assert(NULL != filename); 497 GNUNET_assert (NULL != filename);
497 498
498 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 499 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
499 "Announcing regexes from file %s\n", 500 "Announcing regexes from file %s\n",
500 filename); 501 filename);
501 502
502 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 503 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
503 { 504 {
504 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
505 "Could not find policy file %s\n", 506 "Could not find policy file %s\n",
506 filename); 507 filename);
507 return GNUNET_OK; 508 return GNUNET_OK;
508 } 509 }
509 if (GNUNET_OK != 510 if (GNUNET_OK !=
510 GNUNET_DISK_file_size(filename, &filesize, 511 GNUNET_DISK_file_size (filename, &filesize,
511 GNUNET_YES, GNUNET_YES)) 512 GNUNET_YES, GNUNET_YES))
512 filesize = 0; 513 filesize = 0;
513 if (0 == filesize) 514 if (0 == filesize)
514 { 515 {
515 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", 516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n",
516 filename); 517 filename);
517 return GNUNET_OK; 518 return GNUNET_OK;
518 } 519 }
519 data = GNUNET_malloc(filesize); 520 data = GNUNET_malloc (filesize);
520 if (filesize != GNUNET_DISK_fn_read(filename, data, filesize)) 521 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
521 { 522 {
522 GNUNET_free(data); 523 GNUNET_free (data);
523 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 524 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
524 "Could not read policy file %s.\n", 525 "Could not read policy file %s.\n",
525 filename); 526 filename);
526 return GNUNET_OK; 527 return GNUNET_OK;
527 } 528 }
528 529
529 update_meter(meter); 530 update_meter (meter);
530 531
531 buf = data; 532 buf = data;
532 offset = 0; 533 offset = 0;
533 regex = NULL; 534 regex = NULL;
534 while (offset < (filesize - 1)) 535 while (offset < (filesize - 1))
536 {
537 offset++;
538 if (((data[offset] == '\n')) && (buf != &data[offset]))
535 { 539 {
536 offset++; 540 data[offset] = '|';
537 if (((data[offset] == '\n')) && (buf != &data[offset])) 541 num_policies++;
538 { 542 buf = &data[offset + 1];
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];
545 } 543 }
544 else if ((data[offset] == '\n') || (data[offset] == '\0'))
545 buf = &data[offset + 1];
546 }
546 data[offset] = '\0'; 547 data[offset] = '\0';
547 GNUNET_asprintf(&regex, "%s(%s)", regex_prefix, data); 548 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
548 GNUNET_assert(NULL != regex); 549 GNUNET_assert (NULL != regex);
549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "Announcing regex: %s\n", regex); 551 "Announcing regex: %s\n", regex);
551 552
552 if (GNUNET_OK != announce_regex(regex)) 553 if (GNUNET_OK != announce_regex (regex))
553 { 554 {
554 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Could not announce regex %s\n", 556 "Could not announce regex %s\n",
556 regex); 557 regex);
557 } 558 }
558 GNUNET_free(regex); 559 GNUNET_free (regex);
559 GNUNET_free(data); 560 GNUNET_free (data);
560 return GNUNET_OK; 561 return GNUNET_OK;
561} 562}
562 563
@@ -567,7 +568,7 @@ policy_filename_cb(void *cls, const char *filename)
567 * @param cls NULL 568 * @param cls NULL
568 */ 569 */
569static void 570static void
570do_directory_scan(void *cls) 571do_directory_scan (void *cls)
571{ 572{
572 struct GNUNET_TIME_Absolute start_time; 573 struct GNUNET_TIME_Absolute start_time;
573 struct GNUNET_TIME_Relative duration; 574 struct GNUNET_TIME_Relative duration;
@@ -575,37 +576,37 @@ do_directory_scan(void *cls)
575 576
576 /* Create an MySQL prepared statement for the inserts */ 577 /* Create an MySQL prepared statement for the inserts */
577 scan_task = NULL; 578 scan_task = NULL;
578 GNUNET_asprintf(&stmt, INSERT_EDGE_STMT, table_name); 579 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
579 stmt_handle = GNUNET_MYSQL_statement_prepare(mysql_ctx, stmt); 580 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
580 GNUNET_free(stmt); 581 GNUNET_free (stmt);
581 582
582 GNUNET_asprintf(&stmt, SELECT_KEY_STMT, table_name); 583 GNUNET_asprintf (&stmt, SELECT_KEY_STMT, table_name);
583 select_stmt_handle = GNUNET_MYSQL_statement_prepare(mysql_ctx, stmt); 584 select_stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
584 GNUNET_free(stmt); 585 GNUNET_free (stmt);
585 586
586 GNUNET_assert(NULL != stmt_handle); 587 GNUNET_assert (NULL != stmt_handle);
587 588
588 meter = create_meter(num_policy_files, 589 meter = create_meter (num_policy_files,
589 "Announcing policy files\n", 590 "Announcing policy files\n",
590 GNUNET_YES); 591 GNUNET_YES);
591 start_time = GNUNET_TIME_absolute_get(); 592 start_time = GNUNET_TIME_absolute_get ();
592 GNUNET_DISK_directory_scan(policy_dir, 593 GNUNET_DISK_directory_scan (policy_dir,
593 &policy_filename_cb, 594 &policy_filename_cb,
594 stmt_handle); 595 stmt_handle);
595 duration = GNUNET_TIME_absolute_get_duration(start_time); 596 duration = GNUNET_TIME_absolute_get_duration (start_time);
596 reset_meter(meter); 597 reset_meter (meter);
597 free_meter(meter); 598 free_meter (meter);
598 meter = NULL; 599 meter = NULL;
599 600
600 printf("Announced %u files containing %u policies in %s\n" 601 printf ("Announced %u files containing %u policies in %s\n"
601 "Duplicate transitions: %llu\nMerged states: %llu\n", 602 "Duplicate transitions: %llu\nMerged states: %llu\n",
602 num_policy_files, 603 num_policy_files,
603 num_policies, 604 num_policies,
604 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_NO), 605 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO),
605 num_merged_transitions, 606 num_merged_transitions,
606 num_merged_states); 607 num_merged_states);
607 result = GNUNET_OK; 608 result = GNUNET_OK;
608 GNUNET_SCHEDULER_shutdown(); 609 GNUNET_SCHEDULER_shutdown ();
609} 610}
610 611
611 612
@@ -618,65 +619,65 @@ do_directory_scan(void *cls)
618 * @param config configuration 619 * @param config configuration
619 */ 620 */
620static void 621static void
621run(void *cls, 622run (void *cls,
622 char *const *args, 623 char *const *args,
623 const char *cfgfile, 624 const char *cfgfile,
624 const struct GNUNET_CONFIGURATION_Handle *config) 625 const struct GNUNET_CONFIGURATION_Handle *config)
625{ 626{
626 if (NULL == args[0]) 627 if (NULL == args[0])
627 { 628 {
628 fprintf(stderr, 629 fprintf (stderr,
629 _("No policy directory specified on command line. Exiting.\n")); 630 _ ("No policy directory specified on command line. Exiting.\n"));
630 result = GNUNET_SYSERR; 631 result = GNUNET_SYSERR;
631 return; 632 return;
632 } 633 }
633 if (GNUNET_YES != 634 if (GNUNET_YES !=
634 GNUNET_DISK_directory_test(args[0], GNUNET_YES)) 635 GNUNET_DISK_directory_test (args[0], GNUNET_YES))
635 { 636 {
636 fprintf(stderr, 637 fprintf (stderr,
637 _("Specified policies directory does not exist. Exiting.\n")); 638 _ ("Specified policies directory does not exist. Exiting.\n"));
638 result = GNUNET_SYSERR; 639 result = GNUNET_SYSERR;
639 return; 640 return;
640 } 641 }
641 policy_dir = args[0]; 642 policy_dir = args[0];
642 643
643 num_policy_files = GNUNET_DISK_directory_scan(policy_dir, 644 num_policy_files = GNUNET_DISK_directory_scan (policy_dir,
644 NULL, NULL); 645 NULL, NULL);
645 meter = NULL; 646 meter = NULL;
646 647
647 if (NULL == table_name) 648 if (NULL == table_name)
648 { 649 {
649 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 650 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
650 "No table name specified, using default \"NFA\".\n"); 651 "No table name specified, using default \"NFA\".\n");
651 table_name = "NFA"; 652 table_name = "NFA";
652 } 653 }
653 654
654 mysql_ctx = GNUNET_MYSQL_context_create(config, "regex-mysql"); 655 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
655 if (NULL == mysql_ctx) 656 if (NULL == mysql_ctx)
656 { 657 {
657 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
658 "Failed to create mysql context\n"); 659 "Failed to create mysql context\n");
659 result = GNUNET_SYSERR; 660 result = GNUNET_SYSERR;
660 return; 661 return;
661 } 662 }
662 663
663 if (GNUNET_OK != 664 if (GNUNET_OK !=
664 GNUNET_CONFIGURATION_get_value_string(config, 665 GNUNET_CONFIGURATION_get_value_string (config,
665 "regex-mysql", 666 "regex-mysql",
666 "REGEX_PREFIX", 667 "REGEX_PREFIX",
667 &regex_prefix)) 668 &regex_prefix))
668 { 669 {
669 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 670 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
670 "regex-mysql", 671 "regex-mysql",
671 "REGEX_PREFIX"); 672 "REGEX_PREFIX");
672 result = GNUNET_SYSERR; 673 result = GNUNET_SYSERR;
673 return; 674 return;
674 } 675 }
675 676
676 result = GNUNET_OK; 677 result = GNUNET_OK;
677 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 678 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
678 NULL); 679 NULL);
679 scan_task = GNUNET_SCHEDULER_add_now(&do_directory_scan, NULL); 680 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL);
680} 681}
681 682
682 683
@@ -688,33 +689,34 @@ run(void *cls,
688 * @return 0 on success 689 * @return 0 on success
689 */ 690 */
690int 691int
691main(int argc, char *const *argv) 692main (int argc, char *const *argv)
692{ 693{
693 struct GNUNET_GETOPT_CommandLineOption options[] = { 694 struct GNUNET_GETOPT_CommandLineOption options[] = {
694 GNUNET_GETOPT_option_string('t', 695 GNUNET_GETOPT_option_string ('t',
695 "table", 696 "table",
696 "TABLENAME", 697 "TABLENAME",
697 gettext_noop("name of the table to write DFAs"), 698 gettext_noop (
698 &table_name), 699 "name of the table to write DFAs"),
699 700 &table_name),
700 GNUNET_GETOPT_option_uint('p', 701
701 "max-path-compression", 702 GNUNET_GETOPT_option_uint ('p',
702 "MAX_PATH_COMPRESSION", 703 "max-path-compression",
703 gettext_noop("maximum path compression length"), 704 "MAX_PATH_COMPRESSION",
704 &max_path_compression), 705 gettext_noop ("maximum path compression length"),
706 &max_path_compression),
705 707
706 GNUNET_GETOPT_OPTION_END 708 GNUNET_GETOPT_OPTION_END
707 }; 709 };
708 int ret; 710 int ret;
709 711
710 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 712 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
711 return 2; 713 return 2;
712 714
713 result = GNUNET_SYSERR; 715 result = GNUNET_SYSERR;
714 ret = 716 ret =
715 GNUNET_PROGRAM_run(argc, argv, 717 GNUNET_PROGRAM_run (argc, argv,
716 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir", 718 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir",
717 _("Profiler for regex library"), options, &run, NULL); 719 _ ("Profiler for regex library"), options, &run, NULL);
718 if (GNUNET_OK != ret) 720 if (GNUNET_OK != ret)
719 return ret; 721 return ret;
720 if (GNUNET_OK != result) 722 if (GNUNET_OK != result)