diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-04-06 09:40:36 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-04-06 09:40:36 +0000 |
commit | b24caf06a3d147b2362c210c4e7385b83c9f582b (patch) | |
tree | 29306a4e3ede82b3b68935773a769ca217232316 /src/testing/testing_peergroup.c | |
parent | 626665da9b8b1861a1e09ca91e599ec44f915c9c (diff) | |
download | gnunet-b24caf06a3d147b2362c210c4e7385b83c9f582b.tar.gz gnunet-b24caf06a3d147b2362c210c4e7385b83c9f582b.zip |
peergroup initial version with test case
Diffstat (limited to 'src/testing/testing_peergroup.c')
-rw-r--r-- | src/testing/testing_peergroup.c | 206 |
1 files changed, 168 insertions, 38 deletions
diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c index bd725fedc..b9b6cd313 100644 --- a/src/testing/testing_peergroup.c +++ b/src/testing/testing_peergroup.c | |||
@@ -44,8 +44,9 @@ struct PeerGroupStartupContext | |||
44 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 44 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
45 | unsigned int total; | 45 | unsigned int total; |
46 | unsigned int peers_left; | 46 | unsigned int peers_left; |
47 | unsigned int max_concurrent_connections; | 47 | unsigned long long max_concurrent_connections; |
48 | unsigned int max_concurrent_ssh; | 48 | unsigned long long connect_attempts; |
49 | unsigned long long max_concurrent_ssh; | ||
49 | struct GNUNET_TIME_Absolute timeout; | 50 | struct GNUNET_TIME_Absolute timeout; |
50 | GNUNET_TESTING_NotifyConnection connect_cb; | 51 | GNUNET_TESTING_NotifyConnection connect_cb; |
51 | void *connect_cb_cls; | 52 | void *connect_cb_cls; |
@@ -53,8 +54,13 @@ struct PeerGroupStartupContext | |||
53 | void *peergroup_cb_cls; | 54 | void *peergroup_cb_cls; |
54 | const struct GNUNET_TESTING_Host *hostnames; | 55 | const struct GNUNET_TESTING_Host *hostnames; |
55 | enum GNUNET_TESTING_Topology topology; | 56 | enum GNUNET_TESTING_Topology topology; |
57 | |||
58 | float topology_percentage; | ||
59 | |||
60 | float topology_probability; | ||
61 | |||
56 | enum GNUNET_TESTING_Topology restrict_topology; | 62 | enum GNUNET_TESTING_Topology restrict_topology; |
57 | const char *restrict_transports; | 63 | char *restrict_transports; |
58 | enum GNUNET_TESTING_Topology connect_topology; | 64 | enum GNUNET_TESTING_Topology connect_topology; |
59 | enum GNUNET_TESTING_TopologyOption connect_topology_option; | 65 | enum GNUNET_TESTING_TopologyOption connect_topology_option; |
60 | double connect_topology_option_modifier; | 66 | double connect_topology_option_modifier; |
@@ -401,6 +407,8 @@ internal_topology_callback( | |||
401 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | 407 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); |
402 | 408 | ||
403 | /* Call final callback, signifying that the peer group has been started and connected */ | 409 | /* Call final callback, signifying that the peer group has been started and connected */ |
410 | if (pg_start_ctx->peergroup_cb != NULL) | ||
411 | pg_start_ctx->peergroup_cb(pg_start_ctx->peergroup_cb_cls, NULL); | ||
404 | } | 412 | } |
405 | } | 413 | } |
406 | 414 | ||
@@ -446,7 +454,7 @@ internal_peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
446 | pg_start_ctx->connect_topology_option, | 454 | pg_start_ctx->connect_topology_option, |
447 | pg_start_ctx->connect_topology_option_modifier, | 455 | pg_start_ctx->connect_topology_option_modifier, |
448 | DEFAULT_CONNECT_TIMEOUT, | 456 | DEFAULT_CONNECT_TIMEOUT, |
449 | DEFAULT_CONNECT_ATTEMPTS, | 457 | pg_start_ctx->connect_attempts, |
450 | NULL, NULL); | 458 | NULL, NULL); |
451 | 459 | ||
452 | pg_start_ctx->connect_meter | 460 | pg_start_ctx->connect_meter |
@@ -506,9 +514,6 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
506 | pg_start_ctx->peers_left--; | 514 | pg_start_ctx->peers_left--; |
507 | if (GNUNET_YES == update_meter (pg_start_ctx->hostkey_meter)) | 515 | if (GNUNET_YES == update_meter (pg_start_ctx->hostkey_meter)) |
508 | { | 516 | { |
509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
510 | "All %d hostkeys created, now creating topology!\n", | ||
511 | pg_start_ctx->total); | ||
512 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); | 517 | GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); |
513 | /* Set up task in case topology creation doesn't finish | 518 | /* Set up task in case topology creation doesn't finish |
514 | * within a reasonable amount of time */ | 519 | * within a reasonable amount of time */ |
@@ -549,10 +554,6 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
549 | * | 554 | * |
550 | * @param cfg configuration template to use | 555 | * @param cfg configuration template to use |
551 | * @param total number of daemons to start | 556 | * @param total number of daemons to start |
552 | * @param max_concurrent_connections for testing, how many peers can | ||
553 | * we connect to simultaneously | ||
554 | * @param max_concurrent_ssh when starting with ssh, how many ssh | ||
555 | * connections will we allow at once (based on remote hosts allowed!) | ||
556 | * @param timeout total time allowed for peers to start | 557 | * @param timeout total time allowed for peers to start |
557 | * @param connect_cb function to call each time two daemons are connected | 558 | * @param connect_cb function to call each time two daemons are connected |
558 | * @param connect_cb_cls closure for connect_callback | 559 | * @param connect_cb_cls closure for connect_callback |
@@ -560,58 +561,188 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
560 | * @param peergroup_cb_cls closure for peergroup_cb | 561 | * @param peergroup_cb_cls closure for peergroup_cb |
561 | * @param hostnames linked list of host structs to use to start peers on | 562 | * @param hostnames linked list of host structs to use to start peers on |
562 | * (NULL to run on localhost only) | 563 | * (NULL to run on localhost only) |
563 | * @param topology allowed overlay topology | ||
564 | * @param restrict_topology blacklist connections to this topology | ||
565 | * @param restrict_transports specific transports to blacklist | ||
566 | * @param connect_topology topology to connect peers in (defaults to allowed | ||
567 | * topology) | ||
568 | * @param connect_topology_options options for connect topology | ||
569 | * @param connect_topology_option_modifier option modifier for connect topology | ||
570 | * @param verbose GNUNET_YES to print progress bars, GNUNET_NO otherwise | 564 | * @param verbose GNUNET_YES to print progress bars, GNUNET_NO otherwise |
571 | * | 565 | * |
572 | * @return NULL on error, otherwise handle to control peer group | 566 | * @return NULL on error, otherwise handle to control peer group |
573 | */ | 567 | */ |
574 | struct GNUNET_TESTING_PeerGroup * | 568 | struct GNUNET_TESTING_PeerGroup * |
575 | GNUNET_TESTING_PeerGroup_start( | 569 | GNUNET_TESTING_peergroup_start( |
576 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 570 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
577 | unsigned int total, | 571 | unsigned int total, |
578 | unsigned int max_concurrent_connections, | ||
579 | unsigned int max_concurrent_ssh, | ||
580 | struct GNUNET_TIME_Relative timeout, | 572 | struct GNUNET_TIME_Relative timeout, |
581 | GNUNET_TESTING_NotifyConnection connect_cb, | 573 | GNUNET_TESTING_NotifyConnection connect_cb, |
582 | void *connect_cb_cls, | 574 | void *connect_cb_cls, |
583 | GNUNET_TESTING_NotifyCompletion peergroup_cb, | 575 | GNUNET_TESTING_NotifyCompletion peergroup_cb, |
584 | void *peergroup_cb_cls, | 576 | void *peergroup_cb_cls, |
585 | const struct GNUNET_TESTING_Host *hostnames, | 577 | const struct GNUNET_TESTING_Host *hostnames, |
586 | enum GNUNET_TESTING_Topology topology, | 578 | int verbose) |
587 | enum GNUNET_TESTING_Topology restrict_topology, | ||
588 | const char *restrict_transports, | ||
589 | enum GNUNET_TESTING_Topology connect_topology, | ||
590 | enum GNUNET_TESTING_TopologyOption connect_topology_options, | ||
591 | double connect_topology_option_modifier, int verbose) | ||
592 | { | 579 | { |
593 | struct PeerGroupStartupContext *pg_start_ctx; | 580 | struct PeerGroupStartupContext *pg_start_ctx; |
594 | 581 | unsigned long long temp_config_number; | |
582 | char *temp_str; | ||
595 | GNUNET_assert(total > 0); | 583 | GNUNET_assert(total > 0); |
596 | GNUNET_assert(cfg != NULL); | 584 | GNUNET_assert(cfg != NULL); |
597 | 585 | ||
598 | pg_start_ctx = GNUNET_malloc(sizeof(struct PeerGroupStartupContext)); | 586 | pg_start_ctx = GNUNET_malloc(sizeof(struct PeerGroupStartupContext)); |
587 | |||
588 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | ||
589 | "connect_attempts", | ||
590 | &pg_start_ctx->connect_attempts)) | ||
591 | { | ||
592 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | ||
593 | "testing", "connect_attempts"); | ||
594 | GNUNET_free(pg_start_ctx); | ||
595 | return NULL; | ||
596 | } | ||
597 | |||
598 | if (GNUNET_OK | ||
599 | != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | ||
600 | "max_outstanding_connections", | ||
601 | &pg_start_ctx->max_concurrent_connections)) | ||
602 | { | ||
603 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | ||
604 | "testing", "max_outstanding_connections"); | ||
605 | GNUNET_free(pg_start_ctx); | ||
606 | return NULL; | ||
607 | } | ||
608 | |||
609 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | ||
610 | "max_concurrent_ssh", | ||
611 | &pg_start_ctx->max_concurrent_ssh)) | ||
612 | { | ||
613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | ||
614 | "testing", "max_concurrent_ssh"); | ||
615 | GNUNET_free(pg_start_ctx); | ||
616 | return NULL; | ||
617 | } | ||
618 | |||
619 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | ||
620 | "peergroup_timeout", | ||
621 | &temp_config_number)) | ||
622 | pg_start_ctx->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
623 | temp_config_number)); | ||
624 | else | ||
625 | { | ||
626 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", | ||
627 | "testing", "peergroup_timeout"); | ||
628 | GNUNET_free(pg_start_ctx); | ||
629 | return NULL; | ||
630 | } | ||
631 | |||
632 | |||
633 | /* Read topology related options from the configuration file */ | ||
634 | temp_str = NULL; | ||
635 | if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | ||
636 | "topology", | ||
637 | &temp_str)) | ||
638 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str))) | ||
639 | { | ||
640 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
641 | "Invalid topology `%s' given for section %s option %s\n", | ||
642 | temp_str, "TESTING", "TOPOLOGY"); | ||
643 | pg_start_ctx->topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | ||
644 | } | ||
645 | GNUNET_free_non_null(temp_str); | ||
646 | |||
647 | if (GNUNET_OK | ||
648 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", | ||
649 | &temp_str)) | ||
650 | pg_start_ctx->topology_percentage = 0.5; | ||
651 | else | ||
652 | { | ||
653 | pg_start_ctx->topology_percentage = atof (temp_str); | ||
654 | GNUNET_free(temp_str); | ||
655 | } | ||
656 | |||
657 | if (GNUNET_OK | ||
658 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability", | ||
659 | &temp_str)) | ||
660 | pg_start_ctx->topology_probability = 0.5; | ||
661 | else | ||
662 | { | ||
663 | pg_start_ctx->topology_probability = atof (temp_str); | ||
664 | GNUNET_free(temp_str); | ||
665 | } | ||
666 | |||
667 | if ((GNUNET_YES | ||
668 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | ||
669 | "connect_topology", | ||
670 | &temp_str)) | ||
671 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology, | ||
672 | temp_str))) | ||
673 | { | ||
674 | GNUNET_log ( | ||
675 | GNUNET_ERROR_TYPE_WARNING, | ||
676 | "Invalid connect topology `%s' given for section %s option %s\n", | ||
677 | temp_str, "TESTING", "CONNECT_TOPOLOGY"); | ||
678 | } | ||
679 | GNUNET_free_non_null(temp_str); | ||
680 | |||
681 | if ((GNUNET_YES | ||
682 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | ||
683 | "connect_topology_option", | ||
684 | &temp_str)) | ||
685 | && (GNUNET_NO | ||
686 | == GNUNET_TESTING_topology_option_get (&pg_start_ctx->connect_topology_option, | ||
687 | temp_str))) | ||
688 | { | ||
689 | GNUNET_log ( | ||
690 | GNUNET_ERROR_TYPE_WARNING, | ||
691 | "Invalid connect topology option `%s' given for section %s option %s\n", | ||
692 | temp_str, "TESTING", | ||
693 | "CONNECT_TOPOLOGY_OPTION"); | ||
694 | pg_start_ctx->connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | ||
695 | } | ||
696 | GNUNET_free_non_null(temp_str); | ||
697 | |||
698 | if (GNUNET_YES | ||
699 | == GNUNET_CONFIGURATION_get_value_string ( | ||
700 | cfg, | ||
701 | "testing", | ||
702 | "connect_topology_option_modifier", | ||
703 | &temp_str)) | ||
704 | { | ||
705 | if (sscanf (temp_str, "%lf", | ||
706 | &pg_start_ctx->connect_topology_option_modifier) != 1) | ||
707 | { | ||
708 | GNUNET_log ( | ||
709 | GNUNET_ERROR_TYPE_WARNING, | ||
710 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
711 | temp_str, | ||
712 | "connect_topology_option_modifier", "TESTING"); | ||
713 | GNUNET_free (temp_str); | ||
714 | GNUNET_free(pg_start_ctx); | ||
715 | return NULL; | ||
716 | } | ||
717 | GNUNET_free (temp_str); | ||
718 | } | ||
719 | |||
720 | if (GNUNET_YES | ||
721 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | ||
722 | "blacklist_transports", | ||
723 | &pg_start_ctx->restrict_transports)) | ||
724 | pg_start_ctx->restrict_transports = NULL; | ||
725 | |||
726 | if ((GNUNET_YES | ||
727 | == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", | ||
728 | "blacklist_topology", | ||
729 | &temp_str)) | ||
730 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology, | ||
731 | temp_str))) | ||
732 | { | ||
733 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
734 | "Invalid topology `%s' given for section %s option %s\n", | ||
735 | temp_str, "TESTING", "BLACKLIST_TOPOLOGY"); | ||
736 | } | ||
737 | GNUNET_free_non_null(temp_str); | ||
738 | |||
599 | pg_start_ctx->cfg = cfg; | 739 | pg_start_ctx->cfg = cfg; |
600 | pg_start_ctx->total = total; | 740 | pg_start_ctx->total = total; |
601 | pg_start_ctx->peers_left = total; | 741 | pg_start_ctx->peers_left = total; |
602 | pg_start_ctx->max_concurrent_connections = max_concurrent_connections; | ||
603 | pg_start_ctx->max_concurrent_ssh = max_concurrent_ssh; | ||
604 | pg_start_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); | ||
605 | pg_start_ctx->connect_cb = connect_cb_cls; | 742 | pg_start_ctx->connect_cb = connect_cb_cls; |
606 | pg_start_ctx->peergroup_cb = peergroup_cb; | 743 | pg_start_ctx->peergroup_cb = peergroup_cb; |
607 | pg_start_ctx->peergroup_cb_cls = peergroup_cb_cls; | 744 | pg_start_ctx->peergroup_cb_cls = peergroup_cb_cls; |
608 | pg_start_ctx->hostnames = hostnames; | 745 | pg_start_ctx->hostnames = hostnames; |
609 | pg_start_ctx->topology = topology; | ||
610 | pg_start_ctx->restrict_topology = restrict_topology; | ||
611 | pg_start_ctx->restrict_transports = restrict_transports; | ||
612 | pg_start_ctx->connect_topology = connect_topology; | ||
613 | pg_start_ctx->connect_topology_option = connect_topology_options; | ||
614 | pg_start_ctx->connect_topology_option_modifier = connect_topology_option_modifier; | ||
615 | pg_start_ctx->verbose = verbose; | 746 | pg_start_ctx->verbose = verbose; |
616 | pg_start_ctx->hostkey_meter = create_meter (pg_start_ctx->peers_left, "Hostkeys created ", pg_start_ctx->verbose); | 747 | pg_start_ctx->hostkey_meter = create_meter (pg_start_ctx->peers_left, "Hostkeys created ", pg_start_ctx->verbose); |
617 | pg_start_ctx->peer_start_meter = create_meter (pg_start_ctx->peers_left, "Peers started ", pg_start_ctx->verbose); | 748 | pg_start_ctx->peer_start_meter = create_meter (pg_start_ctx->peers_left, "Peers started ", pg_start_ctx->verbose); |
@@ -640,5 +771,4 @@ GNUNET_TESTING_PeerGroup_start( | |||
640 | return pg_start_ctx->pg; | 771 | return pg_start_ctx->pg; |
641 | } | 772 | } |
642 | 773 | ||
643 | |||
644 | /* end of testing_peergroup.c */ | 774 | /* end of testing_peergroup.c */ |