void testbed_master (void *cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers) { GNUNET_assert (NULL != peers); cpeers = peers; setup_task = GNUNET_SCHEDULER_add_delayed (SETUP_TIMEOUT, &setup_end_badly, NULL); /* peer 0: dave */ GNUNET_assert (NULL != peers[0]); get_cfg_ops[0] = GNUNET_TESTBED_peer_get_information (peers[0], GNUNET_TESTBED_PIT_CONFIGURATION, &peerinfo_cb, NULL); /* peer 1: bob */ GNUNET_assert (NULL != peers[1]); get_cfg_ops[1] = GNUNET_TESTBED_peer_get_information (peers[1], GNUNET_TESTBED_PIT_CONFIGURATION, &peerinfo_cb, NULL ); /* peer 2: alice */ GNUNET_assert (NULL != peers[2]); get_cfg_ops[2] = GNUNET_TESTBED_peer_get_information (peers[2], GNUNET_TESTBED_PIT_CONFIGURATION, &peerinfo_cb, NULL); }
/** * test main: start test when all peers are connected * * @param cls Closure. * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end. * @param num_peers Number of peers that are running. * @param peers Array of peers. * @param cadetes Handle to each of the CADETs of the peers. */ static void tmain (void *cls, struct GNUNET_CADET_TEST_Context *ctx, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, struct GNUNET_CADET_Handle **cadets) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n"); ok = 0; test_ctx = ctx; peers_running = num_peers; GNUNET_assert (peers_running == peers_requested); testbed_peers = peers; h1 = cadets[0]; h2 = cadets[num_peers - 1]; disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_cadet_peers, (void *) __LINE__); GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], GNUNET_TESTBED_PIT_IDENTITY, &pi_cb, (void *) 0L); t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1], GNUNET_TESTBED_PIT_IDENTITY, &pi_cb, (void *) 1L); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); }
/** * Controller event callback * * @param cls NULL * @param event the controller event */ static void controller_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) { case GNUNET_TESTBED_ET_OPERATION_FINISHED: if (NULL != event->details.operation_finished.emsg) { FPRINTF (stderr, "Error while expecting an operation to succeed:%s \n", event->details.operation_finished.emsg); GNUNET_assert (0); } break; case GNUNET_TESTBED_ET_CONNECT: GNUNET_TESTBED_operation_done (common_op); /* Get the peer identity and configuration of peers */ common_op = GNUNET_TESTBED_peer_get_information (peer_data[0].peer, GNUNET_TESTBED_PIT_IDENTITY, &peerinfo_cb, &peer_data[0]); break; default: GNUNET_assert (0); } }
/** * Callback to be called when the requested peer information is available * * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() * @param op the operation this callback corresponds to * @param pinfo the result; will be NULL if the operation has failed * @param emsg error message if the operation has failed; will be NULL if the * operation is successfull */ static void peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg) { struct PeerData *pdata = cb_cls; GNUNET_assert (NULL == emsg); GNUNET_assert (common_op == op); GNUNET_assert (NULL != pdata); memcpy (&pdata->id, pinfo->result.id, sizeof (struct GNUNET_PeerIdentity)); GNUNET_TESTBED_operation_done (op); if (pdata == &peer_data[0]) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s (&pdata->id)); common_op = GNUNET_TESTBED_peer_get_information (peer_data[1].peer, GNUNET_TESTBED_PIT_IDENTITY, &peerinfo_cb, &peer_data[1]); } else if (pdata == &peer_data[1]) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s (&pdata->id)); if (TEST_STEP_2_HOP == test_step) peer_data[1].op = GNUNET_TESTBED_service_connect (&peer_data[1], peer_data[1].peer, "stream", NULL, NULL, stream_ca, stream_da, &peer_data[1]); else GNUNET_break (0); /* FIXME: 3 hop test case here... */ } }
/** * Signature of a main function for a testcase. * * @param cls closure * @param h the run handle * @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, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **started_peers, unsigned int links_succeeded, unsigned int links_failed) { int i; GNUNET_log_setup ("gnunet-secretsharing-profiler", "INFO", NULL); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n"); peers = started_peers; peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity)); session_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Session *); decrypt_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_DecryptionHandle *); testbed_operations = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); shares = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Share *); for (i = 0; i < num_peers; i++) GNUNET_TESTBED_peer_get_information (peers[i], GNUNET_TESTBED_PIT_IDENTITY, peer_info_cb, &peer_ids[i]); }
/** * Signature of a main function for a testcase. * * @param cls closure * @param h the run handle * @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, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_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)); results_for_peer = GNUNET_malloc (num_peers * sizeof (unsigned int)); 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], GNUNET_TESTBED_PIT_IDENTITY, peer_info_cb, &peer_ids[i]); }
/** * Signature of a main function for a testcase. * * @param cls closure * @param h the run handle * @param num_peers number of peers in 'peers' * @param 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 * @see GNUNET_TESTBED_test_run() */ static void test_master (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed) { GNUNET_assert (NUM_PEERS == num_peers); GNUNET_assert (0 == links_failed); shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, NULL); GNUNET_TESTBED_peer_get_information (peers[0], GNUNET_TESTBED_PIT_CONFIGURATION, &peer_info_cb, peers[0]); }
/** * Signature of a main function for a testcase. * * @param cls closure * @param h the run handle * @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, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **started_peers, unsigned int links_succeeded, unsigned int links_failed) { int i; GNUNET_log_setup ("gnunet-secretsharing-profiler", "INFO", NULL); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n"); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &handle_shutdown, NULL); peers = started_peers; peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity)); session_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Session *); decrypt_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_DecryptionHandle *); connect_ops = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); shares = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Share *); for (i = 0; i < num_peers; i++) { // we do not store the returned operation, as peer_info_cb // will receive it as a parameter and call GNUNET_TESTBED_operation_done. GNUNET_TESTBED_peer_get_information (peers[i], GNUNET_TESTBED_PIT_IDENTITY, peer_info_cb, &peer_ids[i]); } }