static struct GNUNET_CONSENSUS_Handle **consensus_handles;
+static struct GNUNET_TESTBED_Operation **testbed_operations;
+
static unsigned int num_connected_handles;
static struct GNUNET_TESTBED_Peer **peers;
static struct GNUNET_HashCode session_id;
+static unsigned int peers_done = 0;
+
/**
* Signature of the event handler function called by the
GNUNET_assert (0);
}
+static void
+destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx)
+{
+ struct GNUNET_CONSENSUS_Handle *consensus;
+ consensus = cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "destroying consensus\n");
+ GNUNET_CONSENSUS_destroy (consensus);
+ peers_done++;
+ if (peers_done == num_peers)
+ {
+ int i;
+ for (i = 0; i < num_peers; i++)
+ GNUNET_TESTBED_operation_done (testbed_operations[i]);
+ GNUNET_SCHEDULER_shutdown ();
+ }
+}
+
/**
* Called when a conclusion was successful.
*
- * @param cls
- * @param group
+ * @param cls closure, the consensus handle
* @return GNUNET_YES if more consensus groups should be offered, GNUNET_NO if not
*/
-static int
-conclude_cb (void *cls, const struct GNUNET_CONSENSUS_Group *group)
+static void
+conclude_cb (void *cls)
{
- return GNUNET_NO;
+ GNUNET_SCHEDULER_add_now (destroy, cls);
}
-
static void
generate_indices (int *indices)
{
}
for (i = 0; i < num_peers; i++)
- GNUNET_CONSENSUS_conclude (consensus_handles[i], conclude_timeout, 0, conclude_cb, consensus_handles[i]);
+ GNUNET_CONSENSUS_conclude (consensus_handles[i], conclude_timeout, conclude_cb, consensus_handles[i]);
}
}
-static int
+static void
new_element_cb (void *cls,
- struct GNUNET_CONSENSUS_Element *element)
+ const struct GNUNET_CONSENSUS_Element *element)
{
- return GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received new element\n");
}
num_retrieved_peer_ids++;
if (num_retrieved_peer_ids == num_peers)
for (i = 0; i < num_peers; i++)
- GNUNET_TESTBED_service_connect (NULL, peers[i], "consensus", connect_complete, &consensus_handles[i],
- connect_adapter, disconnect_adapter, NULL);
+ testbed_operations[i] =
+ GNUNET_TESTBED_service_connect (NULL, peers[i], "consensus", connect_complete, &consensus_handles[i],
+ connect_adapter, disconnect_adapter, NULL);
}
else
{
}
+/**
+ * Signature of a main function for a testcase.
+ *
+ * @param cls closure
+ * @param num_peers number of peers in 'peers'
+ * @param started_peers handle to peers run in the testbed. NULL upon timeout (see
+ * GNUNET_TESTBED_test_run()).
+ * @param links_succeeded the number of overlay link connection attempts that
+ * succeeded
+ * @param links_failed the number of overlay link connection attempts that
+ * failed
+ */
static void
test_master (void *cls,
unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **started_peers)
+ struct GNUNET_TESTBED_Peer **started_peers,
+ unsigned int links_succeeded,
+ unsigned int links_failed)
{
int i;
+ GNUNET_log_setup ("gnunet-consensus", "INFO", NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n");
+
peers = started_peers;
peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity));
consensus_handles = GNUNET_malloc (num_peers * sizeof (struct ConsensusHandle *));
+ testbed_operations = GNUNET_malloc (num_peers * sizeof (struct ConsensusHandle *));
for (i = 0; i < num_peers; i++)
GNUNET_TESTBED_peer_get_information (peers[i],
{
static char *session_str = "gnunet-consensus/test";
+ if (num_peers < replication)
+ {
+ fprintf (stderr, "k must be <=n\n");
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "running gnunet-consensus\n");