/** * Convenience method that iterates over all (running) peers * and retrieves all statistics from each peer. * * @param num_peers number of peers to iterate over * @param peers array of peers to iterate over * @param subsystem limit to the specified subsystem, NULL for all subsystems * @param name name of the statistic value, NULL for all values * @param proc processing function for each statistic retrieved * @param cont continuation to call once call is completed(?) * @param cls closure to pass to proc and cont * @return operation handle to cancel the operation */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_get_statistics (unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, const char *subsystem, const char *name, GNUNET_TESTBED_StatisticsIterator proc, GNUNET_TESTBED_OperationCompletionCallback cont, void *cls) { struct GetStatsContext *sc; GNUNET_assert (NULL != proc); GNUNET_assert (NULL != cont); if (NULL == no_wait_queue) no_wait_queue = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); sc = GNUNET_new (struct GetStatsContext); sc->peers = peers; sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem); sc->name = (NULL == name) ? NULL : GNUNET_strdup (name); sc->proc = proc; sc->cont = cont; sc->cb_cls = cls; sc->num_peers = num_peers; sc->main_op = GNUNET_TESTBED_operation_create_ (sc, &opstart_get_stats, &oprelease_get_stats); GNUNET_TESTBED_operation_queue_insert_ (no_wait_queue, sc->main_op); GNUNET_TESTBED_operation_begin_wait_ (sc->main_op); return sc->main_op; }
/** * Create a host to run peers and controllers on. * * @param id global host ID assigned to the host; 0 is * reserved to always mean 'localhost' * @param hostname name of the host, use "NULL" for localhost * @param username username to use for the login; may be NULL * @param cfg the configuration to use as a template while starting a controller * on this host. Operation queue sizes specific to a host are also * read from this configuration handle * @param port port number to use for ssh; use 0 to let ssh decide * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname, const char *username, const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t port) { struct GNUNET_TESTBED_Host *host; unsigned int new_size; if ((id < host_list_size) && (NULL != host_list[id])) { LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); return NULL; } host = GNUNET_new (struct GNUNET_TESTBED_Host); host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL; host->username = (NULL != username) ? GNUNET_strdup (username) : NULL; host->id = id; host->port = (0 == port) ? 22 : port; host->cfg = GNUNET_CONFIGURATION_dup (cfg); host->opq_parallel_overlay_connect_operations = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE, UINT_MAX); new_size = host_list_size; while (id >= new_size) new_size += HOST_LIST_GROW_STEP; if (new_size != host_list_size) GNUNET_array_grow (host_list, host_list_size, new_size); GNUNET_assert (id < host_list_size); LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); host_list[id] = host; return host; }
/** * Main run function. * * @param cls NULL * @param args arguments passed to GNUNET_PROGRAM_run * @param cfgfile the path to configuration file * @param cfg the configuration file handle */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) { q1 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 1); GNUNET_assert (NULL != q1); q2 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 2); GNUNET_assert (NULL != q2); op1 = GNUNET_TESTBED_operation_create_ (&op1, start_cb, release_cb); GNUNET_assert (NULL != op1); op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb); GNUNET_TESTBED_operation_queue_insert_ (q1, op1); GNUNET_TESTBED_operation_queue_insert_ (q2, op1); GNUNET_TESTBED_operation_begin_wait_ (op1); GNUNET_TESTBED_operation_queue_insert_ (q1, op2); GNUNET_TESTBED_operation_queue_insert_ (q2, op2); GNUNET_TESTBED_operation_begin_wait_ (op2); result = TEST_INIT; }
/** * Testbed setup * * @param cls closure * @param server the initialized server * @param cfg configuration to use */ static void testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg) { static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, {&GST_handle_link_controllers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)}, {&GST_handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0}, {&GST_handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)}, {&GST_handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, sizeof (struct GNUNET_TESTBED_PeerStartMessage)}, {&GST_handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, sizeof (struct GNUNET_TESTBED_PeerStopMessage)}, {&GST_handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)}, {&GST_handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)}, {&GST_handle_remote_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0}, {&GST_handle_manage_peer_service, NULL, GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, 0}, {&handle_slave_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)}, {&GST_handle_shutdown_peers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)}, {&GST_handle_peer_reconfigure, NULL, GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0}, {&GST_handle_barrier_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 0}, {&GST_handle_barrier_cancel, NULL, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 0}, {&GST_handle_barrier_status, NULL, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 0}, {NULL, NULL, 0, 0} }; char *logfile; unsigned long long num; LOG_DEBUG ("Starting testbed\n"); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE", &logfile)) { GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile)); GNUNET_free (logfile); } GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED", "CACHE_SIZE", &num)); GST_cache_init ((unsigned int) num); GST_connection_pool_init ((unsigned int) num); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED", "MAX_OPEN_FDS", &num)); GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, (unsigned int) num); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED", "OPERATION_TIMEOUT", (struct GNUNET_TIME_Relative *) &GST_timeout)); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "HOSTNAME", &hostname)); GST_config = GNUNET_CONFIGURATION_dup (cfg); GNUNET_SERVER_add_handlers (server, message_handlers); GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); shutdown_task_id = GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_SCHEDULER_PRIORITY_IDLE, &shutdown_task, NULL); LOG_DEBUG ("Testbed startup complete\n"); GST_stats_init (GST_config); GST_barriers_init (GST_config); }