-/*
+/**
This file is part of GNUnet.
(C) 2011, 2012 Christian Grothoff (and other contributing authors)
*/
/**
- * @file regex/gnunet-regex-profiler.c
+ * @file mesh/gnunet-regex-profiler.c
* @brief Regex profiler for testing distributed regex use.
* @author Bart Polot
* @author Max Szengel
+ *
*/
#include <string.h>
#include "gnunet_stream_lib.h"
#include "gnunet_testbed_service.h"
-
/**
- * Total number of hosts.
+ * DLL of operations
*/
-#define NUM_HOSTS 2
+struct DLLOperation
+{
+ /**
+ * The testbed operation handle
+ */
+ struct GNUNET_TESTBED_Operation *op;
+
+ /**
+ * Closure
+ */
+ void *cls;
+
+ /**
+ * The next pointer for DLL
+ */
+ struct DLLOperation *next;
+
+ /**
+ * The prev pointer for DLL
+ */
+ struct DLLOperation *prev;
+};
-/**
- * Number of peers per host.
- */
-#define PEER_PER_HOST 1
/**
- * Total number of peers.
+ * Available states during profiling
*/
-#define TOTAL_PEERS (NUM_HOSTS * PEER_PER_HOST)
+enum State
+{
+ /**
+ * Initial state
+ */
+ STATE_INIT = 0,
+
+ /**
+ * Starting slaves
+ */
+ STATE_SLAVES_STARTING,
+
+ /**
+ * Creating peers
+ */
+ STATE_PEERS_CREATING,
+
+ /**
+ * Starting peers
+ */
+ STATE_PEERS_STARTING,
+
+ /**
+ * Linking peers
+ */
+ STATE_PEERS_LINKING,
+
+ /**
+ * Matching strings against announced regexes
+ */
+ STATE_SEARCH_REGEX,
+
+ /**
+ * Destroying peers; we can do this as the controller takes care of stopping a
+ * peer if it is running
+ */
+ STATE_PEERS_DESTROYING
+};
/**
- * Different states in test setup
+ * Peer handles.
*/
-enum SetupState
+struct RegexPeer
{
/**
- * The initial state
+ * Peer id.
+ */
+ unsigned int id;
+
+ /**
+ * Peer configuration handle.
+ */
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * The actual testbed peer handle.
+ */
+ struct GNUNET_TESTBED_Peer *peer_handle;
+
+ /**
+ * Host on which the peer is running.
+ */
+ struct GNUNET_TESTBED_Host *host_handle;
+
+ /**
+ * Filename of the peer's policy file.
+ */
+ char *policy_file;
+
+ /**
+ * Peers search string.
*/
- INIT,
+ const char *search_str;
/**
- * Connecting to slave controller
+ * Set to GNUNET_YES if the peer successfully matched the above
+ * search string. GNUNET_NO if the string could not be matched
+ * during the profiler run. GNUNET_SYSERR if the string matching
+ * timed out. Undefined if search_str is NULL
*/
- LINKING,
+ int search_str_matched;
- LINKING_SLAVES,
+ /**
+ * Peer's mesh handle.
+ */
+ struct GNUNET_MESH_Handle *mesh_handle;
- LINKING_SLAVES_SUCCESS,
+ /**
+ * Peer's mesh tunnel handle.
+ */
+ struct GNUNET_MESH_Tunnel *mesh_tunnel_handle;
+
+ /**
+ * Testbed operation handle for the mesh service.
+ */
+ struct GNUNET_TESTBED_Operation *mesh_op_handle;
- CONNECTING_PEERS,
+ /**
+ * Peers's statistics handle.
+ */
+ struct GNUNET_STATISTICS_Handle *stats_handle;
- CREATING_PEER,
+ /**
+ * Testbed operation handle for the statistics service.
+ */
+ struct GNUNET_TESTBED_Operation *stats_op_handle;
- STARTING_PEER
+ /**
+ * The starting time of a profiling step.
+ */
+ struct GNUNET_TIME_Absolute prof_start_time;
};
/**
- * Event Mask for operation callbacks
+ * An array of hosts loaded from the hostkeys file
*/
-uint64_t event_mask;
+static struct GNUNET_TESTBED_Host **hosts;
/**
- * Testbed operation handle
+ * Array of peer handles used to pass to
+ * GNUNET_TESTBED_overlay_configure_topology
*/
-static struct GNUNET_TESTBED_Operation *op[NUM_HOSTS];
+static struct GNUNET_TESTBED_Peer **peer_handles;
/**
- * Setup state.
+ * The array of peers; we fill this as the peers are given to us by the testbed
*/
-static enum SetupState state[NUM_HOSTS];
+static struct RegexPeer *peers;
/**
- * Abort task.
+ * Host registration handle
*/
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
/**
- * Global test result
+ * Handle to the master controller process
*/
-static int result;
+static struct GNUNET_TESTBED_ControllerProc *mc_proc;
/**
- * Hosts successfully registered
+ * Handle to the master controller
*/
-static unsigned int host_registered;
+static struct GNUNET_TESTBED_Controller *mc;
/**
- * Peers successfully started
+ * Handle to global configuration
*/
-static unsigned int peers_started;
+static struct GNUNET_CONFIGURATION_Handle *cfg;
/**
- * The master controller host
+ * Head of the operations list
*/
-struct GNUNET_TESTBED_Host *master_host;
+static struct DLLOperation *dll_op_head;
/**
- * The master controller process
+ * Tail of the operations list
*/
-static struct GNUNET_TESTBED_ControllerProc *master_proc;
+static struct DLLOperation *dll_op_tail;
/**
- * Handle to master controller
+ * Peer linking - topology operation
*/
-static struct GNUNET_TESTBED_Controller *master_ctrl;
+static struct GNUNET_TESTBED_Operation *topology_op;
+/**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
/**
- * Slave host registration handles
+ * Host registration task identifier
*/
-static struct GNUNET_TESTBED_HostRegistrationHandle *rh;
+static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
+/**
+ * Global event mask for all testbed events
+ */
+static uint64_t event_mask;
/**
- * Handle to global configuration
+ * The starting time of a profiling step
*/
-static struct GNUNET_CONFIGURATION_Handle *cfg;
+static struct GNUNET_TIME_Absolute prof_start_time;
/**
- * Structure for storing host handles
+ * Duration profiling step has taken
*/
-struct Host
-{
- /**
- * IP address of this host.
- */
- char *ip;
+static struct GNUNET_TIME_Relative prof_time;
- /**
- * Host handle.
- */
- struct GNUNET_TESTBED_Host *host;
+/**
+ * Number of peers to be started by the profiler
+ */
+static unsigned int num_peers;
- /**
- * Registration state of this host.
- */
- int host_registered;
+/**
+ * Number of hosts in the hosts array
+ */
+static unsigned int num_hosts;
- /**
- * Operation handle.
- */
- struct GNUNET_TESTBED_Operation *op;
+/**
+ * Factor of number of links. num_links = num_peers * linking_factor.
+ */
+static unsigned int linking_factor;
- /**
- * Host state.
- */
- enum SetupState state;
-};
+/**
+ * Number of random links to be established between peers
+ */
+static unsigned int num_links;
/**
- * List of slaves.
+ * Number of times we try overlay connect operations
*/
-static struct Host slaves[NUM_HOSTS] = { {"192.168.1.33", NULL, 0, NULL, INIT},
-{"192.168.1.34", NULL, 0, NULL, INIT}
-};
+static unsigned int retry_links;
/**
- * Structure for holding peer's handles.
+ * Continuous failures during overlay connect operations
*/
-struct PeerData
-{
- /**
- * Handle to testbed peer.
- */
- struct GNUNET_TESTBED_Peer *peer;
+static unsigned int cont_fails;
- /**
- * Peer's mesh handle.
- */
- struct GNUNET_MESH_Handle *mesh_handle;
+/**
+ * Global testing status
+ */
+static int result;
- /**
- * The service connect operation to stream
- */
- struct GNUNET_TESTBED_Operation *op;
+/**
+ * current state of profiling
+ */
+enum State state;
- /**
- * Peer setup state.
- */
- enum SetupState state;
+/**
+ * Folder where policy files are stored.
+ */
+static char * policy_dir;
- /**
- * Our Peer id
- */
- struct GNUNET_PeerIdentity our_id;
-};
+/**
+ * Search strings.
+ */
+static char **search_strings;
/**
- * The peers
+ * Number of search strings.
*/
-struct PeerData peers[TOTAL_PEERS];
+static int num_search_strings;
+/**
+ * Number of peers found with search strings.
+ */
+static unsigned int peers_found;
+/**
+ * Search task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier search_task;
/**
- * Close sockets and stop testing deamons nicely
+ * Search timeout task identifier.
*/
-void
-do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- unsigned int i;
+static GNUNET_SCHEDULER_TaskIdentifier search_timeout_task;
- if (GNUNET_SCHEDULER_NO_TASK != abort_task)
- GNUNET_SCHEDULER_cancel (abort_task);
+/**
+ * Search timeout in seconds.
+ */
+static struct GNUNET_TIME_Relative search_timeout = { 60000 };
- for (i = 0; i < TOTAL_PEERS; i++)
- {
- if (NULL != peers[i].mesh_handle)
- GNUNET_MESH_disconnect (peers[i].mesh_handle);
- if (NULL != peers[i].op)
- GNUNET_TESTBED_operation_done (peers[i].op);
- }
+/**
+ * How long do we wait before starting the search?
+ * Default: 1 m.
+ */
+static struct GNUNET_TIME_Relative search_delay = { 60000 };
- GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
-}
+/**
+ * Delay to wait before starting to configure the overlay topology
+ */
+static struct GNUNET_TIME_Relative conf_topo_delay = { 10000 };
+/**
+ * File to log statistics to.
+ */
+static struct GNUNET_DISK_FileHandle *data_file;
/**
- * Something went wrong and timed out. Kill everything and set error flag.
- *
- * @param cls close.
- * @param tc task context.
+ * Filename to log statistics to.
*/
-static void
-do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
- result = GNUNET_SYSERR;
- abort_task = 0;
-}
+static char *data_filename;
+
+/**
+ * Maximal path compression length.
+ */
+static unsigned int max_path_compression;
+
+/******************************************************************************/
+/****************************** DECLARATIONS ********************************/
+/******************************************************************************/
/**
- * Method called whenever another peer has added us to a tunnel
- * the other peer initiated.
- * Only called (once) upon reception of data with a message type which was
- * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy
- * causes te tunnel to be ignored and no further notifications are sent about
- * the same tunnel.
+ * Method called whenever a peer has connected to the tunnel.
*
* @param cls closure
- * @param tunnel new handle to the tunnel
- * @param initiator peer that started the tunnel
- * @param atsi performance information for the tunnel
- * @return initial tunnel context for the tunnel
- * (can be NULL -- that's not an error)
- */
-void *
-mesh_inbound_tunnel_handler (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *initiator,
- const struct GNUNET_ATS_Information *atsi)
-{
- return NULL;
-}
+ * @param peer_id peer identity the tunnel was created to, NULL on timeout
+ * @param atsi performance data for the connection
+ *
+ */
+static void
+mesh_peer_connect_handler (void *cls,
+ const struct GNUNET_PeerIdentity* peer_id,
+ const struct GNUNET_ATS_Information * atsi);
/**
- * Function called whenever an inbound tunnel is destroyed. Should clean up
- * any associated state. This function is NOT called if the client has
- * explicitly asked for the tunnel to be destroyed using
- * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on
- * the tunnel.
+ * Method called whenever a peer has disconnected from the tunnel.
+ * Implementations of this callback must NOT call
+ * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those
+ * to run in some other task later. However, calling
+ * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed.
*
- * @param cls closure (set from GNUNET_MESH_connect)
- * @param tunnel connection to the other end (henceforth invalid)
- * @param tunnel_ctx place where local state associated
- * with the tunnel is stored
+ * @param cls closure
+ * @param peer_id peer identity the tunnel stopped working with
*/
-void
-mesh_tunnel_end_handler (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
- void *tunnel_ctx)
-{
-
-}
-
+static void
+mesh_peer_disconnect_handler (void *cls,
+ const struct GNUNET_PeerIdentity * peer_id);
/**
* Mesh connect callback.
* @param ca_result connect adapter result.
* @param emsg error message.
*/
-void
+static void
mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
- void *ca_result, const char *emsg)
-{
- long i = (long) cls;
-
- if (NULL != emsg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Mesh connect failed: %s\n", emsg);
- GNUNET_assert (0);
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect callback for peer %i\n",
- i);
-}
-
+ void *ca_result, const char *emsg);
/**
* Mesh connect adapter.
*
* @return
*/
-void *
-mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct PeerData *peer = (struct PeerData *) cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect adapter\n");
-
- static struct GNUNET_MESH_MessageHandler handlers[] = {
- {NULL, 0, 0}
- };
-
- static GNUNET_MESH_ApplicationType apptypes[] = {
- GNUNET_APPLICATION_TYPE_END
- };
-
- peer->mesh_handle =
- GNUNET_MESH_connect (cfg, cls, &mesh_inbound_tunnel_handler,
- &mesh_tunnel_end_handler, handlers, apptypes);
-
- return NULL;
-}
+static void *
+mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
/**
* @param cls closure
* @param op_result service handle returned from the connect adapter
*/
-void
-mesh_da (void *cls, void *op_result)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh disconnect adapter\n");
-}
+static void
+mesh_da (void *cls, void *op_result);
+
+
+/******************************************************************************/
+/******************************** SHUTDOWN **********************************/
+/******************************************************************************/
/**
- * Functions of this signature are called when a peer has been successfully
- * started or stopped.
+ * Shutdown nicely
*
- * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
- * @param emsg NULL on success; otherwise an error description
+ * @param cls NULL
+ * @param tc the task context
*/
static void
-peer_start_cb (void *cls, const char *emsg)
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- unsigned int cnt;
- long i = (long) cls;
+ struct DLLOperation *dll_op;
+ struct RegexPeer *peer;
+ unsigned int nhost;
+ unsigned int peer_cnt;
+ unsigned int search_str_cnt;
+ char output_buffer[512];
+ size_t size;
- GNUNET_TESTBED_operation_done (op[i]);
- peers_started++;
- // FIXME create and start rest of PEERS_PER_HOST
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u peer(s) started\n", peers_started);
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ GNUNET_SCHEDULER_cancel (abort_task);
+ if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
+ GNUNET_SCHEDULER_cancel (register_hosts_task);
- if (TOTAL_PEERS == peers_started)
+ for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started.\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Linking slave controllers\n");
+ peer = &peers[peer_cnt];
- for (cnt = 0; cnt < NUM_HOSTS - 1; cnt++)
+ if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
{
- state[cnt] = LINKING_SLAVES;
- op[cnt] =
- GNUNET_TESTBED_get_slave_config ((void *) (long) cnt, master_ctrl,
- slaves[cnt + 1].host);
+ prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
+ size =
+ GNUNET_snprintf (output_buffer,
+ sizeof (output_buffer),
+ "Search string not found: %s (%d)\nOn peer: %u (%p)\nWith policy file: %s\nAfter: %s\n",
+ peer->search_str,
+ peer->search_str_matched,
+ peer->id,
+ peer,
+ peer->policy_file,
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
+ if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
}
+
+ if (NULL != peers[peer_cnt].mesh_op_handle)
+ GNUNET_TESTBED_operation_done (peers[peer_cnt].mesh_op_handle);
+ if (NULL != peers[peer_cnt].stats_op_handle)
+ GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle);
+ }
+
+ if (NULL != data_file)
+ GNUNET_DISK_file_close (data_file);
+
+ for (search_str_cnt = 0;
+ search_str_cnt < num_search_strings && NULL != search_strings;
+ search_str_cnt++)
+ {
+ GNUNET_free_non_null (search_strings[search_str_cnt]);
+ }
+ GNUNET_free_non_null (search_strings);
+
+ if (NULL != reg_handle)
+ GNUNET_TESTBED_cancel_registration (reg_handle);
+ if (NULL != topology_op)
+ GNUNET_TESTBED_operation_done (topology_op);
+ for (nhost = 0; nhost < num_hosts; nhost++)
+ if (NULL != hosts[nhost])
+ GNUNET_TESTBED_host_destroy (hosts[nhost]);
+ GNUNET_free_non_null (hosts);
+
+ while (NULL != (dll_op = dll_op_head))
+ {
+ GNUNET_TESTBED_operation_done (dll_op->op);
+ GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+ GNUNET_free (dll_op);
}
+ if (NULL != mc)
+ GNUNET_TESTBED_controller_disconnect (mc);
+ if (NULL != mc_proc)
+ GNUNET_TESTBED_controller_stop (mc_proc);
+ if (NULL != cfg)
+ GNUNET_CONFIGURATION_destroy (cfg);
+
+ GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
}
/**
- * Functions of this signature are called when a peer has been successfully
- * created
+ * abort task to run on test timed out
*
- * @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
+ * @param cls NULL
+ * @param tc the task context
*/
static void
-peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
+ abort_task = GNUNET_SCHEDULER_NO_TASK;
+ result = GNUNET_SYSERR;
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+}
+
+
+/******************************************************************************/
+/********************* STATISTICS SERVICE CONNECTIONS ***********************/
+/******************************************************************************/
+
+/**
+ * Adapter function called to establish a connection to
+ * statistics service.
+ *
+ * @param cls closure
+ * @param cfg configuration of the peer to connect to; will be available until
+ * GNUNET_TESTBED_operation_done() is called on the operation returned
+ * from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- long i = (long) cls;
- long peer_id;
-
-// GNUNET_TESTBED_operation_done(op[i]);
- peer_id = i; // FIXME A * i + B
- peers[peer_id].peer = peer;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer %i created\n", peer_id);
- op[i] = GNUNET_TESTBED_peer_start (NULL, peer, peer_start_cb, (void *) i);
+ return GNUNET_STATISTICS_create ("<driver>", cfg);
}
/**
- * Signature of the event handler function called by the
- * respective event controller.
+ * Adapter function called to destroy a connection to
+ * statistics service.
*
* @param cls closure
- * @param event information about the event
+ * @param op_result service handle returned from the connect adapter
*/
static void
-controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
+stats_da (void *cls, void *op_result)
{
- long i;
+ struct RegexPeer *peer = cls;
- switch (event->type)
- {
- case GNUNET_TESTBED_ET_PEER_START:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer started\n");
- /* event->details.peer_start.peer; */
- /* event->details.peer_start.host; */
+ GNUNET_assert (op_result == peer->stats_handle);
- break;
- case GNUNET_TESTBED_ET_PEER_STOP:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer stopped\n");
- break;
- case GNUNET_TESTBED_ET_CONNECT:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Overlay Connected\n");
- for (i = 0; i < TOTAL_PEERS; i++)
- {
- GNUNET_TESTBED_service_connect (NULL, peers[i].peer, "mesh",
- &mesh_connect_cb, (void *) i, &mesh_ca,
- &mesh_da, NULL);
- }
- break;
- case GNUNET_TESTBED_ET_OPERATION_FINISHED:
- if (NULL != event->details.operation_finished.emsg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed error: %s\n",
- event->details.operation_finished.emsg);
- GNUNET_assert (0);
- }
+ GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
+ peer->stats_handle = NULL;
+}
- i = (long) event->details.operation_finished.op_cls;
- switch (state[i])
- {
- case INIT:
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Init: %u\n", i);
- GNUNET_TESTBED_operation_done (event->details.
- operation_finished.operation);
- op[i] = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i);
- break;
- }
- case LINKING:
- {
- GNUNET_assert (NULL != slaves[i].op);
- GNUNET_TESTBED_operation_done (slaves[i].op);
- slaves[i].op = NULL;
+/**
+ * Process statistic values. Write all values to global 'data_file', if present.
+ *
+ * @param cls closure
+ * @param subsystem name of subsystem that created the statistic
+ * @param name the name of the datum
+ * @param value the current value
+ * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
+ * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ */
+static int
+stats_iterator (void *cls, const char *subsystem, const char *name,
+ uint64_t value, int is_persistent)
+{
+ struct RegexPeer *peer = cls;
+ char output_buffer[512];
+ size_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linked host %i\n", i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating peer...\n");
+ if (NULL == data_file)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%p -> %s [%s]: %llu\n",
+ peer, subsystem, name, value);
+ return GNUNET_OK;
+ }
+ size =
+ GNUNET_snprintf (output_buffer,
+ sizeof (output_buffer),
+ "%p [%s] %llu %s\n",
+ peer,
+ subsystem, value, name);
+ if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
+
+ return GNUNET_OK;
+}
- state[i] = CREATING_PEER;
- op[i] =
- GNUNET_TESTBED_peer_create (master_ctrl, slaves[i].host, cfg,
- peer_create_cb, (void *) i);
- break;
+
+/**
+ * Stats callback. Finish the stats testbed operation and when all stats have
+ * been iterated, shutdown the profiler.
+ *
+ * @param cls closure
+ * @param success GNUNET_OK if statistics were
+ * successfully obtained, GNUNET_SYSERR if not.
+ */
+static void
+stats_cb (void *cls,
+ int success)
+{
+ static unsigned int peer_cnt;
+ struct RegexPeer *peer = cls;
+
+ if (GNUNET_OK != success)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Getting statistics for peer %u failed!\n",
+ peer->id);
+ return;
+ }
+
+ GNUNET_TESTBED_operation_done (peer->stats_op_handle);
+ peer->stats_op_handle = NULL;
+
+ if (++peer_cnt == num_search_strings)
+ {
+ struct GNUNET_TIME_Relative delay = { 100 };
+ GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
+ }
+}
+
+
+/**
+ * Function called by testbed once we are connected to stats service. Create a
+ * mesh tunnel and try to match the peer's string.
+ *
+ * @param cls the 'struct RegexPeer' for which we connected to stats
+ * @param op connect operation handle
+ * @param ca_result handle to stats service
+ * @param emsg error message on failure
+ */
+static void
+stats_connect_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
+{
+ struct RegexPeer *peer = cls;
+
+ if (NULL == ca_result || NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to statistics service on peer %u: %s\n",
+ peer->id, emsg);
+
+ peer->stats_handle = NULL;
+ return;
+ }
+
+ GNUNET_assert (NULL != peer->mesh_handle);
+
+ peer->stats_handle = ca_result;
+
+ peer->mesh_tunnel_handle = GNUNET_MESH_tunnel_create (peer->mesh_handle,
+ NULL,
+ &mesh_peer_connect_handler,
+ &mesh_peer_disconnect_handler,
+ peer);
+
+ peer->prof_start_time = GNUNET_TIME_absolute_get ();
+
+ peer->search_str_matched = GNUNET_NO;
+ GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle,
+ peer->search_str);
+}
+
+
+/******************************************************************************/
+/************************ MESH SERVICE CONNECTIONS **************************/
+/******************************************************************************/
+
+/**
+ * Method called whenever a peer has disconnected from the tunnel.
+ * Implementations of this callback must NOT call
+ * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those
+ * to run in some other task later. However, calling
+ * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed.
+ *
+ * @param cls closure
+ * @param peer_id peer identity the tunnel stopped working with
+ */
+static void
+mesh_peer_disconnect_handler (void *cls,
+ const struct GNUNET_PeerIdentity * peer_id)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer disconnect handler.\n");
+}
+
+
+/**
+ * Method called when the mesh connection succeeded (or timed out), which means
+ * we've found a peer that announced a regex that matches our search string. Now
+ * get the statistics.
+ *
+ * @param cls closure
+ * @param peer_id peer identity the tunnel was created to, NULL on timeout
+ * @param atsi performance data for the connection
+ *
+ */
+static void
+mesh_peer_connect_handler (void *cls,
+ const struct GNUNET_PeerIdentity* peer_id,
+ const struct GNUNET_ATS_Information * atsi)
+{
+ struct RegexPeer *peer = cls;
+ char output_buffer[512];
+ size_t size;
+
+ peers_found++;
+
+ if (NULL == peer_id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "String matching timed out for string %s on peer %u (%i/%i)\n",
+ peer->search_str, peer->id, peers_found, num_search_strings);
+
+ printf ("String matching timed out for string %s on peer %u (%i/%i)\n",
+ peer->search_str, peer->id, peers_found, num_search_strings);
+
+ peer->search_str_matched = GNUNET_SYSERR;
+ }
+ else
+ {
+ prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "String %s successfully matched on peer %u after %s (%i/%i)\n",
+ peer->search_str, peer->id, GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
+ peers_found, num_search_strings);
+
+ printf ("String %s successfully matched on peer %u after %s (%i/%i)\n",
+ peer->search_str, peer->id, GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
+ peers_found, num_search_strings);
+ fflush (stdout);
+
+ peer->search_str_matched = GNUNET_YES;
+
+ if (NULL != data_file)
+ {
+ size =
+ GNUNET_snprintf (output_buffer,
+ sizeof (output_buffer),
+ "Peer: %u (%p)\nHost: %s\nPolicy file: %s\nSearch string: %s\nSearch duration: %s\n\n",
+ peer->id,
+ peer,
+ GNUNET_TESTBED_host_get_hostname (peer->host_handle),
+ peer->policy_file,
+ peer->search_str,
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
+
+ if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
}
- case CREATING_PEER:
+
+ if (NULL == peer->stats_handle)
{
- GNUNET_TESTBED_operation_done (event->details.
- operation_finished.operation);
- op[i] = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer create\n");
- break;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Cannot get statistics for peer %u, stats handle is NULL!\n");
+ return;
}
- case LINKING_SLAVES:
+
+ if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "mesh", NULL,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ NULL,
+ &stats_iterator, peer))
{
- struct GNUNET_CONFIGURATION_Handle *slave_cfg;
-
- GNUNET_assert (NULL != event->details.operation_finished.generic);
- slave_cfg =
- GNUNET_CONFIGURATION_dup ((struct GNUNET_CONFIGURATION_Handle *)
- event->details.operation_finished.generic);
- GNUNET_TESTBED_operation_done (event->details.
- operation_finished.operation);
- op[i] = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i);
- state[i] = LINKING_SLAVES_SUCCESS;
- op[i] =
- GNUNET_TESTBED_controller_link ((void *) (long) i, master_ctrl,
- slaves[i + 1].host, slaves[i].host,
- slave_cfg, GNUNET_NO);
- GNUNET_CONFIGURATION_destroy (slave_cfg);
- break;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not get mesh statistics of peer %u!\n", peer->id);
}
- case LINKING_SLAVES_SUCCESS:
+ if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "regexprofiler", NULL,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ NULL,
+ &stats_iterator, peer))
{
- unsigned int peer_cnt;
- struct GNUNET_TESTBED_Peer *peer_handles[TOTAL_PEERS];
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not get regexprofiler statistics of peer %u!\n", peer->id);
+ }
+ if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "transport", NULL,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ NULL,
+ &stats_iterator, peer))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not get transport statistics of peer %u!\n", peer->id);
+ }
+ if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "dht", NULL,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &stats_cb,
+ &stats_iterator, peer))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not get dht statistics of peer %u!\n", peer->id);
+ }
+ }
+
+ if (peers_found == num_search_strings)
+ {
+ prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "All strings successfully matched in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
+ printf ("All strings successfully matched. Shutting down.\n");
+ fflush (stdout);
+
+ if (GNUNET_SCHEDULER_NO_TASK != search_timeout_task)
+ GNUNET_SCHEDULER_cancel (search_timeout_task);
+ }
+}
+
- GNUNET_TESTBED_operation_done (event->details.
- operation_finished.operation);
- op[i] = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linking slave %i succeeded\n", i);
- state[0] = CONNECTING_PEERS;
+/**
+ * Connect by string timeout task. This will cancel the profiler after the
+ * specified timeout 'search_timeout'.
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+do_connect_by_string_timeout (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Finding matches to all strings did not succeed after %s.\n",
+ GNUNET_STRINGS_relative_time_to_string (search_timeout, GNUNET_NO));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Found %i of %i strings\n", peers_found, num_search_strings);
- for (peer_cnt = 0; peer_cnt < TOTAL_PEERS; peer_cnt++)
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+}
+
+
+/**
+ * Connect by string task that is run to search for a string in the NFA. It
+ * first connects to the mesh service, then connects to the stats service of
+ * this peer and then it starts the string search.
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+do_connect_by_string (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+ unsigned int search_cnt;
+ struct RegexPeer *peer;
+
+ printf ("Starting string search.\n");
+ fflush (stdout);
+
+ for (search_cnt = 0; search_cnt < num_search_strings; search_cnt++)
+ {
+ peer = &peers[search_cnt % num_peers];
+ peer->search_str = search_strings[search_cnt];
+ peer->search_str_matched = GNUNET_NO;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Searching for string \"%s\" on peer %d with file %s\n",
+ peer->search_str, (search_cnt % num_peers), peer->policy_file);
+
+ /* First connect to mesh service, then connect to stats service
+ and then try connecting by string in stats_connect_cb */
+ peer->mesh_op_handle =
+ GNUNET_TESTBED_service_connect (NULL,
+ peers->peer_handle,
+ "mesh",
+ &mesh_connect_cb,
+ peer,
+ &mesh_ca,
+ &mesh_da,
+ peer);
+ }
+
+ search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout,
+ &do_connect_by_string_timeout, NULL);
+}
+
+
+/**
+ * Mesh connect callback. Called when we are connected to the mesh service for
+ * the peer in 'cls'. If successfull we connect to the stats service of this
+ * peer and then try to match the search string of this peer.
+ *
+ * @param cls internal peer id.
+ * @param op operation handle.
+ * @param ca_result connect adapter result.
+ * @param emsg error message.
+ */
+static void
+mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
+ void *ca_result, const char *emsg)
+{
+ struct RegexPeer *peer = (struct RegexPeer *) cls;
+
+ if (NULL != emsg || NULL == op || NULL == ca_result)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Mesh connect failed: %s\n", emsg);
+ GNUNET_assert (0);
+ }
+
+ GNUNET_assert (peer->mesh_handle != NULL);
+ GNUNET_assert (peer->mesh_op_handle == op);
+ GNUNET_assert (peer->mesh_handle == ca_result);
+
+ /* First connect to the stats service, then start to search */
+ peer->stats_op_handle =
+ GNUNET_TESTBED_service_connect (NULL,
+ peers->peer_handle,
+ "statistics",
+ &stats_connect_cb,
+ peer,
+ &stats_ca,
+ &stats_da,
+ peer);
+}
+
+
+/**
+ * Mesh connect adapter. Opens a connection to the mesh service.
+ *
+ * @param cls not used.
+ * @param cfg configuration handle.
+ *
+ * @return
+ */
+static void *
+mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ GNUNET_MESH_ApplicationType app;
+ struct RegexPeer *peer = cls;
+
+ static struct GNUNET_MESH_MessageHandler handlers[] = {
+ {NULL, 0, 0}
+ };
+
+ app = (GNUNET_MESH_ApplicationType)0;
+
+ peer->mesh_handle =
+ GNUNET_MESH_connect (cfg, peer, NULL, NULL, handlers, &app);
+
+ return peer->mesh_handle;
+}
+
+
+/**
+ * Adapter function called to destroy a connection to
+ * the mesh service
+ *
+ * @param cls closure
+ * @param op_result service handle returned from the connect adapter
+ */
+static void
+mesh_da (void *cls, void *op_result)
+{
+ struct RegexPeer *peer = (struct RegexPeer *) cls;
+
+ GNUNET_assert (peer->mesh_handle == op_result);
+
+ if (NULL != peer->mesh_tunnel_handle)
+ {
+ GNUNET_MESH_tunnel_destroy (peer->mesh_tunnel_handle);
+ peer->mesh_tunnel_handle = NULL;
+ }
+
+ if (NULL != peer->mesh_handle)
+ {
+ GNUNET_MESH_disconnect (peer->mesh_handle);
+ peer->mesh_handle = NULL;
+ }
+}
+
+
+/******************************************************************************/
+/*************************** TESTBED PEER SETUP *****************************/
+/******************************************************************************/
+
+
+/**
+ * Configure the peer overlay topology.
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+do_configure_topology (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+ /*
+ if (0 == linking_factor)
+ linking_factor = 1;
+ num_links = linking_factor * num_peers;
+ */
+ /* num_links = num_peers - 1; */
+ num_links = linking_factor;
+
+ /* Do overlay connect */
+ prof_start_time = GNUNET_TIME_absolute_get ();
+ topology_op =
+ GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peer_handles,
+ GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
+ num_links,
+ GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
+ GNUNET_TESTBED_TOPOLOGY_OPTION_END);
+ if (NULL == topology_op)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Cannot create topology, op handle was NULL\n");
+ GNUNET_assert (0);
+ }
+}
+
+
+/**
+ * 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;
+ unsigned int peer_cnt;
+
+ op = dll_op->op;
+ GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+ GNUNET_free (dll_op);
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("An operation has failed while starting peers\n"));
+ GNUNET_TESTBED_operation_done (op);
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ 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);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "All peers started successfully in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
+ result = GNUNET_OK;
+
+ peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * num_peers);
+ for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
+ peer_handles[peer_cnt] = peers[peer_cnt].peer_handle;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Waiting %s before starting to link peers\n",
+ GNUNET_STRINGS_relative_time_to_string (conf_topo_delay, GNUNET_YES));
+
+ printf ("Waiting %s before starting to link peers\n",
+ GNUNET_STRINGS_relative_time_to_string (conf_topo_delay, GNUNET_YES));
+ fflush (stdout);
+
+ state = STATE_PEERS_LINKING;
+ GNUNET_SCHEDULER_add_delayed (conf_topo_delay, &do_configure_topology, NULL);
+ }
+}
+
+
+/**
+ * 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 RegexPeer *peer_ptr;
+ static unsigned int created_peers;
+ unsigned int peer_cnt;
+
+ if (NULL != emsg)
+ {
+ GNUNET_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);
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ 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_handle);
+ GNUNET_CONFIGURATION_destroy (peer_ptr->cfg);
+ peer_ptr->cfg = NULL;
+ peer_ptr->peer_handle = peer;
+ GNUNET_TESTBED_operation_done (dll_op->op);
+ GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+ GNUNET_free (dll_op);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n",
+ peer_ptr->id,
+ GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle));
+
+ if (++created_peers == num_peers)
+ {
+ prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "All peers created successfully in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
+ /* 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_handle,
+ &peer_churn_cb, dll_op);
+ GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
+ }
+ }
+}
+
+
+/**
+ * Function called with a filename for each file in the policy directory. Create
+ * a peer for each filename and update the peer's configuration to include the
+ * max_path_compression specified as a command line argument as well as the
+ * policy_file for this peer. The gnunet-service-regexprofiler service is
+ * automatically started on this peer. The service reads the configurration and
+ * announces the regexes stored in the policy file 'filename'.
+ *
+ * @param cls closure
+ * @param filename complete filename (absolute path)
+ * @return GNUNET_OK to continue to iterate,
+ * GNUNET_SYSERR to abort iteration with error!
+ */
+static int
+policy_filename_cb (void *cls, const char *filename)
+{
+ static unsigned int peer_cnt;
+ struct DLLOperation *dll_op;
+ struct RegexPeer *peer = &peers[peer_cnt];
+
+ GNUNET_assert (NULL != peer);
+
+ peer->policy_file = GNUNET_strdup (filename);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating peer %i on host %s for policy file %s\n",
+ peer->id,
+ GNUNET_TESTBED_host_get_hostname (peer->host_handle),
+ filename);
+
+ /* Set configuration options specific for this peer
+ (max_path_compression and policy_file */
+ peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
+ GNUNET_CONFIGURATION_set_value_number (peer->cfg, "REGEXPROFILER",
+ "MAX_PATH_COMPRESSION",
+ (unsigned long long)max_path_compression);
+ GNUNET_CONFIGURATION_set_value_string (peer->cfg, "REGEXPROFILER",
+ "POLICY_FILE", filename);
+
+ dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+ dll_op->cls = &peers[peer_cnt];
+ dll_op->op = GNUNET_TESTBED_peer_create (mc,
+ peer->host_handle,
+ peer->cfg,
+ &peer_create_cb,
+ dll_op);
+ GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
+
+ peer_cnt++;
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Controller event callback.
+ *
+ * @param cls NULL
+ * @param event the controller event
+ */
+static void
+controller_event_cb (void *cls,
+ const struct GNUNET_TESTBED_EventInformation *event)
+{
+ struct DLLOperation *dll_op;
+ struct GNUNET_TESTBED_Operation *op;
+ int ret;
+
+ switch (state)
+ {
+ case STATE_SLAVES_STARTING:
+ switch (event->type)
+ {
+ case GNUNET_TESTBED_ET_OPERATION_FINISHED:
{
- peer_handles[peer_cnt] = peers[peer_cnt].peer;
+ static unsigned int slaves_started;
+ unsigned int peer_cnt;
+
+ dll_op = event->details.operation_finished.op_cls;
+ GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+ GNUNET_free (dll_op);
+ op = event->details.operation_finished.operation;
+ if (NULL != event->details.operation_finished.emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("An operation has failed while starting slaves\n"));
+ GNUNET_TESTBED_operation_done (op);
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ return;
+ }
+ GNUNET_TESTBED_operation_done (op);
+ /* Proceed to start peers */
+ if (++slaves_started == num_hosts - 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "All slaves started successfully\n");
+
+ state = STATE_PEERS_CREATING;
+ prof_start_time = GNUNET_TIME_absolute_get ();
+
+ if (-1 == (ret = GNUNET_DISK_directory_scan (policy_dir,
+ NULL,
+ NULL)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No files found in `%s'\n"),
+ policy_dir);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ num_peers = (unsigned int) ret;
+ peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers);
+
+ /* Initialize peers */
+ for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
+ {
+ struct RegexPeer *peer = &peers[peer_cnt];
+ peer->id = peer_cnt;
+ peer->policy_file = NULL;
+ /* Do not start peers on hosts[0] (master controller) */
+ peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))];
+ peer->mesh_handle = NULL;
+ peer->mesh_tunnel_handle = NULL;
+ peer->stats_handle = NULL;
+ peer->stats_op_handle = NULL;
+ peer->search_str = NULL;
+ peer->search_str_matched = GNUNET_NO;
+ }
+
+ GNUNET_DISK_directory_scan (policy_dir,
+ &policy_filename_cb,
+ NULL);
+ }
}
- op[0] =
- GNUNET_TESTBED_overlay_configure_topology (NULL, TOTAL_PEERS,
- peer_handles,
- GNUNET_TESTBED_TOPOLOGY_LINE);
- GNUNET_assert (NULL != op[0]);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers...\n");
break;
+ default:
+ GNUNET_assert (0);
}
- case CONNECTING_PEERS:
+ break;
+ case STATE_PEERS_STARTING:
+ switch (event->type)
{
- GNUNET_TESTBED_operation_done (event->details.
- operation_finished.operation);
- op[i] = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
+ case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+ /* Control reaches here when peer start fails */
+ case GNUNET_TESTBED_ET_PEER_START:
+ /* we handle peer starts in peer_churn_cb */
break;
- }
default:
- GNUNET_break (0);
+ GNUNET_assert (0);
}
break;
+ case STATE_PEERS_LINKING:
+ switch (event->type)
+ {
+ static unsigned int established_links;
+ case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+ /* Control reaches here when a peer linking operation fails */
+ if (NULL != event->details.operation_finished.emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("An operation has failed while linking\n"));
+ printf ("F");
+ fflush (stdout);
+ retry_links++;
+ }
+ /* We do no retries, consider this link as established */
+ /* break; */
+ case GNUNET_TESTBED_ET_CONNECT:
+ {
+ char output_buffer[512];
+ size_t size;
+
+ if (0 == established_links)
+ printf ("Establishing links .");
+ else
+ {
+ printf (".");
+ fflush (stdout);
+ }
+ if (++established_links == num_links)
+ {
+ fflush (stdout);
+ prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u links established in %s\n",
+ num_links,
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
+ result = GNUNET_OK;
+ GNUNET_free (peer_handles);
+
+ if (NULL != data_file)
+ {
+ size =
+ GNUNET_snprintf (output_buffer,
+ sizeof (output_buffer),
+ "# of peers: %u\n# of links established: %u\n"
+ "Time to establish links: %s\nLinking failures: %u\n"
+ "path compression length: %u\n# of search strings: %u\n",
+ num_peers,
+ (established_links - cont_fails),
+ GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
+ cont_fails,
+ max_path_compression,
+ num_search_strings);
+
+ if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
+ }
+
+ printf ("\nWaiting %s before starting to search.\n",
+ GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
+ fflush (stdout);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Waiting %s before starting to search.\n",
+ GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_NO));
+
+ state = STATE_SEARCH_REGEX;
+
+ search_task = GNUNET_SCHEDULER_add_delayed (search_delay,
+ &do_connect_by_string, NULL);
+ }
+ }
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ break;
+ case STATE_SEARCH_REGEX:
+ {
+ /* Handled in service connect callback */
+ break;
+ }
default:
- GNUNET_break (0);
+ switch (state)
+ {
+ case STATE_PEERS_CREATING:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create peer\n");
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected controller_cb with state %i!\n", state);
+ }
+ GNUNET_assert (0);
}
}
/**
- * Callback which will be called to after a host registration succeeded or
- * failed. Registration of all slave hosts is continued and linking of the hosts
- * is started.
+ * Task to register all hosts available in the global host list.
*
- * @param cls not used.
- * @param emsg the error message; NULL if host registration is successful.
+ * @param cls NULL
+ * @param tc the scheduler task context
*/
static void
-registration_cont (void *cls, const char *emsg)
-{
- struct Host *slave = (struct Host *) cls;
+register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
- if (NULL != emsg || NULL == slave)
+/**
+ * Callback which will be called to after a host registration succeeded or failed
+ *
+ * @param cls the closure
+ * @param emsg the error message; NULL if host registration is successful
+ */
+static void
+host_registration_completion (void *cls, const char *emsg)
+{
+ reg_handle = NULL;
+ if (NULL != emsg)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
- GNUNET_assert (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Host registration failed for a host. Error: %s\n"), emsg);
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ return;
}
+ register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
+}
- state[host_registered] = LINKING;
- slave->state = LINKING;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linking host %u\n", host_registered);
- slave->op =
- GNUNET_TESTBED_controller_link ((void *) (long) host_registered,
- master_ctrl, slave->host, NULL, cfg,
- GNUNET_YES);
- host_registered++;
- if (NUM_HOSTS != host_registered)
+/**
+ * Task to register all hosts available in the global host list.
+ *
+ * @param cls NULL
+ * @param tc the scheduler task context
+ */
+static void
+register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct DLLOperation *dll_op;
+ static unsigned int reg_host;
+ unsigned int slave;
+
+ register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
+ if (reg_host == num_hosts - 1)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Registering host %u with ip %s\n",
- host_registered, slaves[host_registered].ip);
- rh = GNUNET_TESTBED_register_host (master_ctrl,
- slaves[host_registered].host,
- ®istration_cont,
- &slaves[host_registered]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "All hosts successfully registered\n");
+ /* Start slaves */
+ state = STATE_SLAVES_STARTING;
+ for (slave = 1; slave < num_hosts; slave++)
+ {
+ dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+ dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
+ mc,
+ hosts[slave],
+ hosts[0],
+ cfg,
+ GNUNET_YES);
+ GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
+ }
return;
}
+ reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],
+ host_registration_completion,
+ NULL);
}
/**
- * Callback to signal successfull startup of the controller process. If the
- * startup was successfull the master controller and all slave hosts are
- * created. Registering the slave hosts is started and continued in
- * registration_cont.
+ * Callback to signal successfull startup of the controller process.
*
- * @param cls not used.
+ * @param cls the closure from GNUNET_TESTBED_controller_start()
* @param config the configuration with which the controller has been started;
* NULL if status is not GNUNET_OK
* @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
* GNUNET_TESTBED_controller_stop() shouldn't be called in this case
*/
static void
-status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
- int status)
+status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
{
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+ GNUNET_SCHEDULER_cancel (abort_task);
+ if (GNUNET_OK != status)
+ {
+ mc_proc = NULL;
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ return;
+ }
+ event_mask = 0;
+ event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
+ mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
+ &controller_event_cb, NULL);
+ if (NULL == mc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Unable to connect to master controller -- Check config\n"));
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ return;
+ }
+ register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
+ abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &do_abort, NULL);
+}
+
+
+/**
+ * Load search strings from given filename. One search string per line.
+ *
+ * @param filename filename of the file containing the search strings.
+ * @param strings set of strings loaded from file. Caller needs to free this
+ * if number returned is greater than zero.
+ * @param limit upper limit on the number of strings read from the file
+ * @return number of strings found in the file. GNUNET_SYSERR on error.
+ */
+static int
+load_search_strings (const char *filename, char ***strings, unsigned int limit)
+{
+ char *data;
+ char *buf;
+ uint64_t filesize;
+ unsigned int offset;
+ int str_cnt;
unsigned int i;
- if (NULL == config || GNUNET_OK != status)
- return;
+ if (NULL == filename)
+ {
+ return GNUNET_SYSERR;
+ }
- event_mask = 0;
- event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
- event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
- event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
- event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to master controller\n");
- master_ctrl =
- GNUNET_TESTBED_controller_connect (config, master_host, event_mask,
- &controller_cb, NULL);
- GNUNET_assert (NULL != master_ctrl);
-
- for (i = 0; i < NUM_HOSTS; i++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating host %u with ip %s\n", i,
- slaves[i].ip);
- slaves[i].host = GNUNET_TESTBED_host_create (slaves[i].ip, NULL, 0);
- GNUNET_assert (NULL != slaves[i].host);
- }
- host_registered = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Registering host %u with ip %s\n",
- host_registered, slaves[0].ip);
- rh = GNUNET_TESTBED_register_host (master_ctrl, slaves[0].host,
- ®istration_cont, &slaves[0]);
- GNUNET_assert (NULL != rh);
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not find search strings file %s\n", filename);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK != GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES))
+ filesize = 0;
+ if (0 == filesize)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Search strings file %s is empty.\n", filename);
+ return GNUNET_SYSERR;
+ }
+ data = GNUNET_malloc (filesize);
+ if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
+ {
+ GNUNET_free (data);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read search strings file %s.\n",
+ filename);
+ return GNUNET_SYSERR;
+ }
+ buf = data;
+ offset = 0;
+ str_cnt = 0;
+ while (offset < (filesize - 1) && str_cnt < limit)
+ {
+ offset++;
+ if (((data[offset] == '\n')) && (buf != &data[offset]))
+ {
+ data[offset] = '\0';
+ str_cnt++;
+ buf = &data[offset + 1];
+ }
+ else if ((data[offset] == '\n') || (data[offset] == '\0'))
+ buf = &data[offset + 1];
+ }
+ *strings = GNUNET_malloc (sizeof (char *) * str_cnt);
+ offset = 0;
+ for (i = 0; i < str_cnt; i++)
+ {
+ (*strings)[i] = GNUNET_strdup (&data[offset]);
+ offset += strlen ((*strings)[i]) + 1;
+ }
+ free (data);
+ return str_cnt;
}
/**
- * Main run function.
+ * Main function that will be run by the scheduler.
*
- * @param cls not used.
- * @param args arguments passed to GNUNET_PROGRAM_run
- * @param cfgfile the path to configuration file
- * @param config the configuration file handle
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param config configuration
*/
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
- master_host = GNUNET_TESTBED_host_create ("192.168.1.33", NULL, 0);
- GNUNET_assert (NULL != master_host);
+ unsigned int nhost;
+ unsigned int nsearchstrs;
+
+ if (NULL == args[0])
+ {
+ fprintf (stderr, _("No hosts-file specified on command line. Exiting.\n"));
+ return;
+ }
+ if (NULL == args[1])
+ {
+ fprintf (stderr, _("No policy directory specified on command line. Exiting.\n"));
+ return;
+ }
+ num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
+ if (0 == num_hosts)
+ {
+ fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
+ return;
+ }
+ for (nhost = 0; nhost < num_hosts; nhost++)
+ {
+ if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost], config))
+ {
+ fprintf (stderr, _("Host %s cannot start testbed\n"),
+ GNUNET_TESTBED_host_get_hostname (hosts[nhost]));
+ break;
+ }
+ }
+ if (num_hosts != nhost)
+ {
+ fprintf (stderr, _("Exiting\n"));
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ if (NULL == config)
+ {
+ fprintf (stderr, _("No configuration file given. Exiting\n"));
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ if ( (NULL != data_filename) &&
+ (NULL == (data_file =
+ GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))) )
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ data_filename);
+ if (GNUNET_YES != GNUNET_DISK_directory_test (args[1]))
+ {
+ fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n"));
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ policy_dir = args[1];
+ if (GNUNET_YES != GNUNET_DISK_file_test (args[2]))
+ {
+ fprintf (stderr, _("No search strings file given. Exiting.\n"));
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ nsearchstrs = load_search_strings (args[2], &search_strings, num_search_strings);
+ if (num_search_strings != nsearchstrs)
+ {
+ num_search_strings = nsearchstrs;
+ fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n"));
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ if (0 >= num_search_strings || NULL == search_strings)
+ {
+ fprintf (stderr, _("Error loading search strings. Exiting.\n"));
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ unsigned int i;
+ for (i = 0; i < num_search_strings; i++)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "search string: %s\n", search_strings[i]);
cfg = GNUNET_CONFIGURATION_dup (config);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting master controller\n");
- master_proc =
- GNUNET_TESTBED_controller_start ("192.168.1.33", master_host, cfg,
- status_cb, NULL);
+ mc_proc =
+ GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname
+ (hosts[0]),
+ hosts[0],
+ cfg,
+ status_cb,
+ NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 60), &do_abort,
+ (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
NULL);
}
/**
- * Main function for profiling the regex/mesh implementation. Checks if all ssh
- * connections to each of the hosts in 'slave_ips' is possible before setting up
- * the testbed.
- *
- * @param argc argument count.
- * @param argv argument values.
+ * Main function.
*
- * @return 0 on success.
+ * @param argc argument count
+ * @param argv argument values
+ * @return 0 on success
*/
int
-main (int argc, char **argv)
+main (int argc, char *const *argv)
{
- int ret;
- int test_hosts;
- unsigned int i;
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ {'d', "details", "FILENAME",
+ gettext_noop ("name of the file for writing statistics"),
+ 1, &GNUNET_GETOPT_set_string, &data_filename},
+ {'n', "num-links", "COUNT",
+ gettext_noop ("create COUNT number of random links between peers"),
+ GNUNET_YES, &GNUNET_GETOPT_set_uint, &linking_factor },
+ {'t', "matching-timeout", "TIMEOUT",
+ gettext_noop ("wait TIMEOUT before considering a string match as failed"),
+ GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout },
+ {'s', "search-delay", "DELAY",
+ gettext_noop ("wait DELAY before starting string search"),
+ GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay },
+ {'a', "num-search-strings", "COUNT",
+ gettext_noop ("number of search strings to read from search strings file"),
+ GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_search_strings },
+ {'p', "max-path-compression", "MAX_PATH_COMPRESSION",
+ gettext_noop ("maximum path compression length"),
+ 1, &GNUNET_GETOPT_set_uint, &max_path_compression},
GNUNET_GETOPT_OPTION_END
};
- char *const argv2[] = { "gnunet-regex-profiler",
- "-c", "regex_profiler_test.conf",
- NULL
- };
+ int ret;
- test_hosts = GNUNET_OK;
- for (i = 0; i < NUM_HOSTS; i++)
- {
- char *const remote_args[] = {
- "ssh", "-o", "BatchMode=yes", slaves[i].ip,
- "gnunet-helper-testbed --help > /dev/null", NULL
- };
- struct GNUNET_OS_Process *auxp;
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
-
- fprintf (stderr, "Testing host %i\n", i);
- auxp =
- GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL,
- NULL, "ssh", remote_args);
- GNUNET_assert (NULL != auxp);
- do
- {
- ret = GNUNET_OS_process_status (auxp, &type, &code);
- GNUNET_assert (GNUNET_SYSERR != ret);
- (void) usleep (300);
- }
- while (GNUNET_NO == ret);
- (void) GNUNET_OS_process_wait (auxp);
- GNUNET_OS_process_destroy (auxp);
- if (0 != code)
- {
- fprintf (stderr,
- "Unable to run the test as this system is not configured "
- "to use password less SSH logins to host %s.\n", slaves[i].ip);
- test_hosts = GNUNET_SYSERR;
- }
- }
- if (test_hosts != GNUNET_OK)
- {
- fprintf (stderr, "Some hosts have failed the ssh check. Exiting.\n");
- return 1;
- }
- fprintf (stderr, "START.\n");
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
result = GNUNET_SYSERR;
-
ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "gnunet-regex-profiler", "nohelp", options, &run,
- NULL);
-
- fprintf (stderr, "END.\n");
-
- if (GNUNET_SYSERR == result || GNUNET_OK != ret)
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir search-strings-file",
+ _("Profiler for regex/mesh"),
+ options, &run, NULL);
+ GNUNET_free ((void*) argv);
+ if (GNUNET_OK != ret)
+ return ret;
+ if (GNUNET_OK != result)
return 1;
return 0;
}