diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_testing_group_remote.c | 4 | ||||
-rw-r--r-- | src/testing/test_testing_topology.c | 11 | ||||
-rw-r--r-- | src/testing/testing.c | 89 | ||||
-rw-r--r-- | src/testing/testing_group.c | 1099 |
4 files changed, 817 insertions, 386 deletions
diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c index 8547e4de5..5156007a6 100644 --- a/src/testing/test_testing_group_remote.c +++ b/src/testing/test_testing_group_remote.c | |||
@@ -85,14 +85,14 @@ my_cb (void *cls, | |||
85 | peers_left--; | 85 | peers_left--; |
86 | if (peers_left == 0) | 86 | if (peers_left == 0) |
87 | { | 87 | { |
88 | //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 88 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
89 | ok = 0; | 89 | ok = 0; |
90 | } | 90 | } |
91 | else if (peers_failed == peers_left) | 91 | else if (peers_failed == peers_left) |
92 | { | 92 | { |
93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
94 | "Too many peers failed, ending test!\n"); | 94 | "Too many peers failed, ending test!\n"); |
95 | //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 95 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index 8ad864be7..0e64f93aa 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c | |||
@@ -279,6 +279,7 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
279 | total_server_connections -= 2; | 279 | total_server_connections -= 2; |
280 | } | 280 | } |
281 | 281 | ||
282 | #if DO_STATS | ||
282 | static void | 283 | static void |
283 | stats_finished (void *cls, int result) | 284 | stats_finished (void *cls, int result) |
284 | { | 285 | { |
@@ -306,6 +307,7 @@ stats_print (void *cls, | |||
306 | GNUNET_i2s (peer), subsystem, name, value); | 307 | GNUNET_i2s (peer), subsystem, name, value); |
307 | return GNUNET_OK; | 308 | return GNUNET_OK; |
308 | } | 309 | } |
310 | #endif | ||
309 | 311 | ||
310 | static void | 312 | static void |
311 | topology_cb (void *cls, | 313 | topology_cb (void *cls, |
@@ -331,9 +333,11 @@ topology_cb (void *cls, | |||
331 | { | 333 | { |
332 | fprintf (outfile, "}\n"); | 334 | fprintf (outfile, "}\n"); |
333 | fclose (outfile); | 335 | fclose (outfile); |
336 | #if DO_STATS | ||
334 | GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, | 337 | GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, |
335 | NULL); | 338 | NULL); |
336 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 339 | #endif |
340 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
337 | } | 341 | } |
338 | } | 342 | } |
339 | } | 343 | } |
@@ -811,18 +815,19 @@ connect_topology () | |||
811 | connect_topology_option, | 815 | connect_topology_option, |
812 | connect_topology_option_modifier, | 816 | connect_topology_option_modifier, |
813 | &topology_creation_finished, NULL); | 817 | &topology_creation_finished, NULL); |
814 | #if VERBOSE > 1 | 818 | #if VERBOSE |
815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
816 | "Have %d expected connections\n", expected_connections); | 820 | "Have %d expected connections\n", expected_connections); |
817 | #endif | 821 | #endif |
818 | } | 822 | } |
819 | 823 | ||
820 | GNUNET_SCHEDULER_cancel (die_task); | 824 | GNUNET_SCHEDULER_cancel (die_task); |
821 | if (expected_connections == GNUNET_SYSERR) | 825 | if (expected_connections < 1) |
822 | { | 826 | { |
823 | die_task = | 827 | die_task = |
824 | GNUNET_SCHEDULER_add_now (&end_badly, | 828 | GNUNET_SCHEDULER_add_now (&end_badly, |
825 | "from connect topology (bad return)"); | 829 | "from connect topology (bad return)"); |
830 | return; | ||
826 | } | 831 | } |
827 | 832 | ||
828 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 833 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
diff --git a/src/testing/testing.c b/src/testing/testing.c index a24c1feae..c97b3bda3 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -453,7 +453,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
453 | if (NULL == d->hostname) | 453 | if (NULL == d->hostname) |
454 | { | 454 | { |
455 | #if DEBUG_TESTING | 455 | #if DEBUG_TESTING |
456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 456 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
457 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | 457 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", |
458 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, | 458 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, |
459 | "-L", "DEBUG", "-s"); | 459 | "-L", "DEBUG", "-s"); |
@@ -473,7 +473,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
473 | dst = GNUNET_strdup (d->hostname); | 473 | dst = GNUNET_strdup (d->hostname); |
474 | 474 | ||
475 | #if DEBUG_TESTING | 475 | #if DEBUG_TESTING |
476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 476 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
477 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", | 477 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", |
478 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", | 478 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", |
479 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); | 479 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); |
@@ -526,7 +526,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
526 | return; | 526 | return; |
527 | } | 527 | } |
528 | #if DEBUG_TESTING | 528 | #if DEBUG_TESTING |
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 529 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
530 | "Started `%s', waiting for `%s' to be up.\n", | 530 | "Started `%s', waiting for `%s' to be up.\n", |
531 | "gnunet-arm", "gnunet-service-core"); | 531 | "gnunet-arm", "gnunet-service-core"); |
532 | #endif | 532 | #endif |
@@ -551,6 +551,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
551 | (NULL == d->hostname) | 551 | (NULL == d->hostname) |
552 | ? _("`gnunet-arm' does not seem to terminate.\n") | 552 | ? _("`gnunet-arm' does not seem to terminate.\n") |
553 | : _("`ssh' does not seem to terminate.\n")); | 553 | : _("`ssh' does not seem to terminate.\n")); |
554 | GNUNET_free(d->proc); | ||
554 | return; | 555 | return; |
555 | } | 556 | } |
556 | /* wait some more */ | 557 | /* wait some more */ |
@@ -560,10 +561,15 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
560 | return; | 561 | return; |
561 | } | 562 | } |
562 | #if DEBUG_TESTING | 563 | #if DEBUG_TESTING |
563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 564 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
564 | "Successfully started `%s'.\n", "gnunet-arm"); | 565 | "Successfully started `%s'.\n", "gnunet-arm"); |
565 | #endif | 566 | #endif |
567 | GNUNET_free(d->proc); | ||
566 | d->phase = SP_START_CORE; | 568 | d->phase = SP_START_CORE; |
569 | #if DEBUG_TESTING | ||
570 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
571 | "Calling CORE_connect\n"); | ||
572 | #endif | ||
567 | d->server = GNUNET_CORE_connect (d->cfg, 1, | 573 | d->server = GNUNET_CORE_connect (d->cfg, 1, |
568 | #if NO_MORE_TIMEOUT_FIXME | 574 | #if NO_MORE_TIMEOUT_FIXME |
569 | ARM_START_WAIT, | 575 | ARM_START_WAIT, |
@@ -604,6 +610,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
604 | GNUNET_free_non_null (d->hostname); | 610 | GNUNET_free_non_null (d->hostname); |
605 | GNUNET_free_non_null (d->username); | 611 | GNUNET_free_non_null (d->username); |
606 | GNUNET_free_non_null (d->shortname); | 612 | GNUNET_free_non_null (d->shortname); |
613 | GNUNET_free_non_null (d->proc); | ||
614 | d->proc = NULL; | ||
607 | GNUNET_free (d); | 615 | GNUNET_free (d); |
608 | return; | 616 | return; |
609 | } | 617 | } |
@@ -636,6 +644,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
636 | GNUNET_free_non_null (d->hostname); | 644 | GNUNET_free_non_null (d->hostname); |
637 | GNUNET_free_non_null (d->username); | 645 | GNUNET_free_non_null (d->username); |
638 | GNUNET_free_non_null (d->shortname); | 646 | GNUNET_free_non_null (d->shortname); |
647 | GNUNET_free_non_null (d->proc); | ||
648 | d->proc = NULL; | ||
639 | GNUNET_free (d); | 649 | GNUNET_free (d); |
640 | return; | 650 | return; |
641 | } | 651 | } |
@@ -666,6 +676,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
666 | GNUNET_free_non_null (d->hello); | 676 | GNUNET_free_non_null (d->hello); |
667 | d->hello = NULL; | 677 | d->hello = NULL; |
668 | GNUNET_free_non_null (d->shortname); | 678 | GNUNET_free_non_null (d->shortname); |
679 | GNUNET_free_non_null (d->proc); | ||
680 | d->proc = NULL; | ||
669 | d->shortname = NULL; | 681 | d->shortname = NULL; |
670 | if (NULL != d->dead_cb) | 682 | if (NULL != d->dead_cb) |
671 | d->dead_cb (d->dead_cb_cls, NULL); | 683 | d->dead_cb (d->dead_cb_cls, NULL); |
@@ -815,7 +827,10 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
815 | char *arg; | 827 | char *arg; |
816 | char *username; | 828 | char *username; |
817 | char *servicehome; | 829 | char *servicehome; |
830 | char *baseservicehome; | ||
831 | char *slash; | ||
818 | char *hostkeyfile; | 832 | char *hostkeyfile; |
833 | char *temp_file_name; | ||
819 | struct GNUNET_DISK_FileHandle *fn; | 834 | struct GNUNET_DISK_FileHandle *fn; |
820 | 835 | ||
821 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); | 836 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); |
@@ -826,7 +841,18 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
826 | } | 841 | } |
827 | else | 842 | else |
828 | ret->ssh_port_str = NULL; | 843 | ret->ssh_port_str = NULL; |
829 | ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config"); | 844 | |
845 | /* Find service home and base service home directories, create it if it doesn't exist */ | ||
846 | GNUNET_assert(GNUNET_OK == | ||
847 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
848 | "PATHS", | ||
849 | "SERVICEHOME", | ||
850 | &servicehome)); | ||
851 | |||
852 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome)); | ||
853 | GNUNET_asprintf(&temp_file_name, "%s/gnunet-testing-config", servicehome); | ||
854 | ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name); | ||
855 | GNUNET_free(temp_file_name); | ||
830 | #if DEBUG_TESTING | 856 | #if DEBUG_TESTING |
831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
832 | "Setting up peer with configuration file `%s'.\n", | 858 | "Setting up peer with configuration file `%s'.\n", |
@@ -848,14 +874,11 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
848 | GNUNET_CONFIGURATION_set_value_string (ret->cfg, | 874 | GNUNET_CONFIGURATION_set_value_string (ret->cfg, |
849 | "PATHS", | 875 | "PATHS", |
850 | "DEFAULTCONFIG", ret->cfgfile); | 876 | "DEFAULTCONFIG", ret->cfgfile); |
877 | |||
878 | /* Write hostkey to file, if we were given one */ | ||
879 | hostkeyfile = NULL; | ||
851 | if (hostkey != NULL) | 880 | if (hostkey != NULL) |
852 | { | 881 | { |
853 | GNUNET_assert(GNUNET_OK == | ||
854 | GNUNET_CONFIGURATION_get_value_string (ret->cfg, | ||
855 | "PATHS", | ||
856 | "SERVICEHOME", | ||
857 | &servicehome)); | ||
858 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome)); | ||
859 | GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome); | 882 | GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome); |
860 | fn = | 883 | fn = |
861 | GNUNET_DISK_file_open (hostkeyfile, | 884 | GNUNET_DISK_file_open (hostkeyfile, |
@@ -866,11 +889,9 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
866 | GNUNET_assert(fn != NULL); | 889 | GNUNET_assert(fn != NULL); |
867 | GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE)); | 890 | GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE)); |
868 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn)); | 891 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn)); |
869 | GNUNET_free(servicehome); | ||
870 | GNUNET_free(hostkeyfile); | ||
871 | } | 892 | } |
872 | 893 | ||
873 | /* 1) write configuration to temporary file */ | 894 | /* write configuration to temporary file */ |
874 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) | 895 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) |
875 | { | 896 | { |
876 | if (0 != UNLINK (ret->cfgfile)) | 897 | if (0 != UNLINK (ret->cfgfile)) |
@@ -897,42 +918,54 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
897 | } | 918 | } |
898 | ret->username = username; | 919 | ret->username = username; |
899 | 920 | ||
900 | /* 2) copy file to remote host */ | 921 | /* copy directory to remote host */ |
901 | if (NULL != hostname) | 922 | if (NULL != hostname) |
902 | { | 923 | { |
903 | #if DEBUG_TESTING | 924 | #if DEBUG_TESTING |
904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
905 | "Copying configuration file to host `%s'.\n", hostname); | 926 | "Copying configuration directory to host `%s'.\n", hostname); |
906 | #endif | 927 | #endif |
928 | baseservicehome = GNUNET_strdup(servicehome); | ||
929 | /* Remove trailing /'s */ | ||
930 | while (baseservicehome[strlen(baseservicehome) - 1] == '/') | ||
931 | baseservicehome[strlen(baseservicehome) - 1] = '\0'; | ||
932 | /* Find next directory /, jump one ahead */ | ||
933 | slash = strrchr(baseservicehome, '/'); | ||
934 | if (slash != NULL) | ||
935 | *(++slash) = '\0'; | ||
936 | |||
907 | ret->phase = SP_COPYING; | 937 | ret->phase = SP_COPYING; |
908 | if (NULL != username) | 938 | if (NULL != username) |
909 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile); | 939 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome); |
910 | else | 940 | else |
911 | GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile); | 941 | GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); |
912 | 942 | ||
913 | if (ret->ssh_port_str == NULL) | 943 | if (ret->ssh_port_str == NULL) |
914 | { | 944 | { |
915 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", | 945 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", |
916 | #if !DEBUG_TESTING | 946 | #if !DEBUG_TESTING |
917 | "-q", | 947 | "-q", |
918 | #endif | 948 | #endif |
919 | ret->cfgfile, arg, NULL); | 949 | servicehome, arg, NULL); |
950 | #if DEBUG_TESTING | ||
951 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "copying directory with command scp -r %s %s\n", servicehome, arg); | ||
952 | #endif | ||
920 | } | 953 | } |
921 | else | 954 | else |
922 | { | 955 | { |
923 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", | 956 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", |
924 | "scp", "-P", ret->ssh_port_str, | 957 | "scp", "-r", "-P", ret->ssh_port_str, |
925 | #if !DEBUG_TESTING | 958 | #if !DEBUG_TESTING |
926 | "-q", | 959 | "-q", |
927 | #endif | 960 | #endif |
928 | ret->cfgfile, arg, NULL); | 961 | servicehome, arg, NULL); |
929 | } | 962 | } |
930 | GNUNET_free (arg); | 963 | GNUNET_free (arg); |
931 | if (NULL == ret->proc) | 964 | if (NULL == ret->proc) |
932 | { | 965 | { |
933 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 966 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
934 | _ | 967 | _ |
935 | ("Could not start `%s' process to copy configuration file.\n"), | 968 | ("Could not start `%s' process to copy configuration directory.\n"), |
936 | "scp"); | 969 | "scp"); |
937 | if (0 != UNLINK (ret->cfgfile)) | 970 | if (0 != UNLINK (ret->cfgfile)) |
938 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 971 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
@@ -942,11 +975,19 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
942 | GNUNET_free_non_null (ret->username); | 975 | GNUNET_free_non_null (ret->username); |
943 | GNUNET_free (ret->cfgfile); | 976 | GNUNET_free (ret->cfgfile); |
944 | GNUNET_free (ret); | 977 | GNUNET_free (ret); |
978 | if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile))) | ||
979 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
980 | "unlink", hostkeyfile); | ||
981 | GNUNET_free_non_null(hostkeyfile); | ||
982 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); | ||
983 | GNUNET_free(servicehome); | ||
945 | return NULL; | 984 | return NULL; |
946 | } | 985 | } |
947 | ret->task | 986 | ret->task |
948 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 987 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
949 | &start_fsm, ret); | 988 | &start_fsm, ret); |
989 | GNUNET_free_non_null(hostkeyfile); | ||
990 | GNUNET_free(servicehome); | ||
950 | return ret; | 991 | return ret; |
951 | } | 992 | } |
952 | #if DEBUG_TESTING | 993 | #if DEBUG_TESTING |
@@ -957,6 +998,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
957 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | 998 | GNUNET_SCHEDULER_add_continuation (&start_fsm, |
958 | ret, | 999 | ret, |
959 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1000 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
1001 | GNUNET_free_non_null(hostkeyfile); | ||
1002 | GNUNET_free(servicehome); | ||
960 | return ret; | 1003 | return ret; |
961 | } | 1004 | } |
962 | 1005 | ||
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index da34a8e6e..3c9460879 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -30,12 +30,14 @@ | |||
30 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | #include "gnunet_core_service.h" | 31 | #include "gnunet_core_service.h" |
32 | 32 | ||
33 | #define VERBOSE_TESTING GNUNET_NO | 33 | #define VERBOSE_TESTING GNUNET_YES |
34 | 34 | ||
35 | #define VERBOSE_TOPOLOGY GNUNET_YES | 35 | #define VERBOSE_TOPOLOGY GNUNET_YES |
36 | 36 | ||
37 | #define DEBUG_CHURN GNUNET_NO | 37 | #define DEBUG_CHURN GNUNET_NO |
38 | 38 | ||
39 | #define OLD 1 | ||
40 | |||
39 | /** | 41 | /** |
40 | * Lowest port used for GNUnet testing. Should be high enough to not | 42 | * Lowest port used for GNUnet testing. Should be high enough to not |
41 | * conflict with other applications running on the hosts but be low | 43 | * conflict with other applications running on the hosts but be low |
@@ -53,17 +55,35 @@ | |||
53 | 55 | ||
54 | #define MAX_OUTSTANDING_CONNECTIONS 200 | 56 | #define MAX_OUTSTANDING_CONNECTIONS 200 |
55 | 57 | ||
56 | #define MAX_CONCURRENT_HOSTKEYS 200 | 58 | #define MAX_CONCURRENT_HOSTKEYS 500 |
57 | 59 | ||
58 | #define MAX_CONCURRENT_STARTING 200 | 60 | #define MAX_CONCURRENT_STARTING 200 |
59 | 61 | ||
60 | #define MAX_CONCURRENT_SHUTDOWN 100 | 62 | #define MAX_CONCURRENT_SHUTDOWN 200 |
61 | 63 | ||
62 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180) | 64 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180) |
63 | 65 | ||
64 | #define CONNECT_ATTEMPTS 30 | 66 | #define CONNECT_ATTEMPTS 30 |
65 | 67 | ||
66 | /** | 68 | /** |
69 | * Which list of peers do we need to modify? | ||
70 | */ | ||
71 | enum PeerLists | ||
72 | { | ||
73 | /** Modify allowed peers */ | ||
74 | ALLOWED, | ||
75 | |||
76 | /** Modify connect peers */ | ||
77 | CONNECT, | ||
78 | |||
79 | /** Modify blacklist peers */ | ||
80 | BLACKLIST, | ||
81 | |||
82 | /** Modify workingset peers */ | ||
83 | WORKING_SET | ||
84 | }; | ||
85 | |||
86 | /** | ||
67 | * Prototype of a function called whenever two peers would be connected | 87 | * Prototype of a function called whenever two peers would be connected |
68 | * in a certain topology. | 88 | * in a certain topology. |
69 | */ | 89 | */ |
@@ -73,7 +93,8 @@ typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor) (struct | |||
73 | unsigned int | 93 | unsigned int |
74 | first, | 94 | first, |
75 | unsigned int | 95 | unsigned int |
76 | second); | 96 | second, |
97 | enum PeerLists list); | ||
77 | 98 | ||
78 | 99 | ||
79 | /** | 100 | /** |
@@ -244,18 +265,25 @@ enum States | |||
244 | OTHER_PEER_INDEX | 265 | OTHER_PEER_INDEX |
245 | }; | 266 | }; |
246 | 267 | ||
268 | |||
247 | #if OLD | 269 | #if OLD |
248 | struct PeerConnection | 270 | struct PeerConnection |
249 | { | 271 | { |
272 | /** | ||
273 | * Doubly Linked list | ||
274 | */ | ||
275 | struct PeerConnection *prev; | ||
276 | |||
250 | /* | 277 | /* |
251 | * Linked list | 278 | * Doubly Linked list |
252 | */ | 279 | */ |
253 | struct PeerConnection *next; | 280 | struct PeerConnection *next; |
254 | 281 | ||
282 | |||
255 | /* | 283 | /* |
256 | * Pointer to daemon handle | 284 | * Index of daemon in pg->peers |
257 | */ | 285 | */ |
258 | struct GNUNET_TESTING_Daemon *daemon; | 286 | uint32_t index; |
259 | 287 | ||
260 | }; | 288 | }; |
261 | #endif | 289 | #endif |
@@ -356,6 +384,48 @@ struct PeerData | |||
356 | */ | 384 | */ |
357 | struct GNUNET_TESTING_PeerGroup *pg; | 385 | struct GNUNET_TESTING_PeerGroup *pg; |
358 | 386 | ||
387 | #if OLD | ||
388 | /** | ||
389 | * Linked list of allowed peer connections. | ||
390 | */ | ||
391 | struct PeerConnection *allowed_peers_head; | ||
392 | |||
393 | /** | ||
394 | * Linked list of allowed peer connections. | ||
395 | */ | ||
396 | struct PeerConnection *allowed_peers_tail; | ||
397 | |||
398 | /** | ||
399 | * Linked list of blacklisted peer connections. | ||
400 | */ | ||
401 | struct PeerConnection *blacklisted_peers_head; | ||
402 | |||
403 | /** | ||
404 | * Linked list of blacklisted peer connections. | ||
405 | */ | ||
406 | struct PeerConnection *blacklisted_peers_tail; | ||
407 | |||
408 | /** | ||
409 | * Linked list of connect peer connections. | ||
410 | */ | ||
411 | struct PeerConnection *connect_peers_head; | ||
412 | |||
413 | /** | ||
414 | * Linked list of connect peer connections. | ||
415 | */ | ||
416 | struct PeerConnection *connect_peers_tail; | ||
417 | |||
418 | /** | ||
419 | * Linked list of connect peer connections. | ||
420 | */ | ||
421 | struct PeerConnection *connect_peers_working_set_head; | ||
422 | |||
423 | /** | ||
424 | * Linked list of connect peer connections. | ||
425 | */ | ||
426 | struct PeerConnection *connect_peers_working_set_tail; | ||
427 | |||
428 | #else | ||
359 | /** | 429 | /** |
360 | * Hash map of allowed peer connections (F2F created topology) | 430 | * Hash map of allowed peer connections (F2F created topology) |
361 | */ | 431 | */ |
@@ -375,6 +445,7 @@ struct PeerData | |||
375 | * Temporary hash map of peer connections | 445 | * Temporary hash map of peer connections |
376 | */ | 446 | */ |
377 | struct GNUNET_CONTAINER_MultiHashMap *connect_peers_working_set; | 447 | struct GNUNET_CONTAINER_MultiHashMap *connect_peers_working_set; |
448 | #endif | ||
378 | 449 | ||
379 | /** | 450 | /** |
380 | * Temporary variable for topology creation, should be reset before | 451 | * Temporary variable for topology creation, should be reset before |
@@ -563,6 +634,11 @@ struct GNUNET_TESTING_PeerGroup | |||
563 | * How many peers have already been started? | 634 | * How many peers have already been started? |
564 | */ | 635 | */ |
565 | unsigned int started; | 636 | unsigned int started; |
637 | |||
638 | /** | ||
639 | * Hostkeys loaded from a file. | ||
640 | */ | ||
641 | char *hostkey_data; | ||
566 | }; | 642 | }; |
567 | 643 | ||
568 | struct UpdateContext | 644 | struct UpdateContext |
@@ -587,10 +663,11 @@ struct ConnectTopologyContext | |||
587 | */ | 663 | */ |
588 | struct GNUNET_TESTING_PeerGroup *pg; | 664 | struct GNUNET_TESTING_PeerGroup *pg; |
589 | 665 | ||
666 | |||
590 | /** | 667 | /** |
591 | * Temp value set for each iteration. | 668 | * Temp value set for each iteration. |
592 | */ | 669 | */ |
593 | struct PeerData *first; | 670 | //struct PeerData *first; |
594 | 671 | ||
595 | /** | 672 | /** |
596 | * Notification that all peers are connected. | 673 | * Notification that all peers are connected. |
@@ -724,6 +801,7 @@ struct DFSContext | |||
724 | unsigned int current; | 801 | unsigned int current; |
725 | }; | 802 | }; |
726 | 803 | ||
804 | #if !OLD | ||
727 | /** | 805 | /** |
728 | * Convert unique ID to hash code. | 806 | * Convert unique ID to hash code. |
729 | * | 807 | * |
@@ -748,6 +826,7 @@ uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) | |||
748 | { | 826 | { |
749 | memcpy (uid, hash, sizeof (uint32_t)); | 827 | memcpy (uid, hash, sizeof (uint32_t)); |
750 | } | 828 | } |
829 | #endif | ||
751 | 830 | ||
752 | /** | 831 | /** |
753 | * Number of connects we are waiting on, allows us to rate limit | 832 | * Number of connects we are waiting on, allows us to rate limit |
@@ -984,7 +1063,6 @@ update_config (void *cls, | |||
984 | } | 1063 | } |
985 | GNUNET_free (single_variable); | 1064 | GNUNET_free (single_variable); |
986 | GNUNET_free (per_host_variable); | 1065 | GNUNET_free (per_host_variable); |
987 | |||
988 | } | 1066 | } |
989 | 1067 | ||
990 | if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) | 1068 | if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) |
@@ -1049,12 +1127,20 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1049 | 1127 | ||
1050 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", | 1128 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", |
1051 | allowed_hosts); | 1129 | allowed_hosts); |
1130 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", | ||
1131 | ""); | ||
1052 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", | 1132 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", |
1053 | "ACCEPT_FROM", allowed_hosts); | 1133 | "ACCEPT_FROM", allowed_hosts); |
1134 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", | ||
1135 | ""); | ||
1054 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", | 1136 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", |
1055 | allowed_hosts); | 1137 | allowed_hosts); |
1138 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", | ||
1139 | ""); | ||
1056 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", | 1140 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", |
1057 | "ACCEPT_FROM", allowed_hosts); | 1141 | "ACCEPT_FROM", allowed_hosts); |
1142 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", | ||
1143 | ""); | ||
1058 | GNUNET_free_non_null (control_host); | 1144 | GNUNET_free_non_null (control_host); |
1059 | GNUNET_free (allowed_hosts); | 1145 | GNUNET_free (allowed_hosts); |
1060 | } | 1146 | } |
@@ -1088,251 +1174,261 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1088 | return uc.ret; | 1174 | return uc.ret; |
1089 | } | 1175 | } |
1090 | 1176 | ||
1091 | |||
1092 | /* | 1177 | /* |
1093 | * Add entries to the peers connect list | 1178 | * Add entries to the some list |
1094 | * | 1179 | * |
1095 | * @param pg the peer group we are working with | 1180 | * @param pg the peer group we are working with |
1096 | * @param first index of the first peer | 1181 | * @param first index of the first peer |
1097 | * @param second index of the second peer | 1182 | * @param second index of the second peer |
1183 | * @param list the peer list to use | ||
1098 | * | 1184 | * |
1099 | * @return the number of connections added | 1185 | * @return the number of connections added (can be 0, 1 or 2) |
1100 | * technically should only be 0 or 2 | ||
1101 | * | 1186 | * |
1102 | */ | 1187 | */ |
1103 | static unsigned int | 1188 | static unsigned int |
1104 | add_actual_connections (struct GNUNET_TESTING_PeerGroup *pg, | 1189 | remove_connections (struct GNUNET_TESTING_PeerGroup *pg, |
1105 | unsigned int first, unsigned int second) | 1190 | unsigned int first, unsigned int second, |
1191 | enum PeerLists list) | ||
1106 | { | 1192 | { |
1107 | int added; | 1193 | int removed; |
1108 | int add_first; | 1194 | #if OLD |
1109 | int add_second; | 1195 | struct PeerConnection **first_list; |
1196 | struct PeerConnection **second_list; | ||
1197 | struct PeerConnection *first_iter; | ||
1198 | struct PeerConnection *second_iter; | ||
1199 | struct PeerConnection **first_tail; | ||
1200 | struct PeerConnection **second_tail; | ||
1110 | 1201 | ||
1202 | #else | ||
1111 | GNUNET_HashCode hash_first; | 1203 | GNUNET_HashCode hash_first; |
1112 | GNUNET_HashCode hash_second; | 1204 | GNUNET_HashCode hash_second; |
1113 | 1205 | ||
1114 | hash_from_uid (first, &hash_first); | 1206 | hash_from_uid (first, &hash_first); |
1115 | hash_from_uid (second, &hash_second); | 1207 | hash_from_uid (second, &hash_second); |
1208 | #endif | ||
1116 | 1209 | ||
1117 | add_first = GNUNET_NO; | 1210 | removed = 0; |
1118 | if (GNUNET_NO == | 1211 | #if OLD |
1119 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].connect_peers, | 1212 | switch (list) |
1120 | &hash_second)) | 1213 | { |
1214 | case ALLOWED: | ||
1215 | first_list = &pg->peers[first].allowed_peers_head; | ||
1216 | second_list = &pg->peers[second].allowed_peers_head; | ||
1217 | first_tail = &pg->peers[first].allowed_peers_tail; | ||
1218 | second_tail = &pg->peers[second].allowed_peers_tail; | ||
1219 | break; | ||
1220 | case CONNECT: | ||
1221 | first_list = &pg->peers[first].connect_peers_head; | ||
1222 | second_list = &pg->peers[second].connect_peers_head; | ||
1223 | first_tail = &pg->peers[first].connect_peers_tail; | ||
1224 | second_tail = &pg->peers[second].connect_peers_tail; | ||
1225 | break; | ||
1226 | case BLACKLIST: | ||
1227 | first_list = &pg->peers[first].blacklisted_peers_head; | ||
1228 | second_list = &pg->peers[second].blacklisted_peers_head; | ||
1229 | first_tail = &pg->peers[first].blacklisted_peers_tail; | ||
1230 | second_tail = &pg->peers[second].blacklisted_peers_tail; | ||
1231 | break; | ||
1232 | case WORKING_SET: | ||
1233 | first_list = &pg->peers[first].connect_peers_working_set_head; | ||
1234 | second_list = &pg->peers[second].connect_peers_working_set_head; | ||
1235 | first_tail = &pg->peers[first].connect_peers_working_set_tail; | ||
1236 | second_tail = &pg->peers[second].connect_peers_working_set_tail; | ||
1237 | break; | ||
1238 | default: | ||
1239 | GNUNET_break(0); | ||
1240 | } | ||
1241 | |||
1242 | first_iter = *first_list; | ||
1243 | while (first_iter != NULL) | ||
1121 | { | 1244 | { |
1122 | add_first = GNUNET_YES; | 1245 | if (first_iter->index == second) |
1246 | { | ||
1247 | GNUNET_CONTAINER_DLL_remove(*first_list, *first_tail, first_iter); | ||
1248 | GNUNET_free(first_iter); | ||
1249 | removed++; | ||
1250 | break; | ||
1251 | } | ||
1252 | first_iter = first_iter->next; | ||
1123 | } | 1253 | } |
1124 | 1254 | ||
1125 | add_second = GNUNET_NO; | 1255 | second_iter = *second_list; |
1126 | if (GNUNET_NO == | 1256 | while (second_iter != NULL) |
1127 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].connect_peers, | ||
1128 | &hash_first)) | ||
1129 | { | 1257 | { |
1130 | add_second = GNUNET_YES; | 1258 | if (second_iter->index == first) |
1259 | { | ||
1260 | GNUNET_CONTAINER_DLL_remove(*second_list, *second_tail, second_iter); | ||
1261 | GNUNET_free(second_iter); | ||
1262 | removed++; | ||
1263 | break; | ||
1264 | } | ||
1265 | second_iter = second_iter->next; | ||
1131 | } | 1266 | } |
1132 | 1267 | #else | |
1133 | added = 0; | 1268 | if (GNUNET_YES == |
1134 | if (add_first) | 1269 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, |
1270 | &hash_second)) | ||
1135 | { | 1271 | { |
1136 | GNUNET_assert (GNUNET_OK == | 1272 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[first].blacklisted_peers, |
1137 | GNUNET_CONTAINER_multihashmap_put (pg-> | 1273 | &hash_second); |
1138 | peers | ||
1139 | [first].connect_peers, | ||
1140 | &hash_second, | ||
1141 | pg-> | ||
1142 | peers[second].daemon, | ||
1143 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1144 | pg->peers[first].num_connections++; | ||
1145 | added++; | ||
1146 | } | 1274 | } |
1147 | 1275 | ||
1148 | if (add_second) | 1276 | if (GNUNET_YES == |
1277 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, | ||
1278 | &hash_first)) | ||
1149 | { | 1279 | { |
1150 | GNUNET_assert (GNUNET_OK == | 1280 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[second].blacklisted_peers, |
1151 | GNUNET_CONTAINER_multihashmap_put (pg-> | 1281 | &hash_first); |
1152 | peers | ||
1153 | [second].connect_peers, | ||
1154 | &hash_first, | ||
1155 | pg-> | ||
1156 | peers[first].daemon, | ||
1157 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1158 | pg->peers[second].num_connections++; | ||
1159 | added++; | ||
1160 | } | 1282 | } |
1283 | #endif | ||
1161 | 1284 | ||
1162 | return added; | 1285 | return removed; |
1163 | } | 1286 | } |
1164 | 1287 | ||
1165 | |||
1166 | /* | 1288 | /* |
1167 | * Add entries to the peers allowed connections list | 1289 | * Add entries to the some list |
1168 | * | 1290 | * |
1169 | * @param pg the peer group we are working with | 1291 | * @param pg the peer group we are working with |
1170 | * @param first index of the first peer | 1292 | * @param first index of the first peer |
1171 | * @param second index of the second peer | 1293 | * @param second index of the second peer |
1294 | * @param list the list type that we should modify | ||
1172 | * | 1295 | * |
1173 | * @return the number of connections added (can be 0, 1 or 2) | 1296 | * @return the number of connections added (can be 0, 1 or 2) |
1174 | * technically should only be 0 or 2, but the small price | ||
1175 | * of iterating over the lists (hashmaps in the future) | ||
1176 | * for being sure doesn't bother me! | ||
1177 | * | 1297 | * |
1178 | */ | 1298 | */ |
1179 | static unsigned int | 1299 | static unsigned int |
1180 | add_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg, | 1300 | add_connections (struct GNUNET_TESTING_PeerGroup *pg, |
1181 | unsigned int first, unsigned int second) | 1301 | unsigned int first, unsigned int second, |
1302 | enum PeerLists list) | ||
1182 | { | 1303 | { |
1183 | int added; | 1304 | int added; |
1305 | int add_first; | ||
1306 | int add_second; | ||
1184 | #if OLD | 1307 | #if OLD |
1308 | struct PeerConnection **first_list; | ||
1309 | struct PeerConnection **second_list; | ||
1185 | struct PeerConnection *first_iter; | 1310 | struct PeerConnection *first_iter; |
1186 | struct PeerConnection *second_iter; | 1311 | struct PeerConnection *second_iter; |
1187 | struct PeerConnection *new_first; | 1312 | struct PeerConnection *new_first; |
1188 | struct PeerConnection *new_second; | 1313 | struct PeerConnection *new_second; |
1189 | #endif | 1314 | struct PeerConnection **first_tail; |
1190 | int add_first; | 1315 | struct PeerConnection **second_tail; |
1191 | int add_second; | 1316 | #else |
1192 | |||
1193 | GNUNET_HashCode hash_first; | 1317 | GNUNET_HashCode hash_first; |
1194 | GNUNET_HashCode hash_second; | 1318 | GNUNET_HashCode hash_second; |
1195 | 1319 | ||
1196 | hash_from_uid (first, &hash_first); | 1320 | hash_from_uid (first, &hash_first); |
1197 | hash_from_uid (second, &hash_second); | 1321 | hash_from_uid (second, &hash_second); |
1322 | #endif | ||
1198 | 1323 | ||
1199 | add_first = GNUNET_NO; | ||
1200 | if (GNUNET_NO == | ||
1201 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].allowed_peers, | ||
1202 | &hash_second)) | ||
1203 | { | ||
1204 | add_first = GNUNET_YES; | ||
1205 | } | ||
1206 | |||
1207 | add_second = GNUNET_NO; | ||
1208 | if (GNUNET_NO == | ||
1209 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].allowed_peers, | ||
1210 | &hash_first)) | ||
1211 | { | ||
1212 | add_second = GNUNET_YES; | ||
1213 | } | ||
1214 | #if OLD | 1324 | #if OLD |
1215 | first_iter = pg->peers[first].connected_peers; | 1325 | switch (list) |
1326 | { | ||
1327 | case ALLOWED: | ||
1328 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding to ALLOWED\n"); | ||
1329 | first_list = &pg->peers[first].allowed_peers_head; | ||
1330 | second_list = &pg->peers[second].allowed_peers_head; | ||
1331 | first_tail = &pg->peers[first].allowed_peers_tail; | ||
1332 | second_tail = &pg->peers[second].allowed_peers_tail; | ||
1333 | break; | ||
1334 | case CONNECT: | ||
1335 | first_list = &pg->peers[first].connect_peers_head; | ||
1336 | second_list = &pg->peers[second].connect_peers_head; | ||
1337 | first_tail = &pg->peers[first].connect_peers_tail; | ||
1338 | second_tail = &pg->peers[second].connect_peers_tail; | ||
1339 | break; | ||
1340 | case BLACKLIST: | ||
1341 | first_list = &pg->peers[first].blacklisted_peers_head; | ||
1342 | second_list = &pg->peers[second].blacklisted_peers_head; | ||
1343 | first_tail = &pg->peers[first].blacklisted_peers_tail; | ||
1344 | second_tail = &pg->peers[second].blacklisted_peers_tail; | ||
1345 | break; | ||
1346 | case WORKING_SET: | ||
1347 | first_list = &pg->peers[first].connect_peers_working_set_head; | ||
1348 | second_list = &pg->peers[second].connect_peers_working_set_head; | ||
1349 | first_tail = &pg->peers[first].connect_peers_working_set_tail; | ||
1350 | second_tail = &pg->peers[second].connect_peers_working_set_tail; | ||
1351 | break; | ||
1352 | default: | ||
1353 | GNUNET_break(0); | ||
1354 | } | ||
1355 | |||
1356 | add_first = GNUNET_YES; | ||
1357 | add_second = GNUNET_YES; | ||
1358 | |||
1359 | first_iter = *first_list; | ||
1216 | while (first_iter != NULL) | 1360 | while (first_iter != NULL) |
1217 | { | 1361 | { |
1218 | if (first_iter->daemon == pg->peers[second].daemon) | 1362 | if (first_iter->index == second) |
1219 | add_first = GNUNET_NO; | 1363 | { |
1364 | add_first = GNUNET_NO; | ||
1365 | break; | ||
1366 | } | ||
1220 | first_iter = first_iter->next; | 1367 | first_iter = first_iter->next; |
1221 | } | 1368 | } |
1222 | 1369 | ||
1223 | second_iter = pg->peers[second].connected_peers; | 1370 | second_iter = *second_list; |
1224 | add_second = GNUNET_YES; | ||
1225 | while (second_iter != NULL) | 1371 | while (second_iter != NULL) |
1226 | { | 1372 | { |
1227 | if (second_iter->daemon == pg->peers[first].daemon) | 1373 | if (second_iter->index == first) |
1228 | add_second = GNUNET_NO; | 1374 | { |
1375 | add_second = GNUNET_NO; | ||
1376 | break; | ||
1377 | } | ||
1229 | second_iter = second_iter->next; | 1378 | second_iter = second_iter->next; |
1230 | } | 1379 | } |
1231 | #endif | 1380 | #else |
1232 | |||
1233 | added = 0; | ||
1234 | if (add_first) | ||
1235 | { | ||
1236 | GNUNET_assert (GNUNET_OK == | ||
1237 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1238 | peers | ||
1239 | [first].allowed_peers, | ||
1240 | &hash_second, | ||
1241 | pg-> | ||
1242 | peers[second].daemon, | ||
1243 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1244 | #if OLD | ||
1245 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); | ||
1246 | new_first->daemon = pg->peers[second].daemon; | ||
1247 | new_first->next = pg->peers[first].connected_peers; | ||
1248 | pg->peers[first].connected_peers = new_first; | ||
1249 | #endif | ||
1250 | pg->peers[first].num_connections++; | ||
1251 | added++; | ||
1252 | } | ||
1253 | |||
1254 | if (add_second) | ||
1255 | { | ||
1256 | GNUNET_assert (GNUNET_OK == | ||
1257 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1258 | peers | ||
1259 | [second].allowed_peers, | ||
1260 | &hash_first, | ||
1261 | pg-> | ||
1262 | peers[first].daemon, | ||
1263 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1264 | #if OLD | ||
1265 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); | ||
1266 | new_second->daemon = pg->peers[first].daemon; | ||
1267 | new_second->next = pg->peers[second].connected_peers; | ||
1268 | pg->peers[second].connected_peers = new_second; | ||
1269 | pg->peers[first].num_connections++; | ||
1270 | #endif | ||
1271 | pg->peers[second].num_connections++; | ||
1272 | added++; | ||
1273 | } | ||
1274 | |||
1275 | return added; | ||
1276 | } | ||
1277 | |||
1278 | /* | ||
1279 | * Add entries to the peers blacklisted list | ||
1280 | * | ||
1281 | * @param pg the peer group we are working with | ||
1282 | * @param first index of the first peer | ||
1283 | * @param second index of the second peer | ||
1284 | * | ||
1285 | * @return the number of connections added (can be 0, 1 or 2) | ||
1286 | * | ||
1287 | */ | ||
1288 | static unsigned int | ||
1289 | blacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, | ||
1290 | unsigned int first, unsigned int second) | ||
1291 | { | ||
1292 | int added; | ||
1293 | int add_first; | ||
1294 | int add_second; | ||
1295 | GNUNET_HashCode hash_first; | ||
1296 | GNUNET_HashCode hash_second; | ||
1297 | |||
1298 | hash_from_uid (first, &hash_first); | ||
1299 | hash_from_uid (second, &hash_second); | ||
1300 | |||
1301 | add_first = GNUNET_NO; | ||
1302 | if (GNUNET_NO == | 1381 | if (GNUNET_NO == |
1303 | GNUNET_CONTAINER_multihashmap_contains (pg-> | 1382 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, |
1304 | peers[first].blacklisted_peers, | ||
1305 | &hash_second)) | 1383 | &hash_second)) |
1306 | { | 1384 | { |
1307 | add_first = GNUNET_YES; | 1385 | add_first = GNUNET_YES; |
1308 | } | 1386 | } |
1309 | 1387 | ||
1310 | add_second = GNUNET_NO; | ||
1311 | if (GNUNET_NO == | 1388 | if (GNUNET_NO == |
1312 | GNUNET_CONTAINER_multihashmap_contains (pg-> | 1389 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, |
1313 | peers[second].blacklisted_peers, | ||
1314 | &hash_first)) | 1390 | &hash_first)) |
1315 | { | 1391 | { |
1316 | add_second = GNUNET_YES; | 1392 | add_second = GNUNET_YES; |
1317 | } | 1393 | } |
1394 | #endif | ||
1318 | 1395 | ||
1319 | added = 0; | 1396 | added = 0; |
1320 | if (add_first) | 1397 | if (add_first) |
1321 | { | 1398 | { |
1399 | #if OLD | ||
1400 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding peer %d to %d\n", second, first); | ||
1401 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); | ||
1402 | new_first->index = second; | ||
1403 | GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first); | ||
1404 | /* | ||
1405 | new_first->next = *first_list; | ||
1406 | *first_list = new_first;*/ | ||
1407 | #else | ||
1322 | GNUNET_assert (GNUNET_OK == | 1408 | GNUNET_assert (GNUNET_OK == |
1323 | GNUNET_CONTAINER_multihashmap_put (pg-> | 1409 | GNUNET_CONTAINER_multihashmap_put (pg-> |
1324 | peers | 1410 | peers |
1325 | [first].blacklisted_peers, | 1411 | [first].blacklisted_peers, |
1326 | &hash_second, | 1412 | &hash_second, |
1327 | pg-> | 1413 | pg-> |
1328 | peers[second].daemon, | 1414 | peers[second].daemon, |
1329 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1415 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1416 | #endif | ||
1330 | pg->peers[first].num_connections++; | 1417 | pg->peers[first].num_connections++; |
1331 | added++; | 1418 | added++; |
1332 | } | 1419 | } |
1333 | 1420 | ||
1334 | if (add_second) | 1421 | if (add_second) |
1335 | { | 1422 | { |
1423 | #if OLD | ||
1424 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); | ||
1425 | new_second->index = first; | ||
1426 | GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second); | ||
1427 | /* | ||
1428 | new_second->next = *second_list; | ||
1429 | *second_list = new_second; | ||
1430 | *second_list */ | ||
1431 | #else | ||
1336 | GNUNET_assert (GNUNET_OK == | 1432 | GNUNET_assert (GNUNET_OK == |
1337 | GNUNET_CONTAINER_multihashmap_put (pg-> | 1433 | GNUNET_CONTAINER_multihashmap_put (pg-> |
1338 | peers | 1434 | peers |
@@ -1341,6 +1437,7 @@ blacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1341 | pg-> | 1437 | pg-> |
1342 | peers[first].daemon, | 1438 | peers[first].daemon, |
1343 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1439 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1440 | #endif | ||
1344 | pg->peers[second].num_connections++; | 1441 | pg->peers[second].num_connections++; |
1345 | added++; | 1442 | added++; |
1346 | } | 1443 | } |
@@ -1348,67 +1445,6 @@ blacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1348 | return added; | 1445 | return added; |
1349 | } | 1446 | } |
1350 | 1447 | ||
1351 | /* | ||
1352 | * Remove entries from the peers blacklisted list | ||
1353 | * | ||
1354 | * @param pg the peer group we are working with | ||
1355 | * @param first index of the first peer | ||
1356 | * @param second index of the second peer | ||
1357 | * | ||
1358 | * @return the number of connections removed (can be 0, 1 or 2) | ||
1359 | * | ||
1360 | */ | ||
1361 | static unsigned int | ||
1362 | unblacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, | ||
1363 | unsigned int first, unsigned int second) | ||
1364 | { | ||
1365 | int removed; | ||
1366 | int remove_first; | ||
1367 | int remove_second; | ||
1368 | GNUNET_HashCode hash_first; | ||
1369 | GNUNET_HashCode hash_second; | ||
1370 | |||
1371 | hash_from_uid (first, &hash_first); | ||
1372 | hash_from_uid (second, &hash_second); | ||
1373 | |||
1374 | remove_first = | ||
1375 | GNUNET_CONTAINER_multihashmap_contains (pg-> | ||
1376 | peers[first].blacklisted_peers, | ||
1377 | &hash_second); | ||
1378 | remove_second = | ||
1379 | GNUNET_CONTAINER_multihashmap_contains (pg-> | ||
1380 | peers[second].blacklisted_peers, | ||
1381 | &hash_first); | ||
1382 | |||
1383 | removed = 0; | ||
1384 | if (remove_first) | ||
1385 | { | ||
1386 | GNUNET_assert (GNUNET_YES == | ||
1387 | GNUNET_CONTAINER_multihashmap_remove (pg-> | ||
1388 | peers | ||
1389 | [first].blacklisted_peers, | ||
1390 | &hash_second, | ||
1391 | pg-> | ||
1392 | peers | ||
1393 | [second].daemon)); | ||
1394 | removed++; | ||
1395 | } | ||
1396 | |||
1397 | if (remove_second) | ||
1398 | { | ||
1399 | GNUNET_assert (GNUNET_YES == | ||
1400 | GNUNET_CONTAINER_multihashmap_remove (pg-> | ||
1401 | peers | ||
1402 | [second].blacklisted_peers, | ||
1403 | &hash_first, | ||
1404 | pg-> | ||
1405 | peers | ||
1406 | [first].daemon)); | ||
1407 | removed++; | ||
1408 | } | ||
1409 | |||
1410 | return removed; | ||
1411 | } | ||
1412 | 1448 | ||
1413 | /** | 1449 | /** |
1414 | * Scale free network construction as described in: | 1450 | * Scale free network construction as described in: |
@@ -1427,7 +1463,7 @@ unblacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1427 | */ | 1463 | */ |
1428 | static unsigned int | 1464 | static unsigned int |
1429 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | 1465 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, |
1430 | GNUNET_TESTING_ConnectionProcessor proc) | 1466 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1431 | { | 1467 | { |
1432 | 1468 | ||
1433 | unsigned int total_connections; | 1469 | unsigned int total_connections; |
@@ -1440,7 +1476,7 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | |||
1440 | GNUNET_assert (pg->total > 1); | 1476 | GNUNET_assert (pg->total > 1); |
1441 | 1477 | ||
1442 | /* Add a connection between the first two nodes */ | 1478 | /* Add a connection between the first two nodes */ |
1443 | total_connections = proc (pg, 0, 1); | 1479 | total_connections = proc (pg, 0, 1, list); |
1444 | 1480 | ||
1445 | for (outer_count = 1; outer_count < pg->total; outer_count++) | 1481 | for (outer_count = 1; outer_count < pg->total; outer_count++) |
1446 | { | 1482 | { |
@@ -1465,7 +1501,7 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | |||
1465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1466 | "Connecting peer %d to peer %d\n", outer_count, i); | 1502 | "Connecting peer %d to peer %d\n", outer_count, i); |
1467 | #endif | 1503 | #endif |
1468 | total_connections += proc (pg, outer_count, i); | 1504 | total_connections += proc (pg, outer_count, i, list); |
1469 | } | 1505 | } |
1470 | } | 1506 | } |
1471 | } | 1507 | } |
@@ -1501,7 +1537,7 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | |||
1501 | */ | 1537 | */ |
1502 | static unsigned int | 1538 | static unsigned int |
1503 | create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | 1539 | create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, |
1504 | GNUNET_TESTING_ConnectionProcessor proc) | 1540 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1505 | { | 1541 | { |
1506 | unsigned int i, j; | 1542 | unsigned int i, j; |
1507 | int nodeToConnect; | 1543 | int nodeToConnect; |
@@ -1591,7 +1627,7 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1591 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1627 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1592 | pg->total); | 1628 | pg->total); |
1593 | } | 1629 | } |
1594 | smallWorldConnections += proc (pg, i, randomPeer); | 1630 | smallWorldConnections += proc (pg, i, randomPeer, list); |
1595 | } | 1631 | } |
1596 | else | 1632 | else |
1597 | { | 1633 | { |
@@ -1600,7 +1636,7 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1600 | { | 1636 | { |
1601 | nodeToConnect = nodeToConnect - pg->total; | 1637 | nodeToConnect = nodeToConnect - pg->total; |
1602 | } | 1638 | } |
1603 | connect_attempts += proc (pg, i, nodeToConnect); | 1639 | connect_attempts += proc (pg, i, nodeToConnect, list); |
1604 | } | 1640 | } |
1605 | } | 1641 | } |
1606 | 1642 | ||
@@ -1624,7 +1660,7 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1624 | */ | 1660 | */ |
1625 | static unsigned int | 1661 | static unsigned int |
1626 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | 1662 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, |
1627 | GNUNET_TESTING_ConnectionProcessor proc) | 1663 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1628 | { | 1664 | { |
1629 | unsigned int outer_count, inner_count; | 1665 | unsigned int outer_count, inner_count; |
1630 | unsigned int cutoff; | 1666 | unsigned int cutoff; |
@@ -1664,7 +1700,7 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
1664 | "Connecting peer %d to peer %d\n", | 1700 | "Connecting peer %d to peer %d\n", |
1665 | outer_count, inner_count); | 1701 | outer_count, inner_count); |
1666 | #endif | 1702 | #endif |
1667 | connect_attempts += proc (pg, outer_count, inner_count); | 1703 | connect_attempts += proc (pg, outer_count, inner_count, list); |
1668 | } | 1704 | } |
1669 | } | 1705 | } |
1670 | } | 1706 | } |
@@ -1686,7 +1722,7 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
1686 | */ | 1722 | */ |
1687 | static unsigned int | 1723 | static unsigned int |
1688 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | 1724 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, |
1689 | GNUNET_TESTING_ConnectionProcessor proc) | 1725 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1690 | { | 1726 | { |
1691 | unsigned int i, j, k; | 1727 | unsigned int i, j, k; |
1692 | unsigned int square; | 1728 | unsigned int square; |
@@ -1778,7 +1814,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
1778 | else | 1814 | else |
1779 | nodeToConnect = i - cols + 1; | 1815 | nodeToConnect = i - cols + 1; |
1780 | 1816 | ||
1781 | connect_attempts += proc (pg, i, nodeToConnect); | 1817 | connect_attempts += proc (pg, i, nodeToConnect, list); |
1782 | 1818 | ||
1783 | if (i < cols) | 1819 | if (i < cols) |
1784 | nodeToConnect = (rows * cols) - cols + i; | 1820 | nodeToConnect = (rows * cols) - cols + i; |
@@ -1786,7 +1822,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
1786 | nodeToConnect = i - cols; | 1822 | nodeToConnect = i - cols; |
1787 | 1823 | ||
1788 | if (nodeToConnect < pg->total) | 1824 | if (nodeToConnect < pg->total) |
1789 | connect_attempts += proc (pg, i, nodeToConnect); | 1825 | connect_attempts += proc (pg, i, nodeToConnect, list); |
1790 | } | 1826 | } |
1791 | natLog = log (pg->total); | 1827 | natLog = log (pg->total); |
1792 | #if VERBOSE_TESTING > 2 | 1828 | #if VERBOSE_TESTING > 2 |
@@ -1828,7 +1864,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
1828 | ((double) UINT64_MAX); | 1864 | ((double) UINT64_MAX); |
1829 | /* If random < probability, then connect the two nodes */ | 1865 | /* If random < probability, then connect the two nodes */ |
1830 | if (random < probability) | 1866 | if (random < probability) |
1831 | smallWorldConnections += proc (pg, j, k); | 1867 | smallWorldConnections += proc (pg, j, k, list); |
1832 | 1868 | ||
1833 | } | 1869 | } |
1834 | } | 1870 | } |
@@ -1856,7 +1892,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
1856 | */ | 1892 | */ |
1857 | static unsigned int | 1893 | static unsigned int |
1858 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | 1894 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, |
1859 | GNUNET_TESTING_ConnectionProcessor proc) | 1895 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1860 | { | 1896 | { |
1861 | double temp_rand; | 1897 | double temp_rand; |
1862 | unsigned int outer_count; | 1898 | unsigned int outer_count; |
@@ -1895,7 +1931,7 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | |||
1895 | #endif | 1931 | #endif |
1896 | if (temp_rand < probability) | 1932 | if (temp_rand < probability) |
1897 | { | 1933 | { |
1898 | connect_attempts += proc (pg, outer_count, inner_count); | 1934 | connect_attempts += proc (pg, outer_count, inner_count, list); |
1899 | } | 1935 | } |
1900 | } | 1936 | } |
1901 | } | 1937 | } |
@@ -1918,7 +1954,7 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | |||
1918 | */ | 1954 | */ |
1919 | static unsigned int | 1955 | static unsigned int |
1920 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | 1956 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, |
1921 | GNUNET_TESTING_ConnectionProcessor proc) | 1957 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1922 | { | 1958 | { |
1923 | unsigned int i; | 1959 | unsigned int i; |
1924 | unsigned int square; | 1960 | unsigned int square; |
@@ -1970,7 +2006,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
1970 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1971 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2007 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
1972 | #endif | 2008 | #endif |
1973 | connect_attempts += proc (pg, i, nodeToConnect); | 2009 | connect_attempts += proc (pg, i, nodeToConnect, list); |
1974 | 2010 | ||
1975 | /* Second connect to the node immediately above */ | 2011 | /* Second connect to the node immediately above */ |
1976 | if (i < cols) | 2012 | if (i < cols) |
@@ -1984,7 +2020,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
1984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1985 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2021 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
1986 | #endif | 2022 | #endif |
1987 | connect_attempts += proc (pg, i, nodeToConnect); | 2023 | connect_attempts += proc (pg, i, nodeToConnect, list); |
1988 | } | 2024 | } |
1989 | 2025 | ||
1990 | } | 2026 | } |
@@ -2006,7 +2042,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
2006 | */ | 2042 | */ |
2007 | static unsigned int | 2043 | static unsigned int |
2008 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, | 2044 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, |
2009 | GNUNET_TESTING_ConnectionProcessor proc) | 2045 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2010 | { | 2046 | { |
2011 | unsigned int outer_count; | 2047 | unsigned int outer_count; |
2012 | unsigned int inner_count; | 2048 | unsigned int inner_count; |
@@ -2024,13 +2060,14 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, | |||
2024 | "Connecting peer %d to peer %d\n", | 2060 | "Connecting peer %d to peer %d\n", |
2025 | outer_count, inner_count); | 2061 | outer_count, inner_count); |
2026 | #endif | 2062 | #endif |
2027 | connect_attempts += proc (pg, outer_count, inner_count); | 2063 | connect_attempts += proc (pg, outer_count, inner_count, list); |
2028 | } | 2064 | } |
2029 | } | 2065 | } |
2030 | 2066 | ||
2031 | return connect_attempts; | 2067 | return connect_attempts; |
2032 | } | 2068 | } |
2033 | 2069 | ||
2070 | #if !OLD | ||
2034 | /** | 2071 | /** |
2035 | * Iterator over hash map entries. | 2072 | * Iterator over hash map entries. |
2036 | * | 2073 | * |
@@ -2056,6 +2093,7 @@ unblacklist_iterator (void *cls, | |||
2056 | 2093 | ||
2057 | return GNUNET_YES; | 2094 | return GNUNET_YES; |
2058 | } | 2095 | } |
2096 | #endif | ||
2059 | 2097 | ||
2060 | /** | 2098 | /** |
2061 | * Create a blacklist topology based on the allowed topology | 2099 | * Create a blacklist topology based on the allowed topology |
@@ -2076,13 +2114,24 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2076 | struct UnblacklistContext un_ctx; | 2114 | struct UnblacklistContext un_ctx; |
2077 | unsigned int count; | 2115 | unsigned int count; |
2078 | unsigned int total; | 2116 | unsigned int total; |
2117 | struct PeerConnection *iter; | ||
2079 | 2118 | ||
2080 | un_ctx.pg = pg; | 2119 | un_ctx.pg = pg; |
2081 | total = 0; | 2120 | total = 0; |
2082 | for (count = 0; count < pg->total - 1; count++) | 2121 | for (count = 0; count < pg->total - 1; count++) |
2083 | { | 2122 | { |
2084 | un_ctx.first_uid = count; | 2123 | un_ctx.first_uid = count; |
2124 | #if OLD | ||
2125 | iter = pg->peers[count].allowed_peers_head; | ||
2126 | while (iter != NULL) | ||
2127 | { | ||
2128 | remove_connections(pg, count, iter->index, BLACKLIST); | ||
2129 | //unblacklist_connections(pg, count, iter->index); | ||
2130 | iter = iter->next; | ||
2131 | } | ||
2132 | #else | ||
2085 | total += GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers, &unblacklist_iterator, &un_ctx); | 2133 | total += GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers, &unblacklist_iterator, &un_ctx); |
2134 | #endif | ||
2086 | } | 2135 | } |
2087 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total); | 2136 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total); |
2088 | return total; | 2137 | return total; |
@@ -2095,13 +2144,14 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2095 | * @param pg the peergroup to create the topology on | 2144 | * @param pg the peergroup to create the topology on |
2096 | * @param proc the connection processor to call to actually set | 2145 | * @param proc the connection processor to call to actually set |
2097 | * up connections between two peers | 2146 | * up connections between two peers |
2147 | * @param list which list should be modified | ||
2098 | * | 2148 | * |
2099 | * @return the number of connections that were set up | 2149 | * @return the number of connections that were set up |
2100 | * | 2150 | * |
2101 | */ | 2151 | */ |
2102 | static unsigned int | 2152 | static unsigned int |
2103 | create_line (struct GNUNET_TESTING_PeerGroup *pg, | 2153 | create_line (struct GNUNET_TESTING_PeerGroup *pg, |
2104 | GNUNET_TESTING_ConnectionProcessor proc) | 2154 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2105 | { | 2155 | { |
2106 | unsigned int count; | 2156 | unsigned int count; |
2107 | int connect_attempts; | 2157 | int connect_attempts; |
@@ -2115,7 +2165,7 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, | |||
2115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2116 | "Connecting peer %d to peer %d\n", count, count + 1); | 2166 | "Connecting peer %d to peer %d\n", count, count + 1); |
2117 | #endif | 2167 | #endif |
2118 | connect_attempts += proc (pg, count, count + 1); | 2168 | connect_attempts += proc (pg, count, count + 1, list); |
2119 | } | 2169 | } |
2120 | 2170 | ||
2121 | return connect_attempts; | 2171 | return connect_attempts; |
@@ -2136,7 +2186,7 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, | |||
2136 | static unsigned int | 2186 | static unsigned int |
2137 | create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | 2187 | create_from_file (struct GNUNET_TESTING_PeerGroup *pg, |
2138 | char *filename, | 2188 | char *filename, |
2139 | GNUNET_TESTING_ConnectionProcessor proc) | 2189 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2140 | { | 2190 | { |
2141 | int connect_attempts; | 2191 | int connect_attempts; |
2142 | unsigned int first_peer_index; | 2192 | unsigned int first_peer_index; |
@@ -2225,7 +2275,7 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2225 | return connect_attempts; | 2275 | return connect_attempts; |
2226 | } | 2276 | } |
2227 | /* Assume file is written with first peer 1, but array index is 0 */ | 2277 | /* Assume file is written with first peer 1, but array index is 0 */ |
2228 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index - 1); | 2278 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index - 1, list); |
2229 | while((buf[count] != '\n') && (buf[count] != ',') && (count < frstat.st_size - 1)) | 2279 | while((buf[count] != '\n') && (buf[count] != ',') && (count < frstat.st_size - 1)) |
2230 | count++; | 2280 | count++; |
2231 | if (buf[count] == '\n') | 2281 | if (buf[count] == '\n') |
@@ -2272,7 +2322,7 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2272 | */ | 2322 | */ |
2273 | static unsigned int | 2323 | static unsigned int |
2274 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, | 2324 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, |
2275 | GNUNET_TESTING_ConnectionProcessor proc) | 2325 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2276 | { | 2326 | { |
2277 | unsigned int count; | 2327 | unsigned int count; |
2278 | int connect_attempts; | 2328 | int connect_attempts; |
@@ -2286,16 +2336,16 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
2286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2287 | "Connecting peer %d to peer %d\n", count, count + 1); | 2337 | "Connecting peer %d to peer %d\n", count, count + 1); |
2288 | #endif | 2338 | #endif |
2289 | connect_attempts += proc (pg, count, count + 1); | 2339 | connect_attempts += proc (pg, count, count + 1, list); |
2290 | } | 2340 | } |
2291 | 2341 | ||
2292 | /* Connect the last peer to the first peer */ | 2342 | /* Connect the last peer to the first peer */ |
2293 | connect_attempts += proc (pg, pg->total - 1, 0); | 2343 | connect_attempts += proc (pg, pg->total - 1, 0, list); |
2294 | 2344 | ||
2295 | return connect_attempts; | 2345 | return connect_attempts; |
2296 | } | 2346 | } |
2297 | 2347 | ||
2298 | 2348 | #if !OLD | |
2299 | /** | 2349 | /** |
2300 | * Iterator for writing friends of a peer to a file. | 2350 | * Iterator for writing friends of a peer to a file. |
2301 | * | 2351 | * |
@@ -2366,6 +2416,8 @@ blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
2366 | 2416 | ||
2367 | return GNUNET_YES; | 2417 | return GNUNET_YES; |
2368 | } | 2418 | } |
2419 | #endif | ||
2420 | |||
2369 | 2421 | ||
2370 | /* | 2422 | /* |
2371 | * Create the friend files based on the PeerConnection's | 2423 | * Create the friend files based on the PeerConnection's |
@@ -2388,7 +2440,10 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2388 | int count; | 2440 | int count; |
2389 | int ret; | 2441 | int ret; |
2390 | int max_wait = 10; | 2442 | int max_wait = 10; |
2391 | 2443 | #if OLD | |
2444 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | ||
2445 | struct PeerConnection *conn_iter; | ||
2446 | #endif | ||
2392 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); | 2447 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
2393 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2448 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2394 | { | 2449 | { |
@@ -2396,9 +2451,19 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2396 | GNUNET_assert (mytemp != NULL); | 2451 | GNUNET_assert (mytemp != NULL); |
2397 | temp_friend_handle = fopen (mytemp, "wt"); | 2452 | temp_friend_handle = fopen (mytemp, "wt"); |
2398 | GNUNET_assert (temp_friend_handle != NULL); | 2453 | GNUNET_assert (temp_friend_handle != NULL); |
2454 | #if OLD | ||
2455 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | ||
2456 | while (conn_iter != NULL) | ||
2457 | { | ||
2458 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->id.hashPubKey, &peer_enc); | ||
2459 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | ||
2460 | conn_iter = conn_iter->next; | ||
2461 | } | ||
2462 | #else | ||
2399 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, | 2463 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
2400 | &friend_file_iterator, | 2464 | &friend_file_iterator, |
2401 | temp_friend_handle); | 2465 | temp_friend_handle); |
2466 | #endif | ||
2402 | fclose (temp_friend_handle); | 2467 | fclose (temp_friend_handle); |
2403 | 2468 | ||
2404 | if (GNUNET_OK != | 2469 | if (GNUNET_OK != |
@@ -2521,7 +2586,6 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
2521 | const char *transports) | 2586 | const char *transports) |
2522 | { | 2587 | { |
2523 | FILE *temp_file_handle; | 2588 | FILE *temp_file_handle; |
2524 | static struct BlacklistContext blacklist_ctx; | ||
2525 | unsigned int pg_iter; | 2589 | unsigned int pg_iter; |
2526 | char *temp_service_path; | 2590 | char *temp_service_path; |
2527 | struct GNUNET_OS_Process **procarr; | 2591 | struct GNUNET_OS_Process **procarr; |
@@ -2537,6 +2601,12 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
2537 | char *pos; | 2601 | char *pos; |
2538 | char *temp_transports; | 2602 | char *temp_transports; |
2539 | int entry_count; | 2603 | int entry_count; |
2604 | #if OLD | ||
2605 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | ||
2606 | struct PeerConnection *conn_iter; | ||
2607 | #else | ||
2608 | static struct BlacklistContext blacklist_ctx; | ||
2609 | #endif | ||
2540 | 2610 | ||
2541 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); | 2611 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
2542 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2612 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
@@ -2546,7 +2616,9 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
2546 | temp_file_handle = fopen (mytemp, "wt"); | 2616 | temp_file_handle = fopen (mytemp, "wt"); |
2547 | GNUNET_assert (temp_file_handle != NULL); | 2617 | GNUNET_assert (temp_file_handle != NULL); |
2548 | temp_transports = GNUNET_strdup (transports); | 2618 | temp_transports = GNUNET_strdup (transports); |
2619 | #if !OLD | ||
2549 | blacklist_ctx.temp_file_handle = temp_file_handle; | 2620 | blacklist_ctx.temp_file_handle = temp_file_handle; |
2621 | #endif | ||
2550 | transport_len = strlen (temp_transports) + 1; | 2622 | transport_len = strlen (temp_transports) + 1; |
2551 | pos = NULL; | 2623 | pos = NULL; |
2552 | 2624 | ||
@@ -2557,12 +2629,23 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
2557 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ | 2629 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ |
2558 | { | 2630 | { |
2559 | temp_transports[i] = '\0'; | 2631 | temp_transports[i] = '\0'; |
2632 | #if OLD | ||
2633 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; | ||
2634 | while (conn_iter != NULL) | ||
2635 | { | ||
2636 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->id.hashPubKey, &peer_enc); | ||
2637 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); | ||
2638 | conn_iter = conn_iter->next; | ||
2639 | entry_count++; | ||
2640 | } | ||
2641 | #else | ||
2560 | blacklist_ctx.transport = pos; | 2642 | blacklist_ctx.transport = pos; |
2561 | entry_count = GNUNET_CONTAINER_multihashmap_iterate (pg-> | 2643 | entry_count = GNUNET_CONTAINER_multihashmap_iterate (pg-> |
2562 | peers | 2644 | peers |
2563 | [pg_iter].blacklisted_peers, | 2645 | [pg_iter].blacklisted_peers, |
2564 | &blacklist_file_iterator, | 2646 | &blacklist_file_iterator, |
2565 | &blacklist_ctx); | 2647 | &blacklist_ctx); |
2648 | #endif | ||
2566 | pos = NULL; | 2649 | pos = NULL; |
2567 | } /* At beginning of actual string */ | 2650 | } /* At beginning of actual string */ |
2568 | else if (pos == NULL) | 2651 | else if (pos == NULL) |
@@ -2758,7 +2841,7 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2758 | } | 2841 | } |
2759 | } | 2842 | } |
2760 | 2843 | ||
2761 | 2844 | #if !OLD | |
2762 | /** | 2845 | /** |
2763 | * Iterator for actually scheduling connections to be created | 2846 | * Iterator for actually scheduling connections to be created |
2764 | * between two peers. | 2847 | * between two peers. |
@@ -2785,8 +2868,9 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
2785 | 2868 | ||
2786 | return GNUNET_YES; | 2869 | return GNUNET_YES; |
2787 | } | 2870 | } |
2871 | #endif | ||
2788 | 2872 | ||
2789 | 2873 | #if !OLD | |
2790 | /** | 2874 | /** |
2791 | * Iterator for copying all entries in the allowed hashmap to the | 2875 | * Iterator for copying all entries in the allowed hashmap to the |
2792 | * connect hashmap. | 2876 | * connect hashmap. |
@@ -2809,6 +2893,7 @@ copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
2809 | 2893 | ||
2810 | return GNUNET_YES; | 2894 | return GNUNET_YES; |
2811 | } | 2895 | } |
2896 | #endif | ||
2812 | 2897 | ||
2813 | /** | 2898 | /** |
2814 | * Make the peers to connect the same as those that are allowed to be | 2899 | * Make the peers to connect the same as those that are allowed to be |
@@ -2822,15 +2907,29 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
2822 | unsigned int pg_iter; | 2907 | unsigned int pg_iter; |
2823 | int ret; | 2908 | int ret; |
2824 | int total; | 2909 | int total; |
2825 | 2910 | #if OLD | |
2911 | struct PeerConnection *iter; | ||
2912 | #endif | ||
2826 | total = 0; | 2913 | total = 0; |
2914 | ret = 0; | ||
2827 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2915 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2828 | { | 2916 | { |
2917 | #if OLD | ||
2918 | iter = pg->peers[pg_iter].allowed_peers_head; | ||
2919 | while (iter != NULL) | ||
2920 | { | ||
2921 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating connection between %d and %d\n", pg_iter, iter->index); | ||
2922 | total += add_connections(pg, pg_iter, iter->index, CONNECT); | ||
2923 | //total += add_actual_connections(pg, pg_iter, iter->index); | ||
2924 | iter = iter->next; | ||
2925 | } | ||
2926 | #else | ||
2829 | ret = | 2927 | ret = |
2830 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | 2928 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
2831 | peers[pg_iter].allowed_peers, | 2929 | peers[pg_iter].allowed_peers, |
2832 | ©_topology_iterator, | 2930 | ©_topology_iterator, |
2833 | &pg->peers[pg_iter]); | 2931 | &pg->peers[pg_iter]); |
2932 | #endif | ||
2834 | if (GNUNET_SYSERR == ret) | 2933 | if (GNUNET_SYSERR == ret) |
2835 | return GNUNET_SYSERR; | 2934 | return GNUNET_SYSERR; |
2836 | 2935 | ||
@@ -2857,12 +2956,13 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2857 | void *notify_cls) | 2956 | void *notify_cls) |
2858 | { | 2957 | { |
2859 | unsigned int pg_iter; | 2958 | unsigned int pg_iter; |
2860 | int ret; | ||
2861 | unsigned int total; | 2959 | unsigned int total; |
2862 | struct ConnectTopologyContext *ct_ctx; | 2960 | struct ConnectTopologyContext *ct_ctx; |
2863 | #if OLD | 2961 | #if OLD |
2864 | struct PeerConnection *connection_iter; | 2962 | struct PeerConnection *connection_iter; |
2865 | struct ConnectContext *connect_context; | 2963 | struct ConnectContext *connect_context; |
2964 | #else | ||
2965 | int ret; | ||
2866 | #endif | 2966 | #endif |
2867 | 2967 | ||
2868 | total = 0; | 2968 | total = 0; |
@@ -2873,8 +2973,17 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2873 | 2973 | ||
2874 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2974 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2875 | { | 2975 | { |
2976 | #if OLD | ||
2977 | connection_iter = pg->peers[pg_iter].connect_peers_head; | ||
2978 | while (connection_iter != NULL) | ||
2979 | { | ||
2980 | connection_iter = connection_iter->next; | ||
2981 | total++; | ||
2982 | } | ||
2983 | #else | ||
2876 | total += | 2984 | total += |
2877 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | 2985 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); |
2986 | #endif | ||
2878 | } | 2987 | } |
2879 | 2988 | ||
2880 | if (total == 0) | 2989 | if (total == 0) |
@@ -2887,25 +2996,26 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2887 | 2996 | ||
2888 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2997 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2889 | { | 2998 | { |
2890 | ct_ctx->first = &pg->peers[pg_iter]; | ||
2891 | ret = | ||
2892 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
2893 | peers[pg_iter].connect_peers, | ||
2894 | &connect_iterator, ct_ctx); | ||
2895 | GNUNET_assert (GNUNET_SYSERR != ret && ret >= 0); | ||
2896 | total = total + ret; | ||
2897 | |||
2898 | #if OLD | 2999 | #if OLD |
2899 | connection_iter = FIXME; | 3000 | connection_iter = pg->peers[pg_iter].connect_peers_head; |
2900 | while (connection_iter != NULL) | 3001 | while (connection_iter != NULL) |
2901 | { | 3002 | { |
3003 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling connect of peer %d to peer %d\n", pg_iter, connection_iter->index); | ||
2902 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); | 3004 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
2903 | connect_context->pg = pg; | 3005 | connect_context->first = pg->peers[pg_iter].daemon; |
2904 | connect_context->first = FIXME; | 3006 | connect_context->second = pg->peers[connection_iter->index].daemon; |
2905 | connect_context->second = connection_iter->daemon; | 3007 | connect_context->ct_ctx = ct_ctx; |
2906 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); | 3008 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
2907 | connection_iter = connection_iter->next; | 3009 | connection_iter = connection_iter->next; |
3010 | total++; | ||
2908 | } | 3011 | } |
3012 | #else | ||
3013 | ret = | ||
3014 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
3015 | peers[pg_iter].connect_peers, | ||
3016 | &connect_iterator, ct_ctx); | ||
3017 | GNUNET_assert (GNUNET_SYSERR != ret && ret >= 0); | ||
3018 | total = total + ret; | ||
2909 | #endif | 3019 | #endif |
2910 | } | 3020 | } |
2911 | return total; | 3021 | return total; |
@@ -2941,17 +3051,32 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2941 | const char *restrict_transports) | 3051 | const char *restrict_transports) |
2942 | { | 3052 | { |
2943 | int ret; | 3053 | int ret; |
3054 | |||
2944 | unsigned int num_connections; | 3055 | unsigned int num_connections; |
2945 | int unblacklisted_connections; | 3056 | int unblacklisted_connections; |
2946 | char *filename; | 3057 | char *filename; |
2947 | 3058 | ||
3059 | #if !OLD | ||
3060 | unsigned int i; | ||
3061 | for (i = 0; i < pg->total; i++) | ||
3062 | { | ||
3063 | pg->peers[i].allowed_peers = | ||
3064 | GNUNET_CONTAINER_multihashmap_create (100); | ||
3065 | pg->peers[i].connect_peers = | ||
3066 | GNUNET_CONTAINER_multihashmap_create (100); | ||
3067 | pg->peers[i].blacklisted_peers = | ||
3068 | GNUNET_CONTAINER_multihashmap_create (100); | ||
3069 | pg->peers[i].pg = pg; | ||
3070 | } | ||
3071 | #endif | ||
3072 | |||
2948 | switch (topology) | 3073 | switch (topology) |
2949 | { | 3074 | { |
2950 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 3075 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
2951 | #if VERBOSE_TESTING | 3076 | #if VERBOSE_TESTING |
2952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); | 3077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); |
2953 | #endif | 3078 | #endif |
2954 | num_connections = create_clique (pg, &add_allowed_connections); | 3079 | num_connections = create_clique (pg, &add_connections, ALLOWED); |
2955 | break; | 3080 | break; |
2956 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 3081 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
2957 | #if VERBOSE_TESTING | 3082 | #if VERBOSE_TESTING |
@@ -2959,53 +3084,53 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2959 | _("Creating small world (ring) topology\n")); | 3084 | _("Creating small world (ring) topology\n")); |
2960 | #endif | 3085 | #endif |
2961 | num_connections = | 3086 | num_connections = |
2962 | create_small_world_ring (pg, &add_allowed_connections); | 3087 | create_small_world_ring (pg, &add_connections, ALLOWED); |
2963 | break; | 3088 | break; |
2964 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 3089 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
2965 | #if VERBOSE_TESTING | 3090 | #if VERBOSE_TESTING |
2966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2967 | _("Creating small world (2d-torus) topology\n")); | 3092 | _("Creating small world (2d-torus) topology\n")); |
2968 | #endif | 3093 | #endif |
2969 | num_connections = create_small_world (pg, &add_allowed_connections); | 3094 | num_connections = create_small_world (pg, &add_connections, ALLOWED); |
2970 | break; | 3095 | break; |
2971 | case GNUNET_TESTING_TOPOLOGY_RING: | 3096 | case GNUNET_TESTING_TOPOLOGY_RING: |
2972 | #if VERBOSE_TESTING | 3097 | #if VERBOSE_TESTING |
2973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring topology\n")); | 3098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring topology\n")); |
2974 | #endif | 3099 | #endif |
2975 | num_connections = create_ring (pg, &add_allowed_connections); | 3100 | num_connections = create_ring (pg, &add_connections, ALLOWED); |
2976 | break; | 3101 | break; |
2977 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 3102 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
2978 | #if VERBOSE_TESTING | 3103 | #if VERBOSE_TESTING |
2979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating 2d torus topology\n")); | 3104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating 2d torus topology\n")); |
2980 | #endif | 3105 | #endif |
2981 | num_connections = create_2d_torus (pg, &add_allowed_connections); | 3106 | num_connections = create_2d_torus (pg, &add_connections, ALLOWED); |
2982 | break; | 3107 | break; |
2983 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 3108 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
2984 | #if VERBOSE_TESTING | 3109 | #if VERBOSE_TESTING |
2985 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2986 | _("Creating Erdos-Renyi topology\n")); | 3111 | _("Creating Erdos-Renyi topology\n")); |
2987 | #endif | 3112 | #endif |
2988 | num_connections = create_erdos_renyi (pg, &add_allowed_connections); | 3113 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); |
2989 | break; | 3114 | break; |
2990 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 3115 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
2991 | #if VERBOSE_TESTING | 3116 | #if VERBOSE_TESTING |
2992 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating InterNAT topology\n")); | 3117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating InterNAT topology\n")); |
2993 | #endif | 3118 | #endif |
2994 | num_connections = create_nated_internet (pg, &add_allowed_connections); | 3119 | num_connections = create_nated_internet (pg, &add_connections, ALLOWED); |
2995 | break; | 3120 | break; |
2996 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 3121 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
2997 | #if VERBOSE_TESTING | 3122 | #if VERBOSE_TESTING |
2998 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2999 | _("Creating Scale Free topology\n")); | 3124 | _("Creating Scale Free topology\n")); |
3000 | #endif | 3125 | #endif |
3001 | num_connections = create_scale_free (pg, &add_allowed_connections); | 3126 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); |
3002 | break; | 3127 | break; |
3003 | case GNUNET_TESTING_TOPOLOGY_LINE: | 3128 | case GNUNET_TESTING_TOPOLOGY_LINE: |
3004 | #if VERBOSE_TESTING | 3129 | #if VERBOSE_TESTING |
3005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3006 | _("Creating straight line topology\n")); | 3131 | _("Creating straight line topology\n")); |
3007 | #endif | 3132 | #endif |
3008 | num_connections = create_line (pg, &add_allowed_connections); | 3133 | num_connections = create_line (pg, &add_connections, ALLOWED); |
3009 | break; | 3134 | break; |
3010 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | 3135 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: |
3011 | #if VERBOSE_TESTING | 3136 | #if VERBOSE_TESTING |
@@ -3015,7 +3140,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3015 | if (GNUNET_OK == | 3140 | if (GNUNET_OK == |
3016 | GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", "topology_file", | 3141 | GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", "topology_file", |
3017 | &filename)) | 3142 | &filename)) |
3018 | num_connections = create_from_file (pg, filename, &add_allowed_connections); | 3143 | num_connections = create_from_file (pg, filename, &add_connections, ALLOWED); |
3019 | else | 3144 | else |
3020 | { | 3145 | { |
3021 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!"); | 3146 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!"); |
@@ -3057,7 +3182,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3057 | } | 3182 | } |
3058 | 3183 | ||
3059 | /* Use the create clique method to initially set all connections as blacklisted. */ | 3184 | /* Use the create clique method to initially set all connections as blacklisted. */ |
3060 | create_clique (pg, &blacklist_connections); | 3185 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology != GNUNET_TESTING_TOPOLOGY_FROM_FILE)) |
3186 | create_clique (pg, &add_connections, BLACKLIST); | ||
3061 | 3187 | ||
3062 | unblacklisted_connections = 0; | 3188 | unblacklisted_connections = 0; |
3063 | /* Un-blacklist connections as per the topology specified */ | 3189 | /* Un-blacklist connections as per the topology specified */ |
@@ -3069,7 +3195,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3069 | _("Blacklisting all but clique topology\n")); | 3195 | _("Blacklisting all but clique topology\n")); |
3070 | #endif | 3196 | #endif |
3071 | unblacklisted_connections = | 3197 | unblacklisted_connections = |
3072 | create_clique (pg, &unblacklist_connections); | 3198 | create_clique (pg, &remove_connections, BLACKLIST); |
3073 | break; | 3199 | break; |
3074 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 3200 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
3075 | #if VERBOSE_TESTING | 3201 | #if VERBOSE_TESTING |
@@ -3077,7 +3203,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3077 | _("Blacklisting all but small world (ring) topology\n")); | 3203 | _("Blacklisting all but small world (ring) topology\n")); |
3078 | #endif | 3204 | #endif |
3079 | unblacklisted_connections = | 3205 | unblacklisted_connections = |
3080 | create_small_world_ring (pg, &unblacklist_connections); | 3206 | create_small_world_ring (pg, &remove_connections, BLACKLIST); |
3081 | break; | 3207 | break; |
3082 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 3208 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
3083 | #if VERBOSE_TESTING | 3209 | #if VERBOSE_TESTING |
@@ -3086,14 +3212,14 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3086 | ("Blacklisting all but small world (2d-torus) topology\n")); | 3212 | ("Blacklisting all but small world (2d-torus) topology\n")); |
3087 | #endif | 3213 | #endif |
3088 | unblacklisted_connections = | 3214 | unblacklisted_connections = |
3089 | create_small_world (pg, &unblacklist_connections); | 3215 | create_small_world (pg, &remove_connections, BLACKLIST); |
3090 | break; | 3216 | break; |
3091 | case GNUNET_TESTING_TOPOLOGY_RING: | 3217 | case GNUNET_TESTING_TOPOLOGY_RING: |
3092 | #if VERBOSE_TESTING | 3218 | #if VERBOSE_TESTING |
3093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3094 | _("Blacklisting all but ring topology\n")); | 3220 | _("Blacklisting all but ring topology\n")); |
3095 | #endif | 3221 | #endif |
3096 | unblacklisted_connections = create_ring (pg, &unblacklist_connections); | 3222 | unblacklisted_connections = create_ring (pg, &remove_connections, BLACKLIST); |
3097 | break; | 3223 | break; |
3098 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 3224 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
3099 | #if VERBOSE_TESTING | 3225 | #if VERBOSE_TESTING |
@@ -3101,7 +3227,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3101 | _("Blacklisting all but 2d torus topology\n")); | 3227 | _("Blacklisting all but 2d torus topology\n")); |
3102 | #endif | 3228 | #endif |
3103 | unblacklisted_connections = | 3229 | unblacklisted_connections = |
3104 | create_2d_torus (pg, &unblacklist_connections); | 3230 | create_2d_torus (pg, &remove_connections, BLACKLIST); |
3105 | break; | 3231 | break; |
3106 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 3232 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
3107 | #if VERBOSE_TESTING | 3233 | #if VERBOSE_TESTING |
@@ -3109,7 +3235,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3109 | _("Blacklisting all but Erdos-Renyi topology\n")); | 3235 | _("Blacklisting all but Erdos-Renyi topology\n")); |
3110 | #endif | 3236 | #endif |
3111 | unblacklisted_connections = | 3237 | unblacklisted_connections = |
3112 | create_erdos_renyi (pg, &unblacklist_connections); | 3238 | create_erdos_renyi (pg, &remove_connections, BLACKLIST); |
3113 | break; | 3239 | break; |
3114 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 3240 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
3115 | #if VERBOSE_TESTING | 3241 | #if VERBOSE_TESTING |
@@ -3117,7 +3243,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3117 | _("Blacklisting all but InterNAT topology\n")); | 3243 | _("Blacklisting all but InterNAT topology\n")); |
3118 | #endif | 3244 | #endif |
3119 | unblacklisted_connections = | 3245 | unblacklisted_connections = |
3120 | create_nated_internet (pg, &unblacklist_connections); | 3246 | create_nated_internet (pg, &remove_connections, BLACKLIST); |
3121 | break; | 3247 | break; |
3122 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 3248 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
3123 | #if VERBOSE_TESTING | 3249 | #if VERBOSE_TESTING |
@@ -3125,16 +3251,16 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3125 | _("Blacklisting all but Scale Free topology\n")); | 3251 | _("Blacklisting all but Scale Free topology\n")); |
3126 | #endif | 3252 | #endif |
3127 | unblacklisted_connections = | 3253 | unblacklisted_connections = |
3128 | create_scale_free (pg, &unblacklist_connections); | 3254 | create_scale_free (pg, &remove_connections, BLACKLIST); |
3129 | break; | 3255 | break; |
3130 | case GNUNET_TESTING_TOPOLOGY_LINE: | 3256 | case GNUNET_TESTING_TOPOLOGY_LINE: |
3131 | #if VERBOSE_TESTING | 3257 | #if VERBOSE_TESTING |
3132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3133 | _("Blacklisting all but straight line topology\n")); | 3259 | _("Blacklisting all but straight line topology\n")); |
3134 | #endif | 3260 | #endif |
3135 | unblacklisted_connections = create_line (pg, &unblacklist_connections); | 3261 | unblacklisted_connections = create_line (pg, &remove_connections, BLACKLIST); |
3136 | break; | 3262 | break; |
3137 | case GNUNET_TESTING_TOPOLOGY_NONE: | 3263 | case GNUNET_TESTING_TOPOLOGY_NONE: /* Fall through */ |
3138 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | 3264 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: |
3139 | #if VERBOSE_TESTING | 3265 | #if VERBOSE_TESTING |
3140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -3144,14 +3270,14 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3145 | _ | 3271 | _ |
3146 | ("Creating blacklist topology from allowed\n")); | 3272 | ("Creating blacklist topology from allowed\n")); |
3147 | unblacklisted_connections = copy_allowed (pg, &unblacklist_connections); | 3273 | unblacklisted_connections = copy_allowed (pg, &remove_connections); |
3148 | default: | 3274 | default: |
3149 | break; | 3275 | break; |
3150 | } | 3276 | } |
3151 | 3277 | ||
3152 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) | 3278 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) |
3153 | { | 3279 | { |
3154 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'", restrict_transports); | 3280 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", restrict_transports); |
3155 | ret = create_and_copy_blacklist_files (pg, restrict_transports); | 3281 | ret = create_and_copy_blacklist_files (pg, restrict_transports); |
3156 | if (ret != GNUNET_OK) | 3282 | if (ret != GNUNET_OK) |
3157 | { | 3283 | { |
@@ -3173,6 +3299,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3173 | } | 3299 | } |
3174 | 3300 | ||
3175 | 3301 | ||
3302 | #if !OLD | ||
3176 | /** | 3303 | /** |
3177 | * Iterator for choosing random peers to connect. | 3304 | * Iterator for choosing random peers to connect. |
3178 | * | 3305 | * |
@@ -3201,6 +3328,7 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3201 | key, value, | 3328 | key, value, |
3202 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3329 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3203 | } | 3330 | } |
3331 | |||
3204 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ | 3332 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ |
3205 | uid_from_hash (key, &second_pos); | 3333 | uid_from_hash (key, &second_pos); |
3206 | hash_from_uid (random_ctx->first_uid, &first_hash); | 3334 | hash_from_uid (random_ctx->first_uid, &first_hash); |
@@ -3216,6 +3344,7 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3216 | return GNUNET_YES; | 3344 | return GNUNET_YES; |
3217 | } | 3345 | } |
3218 | 3346 | ||
3347 | |||
3219 | /** | 3348 | /** |
3220 | * Iterator for adding at least X peers to a peers connection set. | 3349 | * Iterator for adding at least X peers to a peers connection set. |
3221 | * | 3350 | * |
@@ -3318,7 +3447,7 @@ dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3318 | dfs_ctx->current++; | 3447 | dfs_ctx->current++; |
3319 | return GNUNET_YES; | 3448 | return GNUNET_YES; |
3320 | } | 3449 | } |
3321 | 3450 | #endif | |
3322 | 3451 | ||
3323 | /** | 3452 | /** |
3324 | * From the set of connections possible, choose percentage percent of connections | 3453 | * From the set of connections possible, choose percentage percent of connections |
@@ -3333,6 +3462,11 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
3333 | { | 3462 | { |
3334 | struct RandomContext random_ctx; | 3463 | struct RandomContext random_ctx; |
3335 | uint32_t pg_iter; | 3464 | uint32_t pg_iter; |
3465 | #if OLD | ||
3466 | struct PeerConnection *temp_peers; | ||
3467 | struct PeerConnection *conn_iter; | ||
3468 | double random_number; | ||
3469 | #endif | ||
3336 | 3470 | ||
3337 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3471 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3338 | { | 3472 | { |
@@ -3340,6 +3474,22 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
3340 | random_ctx.first = &pg->peers[pg_iter]; | 3474 | random_ctx.first = &pg->peers[pg_iter]; |
3341 | random_ctx.percentage = percentage; | 3475 | random_ctx.percentage = percentage; |
3342 | random_ctx.pg = pg; | 3476 | random_ctx.pg = pg; |
3477 | #if OLD | ||
3478 | temp_peers = NULL; | ||
3479 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
3480 | while (conn_iter != NULL) | ||
3481 | { | ||
3482 | random_number = | ||
3483 | ((double) | ||
3484 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
3485 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
3486 | if (random_number < percentage) | ||
3487 | { | ||
3488 | add_connections(pg, pg_iter, conn_iter->index, WORKING_SET); | ||
3489 | } | ||
3490 | conn_iter = conn_iter->next; | ||
3491 | } | ||
3492 | #else | ||
3343 | pg->peers[pg_iter].connect_peers_working_set = | 3493 | pg->peers[pg_iter].connect_peers_working_set = |
3344 | GNUNET_CONTAINER_multihashmap_create (pg->total); | 3494 | GNUNET_CONTAINER_multihashmap_create (pg->total); |
3345 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 3495 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
@@ -3351,9 +3501,108 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
3351 | /* And replace with the random set */ | 3501 | /* And replace with the random set */ |
3352 | pg->peers[pg_iter].connect_peers = | 3502 | pg->peers[pg_iter].connect_peers = |
3353 | pg->peers[pg_iter].connect_peers_working_set; | 3503 | pg->peers[pg_iter].connect_peers_working_set; |
3504 | #endif | ||
3505 | } | ||
3506 | |||
3507 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3508 | { | ||
3509 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
3510 | while (pg->peers[pg_iter].connect_peers_head != NULL) | ||
3511 | remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT); | ||
3512 | |||
3513 | pg->peers[pg_iter].connect_peers_head = pg->peers[pg_iter].connect_peers_working_set_head; | ||
3514 | pg->peers[pg_iter].connect_peers_tail = pg->peers[pg_iter].connect_peers_working_set_tail; | ||
3515 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | ||
3516 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | ||
3354 | } | 3517 | } |
3355 | } | 3518 | } |
3356 | 3519 | ||
3520 | |||
3521 | /** | ||
3522 | * Count the number of connections in a linked list of connections. | ||
3523 | * | ||
3524 | * @param conn_list the connection list to get the count of | ||
3525 | * | ||
3526 | * @return the number of elements in the list | ||
3527 | */ | ||
3528 | static unsigned int | ||
3529 | count_connections (struct PeerConnection *conn_list) | ||
3530 | { | ||
3531 | struct PeerConnection *iter; | ||
3532 | unsigned int count; | ||
3533 | count = 0; | ||
3534 | iter = conn_list; | ||
3535 | while (iter != NULL) | ||
3536 | { | ||
3537 | iter = iter->next; | ||
3538 | count++; | ||
3539 | } | ||
3540 | return count; | ||
3541 | } | ||
3542 | |||
3543 | |||
3544 | static unsigned int | ||
3545 | count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) | ||
3546 | { | ||
3547 | unsigned int count; | ||
3548 | unsigned int pg_iter; | ||
3549 | #if OLD | ||
3550 | struct PeerConnection *conn_iter; | ||
3551 | #endif | ||
3552 | count = 0; | ||
3553 | |||
3554 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3555 | { | ||
3556 | #if OLD | ||
3557 | conn_iter = pg->peers[pg_iter].connect_peers_working_set_head; | ||
3558 | while (conn_iter != NULL) | ||
3559 | { | ||
3560 | count++; | ||
3561 | conn_iter = conn_iter->next; | ||
3562 | } | ||
3563 | #else | ||
3564 | count += | ||
3565 | GNUNET_CONTAINER_multihashmap_size (pg-> | ||
3566 | peers | ||
3567 | [pg_iter].connect_peers_working_set); | ||
3568 | #endif | ||
3569 | } | ||
3570 | |||
3571 | return count; | ||
3572 | } | ||
3573 | |||
3574 | |||
3575 | static unsigned int | ||
3576 | count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) | ||
3577 | { | ||
3578 | unsigned int count; | ||
3579 | unsigned int pg_iter; | ||
3580 | #if OLD | ||
3581 | struct PeerConnection *conn_iter; | ||
3582 | #endif | ||
3583 | |||
3584 | count = 0; | ||
3585 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3586 | { | ||
3587 | #if OLD | ||
3588 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | ||
3589 | while (conn_iter != NULL) | ||
3590 | { | ||
3591 | count++; | ||
3592 | conn_iter = conn_iter->next; | ||
3593 | } | ||
3594 | #else | ||
3595 | count += | ||
3596 | GNUNET_CONTAINER_multihashmap_size (pg-> | ||
3597 | peers | ||
3598 | [pg_iter].allowed_peers); | ||
3599 | #endif | ||
3600 | } | ||
3601 | |||
3602 | return count; | ||
3603 | } | ||
3604 | |||
3605 | |||
3357 | /** | 3606 | /** |
3358 | * From the set of connections possible, choose at least num connections per | 3607 | * From the set of connections possible, choose at least num connections per |
3359 | * peer. | 3608 | * peer. |
@@ -3364,9 +3613,38 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
3364 | static void | 3613 | static void |
3365 | choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 3614 | choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
3366 | { | 3615 | { |
3616 | #if !OLD | ||
3367 | struct MinimumContext minimum_ctx; | 3617 | struct MinimumContext minimum_ctx; |
3618 | #else | ||
3619 | struct PeerConnection *conn_iter; | ||
3620 | unsigned int temp_list_size; | ||
3621 | unsigned int i; | ||
3622 | unsigned int count; | ||
3623 | uint32_t random; /* Random list entry to connect peer to */ | ||
3624 | #endif | ||
3368 | uint32_t pg_iter; | 3625 | uint32_t pg_iter; |
3369 | 3626 | ||
3627 | #if OLD | ||
3628 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3629 | { | ||
3630 | temp_list_size = count_connections(pg->peers[pg_iter].connect_peers_head); | ||
3631 | if (temp_list_size == 0) | ||
3632 | { | ||
3633 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer %d has 0 connections!?!?\n", pg_iter); | ||
3634 | break; | ||
3635 | } | ||
3636 | for (i = 0; i < num; i++) | ||
3637 | { | ||
3638 | random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, temp_list_size); | ||
3639 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
3640 | for (count = 0; count < random; count++) | ||
3641 | conn_iter = conn_iter->next; | ||
3642 | /* We now have a random connection, connect it! */ | ||
3643 | GNUNET_assert(conn_iter != NULL); | ||
3644 | add_connections(pg, pg_iter, conn_iter->index, WORKING_SET); | ||
3645 | } | ||
3646 | } | ||
3647 | #else | ||
3370 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3648 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3371 | { | 3649 | { |
3372 | pg->peers[pg_iter].connect_peers_working_set = | 3650 | pg->peers[pg_iter].connect_peers_working_set = |
@@ -3398,48 +3676,20 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
3398 | pg->peers[pg_iter].connect_peers = | 3676 | pg->peers[pg_iter].connect_peers = |
3399 | pg->peers[pg_iter].connect_peers_working_set; | 3677 | pg->peers[pg_iter].connect_peers_working_set; |
3400 | } | 3678 | } |
3401 | 3679 | #endif | |
3402 | } | ||
3403 | |||
3404 | |||
3405 | static unsigned int | ||
3406 | count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) | ||
3407 | { | ||
3408 | unsigned int count; | ||
3409 | unsigned int pg_iter; | ||
3410 | |||
3411 | count = 0; | ||
3412 | |||
3413 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3680 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3414 | { | 3681 | { |
3415 | count += | 3682 | while (pg->peers[pg_iter].connect_peers_head != NULL) |
3416 | GNUNET_CONTAINER_multihashmap_size (pg-> | 3683 | remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT); |
3417 | peers | ||
3418 | [pg_iter].connect_peers_working_set); | ||
3419 | } | ||
3420 | |||
3421 | return count; | ||
3422 | } | ||
3423 | |||
3424 | |||
3425 | static unsigned int | ||
3426 | count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) | ||
3427 | { | ||
3428 | unsigned int count; | ||
3429 | unsigned int pg_iter; | ||
3430 | |||
3431 | count = 0; | ||
3432 | 3684 | ||
3433 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3685 | pg->peers[pg_iter].connect_peers_head = pg->peers[pg_iter].connect_peers_working_set_head; |
3434 | { | 3686 | pg->peers[pg_iter].connect_peers_tail = pg->peers[pg_iter].connect_peers_working_set_tail; |
3435 | count += | 3687 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
3436 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | 3688 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
3437 | } | 3689 | } |
3438 | |||
3439 | return count; | ||
3440 | } | 3690 | } |
3441 | 3691 | ||
3442 | 3692 | #if !OLD | |
3443 | struct FindClosestContext | 3693 | struct FindClosestContext |
3444 | { | 3694 | { |
3445 | /** | 3695 | /** |
@@ -3503,6 +3753,7 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
3503 | return GNUNET_YES; | 3753 | return GNUNET_YES; |
3504 | } | 3754 | } |
3505 | 3755 | ||
3756 | |||
3506 | /** | 3757 | /** |
3507 | * From the set of connections possible, choose at num connections per | 3758 | * From the set of connections possible, choose at num connections per |
3508 | * peer based on depth which are closest out of those allowed. Guaranteed | 3759 | * peer based on depth which are closest out of those allowed. Guaranteed |
@@ -3515,9 +3766,13 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
3515 | */ | 3766 | */ |
3516 | void | 3767 | void |
3517 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | 3768 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, |
3518 | GNUNET_TESTING_ConnectionProcessor proc) | 3769 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
3519 | { | 3770 | { |
3771 | #if OLD | ||
3772 | |||
3773 | #else | ||
3520 | struct FindClosestContext closest_ctx; | 3774 | struct FindClosestContext closest_ctx; |
3775 | #endif | ||
3521 | uint32_t pg_iter; | 3776 | uint32_t pg_iter; |
3522 | uint32_t i; | 3777 | uint32_t i; |
3523 | 3778 | ||
@@ -3536,11 +3791,12 @@ add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | |||
3536 | if (closest_ctx.closest != NULL) | 3791 | if (closest_ctx.closest != NULL) |
3537 | { | 3792 | { |
3538 | GNUNET_assert (closest_ctx.closest_num < pg->total); | 3793 | GNUNET_assert (closest_ctx.closest_num < pg->total); |
3539 | proc (pg, pg_iter, closest_ctx.closest_num); | 3794 | proc (pg, pg_iter, closest_ctx.closest_num, list); |
3540 | } | 3795 | } |
3541 | } | 3796 | } |
3542 | } | 3797 | } |
3543 | } | 3798 | } |
3799 | #endif | ||
3544 | 3800 | ||
3545 | /** | 3801 | /** |
3546 | * From the set of connections possible, choose at least num connections per | 3802 | * From the set of connections possible, choose at least num connections per |
@@ -3553,13 +3809,59 @@ add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | |||
3553 | void | 3809 | void |
3554 | perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 3810 | perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
3555 | { | 3811 | { |
3556 | struct DFSContext dfs_ctx; | ||
3557 | uint32_t pg_iter; | 3812 | uint32_t pg_iter; |
3558 | uint32_t dfs_count; | 3813 | uint32_t dfs_count; |
3559 | uint32_t starting_peer; | 3814 | uint32_t starting_peer; |
3560 | uint32_t least_connections; | 3815 | uint32_t least_connections; |
3816 | uint32_t random_connection; | ||
3817 | #if OLD | ||
3818 | unsigned int temp_count; | ||
3819 | struct PeerConnection *peer_iter; | ||
3820 | #else | ||
3821 | struct DFSContext dfs_ctx; | ||
3561 | GNUNET_HashCode second_hash; | 3822 | GNUNET_HashCode second_hash; |
3823 | #endif | ||
3824 | |||
3825 | #if OLD | ||
3826 | starting_peer = 0; | ||
3827 | dfs_count = 0; | ||
3828 | while ((count_workingset_connections (pg) < num * pg->total) | ||
3829 | && (count_allowed_connections (pg) > 0)) | ||
3830 | { | ||
3831 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | ||
3832 | { | ||
3833 | least_connections = -1; /* Set to very high number */ | ||
3834 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3835 | { | ||
3836 | temp_count = count_connections(pg->peers[pg_iter].connect_peers_working_set_head); | ||
3837 | if (temp_count < least_connections) | ||
3838 | { | ||
3839 | starting_peer = pg_iter; | ||
3840 | least_connections = temp_count; | ||
3841 | } | ||
3842 | } | ||
3843 | } | ||
3844 | |||
3845 | temp_count = count_connections(pg->peers[starting_peer].connect_peers_head); | ||
3846 | if (temp_count == 0) | ||
3847 | continue; /* FIXME: infinite loop? */ | ||
3848 | |||
3849 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, temp_count); | ||
3850 | temp_count = 0; | ||
3851 | peer_iter = pg->peers[starting_peer].connect_peers_head; | ||
3852 | while (temp_count < random_connection) | ||
3853 | { | ||
3854 | peer_iter = peer_iter->next; | ||
3855 | temp_count++; | ||
3856 | } | ||
3857 | GNUNET_assert(peer_iter != NULL); | ||
3858 | add_connections(pg, starting_peer, peer_iter->index, WORKING_SET); | ||
3859 | remove_connections(pg, starting_peer, peer_iter->index, CONNECT); | ||
3860 | starting_peer = peer_iter->index; | ||
3861 | dfs_count++; | ||
3862 | } | ||
3562 | 3863 | ||
3864 | #else | ||
3563 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3865 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3564 | { | 3866 | { |
3565 | pg->peers[pg_iter].connect_peers_working_set = | 3867 | pg->peers[pg_iter].connect_peers_working_set = |
@@ -3630,8 +3932,10 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
3630 | pg->peers[pg_iter].connect_peers = | 3932 | pg->peers[pg_iter].connect_peers = |
3631 | pg->peers[pg_iter].connect_peers_working_set; | 3933 | pg->peers[pg_iter].connect_peers_working_set; |
3632 | } | 3934 | } |
3935 | #endif | ||
3633 | } | 3936 | } |
3634 | 3937 | ||
3938 | |||
3635 | /** | 3939 | /** |
3636 | * Internal callback for topology information for a particular peer. | 3940 | * Internal callback for topology information for a particular peer. |
3637 | */ | 3941 | */ |
@@ -4028,63 +4332,63 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4029 | _("Creating clique CONNECT topology\n")); | 4333 | _("Creating clique CONNECT topology\n")); |
4030 | #endif | 4334 | #endif |
4031 | create_clique (pg, &add_actual_connections); | 4335 | create_clique (pg, &add_connections, CONNECT); |
4032 | break; | 4336 | break; |
4033 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 4337 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
4034 | #if VERBOSE_TOPOLOGY | 4338 | #if VERBOSE_TOPOLOGY |
4035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4036 | _("Creating small world (ring) CONNECT topology\n")); | 4340 | _("Creating small world (ring) CONNECT topology\n")); |
4037 | #endif | 4341 | #endif |
4038 | create_small_world_ring (pg, &add_actual_connections); | 4342 | create_small_world_ring (pg, &add_connections, CONNECT); |
4039 | break; | 4343 | break; |
4040 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 4344 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
4041 | #if VERBOSE_TOPOLOGY | 4345 | #if VERBOSE_TOPOLOGY |
4042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4043 | _("Creating small world (2d-torus) CONNECT topology\n")); | 4347 | _("Creating small world (2d-torus) CONNECT topology\n")); |
4044 | #endif | 4348 | #endif |
4045 | create_small_world (pg, &add_actual_connections); | 4349 | create_small_world (pg, &add_connections, CONNECT); |
4046 | break; | 4350 | break; |
4047 | case GNUNET_TESTING_TOPOLOGY_RING: | 4351 | case GNUNET_TESTING_TOPOLOGY_RING: |
4048 | #if VERBOSE_TOPOLOGY | 4352 | #if VERBOSE_TOPOLOGY |
4049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4050 | _("Creating ring CONNECT topology\n")); | 4354 | _("Creating ring CONNECT topology\n")); |
4051 | #endif | 4355 | #endif |
4052 | create_ring (pg, &add_actual_connections); | 4356 | create_ring (pg, &add_connections, CONNECT); |
4053 | break; | 4357 | break; |
4054 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 4358 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
4055 | #if VERBOSE_TOPOLOGY | 4359 | #if VERBOSE_TOPOLOGY |
4056 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4057 | _("Creating 2d torus CONNECT topology\n")); | 4361 | _("Creating 2d torus CONNECT topology\n")); |
4058 | #endif | 4362 | #endif |
4059 | create_2d_torus (pg, &add_actual_connections); | 4363 | create_2d_torus (pg, &add_connections, CONNECT); |
4060 | break; | 4364 | break; |
4061 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 4365 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
4062 | #if VERBOSE_TOPOLOGY | 4366 | #if VERBOSE_TOPOLOGY |
4063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4064 | _("Creating Erdos-Renyi CONNECT topology\n")); | 4368 | _("Creating Erdos-Renyi CONNECT topology\n")); |
4065 | #endif | 4369 | #endif |
4066 | create_erdos_renyi (pg, &add_actual_connections); | 4370 | create_erdos_renyi (pg, &add_connections, CONNECT); |
4067 | break; | 4371 | break; |
4068 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 4372 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
4069 | #if VERBOSE_TOPOLOGY | 4373 | #if VERBOSE_TOPOLOGY |
4070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4071 | _("Creating InterNAT CONNECT topology\n")); | 4375 | _("Creating InterNAT CONNECT topology\n")); |
4072 | #endif | 4376 | #endif |
4073 | create_nated_internet (pg, &add_actual_connections); | 4377 | create_nated_internet (pg, &add_connections, CONNECT); |
4074 | break; | 4378 | break; |
4075 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 4379 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
4076 | #if VERBOSE_TOPOLOGY | 4380 | #if VERBOSE_TOPOLOGY |
4077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4078 | _("Creating Scale Free CONNECT topology\n")); | 4382 | _("Creating Scale Free CONNECT topology\n")); |
4079 | #endif | 4383 | #endif |
4080 | create_scale_free (pg, &add_actual_connections); | 4384 | create_scale_free (pg, &add_connections, CONNECT); |
4081 | break; | 4385 | break; |
4082 | case GNUNET_TESTING_TOPOLOGY_LINE: | 4386 | case GNUNET_TESTING_TOPOLOGY_LINE: |
4083 | #if VERBOSE_TOPOLOGY | 4387 | #if VERBOSE_TOPOLOGY |
4084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4085 | _("Creating straight line CONNECT topology\n")); | 4389 | _("Creating straight line CONNECT topology\n")); |
4086 | #endif | 4390 | #endif |
4087 | create_line (pg, &add_actual_connections); | 4391 | create_line (pg, &add_connections, CONNECT); |
4088 | break; | 4392 | break; |
4089 | case GNUNET_TESTING_TOPOLOGY_NONE: | 4393 | case GNUNET_TESTING_TOPOLOGY_NONE: |
4090 | #if VERBOSE_TOPOLOGY | 4394 | #if VERBOSE_TOPOLOGY |
@@ -4126,7 +4430,9 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4126 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), | 4430 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), |
4127 | (unsigned int) option_modifier); | 4431 | (unsigned int) option_modifier); |
4128 | #endif | 4432 | #endif |
4433 | #if FIXME | ||
4129 | perform_dfs (pg, (int) option_modifier); | 4434 | perform_dfs (pg, (int) option_modifier); |
4435 | #endif | ||
4130 | break; | 4436 | break; |
4131 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: | 4437 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: |
4132 | #if VERBOSE_TOPOLOGY | 4438 | #if VERBOSE_TOPOLOGY |
@@ -4135,8 +4441,10 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4135 | ("Finding additional %u closest peers each (if possible)\n"), | 4441 | ("Finding additional %u closest peers each (if possible)\n"), |
4136 | (unsigned int) option_modifier); | 4442 | (unsigned int) option_modifier); |
4137 | #endif | 4443 | #endif |
4444 | #if FIXME | ||
4138 | add_closest (pg, (unsigned int) option_modifier, | 4445 | add_closest (pg, (unsigned int) option_modifier, |
4139 | &add_actual_connections); | 4446 | &add_connections, CONNECT); |
4447 | #endif | ||
4140 | break; | 4448 | break; |
4141 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: | 4449 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: |
4142 | break; | 4450 | break; |
@@ -4412,24 +4720,27 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4412 | char *newservicehome; | 4720 | char *newservicehome; |
4413 | char *tmpdir; | 4721 | char *tmpdir; |
4414 | char *hostkeys_file; | 4722 | char *hostkeys_file; |
4415 | char *hostkey_data; | 4723 | char *arg; |
4724 | char *ssh_port_str; | ||
4416 | struct GNUNET_DISK_FileHandle *fd; | 4725 | struct GNUNET_DISK_FileHandle *fd; |
4417 | struct GNUNET_CONFIGURATION_Handle *pcfg; | 4726 | struct GNUNET_CONFIGURATION_Handle *pcfg; |
4418 | unsigned int off; | 4727 | unsigned int off; |
4419 | unsigned int hostcnt; | 4728 | unsigned int hostcnt; |
4729 | unsigned int i; | ||
4420 | uint16_t minport; | 4730 | uint16_t minport; |
4421 | uint16_t sshport; | 4731 | uint16_t sshport; |
4422 | uint32_t upnum; | 4732 | uint32_t upnum; |
4423 | uint32_t fdnum; | 4733 | uint32_t fdnum; |
4424 | uint64_t fs; | 4734 | uint64_t fs; |
4425 | uint64_t total_hostkeys; | 4735 | uint64_t total_hostkeys; |
4736 | struct GNUNET_OS_Process *proc; | ||
4426 | 4737 | ||
4427 | if (0 == total) | 4738 | if (0 == total) |
4428 | { | 4739 | { |
4429 | GNUNET_break (0); | 4740 | GNUNET_break (0); |
4430 | return NULL; | 4741 | return NULL; |
4431 | } | 4742 | } |
4432 | hostkey_data = NULL; | 4743 | |
4433 | upnum = 0; | 4744 | upnum = 0; |
4434 | fdnum = 0; | 4745 | fdnum = 0; |
4435 | pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup)); | 4746 | pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup)); |
@@ -4522,6 +4833,34 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4522 | minport = LOW_PORT; | 4833 | minport = LOW_PORT; |
4523 | } | 4834 | } |
4524 | 4835 | ||
4836 | /* Create the servicehome directory for each remote peer */ | ||
4837 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | ||
4838 | &baseservicehome)); | ||
4839 | for (i = 0; i < pg->num_hosts; i++) | ||
4840 | { | ||
4841 | |||
4842 | if (NULL != pg->hosts[i].username) | ||
4843 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, pg->hosts[i].hostname); | ||
4844 | else | ||
4845 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); | ||
4846 | if (pg->hosts[i].sshport != 0) | ||
4847 | { | ||
4848 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); | ||
4849 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | ||
4850 | "ssh", "-P", ssh_port_str, | ||
4851 | #if !DEBUG_TESTING | ||
4852 | "-q", | ||
4853 | #endif | ||
4854 | arg, "mkdir -p", baseservicehome, NULL); | ||
4855 | } | ||
4856 | else | ||
4857 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | ||
4858 | "ssh", arg, "mkdir -p", baseservicehome, NULL); | ||
4859 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Creating remote dir with command ssh %s %s %s\n", arg, " mkdir -p ", baseservicehome); | ||
4860 | GNUNET_OS_process_wait(proc); | ||
4861 | } | ||
4862 | GNUNET_free(baseservicehome); | ||
4863 | |||
4525 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE", | 4864 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE", |
4526 | &hostkeys_file)) | 4865 | &hostkeys_file)) |
4527 | { | 4866 | { |
@@ -4541,7 +4880,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4541 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | 4880 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) |
4542 | fs = 0; | 4881 | fs = 0; |
4543 | 4882 | ||
4544 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE); | 4883 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE); |
4545 | 4884 | ||
4546 | if (fs % HOSTKEYFILESIZE != 0) | 4885 | if (fs % HOSTKEYFILESIZE != 0) |
4547 | { | 4886 | { |
@@ -4550,11 +4889,13 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4550 | else | 4889 | else |
4551 | { | 4890 | { |
4552 | total_hostkeys = fs / HOSTKEYFILESIZE; | 4891 | total_hostkeys = fs / HOSTKEYFILESIZE; |
4553 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Will read %llu hostkeys from file\n", total_hostkeys); | 4892 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Will read %llu hostkeys from file\n", total_hostkeys); |
4554 | hostkey_data = GNUNET_malloc_large (fs); | 4893 | pg->hostkey_data = GNUNET_malloc_large (fs); |
4555 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, fs)); | 4894 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); |
4895 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); | ||
4556 | } | 4896 | } |
4557 | } | 4897 | } |
4898 | GNUNET_free(hostkeys_file); | ||
4558 | } | 4899 | } |
4559 | 4900 | ||
4560 | for (off = 0; off < total; off++) | 4901 | for (off = 0; off < total; off++) |
@@ -4605,21 +4946,24 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4605 | "SERVICEHOME", newservicehome); | 4946 | "SERVICEHOME", newservicehome); |
4606 | GNUNET_free (newservicehome); | 4947 | GNUNET_free (newservicehome); |
4607 | pg->peers[off].cfg = pcfg; | 4948 | pg->peers[off].cfg = pcfg; |
4949 | #if DEFER | ||
4950 | /* Can we do this later? */ | ||
4608 | pg->peers[off].allowed_peers = | 4951 | pg->peers[off].allowed_peers = |
4609 | GNUNET_CONTAINER_multihashmap_create (total); | 4952 | GNUNET_CONTAINER_multihashmap_create (total); |
4610 | pg->peers[off].connect_peers = | 4953 | pg->peers[off].connect_peers = |
4611 | GNUNET_CONTAINER_multihashmap_create (total); | 4954 | GNUNET_CONTAINER_multihashmap_create (total); |
4612 | pg->peers[off].blacklisted_peers = | 4955 | pg->peers[off].blacklisted_peers = |
4613 | GNUNET_CONTAINER_multihashmap_create (total); | 4956 | GNUNET_CONTAINER_multihashmap_create (total); |
4614 | pg->peers[off].pg = pg; | ||
4615 | 4957 | ||
4958 | #endif | ||
4959 | pg->peers[off].pg = pg; | ||
4616 | pg->peers[off].internal_context.peer = &pg->peers[off]; | 4960 | pg->peers[off].internal_context.peer = &pg->peers[off]; |
4617 | pg->peers[off].internal_context.timeout = timeout; | 4961 | pg->peers[off].internal_context.timeout = timeout; |
4618 | pg->peers[off].internal_context.hostname = hostname; | 4962 | pg->peers[off].internal_context.hostname = hostname; |
4619 | pg->peers[off].internal_context.username = username; | 4963 | pg->peers[off].internal_context.username = username; |
4620 | pg->peers[off].internal_context.sshport = sshport; | 4964 | pg->peers[off].internal_context.sshport = sshport; |
4621 | if (hostkey_data != NULL) | 4965 | if (pg->hostkey_data != NULL) |
4622 | pg->peers[off].internal_context.hostkey = &hostkey_data[off * HOSTKEYFILESIZE]; | 4966 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off * HOSTKEYFILESIZE]; |
4623 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | 4967 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; |
4624 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | 4968 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; |
4625 | pg->peers[off].internal_context.start_cb = cb; | 4969 | pg->peers[off].internal_context.start_cb = cb; |
@@ -5190,6 +5534,10 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | |||
5190 | unsigned int off; | 5534 | unsigned int off; |
5191 | struct ShutdownContext *shutdown_ctx; | 5535 | struct ShutdownContext *shutdown_ctx; |
5192 | struct PeerShutdownContext *peer_shutdown_ctx; | 5536 | struct PeerShutdownContext *peer_shutdown_ctx; |
5537 | #if OLD | ||
5538 | struct PeerConnection *conn_iter; | ||
5539 | struct PeerConnection *temp_conn; | ||
5540 | #endif | ||
5193 | 5541 | ||
5194 | GNUNET_assert (pg->total > 0); | 5542 | GNUNET_assert (pg->total > 0); |
5195 | 5543 | ||
@@ -5207,9 +5555,42 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | |||
5207 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; | 5555 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; |
5208 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 5556 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
5209 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); | 5557 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); |
5210 | //GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, shutdown_cb, shutdown_ctx, GNUNET_YES, GNUNET_NO); | 5558 | |
5211 | if (NULL != pg->peers[off].cfg) | 5559 | if (NULL != pg->peers[off].cfg) |
5212 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 5560 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
5561 | #if OLD | ||
5562 | conn_iter = pg->peers[off].allowed_peers_head; | ||
5563 | while (conn_iter != NULL) | ||
5564 | { | ||
5565 | temp_conn = conn_iter->next; | ||
5566 | GNUNET_free(conn_iter); | ||
5567 | conn_iter = temp_conn; | ||
5568 | } | ||
5569 | |||
5570 | conn_iter = pg->peers[off].connect_peers_head; | ||
5571 | while (conn_iter != NULL) | ||
5572 | { | ||
5573 | temp_conn = conn_iter->next; | ||
5574 | GNUNET_free(conn_iter); | ||
5575 | conn_iter = temp_conn; | ||
5576 | } | ||
5577 | |||
5578 | conn_iter = pg->peers[off].blacklisted_peers_head; | ||
5579 | while (conn_iter != NULL) | ||
5580 | { | ||
5581 | temp_conn = conn_iter->next; | ||
5582 | GNUNET_free(conn_iter); | ||
5583 | conn_iter = temp_conn; | ||
5584 | } | ||
5585 | |||
5586 | conn_iter = pg->peers[off].connect_peers_working_set_head; | ||
5587 | while (conn_iter != NULL) | ||
5588 | { | ||
5589 | temp_conn = conn_iter->next; | ||
5590 | GNUNET_free(conn_iter); | ||
5591 | conn_iter = temp_conn; | ||
5592 | } | ||
5593 | #else | ||
5213 | if (pg->peers[off].allowed_peers != NULL) | 5594 | if (pg->peers[off].allowed_peers != NULL) |
5214 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); | 5595 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); |
5215 | if (pg->peers[off].connect_peers != NULL) | 5596 | if (pg->peers[off].connect_peers != NULL) |
@@ -5217,8 +5598,10 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | |||
5217 | if (pg->peers[off].blacklisted_peers != NULL) | 5598 | if (pg->peers[off].blacklisted_peers != NULL) |
5218 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 5599 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
5219 | peers[off].blacklisted_peers); | 5600 | peers[off].blacklisted_peers); |
5601 | #endif | ||
5220 | } | 5602 | } |
5221 | GNUNET_free (pg->peers); | 5603 | GNUNET_free (pg->peers); |
5604 | GNUNET_free_non_null(pg->hostkey_data); | ||
5222 | for (off = 0; off < pg->num_hosts; off++) | 5605 | for (off = 0; off < pg->num_hosts; off++) |
5223 | { | 5606 | { |
5224 | GNUNET_free (pg->hosts[off].hostname); | 5607 | GNUNET_free (pg->hosts[off].hostname); |