From a31eacdf89f2c932704cefb6498264895db01eab Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Wed, 28 Apr 2010 12:58:35 +0000 Subject: [PATCH] testing bugfix, add scale free topology --- src/testing/test_testing_topology.c | 11 ++++- src/testing/testing_group.c | 69 +++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index 6961f0418..2006cc468 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -116,6 +116,9 @@ struct TestMessageContext /* Identifier for this message, so we don't disconnect other peers! */ uint32_t uid; + /* Task for disconnecting cores, allow task to be cancelled on shutdown */ + GNUNET_SCHEDULER_TaskIdentifier disconnect_task; + }; static struct TestMessageContext *test_messages; @@ -147,6 +150,10 @@ finish_testing () } free_pos = pos; pos = pos->next; + if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task); + } GNUNET_free(free_pos); } #if VERBOSE @@ -194,6 +201,7 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) /* Set handles to NULL so test case can be ended properly */ pos->peer1handle = NULL; pos->peer2handle = NULL; + pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK; /* Decrement total connections so new can be established */ total_server_connections -= 2; } @@ -225,7 +233,7 @@ process_mtype (void *cls, } else { - GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos); + pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos); } return GNUNET_OK; @@ -443,6 +451,7 @@ topology_callback (void *cls, temp_context->peer2 = second_daemon; temp_context->next = test_messages; temp_context->uid = total_connections; + temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; test_messages = temp_context; expected_messages++; diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 136b167fb..43ebd5e25 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -82,10 +82,15 @@ struct PeerData */ struct GNUNET_TESTING_Daemon *daemon; - /* + /** * Linked list of peer connections (simply indexes of PeerGroup) */ struct PeerConnection *connected_peers; + + /** + * Total number of connections this peer has + */ + int num_connections; }; @@ -332,6 +337,7 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigne new_first->daemon = pg->peers[second].daemon; new_first->next = pg->peers[first].connected_peers; pg->peers[first].connected_peers = new_first; + pg->peers[first].num_connections++; added++; } @@ -341,12 +347,52 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigne new_second->daemon = pg->peers[first].daemon; new_second->next = pg->peers[second].connected_peers; pg->peers[second].connected_peers = new_second; + pg->peers[first].num_connections++; added++; } return added; } +static int +create_scale_free (struct GNUNET_TESTING_PeerGroup *pg) +{ + + int total_connections; + int outer_count; + int i; + int previous_total_connections; + double random; + double probability; + + GNUNET_assert(pg->total > 1); + + /* Add a connection between the first two nodes */ + total_connections = add_connections(pg, 0, 1); + + for (outer_count = 1; outer_count < pg->total - 1; outer_count++) + { + previous_total_connections = total_connections; + for (i = 0; i < outer_count; i++) + { + probability = pg->peers[i].num_connections / previous_total_connections; + random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, + (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); + if (random < probability) + { +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Connecting peer %d to peer %d\n", + outer_count, i); +#endif + total_connections += add_connections(pg, outer_count, i); + } + } + } + + return total_connections; +} + int create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg) { @@ -1076,52 +1122,59 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg) case GNUNET_TESTING_TOPOLOGY_CLIQUE: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating clique topology (may take a bit!)\n")); + _("Creating clique topology\n")); #endif num_connections = create_clique (pg); break; case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating small world (ring) topology (may take a bit!)\n")); + _("Creating small world (ring) topology\n")); #endif num_connections = create_small_world_ring (pg); break; case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating small world (2d-torus) topology (may take a bit!)\n")); + _("Creating small world (2d-torus) topology\n")); #endif num_connections = create_small_world (pg); break; case GNUNET_TESTING_TOPOLOGY_RING: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating ring topology (may take a bit!)\n")); + _("Creating ring topology\n")); #endif num_connections = create_ring (pg); break; case GNUNET_TESTING_TOPOLOGY_2D_TORUS: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating 2d torus topology (may take a bit!)\n")); + _("Creating 2d torus topology\n")); #endif num_connections = create_2d_torus (pg); break; case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating Erdos-Renyi topology (may take a bit!)\n")); + _("Creating Erdos-Renyi topology\n")); #endif num_connections = create_erdos_renyi (pg); break; case GNUNET_TESTING_TOPOLOGY_INTERNAT: #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating InterNAT topology (may take a bit!)\n")); + _("Creating InterNAT topology\n")); #endif num_connections = create_nated_internet (pg); break; + case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating Scale Free topology\n")); +#endif + num_connections = create_scale_free (pg); + break; case GNUNET_TESTING_TOPOLOGY_NONE: num_connections = 0; break; -- 2.25.1