From: Nathan S. Evans Date: Thu, 17 Jun 2010 15:29:40 +0000 (+0000) Subject: some testing changes, including an api change that likely breaks things for others X-Git-Tag: initial-import-from-subversion-38251~21357 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7f06c82295b46f1c8f1f3b16d5e979abea3e5660;p=oweals%2Fgnunet.git some testing changes, including an api change that likely breaks things for others --- diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index dfc59ab74..d7bb836e9 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -25,7 +25,7 @@ #include "gnunet_testing_lib.h" #include "gnunet_core_service.h" -#define VERBOSE GNUNET_NO +#define VERBOSE GNUNET_YES /** * How long until we fail the whole testcase? @@ -445,6 +445,7 @@ void topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second, + uint32_t distance, const struct GNUNET_CONFIGURATION_Handle *first_cfg, const struct GNUNET_CONFIGURATION_Handle *second_cfg, struct GNUNET_TESTING_Daemon *first_daemon, @@ -699,7 +700,7 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); } - + GNUNET_free_non_null(connect_topology_str); if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option", &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str))) @@ -708,7 +709,7 @@ run (void *cls, "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION"); connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ } - + GNUNET_free_non_null(connect_topology_option_str); if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier", &connect_topology_option_modifier_string)) @@ -730,11 +731,13 @@ run (void *cls, if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology", - & blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str))) + &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); } + GNUNET_free_non_null(topology_str); + GNUNET_free_non_null(blacklist_topology_str); if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", diff --git a/src/testing/testing.c b/src/testing/testing.c index 0c650d313..5b36fc380 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -1158,11 +1158,15 @@ struct ConnectContext */ struct GNUNET_TIME_Relative timeout_hello; - /** * Was the connection attempt successful? */ int connected; + + /** + * The distance between the two connected peers + */ + uint32_t distance; }; @@ -1210,7 +1214,7 @@ notify_connect_result (void *cls, { if (ctx->cb != NULL) { - ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, + ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->distance, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); } } @@ -1234,7 +1238,7 @@ notify_connect_result (void *cls, { if (ctx->cb != NULL) { - ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, + ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect")); } @@ -1266,6 +1270,7 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNE if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0) { ctx->connected = GNUNET_YES; + ctx->distance = distance; GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task); ctx->timeout_task = GNUNET_SCHEDULER_add_now (ctx->d1->sched, ¬ify_connect_result, @@ -1319,7 +1324,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) { if (NULL != cb) - cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, + cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, _("Peers are not fully running yet, can not connect!\n")); return; } @@ -1351,7 +1356,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, { GNUNET_free (ctx); if (NULL != cb) - cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, + cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, _("Failed to connect to core service of first peer!\n")); return; } @@ -1372,7 +1377,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, GNUNET_CORE_disconnect(ctx->d1core); GNUNET_free (ctx); if (NULL != cb) - cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, + cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, _("Failed to connect to transport service!\n")); return; } @@ -1412,7 +1417,7 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext if (ctx->d1core == NULL) { if (NULL != ctx->cb) - ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, + ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, _("Failed to connect to core service of first peer!\n")); GNUNET_free (ctx); return; @@ -1425,7 +1430,7 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext GNUNET_CORE_disconnect(ctx->d1core); GNUNET_free (ctx); if (NULL != ctx->cb) - ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, + ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, _("Failed to connect to transport service!\n")); return; } diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 9965bb2fb..b6ae14036 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -22,6 +22,15 @@ * @file testing/testing_group.c * @brief convenience API for writing testcases for GNUnet * @author Christian Grothoff + * + * FIXME: have connection processor functions take a cls argument + * which specifies where to write the connection information + * instead of assuming it's certain peergroup places. (maybe?) + * FIXME: create static struct which contains the TOPOLOGY enum, the + * associated string, and the function used to create it. + * Then replace the create_X calls with topology_struct[i][2] + * or something. (Store function pointers instead of using + * switch statements) */ #include "platform.h" #include "gnunet_arm_service.h" @@ -107,6 +116,11 @@ static char * GNUNET_TESTING_TopologyStrings[] = */ "SCALE_FREE", + /** + * Straight line topology. + */ + "LINE", + /** * All peers are disconnected. */ @@ -902,6 +916,17 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio return total_connections; } +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ int create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1013,7 +1038,17 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn return connect_attempts; } - +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ static int create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1065,8 +1100,17 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conne } - - +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ static int create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1208,8 +1252,17 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti return connect_attempts; } - - +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ static int create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1257,6 +1310,17 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti return connect_attempts; } +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ static int create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1334,7 +1398,17 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionP } - +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ static int create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1361,7 +1435,50 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionPro return connect_attempts; } +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ +static int +create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) +{ + unsigned int count; + int connect_attempts; + + connect_attempts = 0; + + /* Connect each peer to the next highest numbered peer */ + for (count = 0; count < pg->total - 1; count++) + { +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Connecting peer %d to peer %d\n", + count, count + 1); +#endif + connect_attempts += proc(pg, count, count + 1); + } + return connect_attempts; +} + +/** + * Create a topology given a peer group (set of running peers) + * and a connection processor. + * + * @param pg the peergroup to create the topology on + * @param proc the connection processor to call to actually set + * up connections between two peers + * + * @return the number of connections that were set up + * + */ static int create_ring (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) { @@ -1745,6 +1862,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, char *tran static void internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second, + uint32_t distance, const struct GNUNET_CONFIGURATION_Handle *first_cfg, const struct GNUNET_CONFIGURATION_Handle *second_cfg, struct GNUNET_TESTING_Daemon *first_daemon, @@ -1754,12 +1872,16 @@ static void internal_connect_notify (void *cls, struct GNUNET_TESTING_PeerGroup *pg = cls; outstanding_connects--; +<<<<<<< .mine + pg->notify_connection(pg->notify_connection_cls, first, second, distance, first_cfg, second_cfg, first_daemon, second_daemon, emsg); +======= pg->notify_connection(pg->notify_connection_cls, first, second, first_cfg, second_cfg, first_daemon, second_daemon, emsg); +>>>>>>> .r11782 } @@ -2010,6 +2132,13 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, #endif num_connections = create_scale_free (pg, &add_allowed_connections); break; + case GNUNET_TESTING_TOPOLOGY_LINE: +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating straight line topology\n")); +#endif + num_connections = create_line (pg, &add_allowed_connections); + break; case GNUNET_TESTING_TOPOLOGY_NONE: num_connections = 0; break; @@ -2103,6 +2232,13 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, #endif unblacklisted_connections = create_scale_free (pg, &unblacklist_connections); break; + case GNUNET_TESTING_TOPOLOGY_LINE: +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Blacklisting all but straight line topology\n")); +#endif + unblacklisted_connections = create_line (pg, &unblacklist_connections); + break; case GNUNET_TESTING_TOPOLOGY_NONE: /* Fall through */ default: @@ -2581,6 +2717,13 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, #endif create_scale_free (pg, &add_actual_connections); break; + case GNUNET_TESTING_TOPOLOGY_LINE: +#if VERBOSE_TOPOLOGY + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating straight line CONNECT topology\n")); +#endif + create_line (pg, &add_actual_connections); + break; case GNUNET_TESTING_TOPOLOGY_NONE: #if VERBOSE_TOPOLOGY GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,