diff options
Diffstat (limited to 'src/regex/gnunet-regex-profiler.c')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 1308 |
1 files changed, 653 insertions, 655 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index a4d4ce99b..4262107d7 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-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 | * @file regex/gnunet-regex-profiler.c | 22 | * @file regex/gnunet-regex-profiler.c |
@@ -37,13 +37,12 @@ | |||
37 | #include "gnunet_testbed_service.h" | 37 | #include "gnunet_testbed_service.h" |
38 | 38 | ||
39 | #define FIND_TIMEOUT \ | 39 | #define FIND_TIMEOUT \ |
40 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) | 40 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * DLL of operations | 43 | * DLL of operations |
44 | */ | 44 | */ |
45 | struct DLLOperation | 45 | struct DLLOperation { |
46 | { | ||
47 | /** | 46 | /** |
48 | * The testbed operation handle | 47 | * The testbed operation handle |
49 | */ | 48 | */ |
@@ -69,8 +68,7 @@ struct DLLOperation | |||
69 | /** | 68 | /** |
70 | * Available states during profiling | 69 | * Available states during profiling |
71 | */ | 70 | */ |
72 | enum State | 71 | enum State { |
73 | { | ||
74 | /** | 72 | /** |
75 | * Initial state | 73 | * Initial state |
76 | */ | 74 | */ |
@@ -112,8 +110,7 @@ enum State | |||
112 | /** | 110 | /** |
113 | * Peer handles. | 111 | * Peer handles. |
114 | */ | 112 | */ |
115 | struct RegexPeer | 113 | struct RegexPeer { |
116 | { | ||
117 | /** | 114 | /** |
118 | * Peer id. | 115 | * Peer id. |
119 | */ | 116 | */ |
@@ -150,7 +147,7 @@ struct RegexPeer | |||
150 | /** | 147 | /** |
151 | * Handle to a running regex search. | 148 | * Handle to a running regex search. |
152 | */ | 149 | */ |
153 | struct REGEX_INTERNAL_Search *search_handle; | 150 | struct REGEX_INTERNAL_Search *search_handle; |
154 | 151 | ||
155 | /** | 152 | /** |
156 | * Testbed operation handle for DHT. | 153 | * Testbed operation handle for DHT. |
@@ -333,8 +330,8 @@ static struct GNUNET_TIME_Relative reannounce_period_max; | |||
333 | * @param emsg error message. | 330 | * @param emsg error message. |
334 | */ | 331 | */ |
335 | static void | 332 | static void |
336 | dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 333 | dht_connect_cb(void *cls, struct GNUNET_TESTBED_Operation *op, |
337 | void *ca_result, const char *emsg); | 334 | void *ca_result, const char *emsg); |
338 | 335 | ||
339 | /** | 336 | /** |
340 | * DHT connect adapter. | 337 | * DHT connect adapter. |
@@ -345,7 +342,7 @@ dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
345 | * @return | 342 | * @return |
346 | */ | 343 | */ |
347 | static void * | 344 | static void * |
348 | dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); | 345 | dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); |
349 | 346 | ||
350 | 347 | ||
351 | /** | 348 | /** |
@@ -356,7 +353,7 @@ dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
356 | * @param op_result service handle returned from the connect adapter | 353 | * @param op_result service handle returned from the connect adapter |
357 | */ | 354 | */ |
358 | static void | 355 | static void |
359 | dht_da (void *cls, void *op_result); | 356 | dht_da(void *cls, void *op_result); |
360 | 357 | ||
361 | 358 | ||
362 | /** | 359 | /** |
@@ -369,10 +366,10 @@ dht_da (void *cls, void *op_result); | |||
369 | * @param emsg error message on failure | 366 | * @param emsg error message on failure |
370 | */ | 367 | */ |
371 | static void | 368 | static void |
372 | stats_connect_cb (void *cls, | 369 | stats_connect_cb(void *cls, |
373 | struct GNUNET_TESTBED_Operation *op, | 370 | struct GNUNET_TESTBED_Operation *op, |
374 | void *ca_result, | 371 | void *ca_result, |
375 | const char *emsg); | 372 | const char *emsg); |
376 | 373 | ||
377 | 374 | ||
378 | /** | 375 | /** |
@@ -381,7 +378,7 @@ stats_connect_cb (void *cls, | |||
381 | * @param cls Index of the next peer in the peers array. | 378 | * @param cls Index of the next peer in the peers array. |
382 | */ | 379 | */ |
383 | static void | 380 | static void |
384 | announce_next_regex (void *cls); | 381 | announce_next_regex(void *cls); |
385 | 382 | ||
386 | 383 | ||
387 | /******************************************************************************/ | 384 | /******************************************************************************/ |
@@ -395,7 +392,7 @@ announce_next_regex (void *cls); | |||
395 | * @param cls NULL | 392 | * @param cls NULL |
396 | */ | 393 | */ |
397 | static void | 394 | static void |
398 | do_shutdown (void *cls) | 395 | do_shutdown(void *cls) |
399 | { | 396 | { |
400 | struct RegexPeer *peer; | 397 | struct RegexPeer *peer; |
401 | unsigned int peer_cnt; | 398 | unsigned int peer_cnt; |
@@ -404,75 +401,75 @@ do_shutdown (void *cls) | |||
404 | size_t size; | 401 | size_t size; |
405 | 402 | ||
406 | if (NULL != abort_task) | 403 | if (NULL != abort_task) |
407 | { | 404 | { |
408 | GNUNET_SCHEDULER_cancel (abort_task); | 405 | GNUNET_SCHEDULER_cancel(abort_task); |
409 | abort_task = NULL; | 406 | abort_task = NULL; |
410 | } | 407 | } |
411 | if (NULL != register_hosts_task) | 408 | if (NULL != register_hosts_task) |
412 | { | 409 | { |
413 | GNUNET_SCHEDULER_cancel (register_hosts_task); | 410 | GNUNET_SCHEDULER_cancel(register_hosts_task); |
414 | register_hosts_task = NULL; | 411 | register_hosts_task = NULL; |
415 | } | 412 | } |
416 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | 413 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) |
417 | { | ||
418 | peer = &peers[peer_cnt]; | ||
419 | |||
420 | if (GNUNET_YES != peer->search_str_matched && NULL != data_file) | ||
421 | { | 414 | { |
422 | prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time); | 415 | peer = &peers[peer_cnt]; |
423 | size = | 416 | |
424 | GNUNET_snprintf (output_buffer, | 417 | if (GNUNET_YES != peer->search_str_matched && NULL != data_file) |
425 | sizeof (output_buffer), | 418 | { |
426 | "%p Search string not found: %s (%d)\n" | 419 | prof_time = GNUNET_TIME_absolute_get_duration(peer->prof_start_time); |
427 | "%p On peer: %u (%p)\n" | 420 | size = |
428 | "%p After: %s\n", | 421 | GNUNET_snprintf(output_buffer, |
429 | peer, peer->search_str, peer->search_str_matched, | 422 | sizeof(output_buffer), |
430 | peer, peer->id, peer, | 423 | "%p Search string not found: %s (%d)\n" |
431 | peer, | 424 | "%p On peer: %u (%p)\n" |
432 | GNUNET_STRINGS_relative_time_to_string (prof_time, | 425 | "%p After: %s\n", |
433 | GNUNET_NO)); | 426 | peer, peer->search_str, peer->search_str_matched, |
434 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) | 427 | peer, peer->id, peer, |
435 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 428 | peer, |
429 | GNUNET_STRINGS_relative_time_to_string(prof_time, | ||
430 | GNUNET_NO)); | ||
431 | if (size != GNUNET_DISK_file_write(data_file, output_buffer, size)) | ||
432 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | ||
433 | } | ||
434 | |||
435 | if (NULL != peers[peer_cnt].op_handle) | ||
436 | GNUNET_TESTBED_operation_done(peers[peer_cnt].op_handle); | ||
436 | } | 437 | } |
437 | 438 | ||
438 | if (NULL != peers[peer_cnt].op_handle) | ||
439 | GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle); | ||
440 | } | ||
441 | |||
442 | if (NULL != data_file) | 439 | if (NULL != data_file) |
443 | { | 440 | { |
444 | GNUNET_DISK_file_close (data_file); | 441 | GNUNET_DISK_file_close(data_file); |
445 | data_file = NULL; | 442 | data_file = NULL; |
446 | } | 443 | } |
447 | for (search_str_cnt = 0; | 444 | for (search_str_cnt = 0; |
448 | search_str_cnt < num_peers && NULL != search_strings; | 445 | search_str_cnt < num_peers && NULL != search_strings; |
449 | search_str_cnt++) | 446 | search_str_cnt++) |
450 | { | 447 | { |
451 | GNUNET_free_non_null (search_strings[search_str_cnt]); | 448 | GNUNET_free_non_null(search_strings[search_str_cnt]); |
452 | } | 449 | } |
453 | GNUNET_free_non_null (search_strings); | 450 | GNUNET_free_non_null(search_strings); |
454 | search_strings = NULL; | 451 | search_strings = NULL; |
455 | 452 | ||
456 | if (NULL != reg_handle) | 453 | if (NULL != reg_handle) |
457 | { | 454 | { |
458 | GNUNET_TESTBED_cancel_registration (reg_handle); | 455 | GNUNET_TESTBED_cancel_registration(reg_handle); |
459 | reg_handle = NULL; | 456 | reg_handle = NULL; |
460 | } | 457 | } |
461 | if (NULL != mc) | 458 | if (NULL != mc) |
462 | { | 459 | { |
463 | GNUNET_TESTBED_controller_disconnect (mc); | 460 | GNUNET_TESTBED_controller_disconnect(mc); |
464 | mc = NULL; | 461 | mc = NULL; |
465 | } | 462 | } |
466 | if (NULL != mc_proc) | 463 | if (NULL != mc_proc) |
467 | { | 464 | { |
468 | GNUNET_TESTBED_controller_stop (mc_proc); | 465 | GNUNET_TESTBED_controller_stop(mc_proc); |
469 | mc_proc = NULL; | 466 | mc_proc = NULL; |
470 | } | 467 | } |
471 | if (NULL != cfg) | 468 | if (NULL != cfg) |
472 | { | 469 | { |
473 | GNUNET_CONFIGURATION_destroy (cfg); | 470 | GNUNET_CONFIGURATION_destroy(cfg); |
474 | cfg = NULL; | 471 | cfg = NULL; |
475 | } | 472 | } |
476 | } | 473 | } |
477 | 474 | ||
478 | 475 | ||
@@ -482,15 +479,15 @@ do_shutdown (void *cls) | |||
482 | * @param cls NULL | 479 | * @param cls NULL |
483 | */ | 480 | */ |
484 | static void | 481 | static void |
485 | do_abort (void *cls) | 482 | do_abort(void *cls) |
486 | { | 483 | { |
487 | unsigned long i = (unsigned long) cls; | 484 | unsigned long i = (unsigned long)cls; |
488 | 485 | ||
489 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 486 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
490 | "Aborting from line %lu...\n", i); | 487 | "Aborting from line %lu...\n", i); |
491 | abort_task = NULL; | 488 | abort_task = NULL; |
492 | result = GNUNET_SYSERR; | 489 | result = GNUNET_SYSERR; |
493 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 490 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
494 | } | 491 | } |
495 | 492 | ||
496 | 493 | ||
@@ -509,10 +506,10 @@ do_abort (void *cls) | |||
509 | * @return service handle to return in 'op_result', NULL on error | 506 | * @return service handle to return in 'op_result', NULL on error |
510 | */ | 507 | */ |
511 | static void * | 508 | static void * |
512 | stats_ca (void *cls, | 509 | stats_ca(void *cls, |
513 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 510 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
514 | { | 511 | { |
515 | return GNUNET_STATISTICS_create ("<driver>", cfg); | 512 | return GNUNET_STATISTICS_create("<driver>", cfg); |
516 | } | 513 | } |
517 | 514 | ||
518 | 515 | ||
@@ -524,13 +521,13 @@ stats_ca (void *cls, | |||
524 | * @param op_result service handle returned from the connect adapter | 521 | * @param op_result service handle returned from the connect adapter |
525 | */ | 522 | */ |
526 | static void | 523 | static void |
527 | stats_da (void *cls, void *op_result) | 524 | stats_da(void *cls, void *op_result) |
528 | { | 525 | { |
529 | struct RegexPeer *peer = cls; | 526 | struct RegexPeer *peer = cls; |
530 | 527 | ||
531 | GNUNET_assert (op_result == peer->stats_handle); | 528 | GNUNET_assert(op_result == peer->stats_handle); |
532 | 529 | ||
533 | GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO); | 530 | GNUNET_STATISTICS_destroy(peer->stats_handle, GNUNET_NO); |
534 | peer->stats_handle = NULL; | 531 | peer->stats_handle = NULL; |
535 | } | 532 | } |
536 | 533 | ||
@@ -546,34 +543,34 @@ stats_da (void *cls, void *op_result) | |||
546 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 543 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
547 | */ | 544 | */ |
548 | static int | 545 | static int |
549 | stats_iterator (void *cls, | 546 | stats_iterator(void *cls, |
550 | const char *subsystem, | 547 | const char *subsystem, |
551 | const char *name, | 548 | const char *name, |
552 | uint64_t value, int is_persistent) | 549 | uint64_t value, int is_persistent) |
553 | { | 550 | { |
554 | struct RegexPeer *peer = cls; | 551 | struct RegexPeer *peer = cls; |
555 | char output_buffer[512]; | 552 | char output_buffer[512]; |
556 | size_t size; | 553 | size_t size; |
557 | 554 | ||
558 | if (NULL == data_file) | 555 | if (NULL == data_file) |
559 | { | 556 | { |
560 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 557 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
561 | "%p -> %s [%s]: %llu\n", | 558 | "%p -> %s [%s]: %llu\n", |
562 | peer, | 559 | peer, |
563 | subsystem, | 560 | subsystem, |
564 | name, | 561 | name, |
565 | (unsigned long long) value); | 562 | (unsigned long long)value); |
566 | return GNUNET_OK; | 563 | return GNUNET_OK; |
567 | } | 564 | } |
568 | size = | 565 | size = |
569 | GNUNET_snprintf (output_buffer, | 566 | GNUNET_snprintf(output_buffer, |
570 | sizeof (output_buffer), | 567 | sizeof(output_buffer), |
571 | "%p [%s] %llu %s\n", | 568 | "%p [%s] %llu %s\n", |
572 | peer, | 569 | peer, |
573 | subsystem, value, name); | 570 | subsystem, value, name); |
574 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) | 571 | if (size != GNUNET_DISK_file_write(data_file, output_buffer, size)) |
575 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 572 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
576 | "Unable to write to file!\n"); | 573 | "Unable to write to file!\n"); |
577 | 574 | ||
578 | return GNUNET_OK; | 575 | return GNUNET_OK; |
579 | } | 576 | } |
@@ -588,48 +585,48 @@ stats_iterator (void *cls, | |||
588 | * successfully obtained, GNUNET_SYSERR if not. | 585 | * successfully obtained, GNUNET_SYSERR if not. |
589 | */ | 586 | */ |
590 | static void | 587 | static void |
591 | stats_cb (void *cls, | 588 | stats_cb(void *cls, |
592 | int success) | 589 | int success) |
593 | { | 590 | { |
594 | static unsigned int peer_cnt; | 591 | static unsigned int peer_cnt; |
595 | struct RegexPeer *peer = cls; | 592 | struct RegexPeer *peer = cls; |
596 | 593 | ||
597 | if (GNUNET_OK != success) | 594 | if (GNUNET_OK != success) |
598 | { | 595 | { |
599 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 596 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
600 | "Getting statistics for peer %u failed!\n", | 597 | "Getting statistics for peer %u failed!\n", |
601 | peer->id); | 598 | peer->id); |
602 | return; | 599 | return; |
603 | } | 600 | } |
604 | 601 | ||
605 | GNUNET_assert (NULL != peer->op_handle); | 602 | GNUNET_assert(NULL != peer->op_handle); |
606 | 603 | ||
607 | GNUNET_TESTBED_operation_done (peer->op_handle); | 604 | GNUNET_TESTBED_operation_done(peer->op_handle); |
608 | peer->op_handle = NULL; | 605 | peer->op_handle = NULL; |
609 | 606 | ||
610 | peer_cnt++; | 607 | peer_cnt++; |
611 | peer = &peers[peer_cnt]; | 608 | peer = &peers[peer_cnt]; |
612 | 609 | ||
613 | fprintf (stderr, "s"); | 610 | fprintf(stderr, "s"); |
614 | if (peer_cnt == num_peers) | 611 | if (peer_cnt == num_peers) |
615 | { | 612 | { |
616 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 613 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
617 | "\nCollecting stats finished. Shutting down.\n"); | 614 | "\nCollecting stats finished. Shutting down.\n"); |
618 | GNUNET_SCHEDULER_shutdown (); | 615 | GNUNET_SCHEDULER_shutdown(); |
619 | result = GNUNET_OK; | 616 | result = GNUNET_OK; |
620 | } | 617 | } |
621 | else | 618 | else |
622 | { | 619 | { |
623 | peer->op_handle = | 620 | peer->op_handle = |
624 | GNUNET_TESTBED_service_connect (NULL, | 621 | GNUNET_TESTBED_service_connect(NULL, |
625 | peer->peer_handle, | 622 | peer->peer_handle, |
626 | "statistics", | 623 | "statistics", |
627 | &stats_connect_cb, | 624 | &stats_connect_cb, |
628 | peer, | 625 | peer, |
629 | &stats_ca, | 626 | &stats_ca, |
630 | &stats_da, | 627 | &stats_da, |
631 | peer); | 628 | peer); |
632 | } | 629 | } |
633 | } | 630 | } |
634 | 631 | ||
635 | 632 | ||
@@ -643,32 +640,32 @@ stats_cb (void *cls, | |||
643 | * @param emsg error message on failure | 640 | * @param emsg error message on failure |
644 | */ | 641 | */ |
645 | static void | 642 | static void |
646 | stats_connect_cb (void *cls, | 643 | stats_connect_cb(void *cls, |
647 | struct GNUNET_TESTBED_Operation *op, | 644 | struct GNUNET_TESTBED_Operation *op, |
648 | void *ca_result, | 645 | void *ca_result, |
649 | const char *emsg) | 646 | const char *emsg) |
650 | { | 647 | { |
651 | struct RegexPeer *peer = cls; | 648 | struct RegexPeer *peer = cls; |
652 | 649 | ||
653 | if (NULL == ca_result || NULL != emsg) | 650 | if (NULL == ca_result || NULL != emsg) |
654 | { | 651 | { |
655 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 652 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
656 | "Failed to connect to statistics service on peer %u: %s\n", | 653 | "Failed to connect to statistics service on peer %u: %s\n", |
657 | peer->id, emsg); | 654 | peer->id, emsg); |
658 | 655 | ||
659 | peer->stats_handle = NULL; | 656 | peer->stats_handle = NULL; |
660 | return; | 657 | return; |
661 | } | 658 | } |
662 | 659 | ||
663 | peer->stats_handle = ca_result; | 660 | peer->stats_handle = ca_result; |
664 | 661 | ||
665 | if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL, | 662 | if (NULL == GNUNET_STATISTICS_get(peer->stats_handle, NULL, NULL, |
666 | &stats_cb, | 663 | &stats_cb, |
667 | &stats_iterator, peer)) | 664 | &stats_iterator, peer)) |
668 | { | 665 | { |
669 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 666 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
670 | "Could not get statistics of peer %u!\n", peer->id); | 667 | "Could not get statistics of peer %u!\n", peer->id); |
671 | } | 668 | } |
672 | } | 669 | } |
673 | 670 | ||
674 | 671 | ||
@@ -679,21 +676,21 @@ stats_connect_cb (void *cls, | |||
679 | * @param cls NULL | 676 | * @param cls NULL |
680 | */ | 677 | */ |
681 | static void | 678 | static void |
682 | do_collect_stats (void *cls) | 679 | do_collect_stats(void *cls) |
683 | { | 680 | { |
684 | struct RegexPeer *peer = &peers[0]; | 681 | struct RegexPeer *peer = &peers[0]; |
685 | 682 | ||
686 | GNUNET_assert (NULL != peer->peer_handle); | 683 | GNUNET_assert(NULL != peer->peer_handle); |
687 | 684 | ||
688 | peer->op_handle = | 685 | peer->op_handle = |
689 | GNUNET_TESTBED_service_connect (NULL, | 686 | GNUNET_TESTBED_service_connect(NULL, |
690 | peer->peer_handle, | 687 | peer->peer_handle, |
691 | "statistics", | 688 | "statistics", |
692 | &stats_connect_cb, | 689 | &stats_connect_cb, |
693 | peer, | 690 | peer, |
694 | &stats_ca, | 691 | &stats_ca, |
695 | &stats_da, | 692 | &stats_da, |
696 | peer); | 693 | peer); |
697 | } | 694 | } |
698 | 695 | ||
699 | 696 | ||
@@ -708,7 +705,7 @@ do_collect_stats (void *cls) | |||
708 | * @param cls Index of the next peer in the peers array. | 705 | * @param cls Index of the next peer in the peers array. |
709 | */ | 706 | */ |
710 | static void | 707 | static void |
711 | find_string (void *cls); | 708 | find_string(void *cls); |
712 | 709 | ||
713 | 710 | ||
714 | /** | 711 | /** |
@@ -723,94 +720,94 @@ find_string (void *cls); | |||
723 | * @param put_path_length Length of the put_path. | 720 | * @param put_path_length Length of the put_path. |
724 | */ | 721 | */ |
725 | static void | 722 | static void |
726 | regex_found_handler (void *cls, | 723 | regex_found_handler(void *cls, |
727 | const struct GNUNET_PeerIdentity *id, | 724 | const struct GNUNET_PeerIdentity *id, |
728 | const struct GNUNET_PeerIdentity *get_path, | 725 | const struct GNUNET_PeerIdentity *get_path, |
729 | unsigned int get_path_length, | 726 | unsigned int get_path_length, |
730 | const struct GNUNET_PeerIdentity *put_path, | 727 | const struct GNUNET_PeerIdentity *put_path, |
731 | unsigned int put_path_length) | 728 | unsigned int put_path_length) |
732 | { | 729 | { |
733 | struct RegexPeer *peer = cls; | 730 | struct RegexPeer *peer = cls; |
734 | char output_buffer[512]; | 731 | char output_buffer[512]; |
735 | size_t size; | 732 | size_t size; |
736 | 733 | ||
737 | if (GNUNET_YES == peer->search_str_matched) | 734 | if (GNUNET_YES == peer->search_str_matched) |
738 | { | 735 | { |
739 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 736 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
740 | "String %s on peer %u already matched!\n", | 737 | "String %s on peer %u already matched!\n", |
741 | peer->search_str, peer->id); | 738 | peer->search_str, peer->id); |
742 | return; | 739 | return; |
743 | } | 740 | } |
744 | 741 | ||
745 | strings_found++; | 742 | strings_found++; |
746 | parallel_searches--; | 743 | parallel_searches--; |
747 | 744 | ||
748 | if (NULL != peer->timeout) | 745 | if (NULL != peer->timeout) |
749 | { | 746 | { |
750 | GNUNET_SCHEDULER_cancel (peer->timeout); | 747 | GNUNET_SCHEDULER_cancel(peer->timeout); |
751 | peer->timeout = NULL; | 748 | peer->timeout = NULL; |
752 | if (GNUNET_NO == in_shutdown) | 749 | if (GNUNET_NO == in_shutdown) |
753 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | 750 | GNUNET_SCHEDULER_add_now(&announce_next_regex, NULL); |
754 | } | 751 | } |
755 | 752 | ||
756 | if (NULL == id) | 753 | if (NULL == id) |
757 | { | 754 | { |
758 | // FIXME not possible right now | 755 | // FIXME not possible right now |
759 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 756 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
760 | "String matching timed out for string %s on peer %u (%i/%i)\n", | 757 | "String matching timed out for string %s on peer %u (%i/%i)\n", |
761 | peer->search_str, peer->id, strings_found, num_peers); | 758 | peer->search_str, peer->id, strings_found, num_peers); |
762 | peer->search_str_matched = GNUNET_SYSERR; | 759 | peer->search_str_matched = GNUNET_SYSERR; |
763 | } | 760 | } |
764 | else | 761 | else |
765 | { | ||
766 | prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time); | ||
767 | |||
768 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
769 | "String %s found on peer %u after %s (%i/%i) (%u||)\n", | ||
770 | peer->search_str, peer->id, | ||
771 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO), | ||
772 | strings_found, num_peers, parallel_searches); | ||
773 | |||
774 | peer->search_str_matched = GNUNET_YES; | ||
775 | |||
776 | if (NULL != data_file) | ||
777 | { | 762 | { |
778 | size = | 763 | prof_time = GNUNET_TIME_absolute_get_duration(peer->prof_start_time); |
779 | GNUNET_snprintf (output_buffer, | 764 | |
780 | sizeof (output_buffer), | 765 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
781 | "%p Peer: %u\n" | 766 | "String %s found on peer %u after %s (%i/%i) (%u||)\n", |
782 | "%p Search string: %s\n" | 767 | peer->search_str, peer->id, |
783 | "%p Search duration: %s\n\n", | 768 | GNUNET_STRINGS_relative_time_to_string(prof_time, GNUNET_NO), |
784 | peer, peer->id, | 769 | strings_found, num_peers, parallel_searches); |
785 | peer, peer->search_str, | 770 | |
786 | peer, | 771 | peer->search_str_matched = GNUNET_YES; |
787 | GNUNET_STRINGS_relative_time_to_string (prof_time, | 772 | |
788 | GNUNET_NO)); | 773 | if (NULL != data_file) |
789 | 774 | { | |
790 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) | 775 | size = |
791 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 776 | GNUNET_snprintf(output_buffer, |
777 | sizeof(output_buffer), | ||
778 | "%p Peer: %u\n" | ||
779 | "%p Search string: %s\n" | ||
780 | "%p Search duration: %s\n\n", | ||
781 | peer, peer->id, | ||
782 | peer, peer->search_str, | ||
783 | peer, | ||
784 | GNUNET_STRINGS_relative_time_to_string(prof_time, | ||
785 | GNUNET_NO)); | ||
786 | |||
787 | if (size != GNUNET_DISK_file_write(data_file, output_buffer, size)) | ||
788 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | ||
789 | } | ||
792 | } | 790 | } |
793 | } | ||
794 | 791 | ||
795 | GNUNET_TESTBED_operation_done (peer->op_handle); | 792 | GNUNET_TESTBED_operation_done(peer->op_handle); |
796 | peer->op_handle = NULL; | 793 | peer->op_handle = NULL; |
797 | 794 | ||
798 | if (strings_found == num_peers) | 795 | if (strings_found == num_peers) |
799 | { | ||
800 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
801 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
802 | "All strings successfully matched in %s\n", | ||
803 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); | ||
804 | |||
805 | if (NULL != search_timeout_task) | ||
806 | { | 796 | { |
807 | GNUNET_SCHEDULER_cancel (search_timeout_task); | 797 | prof_time = GNUNET_TIME_absolute_get_duration(prof_start_time); |
808 | search_timeout_task = NULL; | 798 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
809 | } | 799 | "All strings successfully matched in %s\n", |
800 | GNUNET_STRINGS_relative_time_to_string(prof_time, GNUNET_NO)); | ||
801 | |||
802 | if (NULL != search_timeout_task) | ||
803 | { | ||
804 | GNUNET_SCHEDULER_cancel(search_timeout_task); | ||
805 | search_timeout_task = NULL; | ||
806 | } | ||
810 | 807 | ||
811 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n"); | 808 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n"); |
812 | GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL); | 809 | GNUNET_SCHEDULER_add_now(&do_collect_stats, NULL); |
813 | } | 810 | } |
814 | } | 811 | } |
815 | 812 | ||
816 | 813 | ||
@@ -821,33 +818,33 @@ regex_found_handler (void *cls, | |||
821 | * @param cls NULL | 818 | * @param cls NULL |
822 | */ | 819 | */ |
823 | static void | 820 | static void |
824 | search_timed_out (void *cls) | 821 | search_timed_out(void *cls) |
825 | { | 822 | { |
826 | unsigned int i; | 823 | unsigned int i; |
827 | 824 | ||
828 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 825 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
829 | "Finding matches to all strings did not succeed after %s.\n", | 826 | "Finding matches to all strings did not succeed after %s.\n", |
830 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, | 827 | GNUNET_STRINGS_relative_time_to_string(search_timeout_time, |
831 | GNUNET_NO)); | 828 | GNUNET_NO)); |
832 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 829 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
833 | "Found %i of %i strings\n", strings_found, num_peers); | 830 | "Found %i of %i strings\n", strings_found, num_peers); |
834 | 831 | ||
835 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 832 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
836 | "Search timed out after %s." | 833 | "Search timed out after %s." |
837 | "Collecting stats and shutting down.\n", | 834 | "Collecting stats and shutting down.\n", |
838 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, | 835 | GNUNET_STRINGS_relative_time_to_string(search_timeout_time, |
839 | GNUNET_NO)); | 836 | GNUNET_NO)); |
840 | 837 | ||
841 | in_shutdown = GNUNET_YES; | 838 | in_shutdown = GNUNET_YES; |
842 | for (i = 0; i < num_peers; i++) | 839 | for (i = 0; i < num_peers; i++) |
843 | { | ||
844 | if (NULL != peers[i].op_handle) | ||
845 | { | 840 | { |
846 | GNUNET_TESTBED_operation_done (peers[i].op_handle); | 841 | if (NULL != peers[i].op_handle) |
847 | peers[i].op_handle = NULL; | 842 | { |
843 | GNUNET_TESTBED_operation_done(peers[i].op_handle); | ||
844 | peers[i].op_handle = NULL; | ||
845 | } | ||
848 | } | 846 | } |
849 | } | 847 | GNUNET_SCHEDULER_add_now(&do_collect_stats, NULL); |
850 | GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL); | ||
851 | } | 848 | } |
852 | 849 | ||
853 | 850 | ||
@@ -858,17 +855,17 @@ search_timed_out (void *cls) | |||
858 | * @param cls Index of the next peer in the peers array. | 855 | * @param cls Index of the next peer in the peers array. |
859 | */ | 856 | */ |
860 | static void | 857 | static void |
861 | find_timed_out (void *cls) | 858 | find_timed_out(void *cls) |
862 | { | 859 | { |
863 | struct RegexPeer *p = cls; | 860 | struct RegexPeer *p = cls; |
864 | 861 | ||
865 | p->timeout = NULL; | 862 | p->timeout = NULL; |
866 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 863 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
867 | "Searching for string \"%s\" on peer %d timed out.\n", | 864 | "Searching for string \"%s\" on peer %d timed out.\n", |
868 | p->search_str, | 865 | p->search_str, |
869 | p->id); | 866 | p->id); |
870 | if (GNUNET_NO == in_shutdown) | 867 | if (GNUNET_NO == in_shutdown) |
871 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | 868 | GNUNET_SCHEDULER_add_now(&announce_next_regex, NULL); |
872 | } | 869 | } |
873 | 870 | ||
874 | 871 | ||
@@ -878,34 +875,34 @@ find_timed_out (void *cls) | |||
878 | * @param cls Index of the next peer in the peers array. | 875 | * @param cls Index of the next peer in the peers array. |
879 | */ | 876 | */ |
880 | static void | 877 | static void |
881 | find_string (void *cls) | 878 | find_string(void *cls) |
882 | { | 879 | { |
883 | unsigned int search_peer = (unsigned int) (long) cls; | 880 | unsigned int search_peer = (unsigned int)(long)cls; |
884 | 881 | ||
885 | if ( (search_peer >= num_peers) || | 882 | if ((search_peer >= num_peers) || |
886 | (GNUNET_YES == in_shutdown) ) | 883 | (GNUNET_YES == in_shutdown)) |
887 | return; | 884 | return; |
888 | 885 | ||
889 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 886 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
890 | "Searching for string \"%s\" on peer %d (%u||)\n", | 887 | "Searching for string \"%s\" on peer %d (%u||)\n", |
891 | peers[search_peer].search_str, | 888 | peers[search_peer].search_str, |
892 | search_peer, | 889 | search_peer, |
893 | parallel_searches); | 890 | parallel_searches); |
894 | 891 | ||
895 | peers[search_peer].op_handle = | 892 | peers[search_peer].op_handle = |
896 | GNUNET_TESTBED_service_connect (NULL, | 893 | GNUNET_TESTBED_service_connect(NULL, |
897 | peers[search_peer].peer_handle, | 894 | peers[search_peer].peer_handle, |
898 | "dht", | 895 | "dht", |
899 | &dht_connect_cb, | 896 | &dht_connect_cb, |
900 | &peers[search_peer], | 897 | &peers[search_peer], |
901 | &dht_ca, | 898 | &dht_ca, |
902 | &dht_da, | 899 | &dht_da, |
903 | &peers[search_peer]); | 900 | &peers[search_peer]); |
904 | GNUNET_assert (NULL != peers[search_peer].op_handle); | 901 | GNUNET_assert(NULL != peers[search_peer].op_handle); |
905 | peers[search_peer].timeout | 902 | peers[search_peer].timeout |
906 | = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT, | 903 | = GNUNET_SCHEDULER_add_delayed(FIND_TIMEOUT, |
907 | &find_timed_out, | 904 | &find_timed_out, |
908 | &peers[search_peer]); | 905 | &peers[search_peer]); |
909 | } | 906 | } |
910 | 907 | ||
911 | 908 | ||
@@ -917,44 +914,44 @@ find_string (void *cls) | |||
917 | * @param emsg NULL on success; otherwise an error description | 914 | * @param emsg NULL on success; otherwise an error description |
918 | */ | 915 | */ |
919 | static void | 916 | static void |
920 | daemon_started (void *cls, | 917 | daemon_started(void *cls, |
921 | struct GNUNET_TESTBED_Operation *op, | 918 | struct GNUNET_TESTBED_Operation *op, |
922 | const char *emsg) | 919 | const char *emsg) |
923 | { | 920 | { |
924 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 921 | struct RegexPeer *peer = (struct RegexPeer *)cls; |
925 | unsigned long search_peer; | 922 | unsigned long search_peer; |
926 | unsigned int i; | 923 | unsigned int i; |
927 | 924 | ||
928 | GNUNET_TESTBED_operation_done (peer->daemon_op); | 925 | GNUNET_TESTBED_operation_done(peer->daemon_op); |
929 | peer->daemon_op = NULL; | 926 | peer->daemon_op = NULL; |
930 | if (NULL != emsg) | 927 | if (NULL != emsg) |
931 | { | 928 | { |
932 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 929 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
933 | "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg); | 930 | "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg); |
934 | GNUNET_assert (0); | 931 | GNUNET_assert(0); |
935 | } | 932 | } |
936 | else | 933 | else |
937 | { | 934 | { |
938 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 935 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
939 | "Deamon %u started successfully\n", peer->id); | 936 | "Deamon %u started successfully\n", peer->id); |
940 | } | 937 | } |
941 | 938 | ||
942 | /* Find a peer to look for a string matching the regex announced */ | 939 | /* Find a peer to look for a string matching the regex announced */ |
943 | search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 940 | search_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
944 | num_peers); | 941 | num_peers); |
945 | for (i = 0; peers[search_peer].search_str != NULL; i++) | 942 | for (i = 0; peers[search_peer].search_str != NULL; i++) |
946 | { | 943 | { |
947 | search_peer = (search_peer + 1) % num_peers; | 944 | search_peer = (search_peer + 1) % num_peers; |
948 | if (i > num_peers) | 945 | if (i > num_peers) |
949 | GNUNET_assert (0); /* we ran out of peers, must be a bug */ | 946 | GNUNET_assert(0); /* we ran out of peers, must be a bug */ |
950 | } | 947 | } |
951 | peers[search_peer].search_str = search_strings[peer->id]; | 948 | peers[search_peer].search_str = search_strings[peer->id]; |
952 | peers[search_peer].search_str_matched = GNUNET_NO; | 949 | peers[search_peer].search_str_matched = GNUNET_NO; |
953 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_saturating_multiply( | 950 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_saturating_multiply( |
954 | reannounce_period_max, | 951 | reannounce_period_max, |
955 | 2), | 952 | 2), |
956 | &find_string, | 953 | &find_string, |
957 | (void *) search_peer); | 954 | (void *)search_peer); |
958 | } | 955 | } |
959 | 956 | ||
960 | 957 | ||
@@ -966,21 +963,21 @@ daemon_started (void *cls, | |||
966 | * @param tc the task context | 963 | * @param tc the task context |
967 | */ | 964 | */ |
968 | static void | 965 | static void |
969 | do_announce (void *cls) | 966 | do_announce(void *cls) |
970 | { | 967 | { |
971 | unsigned int i; | 968 | unsigned int i; |
972 | 969 | ||
973 | if (GNUNET_YES == in_shutdown) | 970 | if (GNUNET_YES == in_shutdown) |
974 | return; | 971 | return; |
975 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 972 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
976 | "Starting announce.\n"); | 973 | "Starting announce.\n"); |
977 | for (i = 0; i < init_parallel_searches; i++) | 974 | for (i = 0; i < init_parallel_searches; i++) |
978 | { | 975 | { |
979 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 976 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
980 | " scheduling announce %u\n", | 977 | " scheduling announce %u\n", |
981 | i); | 978 | i); |
982 | (void) GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | 979 | (void)GNUNET_SCHEDULER_add_now(&announce_next_regex, NULL); |
983 | } | 980 | } |
984 | } | 981 | } |
985 | 982 | ||
986 | 983 | ||
@@ -990,36 +987,36 @@ do_announce (void *cls) | |||
990 | * @param cls Closure (unused). | 987 | * @param cls Closure (unused). |
991 | */ | 988 | */ |
992 | static void | 989 | static void |
993 | announce_next_regex (void *cls) | 990 | announce_next_regex(void *cls) |
994 | { | 991 | { |
995 | struct RegexPeer *peer; | 992 | struct RegexPeer *peer; |
996 | 993 | ||
997 | if (GNUNET_YES == in_shutdown) | 994 | if (GNUNET_YES == in_shutdown) |
998 | return; | 995 | return; |
999 | if (next_search >= num_peers) | 996 | if (next_search >= num_peers) |
1000 | { | ||
1001 | if (strings_found != num_peers) | ||
1002 | { | 997 | { |
1003 | struct GNUNET_TIME_Relative new_delay; | 998 | if (strings_found != num_peers) |
1004 | if (NULL != search_timeout_task) | 999 | { |
1005 | GNUNET_SCHEDULER_cancel (search_timeout_task); | 1000 | struct GNUNET_TIME_Relative new_delay; |
1006 | new_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15); | 1001 | if (NULL != search_timeout_task) |
1007 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (new_delay, | 1002 | GNUNET_SCHEDULER_cancel(search_timeout_task); |
1008 | &search_timed_out, | 1003 | new_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15); |
1009 | NULL); | 1004 | search_timeout_task = GNUNET_SCHEDULER_add_delayed(new_delay, |
1005 | &search_timed_out, | ||
1006 | NULL); | ||
1007 | } | ||
1008 | return; | ||
1010 | } | 1009 | } |
1011 | return; | ||
1012 | } | ||
1013 | 1010 | ||
1014 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search); | 1011 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search); |
1015 | peer = &peers[next_search]; | 1012 | peer = &peers[next_search]; |
1016 | peer->daemon_op = | 1013 | peer->daemon_op = |
1017 | GNUNET_TESTBED_peer_manage_service (NULL, | 1014 | GNUNET_TESTBED_peer_manage_service(NULL, |
1018 | peer->peer_handle, | 1015 | peer->peer_handle, |
1019 | "regexprofiler", | 1016 | "regexprofiler", |
1020 | &daemon_started, | 1017 | &daemon_started, |
1021 | peer, | 1018 | peer, |
1022 | 1); | 1019 | 1); |
1023 | next_search++; | 1020 | next_search++; |
1024 | parallel_searches++; | 1021 | parallel_searches++; |
1025 | } | 1022 | } |
@@ -1036,29 +1033,29 @@ announce_next_regex (void *cls) | |||
1036 | * @param emsg error message. | 1033 | * @param emsg error message. |
1037 | */ | 1034 | */ |
1038 | static void | 1035 | static void |
1039 | dht_connect_cb (void *cls, | 1036 | dht_connect_cb(void *cls, |
1040 | struct GNUNET_TESTBED_Operation *op, | 1037 | struct GNUNET_TESTBED_Operation *op, |
1041 | void *ca_result, | 1038 | void *ca_result, |
1042 | const char *emsg) | 1039 | const char *emsg) |
1043 | { | 1040 | { |
1044 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1041 | struct RegexPeer *peer = (struct RegexPeer *)cls; |
1045 | 1042 | ||
1046 | if (NULL != emsg || NULL == op || NULL == ca_result) | 1043 | if (NULL != emsg || NULL == op || NULL == ca_result) |
1047 | { | 1044 | { |
1048 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg); | 1045 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg); |
1049 | GNUNET_assert (0); | 1046 | GNUNET_assert(0); |
1050 | } | 1047 | } |
1051 | 1048 | ||
1052 | GNUNET_assert (NULL != peer->dht_handle); | 1049 | GNUNET_assert(NULL != peer->dht_handle); |
1053 | GNUNET_assert (peer->op_handle == op); | 1050 | GNUNET_assert(peer->op_handle == op); |
1054 | GNUNET_assert (peer->dht_handle == ca_result); | 1051 | GNUNET_assert(peer->dht_handle == ca_result); |
1055 | 1052 | ||
1056 | peer->search_str_matched = GNUNET_NO; | 1053 | peer->search_str_matched = GNUNET_NO; |
1057 | peer->search_handle = REGEX_INTERNAL_search (peer->dht_handle, | 1054 | peer->search_handle = REGEX_INTERNAL_search(peer->dht_handle, |
1058 | peer->search_str, | 1055 | peer->search_str, |
1059 | ®ex_found_handler, peer, | 1056 | ®ex_found_handler, peer, |
1060 | NULL); | 1057 | NULL); |
1061 | peer->prof_start_time = GNUNET_TIME_absolute_get (); | 1058 | peer->prof_start_time = GNUNET_TIME_absolute_get(); |
1062 | } | 1059 | } |
1063 | 1060 | ||
1064 | 1061 | ||
@@ -1071,11 +1068,11 @@ dht_connect_cb (void *cls, | |||
1071 | * @return | 1068 | * @return |
1072 | */ | 1069 | */ |
1073 | static void * | 1070 | static void * |
1074 | dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 1071 | dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
1075 | { | 1072 | { |
1076 | struct RegexPeer *peer = cls; | 1073 | struct RegexPeer *peer = cls; |
1077 | 1074 | ||
1078 | peer->dht_handle = GNUNET_DHT_connect (cfg, 32); | 1075 | peer->dht_handle = GNUNET_DHT_connect(cfg, 32); |
1079 | 1076 | ||
1080 | return peer->dht_handle; | 1077 | return peer->dht_handle; |
1081 | } | 1078 | } |
@@ -1088,23 +1085,23 @@ dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1088 | * @param op_result Service handle returned from the connect adapter. | 1085 | * @param op_result Service handle returned from the connect adapter. |
1089 | */ | 1086 | */ |
1090 | static void | 1087 | static void |
1091 | dht_da (void *cls, void *op_result) | 1088 | dht_da(void *cls, void *op_result) |
1092 | { | 1089 | { |
1093 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1090 | struct RegexPeer *peer = (struct RegexPeer *)cls; |
1094 | 1091 | ||
1095 | GNUNET_assert (peer->dht_handle == op_result); | 1092 | GNUNET_assert(peer->dht_handle == op_result); |
1096 | 1093 | ||
1097 | if (NULL != peer->search_handle) | 1094 | if (NULL != peer->search_handle) |
1098 | { | 1095 | { |
1099 | REGEX_INTERNAL_search_cancel (peer->search_handle); | 1096 | REGEX_INTERNAL_search_cancel(peer->search_handle); |
1100 | peer->search_handle = NULL; | 1097 | peer->search_handle = NULL; |
1101 | } | 1098 | } |
1102 | 1099 | ||
1103 | if (NULL != peer->dht_handle) | 1100 | if (NULL != peer->dht_handle) |
1104 | { | 1101 | { |
1105 | GNUNET_DHT_disconnect (peer->dht_handle); | 1102 | GNUNET_DHT_disconnect(peer->dht_handle); |
1106 | peer->dht_handle = NULL; | 1103 | peer->dht_handle = NULL; |
1107 | } | 1104 | } |
1108 | } | 1105 | } |
1109 | 1106 | ||
1110 | 1107 | ||
@@ -1122,51 +1119,51 @@ dht_da (void *cls, void *op_result) | |||
1122 | * failed | 1119 | * failed |
1123 | */ | 1120 | */ |
1124 | static void | 1121 | static void |
1125 | test_master (void *cls, | 1122 | test_master(void *cls, |
1126 | struct GNUNET_TESTBED_RunHandle *h, | 1123 | struct GNUNET_TESTBED_RunHandle *h, |
1127 | unsigned int num_peers_, | 1124 | unsigned int num_peers_, |
1128 | struct GNUNET_TESTBED_Peer **testbed_peers, | 1125 | struct GNUNET_TESTBED_Peer **testbed_peers, |
1129 | unsigned int links_succeeded, | 1126 | unsigned int links_succeeded, |
1130 | unsigned int links_failed) | 1127 | unsigned int links_failed) |
1131 | { | 1128 | { |
1132 | unsigned int i; | 1129 | unsigned int i; |
1133 | 1130 | ||
1134 | GNUNET_assert (num_peers_ == num_peers); | 1131 | GNUNET_assert(num_peers_ == num_peers); |
1135 | 1132 | ||
1136 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | 1133 | prof_time = GNUNET_TIME_absolute_get_duration(prof_start_time); |
1137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1134 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1138 | "Testbed started in %s\n", | 1135 | "Testbed started in %s\n", |
1139 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); | 1136 | GNUNET_STRINGS_relative_time_to_string(prof_time, GNUNET_NO)); |
1140 | 1137 | ||
1141 | if (NULL != abort_task) | 1138 | if (NULL != abort_task) |
1142 | { | 1139 | { |
1143 | GNUNET_SCHEDULER_cancel (abort_task); | 1140 | GNUNET_SCHEDULER_cancel(abort_task); |
1144 | abort_task = NULL; | 1141 | abort_task = NULL; |
1145 | } | 1142 | } |
1146 | 1143 | ||
1147 | for (i = 0; i < num_peers; i++) | 1144 | for (i = 0; i < num_peers; i++) |
1148 | { | 1145 | { |
1149 | peers[i].peer_handle = testbed_peers[i]; | 1146 | peers[i].peer_handle = testbed_peers[i]; |
1150 | } | 1147 | } |
1151 | if (GNUNET_NO == | 1148 | if (GNUNET_NO == |
1152 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", "DISABLE_TRY_CONNECT")) | 1149 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "DHT", "DISABLE_TRY_CONNECT")) |
1153 | { | 1150 | { |
1154 | struct GNUNET_TIME_Relative settle_time; | 1151 | struct GNUNET_TIME_Relative settle_time; |
1155 | 1152 | ||
1156 | settle_time = | 1153 | settle_time = |
1157 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 1154 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
1158 | 10 * num_peers); | 1155 | 10 * num_peers); |
1159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1156 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1160 | "Waiting for DHT for %s to settle new connections.\n\n", | 1157 | "Waiting for DHT for %s to settle new connections.\n\n", |
1161 | GNUNET_STRINGS_relative_time_to_string(settle_time, GNUNET_NO)); | 1158 | GNUNET_STRINGS_relative_time_to_string(settle_time, GNUNET_NO)); |
1162 | GNUNET_SCHEDULER_add_delayed (settle_time, &do_announce, NULL); | 1159 | GNUNET_SCHEDULER_add_delayed(settle_time, &do_announce, NULL); |
1163 | } | 1160 | } |
1164 | else | 1161 | else |
1165 | { | 1162 | { |
1166 | GNUNET_SCHEDULER_add_now (&do_announce, NULL); | 1163 | GNUNET_SCHEDULER_add_now(&do_announce, NULL); |
1167 | } | 1164 | } |
1168 | search_timeout_task = | 1165 | search_timeout_task = |
1169 | GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timed_out, NULL); | 1166 | GNUNET_SCHEDULER_add_delayed(search_timeout_time, &search_timed_out, NULL); |
1170 | } | 1167 | } |
1171 | 1168 | ||
1172 | /** | 1169 | /** |
@@ -1176,20 +1173,22 @@ test_master (void *cls, | |||
1176 | * @param event information on what is happening | 1173 | * @param event information on what is happening |
1177 | */ | 1174 | */ |
1178 | static void | 1175 | static void |
1179 | master_controller_cb (void *cls, | 1176 | master_controller_cb(void *cls, |
1180 | const struct GNUNET_TESTBED_EventInformation *event) | 1177 | const struct GNUNET_TESTBED_EventInformation *event) |
1181 | { | 1178 | { |
1182 | switch (event->type) | 1179 | switch (event->type) |
1183 | { | 1180 | { |
1184 | case GNUNET_TESTBED_ET_CONNECT: | 1181 | case GNUNET_TESTBED_ET_CONNECT: |
1185 | printf("."); | 1182 | printf("."); |
1186 | break; | 1183 | break; |
1187 | case GNUNET_TESTBED_ET_PEER_START: | 1184 | |
1188 | printf("#"); | 1185 | case GNUNET_TESTBED_ET_PEER_START: |
1189 | break; | 1186 | printf("#"); |
1190 | default: | 1187 | break; |
1191 | break; | 1188 | |
1192 | } | 1189 | default: |
1190 | break; | ||
1191 | } | ||
1193 | fflush(stdout); | 1192 | fflush(stdout); |
1194 | } | 1193 | } |
1195 | 1194 | ||
@@ -1209,9 +1208,9 @@ master_controller_cb (void *cls, | |||
1209 | * #GNUNET_SYSERR otherwise. | 1208 | * #GNUNET_SYSERR otherwise. |
1210 | */ | 1209 | */ |
1211 | static int | 1210 | static int |
1212 | count_and_separate_strings (char *data, | 1211 | count_and_separate_strings(char *data, |
1213 | uint64_t data_size, | 1212 | uint64_t data_size, |
1214 | unsigned int str_max) | 1213 | unsigned int str_max) |
1215 | { | 1214 | { |
1216 | char *buf; // Keep track of last string to skip blank lines | 1215 | char *buf; // Keep track of last string to skip blank lines |
1217 | unsigned int offset; | 1216 | unsigned int offset; |
@@ -1220,20 +1219,20 @@ count_and_separate_strings (char *data, | |||
1220 | buf = data; | 1219 | buf = data; |
1221 | offset = 0; | 1220 | offset = 0; |
1222 | str_cnt = 0; | 1221 | str_cnt = 0; |
1223 | while ( (offset < (data_size - 1)) && (str_cnt < str_max) ) | 1222 | while ((offset < (data_size - 1)) && (str_cnt < str_max)) |
1224 | { | ||
1225 | offset++; | ||
1226 | if ( ((data[offset] == '\n')) && | ||
1227 | (buf != &data[offset]) ) | ||
1228 | { | 1223 | { |
1229 | data[offset] = '\0'; | 1224 | offset++; |
1230 | str_cnt++; | 1225 | if (((data[offset] == '\n')) && |
1231 | buf = &data[offset + 1]; | 1226 | (buf != &data[offset])) |
1227 | { | ||
1228 | data[offset] = '\0'; | ||
1229 | str_cnt++; | ||
1230 | buf = &data[offset + 1]; | ||
1231 | } | ||
1232 | else if ((data[offset] == '\n') || | ||
1233 | (data[offset] == '\0')) | ||
1234 | buf = &data[offset + 1]; | ||
1232 | } | 1235 | } |
1233 | else if ( (data[offset] == '\n') || | ||
1234 | (data[offset] == '\0') ) | ||
1235 | buf = &data[offset + 1]; | ||
1236 | } | ||
1237 | return str_cnt; | 1236 | return str_cnt; |
1238 | } | 1237 | } |
1239 | 1238 | ||
@@ -1252,37 +1251,37 @@ count_and_separate_strings (char *data, | |||
1252 | * In case of error @a strings must not be freed. | 1251 | * In case of error @a strings must not be freed. |
1253 | */ | 1252 | */ |
1254 | static int | 1253 | static int |
1255 | create_string_array (char *data, uint64_t data_size, | 1254 | create_string_array(char *data, uint64_t data_size, |
1256 | char ***strings, unsigned int str_cnt) | 1255 | char ***strings, unsigned int str_cnt) |
1257 | { | 1256 | { |
1258 | uint64_t offset; | 1257 | uint64_t offset; |
1259 | uint64_t len; | 1258 | uint64_t len; |
1260 | unsigned int i; | 1259 | unsigned int i; |
1261 | 1260 | ||
1262 | *strings = GNUNET_malloc (sizeof (char *) * str_cnt); | 1261 | *strings = GNUNET_malloc(sizeof(char *) * str_cnt); |
1263 | offset = 0; | 1262 | offset = 0; |
1264 | for (i = 0; i < str_cnt; i++) | 1263 | for (i = 0; i < str_cnt; i++) |
1265 | { | ||
1266 | len = strlen (&data[offset]); | ||
1267 | if (offset + len >= data_size) | ||
1268 | { | ||
1269 | GNUNET_free (*strings); | ||
1270 | *strings = NULL; | ||
1271 | return GNUNET_SYSERR; | ||
1272 | } | ||
1273 | if (0 == len) // empty line | ||
1274 | { | 1264 | { |
1275 | offset++; | 1265 | len = strlen(&data[offset]); |
1276 | i--; | 1266 | if (offset + len >= data_size) |
1277 | continue; | 1267 | { |
1268 | GNUNET_free(*strings); | ||
1269 | *strings = NULL; | ||
1270 | return GNUNET_SYSERR; | ||
1271 | } | ||
1272 | if (0 == len) // empty line | ||
1273 | { | ||
1274 | offset++; | ||
1275 | i--; | ||
1276 | continue; | ||
1277 | } | ||
1278 | |||
1279 | GNUNET_asprintf(&(*strings)[i], | ||
1280 | "%s%s", | ||
1281 | regex_prefix, | ||
1282 | &data[offset]); | ||
1283 | offset += len + 1; | ||
1278 | } | 1284 | } |
1279 | |||
1280 | GNUNET_asprintf (&(*strings)[i], | ||
1281 | "%s%s", | ||
1282 | regex_prefix, | ||
1283 | &data[offset]); | ||
1284 | offset += len + 1; | ||
1285 | } | ||
1286 | return GNUNET_OK; | 1285 | return GNUNET_OK; |
1287 | } | 1286 | } |
1288 | 1287 | ||
@@ -1297,9 +1296,9 @@ create_string_array (char *data, uint64_t data_size, | |||
1297 | * @return number of strings found in the file. #GNUNET_SYSERR on error. | 1296 | * @return number of strings found in the file. #GNUNET_SYSERR on error. |
1298 | */ | 1297 | */ |
1299 | static int | 1298 | static int |
1300 | load_search_strings (const char *filename, | 1299 | load_search_strings(const char *filename, |
1301 | char ***strings, | 1300 | char ***strings, |
1302 | unsigned int limit) | 1301 | unsigned int limit) |
1303 | { | 1302 | { |
1304 | char *data; | 1303 | char *data; |
1305 | uint64_t filesize; | 1304 | uint64_t filesize; |
@@ -1307,54 +1306,54 @@ load_search_strings (const char *filename, | |||
1307 | 1306 | ||
1308 | /* Sanity checks */ | 1307 | /* Sanity checks */ |
1309 | if (NULL == filename) | 1308 | if (NULL == filename) |
1310 | { | 1309 | { |
1311 | return GNUNET_SYSERR; | 1310 | return GNUNET_SYSERR; |
1312 | } | 1311 | } |
1313 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 1312 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) |
1314 | { | 1313 | { |
1315 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1314 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1316 | "Could not find search strings file %s\n", filename); | 1315 | "Could not find search strings file %s\n", filename); |
1317 | return GNUNET_SYSERR; | 1316 | return GNUNET_SYSERR; |
1318 | } | 1317 | } |
1319 | if (GNUNET_OK != | 1318 | if (GNUNET_OK != |
1320 | GNUNET_DISK_file_size (filename, | 1319 | GNUNET_DISK_file_size(filename, |
1321 | &filesize, | 1320 | &filesize, |
1322 | GNUNET_YES, | 1321 | GNUNET_YES, |
1323 | GNUNET_YES)) | 1322 | GNUNET_YES)) |
1324 | { | 1323 | { |
1325 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1324 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1326 | "Search strings file %s cannot be read.\n", | 1325 | "Search strings file %s cannot be read.\n", |
1327 | filename); | 1326 | filename); |
1328 | return GNUNET_SYSERR; | 1327 | return GNUNET_SYSERR; |
1329 | } | 1328 | } |
1330 | if (0 == filesize) | 1329 | if (0 == filesize) |
1331 | { | 1330 | { |
1332 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1331 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1333 | "Search strings file %s is empty.\n", | 1332 | "Search strings file %s is empty.\n", |
1334 | filename); | 1333 | filename); |
1335 | return GNUNET_SYSERR; | 1334 | return GNUNET_SYSERR; |
1336 | } | 1335 | } |
1337 | 1336 | ||
1338 | /* Read data into memory */ | 1337 | /* Read data into memory */ |
1339 | data = GNUNET_malloc (filesize + 1); | 1338 | data = GNUNET_malloc(filesize + 1); |
1340 | if (filesize != GNUNET_DISK_fn_read (filename, | 1339 | if (filesize != GNUNET_DISK_fn_read(filename, |
1341 | data, | 1340 | data, |
1342 | filesize)) | 1341 | filesize)) |
1343 | { | 1342 | { |
1344 | GNUNET_free (data); | 1343 | GNUNET_free(data); |
1345 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1344 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1346 | "Could not read search strings file %s.\n", | 1345 | "Could not read search strings file %s.\n", |
1347 | filename); | 1346 | filename); |
1348 | return GNUNET_SYSERR; | 1347 | return GNUNET_SYSERR; |
1349 | } | 1348 | } |
1350 | 1349 | ||
1351 | /* Process buffer and build array */ | 1350 | /* Process buffer and build array */ |
1352 | str_cnt = count_and_separate_strings (data, filesize, limit); | 1351 | str_cnt = count_and_separate_strings(data, filesize, limit); |
1353 | if (GNUNET_OK != create_string_array (data, filesize, strings, str_cnt)) | 1352 | if (GNUNET_OK != create_string_array(data, filesize, strings, str_cnt)) |
1354 | { | 1353 | { |
1355 | str_cnt = GNUNET_SYSERR; | 1354 | str_cnt = GNUNET_SYSERR; |
1356 | } | 1355 | } |
1357 | GNUNET_free (data); | 1356 | GNUNET_free(data); |
1358 | return str_cnt; | 1357 | return str_cnt; |
1359 | } | 1358 | } |
1360 | 1359 | ||
@@ -1368,10 +1367,10 @@ load_search_strings (const char *filename, | |||
1368 | * @param config configuration | 1367 | * @param config configuration |
1369 | */ | 1368 | */ |
1370 | static void | 1369 | static void |
1371 | run (void *cls, | 1370 | run(void *cls, |
1372 | char *const *args, | 1371 | char *const *args, |
1373 | const char *cfgfile, | 1372 | const char *cfgfile, |
1374 | const struct GNUNET_CONFIGURATION_Handle *config) | 1373 | const struct GNUNET_CONFIGURATION_Handle *config) |
1375 | { | 1374 | { |
1376 | unsigned int nsearchstrs; | 1375 | unsigned int nsearchstrs; |
1377 | unsigned int i; | 1376 | unsigned int i; |
@@ -1381,161 +1380,161 @@ run (void *cls, | |||
1381 | 1380 | ||
1382 | /* Check config */ | 1381 | /* Check config */ |
1383 | if (NULL == config) | 1382 | if (NULL == config) |
1384 | { | 1383 | { |
1385 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1384 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1386 | _("No configuration file given. Exiting\n")); | 1385 | _("No configuration file given. Exiting\n")); |
1387 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1386 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
1388 | return; | 1387 | return; |
1389 | } | 1388 | } |
1390 | cfg = GNUNET_CONFIGURATION_dup (config); | 1389 | cfg = GNUNET_CONFIGURATION_dup(config); |
1391 | if (GNUNET_OK != | 1390 | if (GNUNET_OK != |
1392 | GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER", | 1391 | GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER", |
1393 | "REGEX_PREFIX", | 1392 | "REGEX_PREFIX", |
1394 | ®ex_prefix)) | 1393 | ®ex_prefix)) |
1395 | { | 1394 | { |
1396 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1395 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
1397 | "regexprofiler", | 1396 | "regexprofiler", |
1398 | "regex_prefix"); | 1397 | "regex_prefix"); |
1399 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1398 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
1400 | return; | 1399 | return; |
1401 | } | 1400 | } |
1402 | if (GNUNET_OK != | 1401 | if (GNUNET_OK != |
1403 | GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", | 1402 | GNUNET_CONFIGURATION_get_value_number(cfg, "REGEXPROFILER", |
1404 | "PARALLEL_SEARCHES", | 1403 | "PARALLEL_SEARCHES", |
1405 | &init_parallel_searches)) | 1404 | &init_parallel_searches)) |
1406 | { | 1405 | { |
1407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1406 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1408 | "Configuration option \"PARALLEL_SEARCHES\" missing." | 1407 | "Configuration option \"PARALLEL_SEARCHES\" missing." |
1409 | " Using default (%d)\n", 10); | 1408 | " Using default (%d)\n", 10); |
1410 | init_parallel_searches = 10; | 1409 | init_parallel_searches = 10; |
1411 | } | 1410 | } |
1412 | if (GNUNET_OK != | 1411 | if (GNUNET_OK != |
1413 | GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER", | 1412 | GNUNET_CONFIGURATION_get_value_time(cfg, "REGEXPROFILER", |
1414 | "REANNOUNCE_PERIOD_MAX", | 1413 | "REANNOUNCE_PERIOD_MAX", |
1415 | &reannounce_period_max)) | 1414 | &reannounce_period_max)) |
1416 | { | 1415 | { |
1417 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1416 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1418 | "reannounce_period_max not given. Using 10 minutes.\n"); | 1417 | "reannounce_period_max not given. Using 10 minutes.\n"); |
1419 | reannounce_period_max = | 1418 | reannounce_period_max = |
1420 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10); | 1419 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10); |
1421 | } | 1420 | } |
1422 | 1421 | ||
1423 | /* Check arguments */ | 1422 | /* Check arguments */ |
1424 | if (NULL == policy_dir) | 1423 | if (NULL == policy_dir) |
1425 | { | 1424 | { |
1426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1425 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1427 | _("No policy directory specified on command line. Exiting.\n")); | 1426 | _("No policy directory specified on command line. Exiting.\n")); |
1428 | return; | 1427 | return; |
1429 | } | 1428 | } |
1430 | if (GNUNET_YES != GNUNET_DISK_directory_test (policy_dir, GNUNET_YES)) | 1429 | if (GNUNET_YES != GNUNET_DISK_directory_test(policy_dir, GNUNET_YES)) |
1431 | { | 1430 | { |
1432 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1431 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1433 | _("Specified policies directory does not exist. Exiting.\n")); | 1432 | _("Specified policies directory does not exist. Exiting.\n")); |
1434 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1433 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
1435 | return; | 1434 | return; |
1436 | } | 1435 | } |
1437 | if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL))) | 1436 | if (0 >= (int)(num_peers = GNUNET_DISK_directory_scan(policy_dir, NULL, NULL))) |
1438 | { | 1437 | { |
1439 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1438 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1440 | _("No files found in `%s'\n"), | 1439 | _("No files found in `%s'\n"), |
1441 | policy_dir); | 1440 | policy_dir); |
1442 | return; | 1441 | return; |
1443 | } | 1442 | } |
1444 | GNUNET_CONFIGURATION_set_value_string (cfg, "REGEXPROFILER", | 1443 | GNUNET_CONFIGURATION_set_value_string(cfg, "REGEXPROFILER", |
1445 | "POLICY_DIR", policy_dir); | 1444 | "POLICY_DIR", policy_dir); |
1446 | if (GNUNET_YES != GNUNET_DISK_file_test (strings_file)) | 1445 | if (GNUNET_YES != GNUNET_DISK_file_test(strings_file)) |
1447 | { | 1446 | { |
1448 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1447 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1449 | _("No search strings file given. Exiting.\n")); | 1448 | _("No search strings file given. Exiting.\n")); |
1450 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1449 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
1451 | return; | 1450 | return; |
1452 | } | 1451 | } |
1453 | nsearchstrs = load_search_strings (strings_file, | 1452 | nsearchstrs = load_search_strings(strings_file, |
1454 | &search_strings, | 1453 | &search_strings, |
1455 | num_peers); | 1454 | num_peers); |
1456 | if (num_peers != nsearchstrs) | 1455 | if (num_peers != nsearchstrs) |
1457 | { | 1456 | { |
1458 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1457 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1459 | "Error loading search strings.\n"); | 1458 | "Error loading search strings.\n"); |
1460 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1459 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1461 | "File (%s) does not contain enough strings (%u/%u).\n", | 1460 | "File (%s) does not contain enough strings (%u/%u).\n", |
1462 | strings_file, nsearchstrs, num_peers); | 1461 | strings_file, nsearchstrs, num_peers); |
1463 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1462 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
1464 | return; | 1463 | return; |
1465 | } | 1464 | } |
1466 | if ( (0 == num_peers) || (NULL == search_strings)) | 1465 | if ((0 == num_peers) || (NULL == search_strings)) |
1467 | { | 1466 | { |
1468 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1467 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1469 | _("Error loading search strings. Exiting.\n")); | 1468 | _("Error loading search strings. Exiting.\n")); |
1470 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1469 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
1471 | return; | 1470 | return; |
1472 | } | 1471 | } |
1473 | for (i = 0; i < num_peers; i++) | 1472 | for (i = 0; i < num_peers; i++) |
1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1473 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1475 | "search string: %s\n", | 1474 | "search string: %s\n", |
1476 | search_strings[i]); | 1475 | search_strings[i]); |
1477 | 1476 | ||
1478 | /* Check logfile */ | 1477 | /* Check logfile */ |
1479 | if ( (NULL != data_filename) && | 1478 | if ((NULL != data_filename) && |
1480 | (NULL == (data_file = | 1479 | (NULL == (data_file = |
1481 | GNUNET_DISK_file_open (data_filename, | 1480 | GNUNET_DISK_file_open(data_filename, |
1482 | GNUNET_DISK_OPEN_READWRITE | | 1481 | GNUNET_DISK_OPEN_READWRITE | |
1483 | GNUNET_DISK_OPEN_TRUNCATE | | 1482 | GNUNET_DISK_OPEN_TRUNCATE | |
1484 | GNUNET_DISK_OPEN_CREATE, | 1483 | GNUNET_DISK_OPEN_CREATE, |
1485 | GNUNET_DISK_PERM_USER_READ | | 1484 | GNUNET_DISK_PERM_USER_READ | |
1486 | GNUNET_DISK_PERM_USER_WRITE))) ) | 1485 | GNUNET_DISK_PERM_USER_WRITE)))) |
1487 | { | 1486 | { |
1488 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 1487 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, |
1489 | "open", | 1488 | "open", |
1490 | data_filename); | 1489 | data_filename); |
1491 | return; | 1490 | return; |
1492 | } | 1491 | } |
1493 | 1492 | ||
1494 | /* Initialize peers */ | 1493 | /* Initialize peers */ |
1495 | peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers); | 1494 | peers = GNUNET_malloc(sizeof(struct RegexPeer) * num_peers); |
1496 | for (i = 0; i < num_peers; i++) | 1495 | for (i = 0; i < num_peers; i++) |
1497 | peers[i].id = i; | 1496 | peers[i].id = i; |
1498 | 1497 | ||
1499 | GNUNET_CONFIGURATION_set_value_number (cfg, | 1498 | GNUNET_CONFIGURATION_set_value_number(cfg, |
1500 | "TESTBED", "OVERLAY_RANDOM_LINKS", | 1499 | "TESTBED", "OVERLAY_RANDOM_LINKS", |
1501 | num_peers * 20); | 1500 | num_peers * 20); |
1502 | GNUNET_CONFIGURATION_set_value_number (cfg, | 1501 | GNUNET_CONFIGURATION_set_value_number(cfg, |
1503 | "DHT", "FORCE_NSE", | 1502 | "DHT", "FORCE_NSE", |
1504 | (long long unsigned) | 1503 | (long long unsigned) |
1505 | (log (num_peers) / log (2.0))); | 1504 | (log(num_peers) / log(2.0))); |
1506 | event_mask = 0LL; | 1505 | event_mask = 0LL; |
1507 | /* For feedback about the start process activate these and pass master_cb */ | 1506 | /* For feedback about the start process activate these and pass master_cb */ |
1508 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 1507 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
1509 | // event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 1508 | // event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
1510 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 1509 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
1511 | // event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | 1510 | // event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); |
1512 | prof_start_time = GNUNET_TIME_absolute_get (); | 1511 | prof_start_time = GNUNET_TIME_absolute_get(); |
1513 | GNUNET_TESTBED_run (hosts_file, | 1512 | GNUNET_TESTBED_run(hosts_file, |
1514 | cfg, | 1513 | cfg, |
1515 | num_peers, | 1514 | num_peers, |
1516 | event_mask, | 1515 | event_mask, |
1517 | &master_controller_cb, | 1516 | &master_controller_cb, |
1518 | NULL, /* master_controller_cb cls */ | 1517 | NULL, /* master_controller_cb cls */ |
1519 | &test_master, | 1518 | &test_master, |
1520 | NULL); /* test_master cls */ | 1519 | NULL); /* test_master cls */ |
1521 | if (GNUNET_OK != | 1520 | if (GNUNET_OK != |
1522 | GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED", | 1521 | GNUNET_CONFIGURATION_get_value_time(cfg, "TESTBED", |
1523 | "SETUP_TIMEOUT", | 1522 | "SETUP_TIMEOUT", |
1524 | &abort_time)) | 1523 | &abort_time)) |
1525 | { | 1524 | { |
1526 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1525 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1527 | "SETUP_TIMEOUT not given. Using 15 minutes.\n"); | 1526 | "SETUP_TIMEOUT not given. Using 15 minutes.\n"); |
1528 | abort_time = | 1527 | abort_time = |
1529 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15); | 1528 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15); |
1530 | } | 1529 | } |
1531 | abort_time = GNUNET_TIME_relative_add (abort_time, GNUNET_TIME_UNIT_MINUTES); | 1530 | abort_time = GNUNET_TIME_relative_add(abort_time, GNUNET_TIME_UNIT_MINUTES); |
1532 | abort_task = | 1531 | abort_task = |
1533 | GNUNET_SCHEDULER_add_delayed (abort_time, | 1532 | GNUNET_SCHEDULER_add_delayed(abort_time, |
1534 | &do_abort, | 1533 | &do_abort, |
1535 | (void*) __LINE__); | 1534 | (void*)__LINE__); |
1536 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1535 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1537 | "setup_timeout: %s\n", | 1536 | "setup_timeout: %s\n", |
1538 | GNUNET_STRINGS_relative_time_to_string (abort_time, GNUNET_YES)); | 1537 | GNUNET_STRINGS_relative_time_to_string(abort_time, GNUNET_YES)); |
1539 | } | 1538 | } |
1540 | 1539 | ||
1541 | 1540 | ||
@@ -1547,53 +1546,52 @@ run (void *cls, | |||
1547 | * @return 0 on success | 1546 | * @return 0 on success |
1548 | */ | 1547 | */ |
1549 | int | 1548 | int |
1550 | main (int argc, char *const *argv) | 1549 | main(int argc, char *const *argv) |
1551 | { | 1550 | { |
1552 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 1551 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
1553 | 1552 | GNUNET_GETOPT_option_filename('o', | |
1554 | GNUNET_GETOPT_option_filename ('o', | 1553 | "output-file", |
1555 | "output-file", | 1554 | "FILENAME", |
1556 | "FILENAME", | 1555 | gettext_noop("name of the file for writing statistics"), |
1557 | gettext_noop ("name of the file for writing statistics"), | 1556 | &data_filename), |
1558 | &data_filename), | 1557 | |
1559 | 1558 | GNUNET_GETOPT_option_relative_time('t', | |
1560 | GNUNET_GETOPT_option_relative_time ('t', | 1559 | "matching-timeout", |
1561 | "matching-timeout", | 1560 | "TIMEOUT", |
1562 | "TIMEOUT", | 1561 | gettext_noop("wait TIMEOUT before ending the experiment"), |
1563 | gettext_noop ("wait TIMEOUT before ending the experiment"), | 1562 | &search_timeout_time), |
1564 | &search_timeout_time), | 1563 | |
1565 | 1564 | GNUNET_GETOPT_option_filename('p', | |
1566 | GNUNET_GETOPT_option_filename ('p', | 1565 | "policy-dir", |
1567 | "policy-dir", | 1566 | "DIRECTORY", |
1568 | "DIRECTORY", | 1567 | gettext_noop("directory with policy files"), |
1569 | gettext_noop ("directory with policy files"), | 1568 | &policy_dir), |
1570 | &policy_dir), | 1569 | |
1571 | 1570 | ||
1572 | 1571 | GNUNET_GETOPT_option_filename('s', | |
1573 | GNUNET_GETOPT_option_filename ('s', | 1572 | "strings-file", |
1574 | "strings-file", | 1573 | "FILENAME", |
1575 | "FILENAME", | 1574 | gettext_noop("name of file with input strings"), |
1576 | gettext_noop ("name of file with input strings"), | 1575 | &strings_file), |
1577 | &strings_file), | 1576 | |
1578 | 1577 | GNUNET_GETOPT_option_filename('H', | |
1579 | GNUNET_GETOPT_option_filename ('H', | 1578 | "hosts-file", |
1580 | "hosts-file", | 1579 | "FILENAME", |
1581 | "FILENAME", | 1580 | gettext_noop("name of file with hosts' names"), |
1582 | gettext_noop ("name of file with hosts' names"), | 1581 | &hosts_file), |
1583 | &hosts_file), | ||
1584 | 1582 | ||
1585 | GNUNET_GETOPT_OPTION_END | 1583 | GNUNET_GETOPT_OPTION_END |
1586 | }; | 1584 | }; |
1587 | int ret; | 1585 | int ret; |
1588 | 1586 | ||
1589 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1587 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
1590 | return 2; | 1588 | return 2; |
1591 | result = GNUNET_SYSERR; | 1589 | result = GNUNET_SYSERR; |
1592 | ret = | 1590 | ret = |
1593 | GNUNET_PROGRAM_run (argc, argv, | 1591 | GNUNET_PROGRAM_run(argc, argv, |
1594 | "gnunet-regex-profiler", | 1592 | "gnunet-regex-profiler", |
1595 | _("Profiler for regex"), | 1593 | _("Profiler for regex"), |
1596 | options, &run, NULL); | 1594 | options, &run, NULL); |
1597 | if (GNUNET_OK != ret) | 1595 | if (GNUNET_OK != ret) |
1598 | return ret; | 1596 | return ret; |
1599 | if (GNUNET_OK != result) | 1597 | if (GNUNET_OK != result) |