-
-
-
-/**
- * Functions of this signature are called when a peer has been successfully
- * started or stopped.
- *
- * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
- * @param emsg NULL on success; otherwise an error description
- */
-static void
-peer_churn_cb (void *cls, const char *emsg)
-{
- struct DLLOperation *dll_op = cls;
- struct GNUNET_TESTBED_Operation *op;
- static unsigned int started_peers;
-
- op = dll_op->op;
- GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
- GNUNET_free (dll_op);
- if (NULL != emsg)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("An operation has failed while starting peers\n"));
- GNUNET_TESTBED_operation_done (op);
- GNUNET_SCHEDULER_cancel (abort_task);
- abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
- return;
- }
- GNUNET_TESTBED_operation_done (op);
- if (++started_peers == num_peers)
- {
- prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
- printf ("%u peers started successfully in %.2f seconds\n",
- num_peers, ((double) prof_time.rel_value) / 1000.00);
- fflush (stdout);
- result = GNUNET_OK;
- if ((0 == num_links) && (topology == GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI))
- {
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
- return;
- }
- state = STATE_PEERS_LINKING;
- /* Do overlay connect */
- prof_start_time = GNUNET_TIME_absolute_get ();
- switch (topology)
- {
- case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
- topology_op =
- GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peers,
- topology,
- num_links,
- GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
- GNUNET_TESTBED_TOPOLOGY_OPTION_END);
- break;
- case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
- topology_op =
- GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peers,
- topology,
- GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
- GNUNET_TESTBED_TOPOLOGY_OPTION_END);
- num_links = num_peers * (num_peers - 1);
- break;
- default:
- GNUNET_assert (0);
- }
- }
-}
-
-
-/**
- * Functions of this signature are called when a peer has been successfully
- * created
- *
- * @param cls the closure from GNUNET_TESTBED_peer_create()
- * @param peer the handle for the created peer; NULL on any error during
- * creation
- * @param emsg NULL if peer is not NULL; else MAY contain the error description
- */
-static void
-peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
-{
- struct DLLOperation *dll_op = cls;
- struct GNUNET_TESTBED_Peer **peer_ptr;
- static unsigned int created_peers;
- unsigned int peer_cnt;
-
- if (NULL != emsg)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Creating a peer failed. Error: %s\n"), emsg);
- GNUNET_TESTBED_operation_done (dll_op->op);
- GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
- GNUNET_free (dll_op);
- GNUNET_SCHEDULER_cancel (abort_task);
- abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
- return;
- }
- peer_ptr = dll_op->cls;
- GNUNET_assert (NULL == *peer_ptr);
- *peer_ptr = peer;
- GNUNET_TESTBED_operation_done (dll_op->op);
- GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
- GNUNET_free (dll_op);
- if (++created_peers == num_peers)
- {
- prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
- printf ("%u peers created successfully in %.2f seconds\n",
- num_peers, ((double) prof_time.rel_value) / 1000.00);
- fflush (stdout);
- /* Now peers are to be started */
- state = STATE_PEERS_STARTING;
- prof_start_time = GNUNET_TIME_absolute_get ();
- for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
- {
- dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
- dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt],
- &peer_churn_cb, dll_op);
- GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
- }
- }
-}
-
-