diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-09-21 12:57:16 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-09-21 12:57:16 +0000 |
commit | ba62fb823f6801608250a97c719981ba823faae3 (patch) | |
tree | cd0675f9b06176c9227f1ca8dd13ad9890a002da | |
parent | fe43907c45344d500907e593f3132db71f7e4a58 (diff) | |
download | gnunet-ba62fb823f6801608250a97c719981ba823faae3.tar.gz gnunet-ba62fb823f6801608250a97c719981ba823faae3.zip |
additional topology creation option, for adding closest underlay capable peers to topology
-rw-r--r-- | src/testing/test_testing_topology.c | 5 | ||||
-rw-r--r-- | src/testing/testing_group.c | 114 |
2 files changed, 113 insertions, 6 deletions
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index af4a6a39f..1dc4f47dd 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include "gnunet_core_service.h" | 26 | #include "gnunet_core_service.h" |
27 | #include "gnunet_os_lib.h" | 27 | #include "gnunet_os_lib.h" |
28 | 28 | ||
29 | #define VERBOSE GNUNET_YES | 29 | #define VERBOSE GNUNET_NO |
30 | 30 | ||
31 | #define DELAY_FOR_LOGGING GNUNET_NO | 31 | #define DELAY_FOR_LOGGING GNUNET_NO |
32 | 32 | ||
@@ -270,7 +270,6 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
270 | 270 | ||
271 | static void stats_finished (void *cls, int result) | 271 | static void stats_finished (void *cls, int result) |
272 | { | 272 | { |
273 | fprintf(stderr, "Finished getting all peers statistics!\n"); | ||
274 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | 273 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); |
275 | } | 274 | } |
276 | 275 | ||
@@ -292,7 +291,7 @@ static int stats_print (void *cls, | |||
292 | uint64_t value, | 291 | uint64_t value, |
293 | int is_persistent) | 292 | int is_persistent) |
294 | { | 293 | { |
295 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), subsystem, name, value); | 294 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), subsystem, name, value); |
296 | return GNUNET_OK; | 295 | return GNUNET_OK; |
297 | } | 296 | } |
298 | 297 | ||
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index e43beecaf..f92d0c014 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -32,6 +32,8 @@ | |||
32 | 32 | ||
33 | #define VERBOSE_TESTING GNUNET_NO | 33 | #define VERBOSE_TESTING GNUNET_NO |
34 | 34 | ||
35 | #define VERBOSE_TOPOLOGY GNUNET_YES | ||
36 | |||
35 | #define DEBUG_CHURN GNUNET_NO | 37 | #define DEBUG_CHURN GNUNET_NO |
36 | 38 | ||
37 | /** | 39 | /** |
@@ -726,6 +728,13 @@ GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption *topology | |||
726 | "CONNECT_DFS", | 728 | "CONNECT_DFS", |
727 | 729 | ||
728 | /** | 730 | /** |
731 | * Find the N closest peers to each allowed peer in the | ||
732 | * topology and make sure a connection to those peers | ||
733 | * exists in the connect topology. | ||
734 | */ | ||
735 | "CONNECT_CLOSEST", | ||
736 | |||
737 | /** | ||
729 | * No options specified. | 738 | * No options specified. |
730 | */ | 739 | */ |
731 | "CONNECT_NONE", | 740 | "CONNECT_NONE", |
@@ -1609,7 +1618,9 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1609 | 1618 | ||
1610 | /** | 1619 | /** |
1611 | * Create a topology given a peer group (set of running peers) | 1620 | * Create a topology given a peer group (set of running peers) |
1612 | * and a connection processor. | 1621 | * and a connection processor. This particular function creates |
1622 | * the connections for a 2d-torus, plus additional "closest" | ||
1623 | * connections per peer. | ||
1613 | * | 1624 | * |
1614 | * @param pg the peergroup to create the topology on | 1625 | * @param pg the peergroup to create the topology on |
1615 | * @param proc the connection processor to call to actually set | 1626 | * @param proc the connection processor to call to actually set |
@@ -2669,8 +2680,8 @@ struct DFSContext | |||
2669 | */ | 2680 | */ |
2670 | static int | 2681 | static int |
2671 | random_connect_iterator (void *cls, | 2682 | random_connect_iterator (void *cls, |
2672 | const GNUNET_HashCode * key, | 2683 | const GNUNET_HashCode * key, |
2673 | void *value) | 2684 | void *value) |
2674 | { | 2685 | { |
2675 | struct RandomContext *random_ctx = cls; | 2686 | struct RandomContext *random_ctx = cls; |
2676 | double random_number; | 2687 | double random_number; |
@@ -2870,6 +2881,96 @@ static unsigned int count_allowed_connections(struct GNUNET_TESTING_PeerGroup *p | |||
2870 | return count; | 2881 | return count; |
2871 | } | 2882 | } |
2872 | 2883 | ||
2884 | |||
2885 | struct FindClosestContext | ||
2886 | { | ||
2887 | /** | ||
2888 | * The currently known closest peer. | ||
2889 | */ | ||
2890 | struct GNUNET_TESTING_Daemon *closest; | ||
2891 | |||
2892 | /** | ||
2893 | * The info for the peer we are adding connections for. | ||
2894 | */ | ||
2895 | struct PeerData *curr_peer; | ||
2896 | |||
2897 | /** | ||
2898 | * The distance (bits) between the current | ||
2899 | * peer and the currently known closest. | ||
2900 | */ | ||
2901 | unsigned int closest_dist; | ||
2902 | |||
2903 | /** | ||
2904 | * The offset of the closest known peer in | ||
2905 | * the peer group. | ||
2906 | */ | ||
2907 | unsigned int closest_num; | ||
2908 | }; | ||
2909 | |||
2910 | /** | ||
2911 | * Iterator over hash map entries of the allowed | ||
2912 | * peer connections. Find the closest, not already | ||
2913 | * connected peer and return it. | ||
2914 | * | ||
2915 | * @param cls closure (struct FindClosestContext) | ||
2916 | * @param key current key code (hash of offset in pg) | ||
2917 | * @param value value in the hash map - a GNUNET_TESTING_Daemon | ||
2918 | * @return GNUNET_YES if we should continue to | ||
2919 | * iterate, | ||
2920 | * GNUNET_NO if not. | ||
2921 | */ | ||
2922 | static | ||
2923 | int find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | ||
2924 | { | ||
2925 | struct FindClosestContext *closest_ctx = cls; | ||
2926 | struct GNUNET_TESTING_Daemon *daemon = value; | ||
2927 | |||
2928 | if (((closest_ctx->closest == NULL) || | ||
2929 | (GNUNET_CRYPTO_hash_matching_bits(&daemon->id.hashPubKey, &closest_ctx->curr_peer->daemon->id.hashPubKey) > closest_ctx->closest_dist)) | ||
2930 | && (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains(closest_ctx->curr_peer->connect_peers, key))) | ||
2931 | { | ||
2932 | closest_ctx->closest_dist = GNUNET_CRYPTO_hash_matching_bits(&daemon->id.hashPubKey, &closest_ctx->curr_peer->daemon->id.hashPubKey); | ||
2933 | closest_ctx->closest = daemon; | ||
2934 | uid_from_hash(key, &closest_ctx->closest_num); | ||
2935 | } | ||
2936 | return GNUNET_YES; | ||
2937 | } | ||
2938 | |||
2939 | /** | ||
2940 | * From the set of connections possible, choose at num connections per | ||
2941 | * peer based on depth which are closest out of those allowed. Guaranteed | ||
2942 | * to add num peers to connect to, provided there are that many peers | ||
2943 | * in the underlay topology to connect to. | ||
2944 | * | ||
2945 | * @param pg the peergroup we are dealing with | ||
2946 | * @param num how many connections at least should each peer have (if possible)? | ||
2947 | * @param proc processor to actually add the connections | ||
2948 | */ | ||
2949 | void | ||
2950 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, GNUNET_TESTING_ConnectionProcessor proc) | ||
2951 | { | ||
2952 | struct FindClosestContext closest_ctx; | ||
2953 | uint32_t pg_iter; | ||
2954 | uint32_t i; | ||
2955 | |||
2956 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ | ||
2957 | { | ||
2958 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
2959 | { | ||
2960 | closest_ctx.curr_peer = &pg->peers[pg_iter]; | ||
2961 | closest_ctx.closest = NULL; | ||
2962 | closest_ctx.closest_dist = 0; | ||
2963 | closest_ctx.closest_num = 0; | ||
2964 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].allowed_peers, &find_closest_peers, &closest_ctx); | ||
2965 | if (closest_ctx.closest != NULL) | ||
2966 | { | ||
2967 | GNUNET_assert((0 <= closest_ctx.closest_num) && (closest_ctx.closest_num < pg->total)); | ||
2968 | proc(pg, pg_iter, closest_ctx.closest_num); | ||
2969 | } | ||
2970 | } | ||
2971 | } | ||
2972 | } | ||
2973 | |||
2873 | /** | 2974 | /** |
2874 | * From the set of connections possible, choose at least num connections per | 2975 | * From the set of connections possible, choose at least num connections per |
2875 | * peer based on depth first traversal of peer connections. If DFS leaves | 2976 | * peer based on depth first traversal of peer connections. If DFS leaves |
@@ -3293,6 +3394,13 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3293 | #endif | 3394 | #endif |
3294 | perform_dfs(pg, (int)option_modifier); | 3395 | perform_dfs(pg, (int)option_modifier); |
3295 | break; | 3396 | break; |
3397 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: | ||
3398 | #if VERBOSE_TOPOLOGY | ||
3399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3400 | _("Finding additional %u closest peers each (if possible)\n"), (unsigned int)option_modifier); | ||
3401 | #endif | ||
3402 | add_closest(pg, (unsigned int)option_modifier, &add_actual_connections); | ||
3403 | break; | ||
3296 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: | 3404 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: |
3297 | break; | 3405 | break; |
3298 | case GNUNET_TESTING_TOPOLOGY_OPTION_ALL: | 3406 | case GNUNET_TESTING_TOPOLOGY_OPTION_ALL: |