#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?
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,
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)))
"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))
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",
*/
struct GNUNET_TIME_Relative timeout_hello;
-
/**
* Was the connection attempt successful?
*/
int connected;
+
+ /**
+ * The distance between the two connected peers
+ */
+ uint32_t distance;
};
{
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);
}
}
{
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"));
}
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,
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;
}
{
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;
}
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;
}
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;
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;
}
* @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"
*/
"SCALE_FREE",
+ /**
+ * Straight line topology.
+ */
+ "LINE",
+
/**
* All peers are disconnected.
*/
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)
{
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)
{
}
-
-
+/**
+ * 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)
{
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)
{
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)
{
}
-
+/**
+ * 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)
{
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)
{
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,
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
}
#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;
#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:
#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,