-/*
+/**
This file is part of GNUnet.
(C) 2011, 2012 Christian Grothoff (and other contributing authors)
*/
const char *search_str;
+ /**
+ * 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
+ */
+ int search_str_matched;
+
/**
* Peer's mesh handle.
*/
*/
static unsigned int num_links;
-/**
- * Number of timeout failures to tolerate
- */
-static unsigned int num_cont_fails;
-
/**
* Number of times we try overlay connect operations
*/
*/
static struct GNUNET_TIME_Relative search_delay = { 60000 };
+/**
+ * Delay before setting mesh service op as done.
+ */
+static struct GNUNET_TIME_Relative mesh_done_delay = { 1000 };
+
+/**
+ * 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 unsigned int max_path_compression;
-/**
- * Delay before setting mesh service op as done.
- */
-static struct GNUNET_TIME_Relative mesh_done_delay = { 1000 };
-
/******************************************************************************/
/****************************** DECLARATIONS ********************************/
/******************************************************************************/
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
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;
+
+ 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);
for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
{
+ peer = &peers[peer_cnt];
+
+ if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
+ {
+ 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);
}
- for (search_str_cnt = 0; search_str_cnt < num_search_strings; search_str_cnt++)
+
+ 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 (search_strings[search_str_cnt]);
+ GNUNET_free_non_null (search_strings[search_str_cnt]);
}
- GNUNET_free (search_strings);
- 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);
+ GNUNET_free_non_null (search_strings);
+
if (NULL != reg_handle)
GNUNET_TESTBED_cancel_registration (reg_handle);
if (NULL != topology_op)
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_TESTBED_controller_stop (mc_proc);
if (NULL != cfg)
GNUNET_CONFIGURATION_destroy (cfg);
- if (NULL != data_file)
- GNUNET_DISK_file_close (data_file);
GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
}
static void
stats_da (void *cls, void *op_result)
{
- GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
+ struct RegexPeer *peer = cls;
+
+ GNUNET_assert (op_result == peer->stats_handle);
+
+ GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
+ peer->stats_handle = NULL;
}
if (++peer_cnt == num_search_strings)
{
- GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ struct GNUNET_TIME_Relative delay = { 100 };
+ GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
}
}
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);
}
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
{
peers_found, num_search_strings);
fflush (stdout);
+ peer->search_str_matched = GNUNET_YES;
+
if (NULL != data_file)
{
size =
{
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",
const struct GNUNET_SCHEDULER_TaskContext * tc)
{
struct RegexPeer *peer = cls;
+ static unsigned int peer_cnt;
GNUNET_TESTBED_operation_done (peer->mesh_op_handle);
peer->mesh_op_handle = NULL;
+
+ if (++peer_cnt < num_peers)
+ {
+ peers[peer_cnt].mesh_op_handle =
+ GNUNET_TESTBED_service_connect (NULL,
+ peers[peer_cnt].peer_handle,
+ "mesh",
+ &mesh_connect_cb,
+ &peers[peer_cnt],
+ &mesh_ca,
+ &mesh_da,
+ &peers[peer_cnt]);
+ }
}
mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
void *ca_result, const char *emsg)
{
- static unsigned int peer_cnt;
struct RegexPeer *peer = (struct RegexPeer *) cls;
char *regex;
char *data;
GNUNET_SCHEDULER_add_delayed (mesh_done_delay, &do_mesh_op_done, peer);
- if (++peer_cnt < num_peers)
- {
- peers[peer_cnt].mesh_op_handle =
- GNUNET_TESTBED_service_connect (NULL,
- peers[peer_cnt].peer_handle,
- "mesh",
- &mesh_connect_cb,
- &peers[peer_cnt],
- &mesh_ca,
- &mesh_da,
- &peers[peer_cnt]);
- }
-
if (++num_files_announced == num_peers)
{
state = STATE_SEARCH_REGEX;
/******************************************************************************/
+/**
+ * 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.
for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
peer_handles[peer_cnt] = peers[peer_cnt].peer_handle;
- /*
- if (0 == linking_factor)
- linking_factor = 1;
- num_links = linking_factor * num_peers;
- */
- /* num_links = num_peers - 1; */
- num_links = linking_factor;
+ 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;
- /* 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);
- }
+ GNUNET_SCHEDULER_add_delayed (conf_topo_delay, &do_configure_topology, NULL);
}
}
GNUNET_assert (NULL != peer);
- peer->id = peer_cnt;
peer->policy_file = GNUNET_strdup (filename);
- /* 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;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating peer %i on host %s for policy file %s\n",
peer->id,
case GNUNET_TESTBED_ET_OPERATION_FINISHED:
{
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);
NULL);
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);
printf ("F");
fflush (stdout);
retry_links++;
-
- if (++cont_fails > num_cont_fails)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "We have a very high peer linking failure rate: %u (threshold: %u)\n",
- cont_fails,
- num_cont_fails);
- }
- }
+ }
/* We do no retries, consider this link as established */
/* break; */
case GNUNET_TESTBED_ET_CONNECT:
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",
+ "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);
+ 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");
* @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
const struct GNUNET_CONFIGURATION_Handle *config)
{
unsigned int nhost;
+ unsigned int nsearchstrs;
if (NULL == args[0])
{
}
for (nhost = 0; nhost < num_hosts; nhost++)
{
- if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (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]));
GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
- if (num_search_strings != load_search_strings (args[2], &search_strings, num_search_strings))
+ 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;
{'d', "details", "FILENAME",
gettext_noop ("name of the file for writing statistics"),
1, &GNUNET_GETOPT_set_string, &data_filename},
- {'n', "linking-factor", "FACTOR",
- gettext_noop ("create FACTOR times number of peers random links"),
+ {'n', "num-links", "COUNT",
+ gettext_noop ("create COUNT number of random links between peers"),
GNUNET_YES, &GNUNET_GETOPT_set_uint, &linking_factor },
- {'e', "num-errors", "COUNT",
- gettext_noop ("tolerate COUNT number of continious timeout failures"),
- GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_cont_fails },
{'t', "matching-timeout", "TIMEOUT",
gettext_noop ("wait TIMEOUT before considering a string match as failed"),
GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout },
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)