2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/gnunet-regex-profiler.c
23 * @brief Regex profiler for testing distributed regex use.
32 #include "gnunet_applications.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_mesh_service.h"
35 #include "gnunet_stream_lib.h"
36 #include "gnunet_testbed_service.h"
44 * The testbed operation handle
46 struct GNUNET_TESTBED_Operation *op;
54 * The next pointer for DLL
56 struct DLLOperation *next;
59 * The prev pointer for DLL
61 struct DLLOperation *prev;
66 * Available states during profiling
78 STATE_SLAVES_STARTING,
96 * Matching strings against announced regexes
101 * Destroying peers; we can do this as the controller takes care of stopping a
102 * peer if it is running
104 STATE_PEERS_DESTROYING
119 * Peer configuration handle.
121 struct GNUNET_CONFIGURATION_Handle *cfg;
124 * The actual testbed peer handle.
126 struct GNUNET_TESTBED_Peer *peer_handle;
129 * Host on which the peer is running.
131 struct GNUNET_TESTBED_Host *host_handle;
134 * Filename of the peer's policy file.
139 * Peers search string.
141 const char *search_str;
144 * Set to GNUNET_YES if the peer successfully matched the above
145 * search string. GNUNET_NO if the string could not be matched
146 * during the profiler run. GNUNET_SYSERR if the string matching
147 * timed out. Undefined if search_str is NULL
149 int search_str_matched;
152 * Peer's mesh handle.
154 struct GNUNET_MESH_Handle *mesh_handle;
157 * Peer's mesh tunnel handle.
159 struct GNUNET_MESH_Tunnel *mesh_tunnel_handle;
162 * Testbed operation handle for the mesh service.
164 struct GNUNET_TESTBED_Operation *mesh_op_handle;
167 * Peers's statistics handle.
169 struct GNUNET_STATISTICS_Handle *stats_handle;
172 * Testbed operation handle for the statistics service.
174 struct GNUNET_TESTBED_Operation *stats_op_handle;
177 * The starting time of a profiling step.
179 struct GNUNET_TIME_Absolute prof_start_time;
184 * An array of hosts loaded from the hostkeys file
186 static struct GNUNET_TESTBED_Host **hosts;
189 * Array of peer handles used to pass to
190 * GNUNET_TESTBED_overlay_configure_topology
192 static struct GNUNET_TESTBED_Peer **peer_handles;
195 * The array of peers; we fill this as the peers are given to us by the testbed
197 static struct RegexPeer *peers;
200 * Host registration handle
202 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
205 * Handle to the master controller process
207 static struct GNUNET_TESTBED_ControllerProc *mc_proc;
210 * Handle to the master controller
212 static struct GNUNET_TESTBED_Controller *mc;
215 * Handle to global configuration
217 static struct GNUNET_CONFIGURATION_Handle *cfg;
220 * Head of the operations list
222 static struct DLLOperation *dll_op_head;
225 * Tail of the operations list
227 static struct DLLOperation *dll_op_tail;
230 * Peer linking - topology operation
232 static struct GNUNET_TESTBED_Operation *topology_op;
235 * The handle for whether a host is habitable or not
237 struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles;
240 * Abort task identifier
242 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
245 * Shutdown task identifier
247 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
250 * Host registration task identifier
252 static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
255 * Global event mask for all testbed events
257 static uint64_t event_mask;
260 * The starting time of a profiling step
262 static struct GNUNET_TIME_Absolute prof_start_time;
265 * Duration profiling step has taken
267 static struct GNUNET_TIME_Relative prof_time;
270 * Number of peers to be started by the profiler
272 static unsigned int num_peers;
275 * Number of hosts in the hosts array
277 static unsigned int num_hosts;
280 * Factor of number of links. num_links = num_peers * linking_factor.
282 static unsigned int linking_factor;
285 * Number of random links to be established between peers
287 static unsigned int num_links;
290 * Number of times we try overlay connect operations
292 static unsigned int retry_links;
295 * Continuous failures during overlay connect operations
297 static unsigned int cont_fails;
300 * Global testing status
305 * current state of profiling
310 * Folder where policy files are stored.
312 static char * policy_dir;
317 static char **search_strings;
320 * Number of search strings.
322 static int num_search_strings;
325 * Number of peers found with search strings.
327 static unsigned int peers_found;
330 * Search task identifier
332 static GNUNET_SCHEDULER_TaskIdentifier search_task;
335 * Search timeout task identifier.
337 static GNUNET_SCHEDULER_TaskIdentifier search_timeout_task;
340 * Search timeout in seconds.
342 static struct GNUNET_TIME_Relative search_timeout = { 60000 };
345 * How long do we wait before starting the search?
348 static struct GNUNET_TIME_Relative search_delay = { 60000 };
351 * File to log statistics to.
353 static struct GNUNET_DISK_FileHandle *data_file;
356 * Filename to log statistics to.
358 static char *data_filename;
361 * Maximal path compression length.
363 static unsigned int max_path_compression;
366 * If we should distribute the search evenly throught all peers (each
367 * peer searches for a string) or if only one peer should search for
370 static int no_distributed_search;
373 * Prefix used for regex announcing. We need to prefix the search
374 * strings with it, in order to find something.
376 static char * regex_prefix;
379 /******************************************************************************/
380 /****************************** DECLARATIONS ********************************/
381 /******************************************************************************/
385 * Method called whenever a peer has connected to the tunnel.
388 * @param peer_id peer identity the tunnel was created to, NULL on timeout
389 * @param atsi performance data for the connection
393 mesh_peer_connect_handler (void *cls,
394 const struct GNUNET_PeerIdentity* peer_id,
395 const struct GNUNET_ATS_Information * atsi);
399 * Method called whenever a peer has disconnected from the tunnel.
400 * Implementations of this callback must NOT call
401 * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those
402 * to run in some other task later. However, calling
403 * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed.
406 * @param peer_id peer identity the tunnel stopped working with
409 mesh_peer_disconnect_handler (void *cls,
410 const struct GNUNET_PeerIdentity * peer_id);
413 * Mesh connect callback.
415 * @param cls internal peer id.
416 * @param op operation handle.
417 * @param ca_result connect adapter result.
418 * @param emsg error message.
421 mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
422 void *ca_result, const char *emsg);
425 * Mesh connect adapter.
427 * @param cls not used.
428 * @param cfg configuration handle.
433 mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
437 * Adapter function called to destroy a connection to
441 * @param op_result service handle returned from the connect adapter
444 mesh_da (void *cls, void *op_result);
448 * Function called by testbed once we are connected to stats
449 * service. Get the statistics for the services of interest.
451 * @param cls the 'struct RegexPeer' for which we connected to stats
452 * @param op connect operation handle
453 * @param ca_result handle to stats service
454 * @param emsg error message on failure
457 stats_connect_cb (void *cls,
458 struct GNUNET_TESTBED_Operation *op,
464 * Task to collect all statistics from all peers, will shutdown the
465 * profiler, when done.
468 * @param tc the task context
471 do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
474 /******************************************************************************/
475 /******************************** SHUTDOWN **********************************/
476 /******************************************************************************/
483 * @param tc the task context
486 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
488 struct DLLOperation *dll_op;
489 struct RegexPeer *peer;
491 unsigned int peer_cnt;
492 unsigned int search_str_cnt;
493 char output_buffer[512];
496 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
497 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
498 GNUNET_SCHEDULER_cancel (abort_task);
499 if (NULL != hc_handles)
501 for (nhost = 0; nhost < num_hosts; nhost++)
502 if (NULL != hc_handles[nhost])
503 GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[nhost]);
504 GNUNET_free (hc_handles);
507 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
508 GNUNET_SCHEDULER_cancel (register_hosts_task);
510 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
512 peer = &peers[peer_cnt];
514 if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
516 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
518 GNUNET_snprintf (output_buffer,
519 sizeof (output_buffer),
520 "%p Search string not found: %s (%d)\n%p On peer: %u (%p)\n%p With policy file: %s\n%p After: %s\n",
523 peer->search_str_matched,
530 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
531 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
535 if (NULL != peers[peer_cnt].mesh_op_handle)
536 GNUNET_TESTBED_operation_done (peers[peer_cnt].mesh_op_handle);
537 if (NULL != peers[peer_cnt].stats_op_handle)
538 GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle);
541 if (NULL != data_file)
542 GNUNET_DISK_file_close (data_file);
544 for (search_str_cnt = 0;
545 search_str_cnt < num_search_strings && NULL != search_strings;
548 GNUNET_free_non_null (search_strings[search_str_cnt]);
550 GNUNET_free_non_null (search_strings);
552 if (NULL != reg_handle)
553 GNUNET_TESTBED_cancel_registration (reg_handle);
554 if (NULL != topology_op)
555 GNUNET_TESTBED_operation_done (topology_op);
556 for (nhost = 0; nhost < num_hosts; nhost++)
557 if (NULL != hosts[nhost])
558 GNUNET_TESTBED_host_destroy (hosts[nhost]);
559 GNUNET_free_non_null (hosts);
561 while (NULL != (dll_op = dll_op_head))
563 GNUNET_TESTBED_operation_done (dll_op->op);
564 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
565 GNUNET_free (dll_op);
568 GNUNET_TESTBED_controller_disconnect (mc);
570 GNUNET_TESTBED_controller_stop (mc_proc);
572 GNUNET_CONFIGURATION_destroy (cfg);
574 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
579 * abort task to run on test timed out
582 * @param tc the task context
585 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
587 unsigned long i = (unsigned long) cls;
589 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting %lu...\n", i);
590 abort_task = GNUNET_SCHEDULER_NO_TASK;
591 result = GNUNET_SYSERR;
592 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
593 GNUNET_SCHEDULER_cancel (shutdown_task);
594 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
598 /******************************************************************************/
599 /********************* STATISTICS SERVICE CONNECTIONS ***********************/
600 /******************************************************************************/
603 * Adapter function called to establish a connection to
604 * statistics service.
607 * @param cfg configuration of the peer to connect to; will be available until
608 * GNUNET_TESTBED_operation_done() is called on the operation returned
609 * from GNUNET_TESTBED_service_connect()
610 * @return service handle to return in 'op_result', NULL on error
613 stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
615 return GNUNET_STATISTICS_create ("<driver>", cfg);
620 * Adapter function called to destroy a connection to
621 * statistics service.
624 * @param op_result service handle returned from the connect adapter
627 stats_da (void *cls, void *op_result)
629 struct RegexPeer *peer = cls;
631 GNUNET_assert (op_result == peer->stats_handle);
633 GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
634 peer->stats_handle = NULL;
639 * Process statistic values. Write all values to global 'data_file', if present.
642 * @param subsystem name of subsystem that created the statistic
643 * @param name the name of the datum
644 * @param value the current value
645 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
646 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
649 stats_iterator (void *cls, const char *subsystem, const char *name,
650 uint64_t value, int is_persistent)
652 struct RegexPeer *peer = cls;
653 char output_buffer[512];
656 if (NULL == data_file)
658 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
659 "%p -> %s [%s]: %llu\n",
660 peer, subsystem, name, value);
664 GNUNET_snprintf (output_buffer,
665 sizeof (output_buffer),
668 subsystem, value, name);
669 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
670 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
677 * Stats callback. Finish the stats testbed operation and when all stats have
678 * been iterated, shutdown the profiler.
681 * @param success GNUNET_OK if statistics were
682 * successfully obtained, GNUNET_SYSERR if not.
688 static unsigned int peer_cnt;
689 struct RegexPeer *peer = cls;
691 if (GNUNET_OK != success)
693 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
694 "Getting statistics for peer %u failed!\n",
699 GNUNET_assert (NULL != peer->stats_op_handle);
701 GNUNET_TESTBED_operation_done (peer->stats_op_handle);
702 peer->stats_op_handle = NULL;
705 peer = &peers[peer_cnt];
707 if (peer_cnt == num_peers)
709 struct GNUNET_TIME_Relative delay = { 100 };
710 shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
714 peer->stats_op_handle =
715 GNUNET_TESTBED_service_connect (NULL,
728 * Function called by testbed once we are connected to stats
729 * service. Get the statistics for the services of interest.
731 * @param cls the 'struct RegexPeer' for which we connected to stats
732 * @param op connect operation handle
733 * @param ca_result handle to stats service
734 * @param emsg error message on failure
737 stats_connect_cb (void *cls,
738 struct GNUNET_TESTBED_Operation *op,
742 struct RegexPeer *peer = cls;
744 if (NULL == ca_result || NULL != emsg)
746 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
747 "Failed to connect to statistics service on peer %u: %s\n",
750 peer->stats_handle = NULL;
754 peer->stats_handle = ca_result;
756 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL,
757 GNUNET_TIME_UNIT_FOREVER_REL,
759 &stats_iterator, peer))
761 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
762 "Could not get statistics of peer %u!\n", peer->id);
768 * Task to collect all statistics from all peers, will shutdown the
769 * profiler, when done.
772 * @param tc the task context
775 do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
777 struct RegexPeer *peer = &peers[0];
779 GNUNET_assert (NULL != peer->peer_handle);
781 peer->stats_op_handle =
782 GNUNET_TESTBED_service_connect (NULL,
793 /******************************************************************************/
794 /************************ MESH SERVICE CONNECTIONS **************************/
795 /******************************************************************************/
798 * Method called whenever a peer has disconnected from the tunnel.
799 * Implementations of this callback must NOT call
800 * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those
801 * to run in some other task later. However, calling
802 * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed.
805 * @param peer_id peer identity the tunnel stopped working with
808 mesh_peer_disconnect_handler (void *cls,
809 const struct GNUNET_PeerIdentity * peer_id)
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer disconnect handler.\n");
816 * Method called when the mesh connection succeeded (or timed out), which means
817 * we've found a peer that announced a regex that matches our search string. Now
818 * get the statistics.
821 * @param peer_id peer identity the tunnel was created to, NULL on timeout
822 * @param atsi performance data for the connection
826 mesh_peer_connect_handler (void *cls,
827 const struct GNUNET_PeerIdentity* peer_id,
828 const struct GNUNET_ATS_Information * atsi)
830 struct RegexPeer *peer = cls;
831 char output_buffer[512];
834 if (GNUNET_YES == peer->search_str_matched)
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "String %s on peer %u already matched!\n",
838 peer->search_str, peer->id);
846 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
847 "String matching timed out for string %s on peer %u (%i/%i)\n",
848 peer->search_str, peer->id, peers_found, num_search_strings);
850 printf ("String matching timed out for string %s on peer %u (%i/%i)\n",
851 peer->search_str, peer->id, peers_found, num_search_strings);
853 peer->search_str_matched = GNUNET_SYSERR;
857 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
858 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
859 "String %s successfully matched on peer %u after %s (%i/%i)\n",
860 peer->search_str, peer->id, GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
861 peers_found, num_search_strings);
863 printf ("String %s successfully matched on peer %u after %s (%i/%i)\n",
864 peer->search_str, peer->id, GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
865 peers_found, num_search_strings);
868 peer->search_str_matched = GNUNET_YES;
870 if (NULL != data_file)
873 GNUNET_snprintf (output_buffer,
874 sizeof (output_buffer),
875 "%p Peer: %u\n%p Host: %s\n%p Policy file: %s\n%p Search string: %s\n%p Search duration: %s\n\n",
879 GNUNET_TESTBED_host_get_hostname (peer->host_handle),
885 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
887 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
888 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
892 GNUNET_TESTBED_operation_done (peer->mesh_op_handle);
893 peer->mesh_op_handle = NULL;
895 if (peers_found == num_search_strings)
897 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
898 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
899 "All strings successfully matched in %s\n",
900 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
901 printf ("All strings successfully matched.\n");
904 if (GNUNET_SCHEDULER_NO_TASK != search_timeout_task)
905 GNUNET_SCHEDULER_cancel (search_timeout_task);
907 printf ("Collecting stats and shutting down.\n");
908 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
914 * Connect by string timeout task. This will cancel the profiler after the
915 * specified timeout 'search_timeout'.
918 * @param tc the task context
921 do_connect_by_string_timeout (void *cls,
922 const struct GNUNET_SCHEDULER_TaskContext * tc)
924 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
925 "Finding matches to all strings did not succeed after %s.\n",
926 GNUNET_STRINGS_relative_time_to_string (search_timeout, GNUNET_NO));
927 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
928 "Found %i of %i strings\n", peers_found, num_search_strings);
930 printf ("Search timed out after %s. Collecting stats and shutting down.\n",
931 GNUNET_STRINGS_relative_time_to_string (search_timeout, GNUNET_NO));
934 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
939 * Connect by string task that is run to search for a string in the
940 * NFA. It first connects to the mesh service and when a connection is
941 * established it starts to search for the string.
944 * @param tc the task context
947 do_connect_by_string (void *cls,
948 const struct GNUNET_SCHEDULER_TaskContext * tc)
950 printf ("Starting string search.\n");
953 peers[0].search_str = search_strings[0];
954 peers[0].search_str_matched = GNUNET_NO;
956 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
957 "Searching for string \"%s\" on peer %d with file %s\n",
958 peers[0].search_str, 0, peers[0].policy_file);
960 /* First connect to mesh service, then search for string. Next
961 connect will be in mesh_connect_cb */
962 peers[0].mesh_op_handle =
963 GNUNET_TESTBED_service_connect (NULL,
964 peers[0].peer_handle,
972 search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout,
973 &do_connect_by_string_timeout, NULL);
978 * Mesh connect callback. Called when we are connected to the mesh service for
979 * the peer in 'cls'. If successfull we connect to the stats service of this
980 * peer and then try to match the search string of this peer.
982 * @param cls internal peer id.
983 * @param op operation handle.
984 * @param ca_result connect adapter result.
985 * @param emsg error message.
988 mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
989 void *ca_result, const char *emsg)
991 struct RegexPeer *peer = (struct RegexPeer *) cls;
992 static unsigned int peer_cnt;
995 if (NULL != emsg || NULL == op || NULL == ca_result)
997 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Mesh connect failed: %s\n", emsg);
1001 GNUNET_assert (NULL != peer->mesh_handle);
1002 GNUNET_assert (peer->mesh_op_handle == op);
1003 GNUNET_assert (peer->mesh_handle == ca_result);
1005 peer->mesh_tunnel_handle =
1006 GNUNET_MESH_tunnel_create (peer->mesh_handle,
1008 &mesh_peer_connect_handler,
1009 &mesh_peer_disconnect_handler,
1012 peer->prof_start_time = GNUNET_TIME_absolute_get ();
1014 peer->search_str_matched = GNUNET_NO;
1015 GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle,
1018 if (peer_cnt < (num_search_strings - 1))
1020 if (GNUNET_YES == no_distributed_search)
1023 next_p = (++peer_cnt % num_peers);
1025 peers[next_p].search_str = search_strings[next_p];
1026 peers[next_p].search_str_matched = GNUNET_NO;
1028 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1029 "Searching for string \"%s\" on peer %d with file %s\n",
1030 peers[next_p].search_str, next_p, peers[next_p].policy_file);
1032 peers[next_p].mesh_op_handle =
1033 GNUNET_TESTBED_service_connect (NULL,
1034 peers[next_p].peer_handle,
1046 * Mesh connect adapter. Opens a connection to the mesh service.
1048 * @param cls not used.
1049 * @param cfg configuration handle.
1054 mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1056 GNUNET_MESH_ApplicationType app;
1057 struct RegexPeer *peer = cls;
1059 static struct GNUNET_MESH_MessageHandler handlers[] = {
1063 app = (GNUNET_MESH_ApplicationType)0;
1066 GNUNET_MESH_connect (cfg, peer, NULL, NULL, handlers, &app);
1068 return peer->mesh_handle;
1073 * Adapter function called to destroy a connection to
1076 * @param cls closure
1077 * @param op_result service handle returned from the connect adapter
1080 mesh_da (void *cls, void *op_result)
1082 struct RegexPeer *peer = (struct RegexPeer *) cls;
1084 GNUNET_assert (peer->mesh_handle == op_result);
1086 if (NULL != peer->mesh_tunnel_handle)
1088 GNUNET_MESH_tunnel_destroy (peer->mesh_tunnel_handle);
1089 peer->mesh_tunnel_handle = NULL;
1092 if (NULL != peer->mesh_handle)
1094 GNUNET_MESH_disconnect (peer->mesh_handle);
1095 peer->mesh_handle = NULL;
1100 /******************************************************************************/
1101 /*************************** TESTBED PEER SETUP *****************************/
1102 /******************************************************************************/
1106 * Configure the peer overlay topology.
1109 * @param tc the task context
1112 do_configure_topology (void *cls,
1113 const struct GNUNET_SCHEDULER_TaskContext * tc)
1116 if (0 == linking_factor)
1118 num_links = linking_factor * num_peers;
1120 /* num_links = num_peers - 1; */
1121 num_links = linking_factor;
1123 /* Do overlay connect */
1124 prof_start_time = GNUNET_TIME_absolute_get ();
1126 GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peer_handles,
1128 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
1130 GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
1131 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
1132 if (NULL == topology_op)
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1135 "Cannot create topology, op handle was NULL\n");
1142 * Functions of this signature are called when a peer has been successfully
1143 * started or stopped.
1145 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
1146 * @param emsg NULL on success; otherwise an error description
1149 peer_churn_cb (void *cls, const char *emsg)
1151 struct DLLOperation *dll_op = cls;
1152 struct GNUNET_TESTBED_Operation *op;
1153 static unsigned int started_peers;
1154 unsigned int peer_cnt;
1157 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1158 GNUNET_free (dll_op);
1161 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1162 _("An operation has failed while starting peers\n"));
1163 GNUNET_TESTBED_operation_done (op);
1164 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1165 GNUNET_SCHEDULER_cancel (abort_task);
1166 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1169 GNUNET_TESTBED_operation_done (op);
1170 if (++started_peers == num_peers)
1172 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1173 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1174 "All peers started successfully in %s\n",
1175 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1178 peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * num_peers);
1179 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1180 peer_handles[peer_cnt] = peers[peer_cnt].peer_handle;
1182 state = STATE_PEERS_LINKING;
1183 GNUNET_SCHEDULER_add_now (&do_configure_topology, NULL);
1189 * Functions of this signature are called when a peer has been successfully
1192 * @param cls the closure from GNUNET_TESTBED_peer_create()
1193 * @param peer the handle for the created peer; NULL on any error during
1195 * @param emsg NULL if peer is not NULL; else MAY contain the error description
1198 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
1200 struct DLLOperation *dll_op = cls;
1201 struct RegexPeer *peer_ptr;
1202 static unsigned int created_peers;
1203 unsigned int peer_cnt;
1207 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1208 _("Creating a peer failed. Error: %s\n"), emsg);
1209 GNUNET_TESTBED_operation_done (dll_op->op);
1210 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1211 GNUNET_free (dll_op);
1212 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1213 GNUNET_SCHEDULER_cancel (abort_task);
1214 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1218 peer_ptr = dll_op->cls;
1219 GNUNET_assert (NULL == peer_ptr->peer_handle);
1220 GNUNET_CONFIGURATION_destroy (peer_ptr->cfg);
1221 peer_ptr->cfg = NULL;
1222 peer_ptr->peer_handle = peer;
1223 GNUNET_TESTBED_operation_done (dll_op->op);
1224 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1225 GNUNET_free (dll_op);
1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n",
1229 GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle));
1231 if (++created_peers == num_peers)
1233 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1234 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1235 "All peers created successfully in %s\n",
1236 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1237 /* Now peers are to be started */
1238 state = STATE_PEERS_STARTING;
1239 prof_start_time = GNUNET_TIME_absolute_get ();
1240 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1242 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
1243 dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt].peer_handle,
1244 &peer_churn_cb, dll_op);
1245 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
1252 * Function called with a filename for each file in the policy directory. Create
1253 * a peer for each filename and update the peer's configuration to include the
1254 * max_path_compression specified as a command line argument as well as the
1255 * policy_file for this peer. The gnunet-service-regexprofiler service is
1256 * automatically started on this peer. The service reads the configurration and
1257 * announces the regexes stored in the policy file 'filename'.
1259 * @param cls closure
1260 * @param filename complete filename (absolute path)
1261 * @return GNUNET_OK to continue to iterate,
1262 * GNUNET_SYSERR to abort iteration with error!
1265 policy_filename_cb (void *cls, const char *filename)
1267 static unsigned int peer_cnt;
1268 struct DLLOperation *dll_op;
1269 struct RegexPeer *peer = &peers[peer_cnt];
1271 GNUNET_assert (NULL != peer);
1273 peer->policy_file = GNUNET_strdup (filename);
1275 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating peer %i on host %s for policy file %s\n",
1277 GNUNET_TESTBED_host_get_hostname (peer->host_handle),
1280 /* Set configuration options specific for this peer
1281 (max_path_compression and policy_file */
1282 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1283 GNUNET_CONFIGURATION_set_value_number (peer->cfg, "REGEXPROFILER",
1284 "MAX_PATH_COMPRESSION",
1285 (unsigned long long)max_path_compression);
1286 GNUNET_CONFIGURATION_set_value_string (peer->cfg, "REGEXPROFILER",
1287 "POLICY_FILE", filename);
1289 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
1290 dll_op->cls = &peers[peer_cnt];
1291 dll_op->op = GNUNET_TESTBED_peer_create (mc,
1296 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
1305 * Controller event callback.
1308 * @param event the controller event
1311 controller_event_cb (void *cls,
1312 const struct GNUNET_TESTBED_EventInformation *event)
1314 struct DLLOperation *dll_op;
1315 struct GNUNET_TESTBED_Operation *op;
1320 case STATE_SLAVES_STARTING:
1321 switch (event->type)
1323 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1325 static unsigned int slaves_started;
1326 unsigned int peer_cnt;
1328 dll_op = event->details.operation_finished.op_cls;
1329 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1330 GNUNET_free (dll_op);
1331 op = event->details.operation_finished.operation;
1332 if (NULL != event->details.operation_finished.emsg)
1334 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1335 _("An operation has failed while starting slaves\n"));
1336 GNUNET_TESTBED_operation_done (op);
1337 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1338 GNUNET_SCHEDULER_cancel (abort_task);
1339 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1342 GNUNET_TESTBED_operation_done (op);
1343 /* Proceed to start peers */
1344 if (++slaves_started == num_hosts - 1)
1346 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1347 "All slaves started successfully\n");
1349 state = STATE_PEERS_CREATING;
1350 prof_start_time = GNUNET_TIME_absolute_get ();
1352 if (-1 == (ret = GNUNET_DISK_directory_scan (policy_dir,
1356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1357 _("No files found in `%s'\n"),
1359 GNUNET_SCHEDULER_shutdown ();
1362 num_peers = (unsigned int) ret;
1363 peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers);
1365 /* Initialize peers */
1366 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1368 struct RegexPeer *peer = &peers[peer_cnt];
1369 peer->id = peer_cnt;
1370 peer->policy_file = NULL;
1371 /* Do not start peers on hosts[0] (master controller) */
1372 peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))];
1373 peer->mesh_handle = NULL;
1374 peer->mesh_tunnel_handle = NULL;
1375 peer->stats_handle = NULL;
1376 peer->stats_op_handle = NULL;
1377 peer->search_str = NULL;
1378 peer->search_str_matched = GNUNET_NO;
1381 GNUNET_DISK_directory_scan (policy_dir,
1382 &policy_filename_cb,
1391 case STATE_PEERS_STARTING:
1392 switch (event->type)
1394 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1395 /* Control reaches here when peer start fails */
1396 case GNUNET_TESTBED_ET_PEER_START:
1397 /* we handle peer starts in peer_churn_cb */
1403 case STATE_PEERS_LINKING:
1404 switch (event->type)
1406 static unsigned int established_links;
1407 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1408 /* Control reaches here when a peer linking operation fails */
1409 if (NULL != event->details.operation_finished.emsg)
1411 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1412 _("An operation has failed while linking\n"));
1417 /* We do no retries, consider this link as established */
1419 case GNUNET_TESTBED_ET_CONNECT:
1421 char output_buffer[512];
1424 if (0 == established_links)
1425 printf ("Establishing links .");
1431 if (++established_links == num_links)
1434 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1435 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1436 "%u links established in %s\n",
1438 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1440 GNUNET_free (peer_handles);
1442 if (NULL != data_file)
1445 GNUNET_snprintf (output_buffer,
1446 sizeof (output_buffer),
1447 "# of peers: %u\n# of links established: %u\n"
1448 "Time to establish links: %s\nLinking failures: %u\n"
1449 "path compression length: %u\n# of search strings: %u\n",
1451 (established_links - cont_fails),
1452 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
1454 max_path_compression,
1455 num_search_strings);
1457 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
1458 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
1461 printf ("\nWaiting %s before starting to search.\n",
1462 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
1465 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1466 "Waiting %s before starting to search.\n",
1467 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_NO));
1469 state = STATE_SEARCH_REGEX;
1471 search_task = GNUNET_SCHEDULER_add_delayed (search_delay,
1472 &do_connect_by_string, NULL);
1480 case STATE_SEARCH_REGEX:
1482 /* Handled in service connect callback */
1488 case STATE_PEERS_CREATING:
1489 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create peer\n");
1492 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1493 "Unexpected controller_cb with state %i!\n", state);
1501 * Task to register all hosts available in the global host list.
1504 * @param tc the scheduler task context
1507 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1511 * Callback which will be called to after a host registration succeeded or failed
1513 * @param cls the closure
1514 * @param emsg the error message; NULL if host registration is successful
1517 host_registration_completion (void *cls, const char *emsg)
1522 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1523 _("Host registration failed for a host. Error: %s\n"), emsg);
1524 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1525 GNUNET_SCHEDULER_cancel (abort_task);
1526 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1529 register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
1534 * Task to register all hosts available in the global host list.
1537 * @param tc the scheduler task context
1540 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1542 struct DLLOperation *dll_op;
1543 static unsigned int reg_host;
1546 register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
1547 if (reg_host == num_hosts - 1)
1549 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1550 "All hosts successfully registered\n");
1552 state = STATE_SLAVES_STARTING;
1553 for (slave = 1; slave < num_hosts; slave++)
1555 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
1556 dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
1562 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
1566 reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],
1567 host_registration_completion,
1573 * Callback to signal successfull startup of the controller process.
1575 * @param cls the closure from GNUNET_TESTBED_controller_start()
1576 * @param config the configuration with which the controller has been started;
1577 * NULL if status is not GNUNET_OK
1578 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1579 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1582 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
1584 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1585 GNUNET_SCHEDULER_cancel (abort_task);
1586 if (GNUNET_OK != status)
1590 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1594 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
1595 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
1596 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1597 event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
1598 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1599 mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
1600 &controller_event_cb, NULL);
1603 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1604 _("Unable to connect to master controller -- Check config\n"));
1605 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1608 register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
1609 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1610 &do_abort, (void*) __LINE__);
1615 * Load search strings from given filename. One search string per line.
1617 * @param filename filename of the file containing the search strings.
1618 * @param strings set of strings loaded from file. Caller needs to free this
1619 * if number returned is greater than zero.
1620 * @param limit upper limit on the number of strings read from the file
1621 * @return number of strings found in the file. GNUNET_SYSERR on error.
1624 load_search_strings (const char *filename, char ***strings, unsigned int limit)
1629 unsigned int offset;
1633 if (NULL == filename)
1635 return GNUNET_SYSERR;
1638 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1640 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1641 "Could not find search strings file %s\n", filename);
1642 return GNUNET_SYSERR;
1644 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES))
1648 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Search strings file %s is empty.\n", filename);
1649 return GNUNET_SYSERR;
1651 data = GNUNET_malloc (filesize);
1652 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
1655 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read search strings file %s.\n",
1657 return GNUNET_SYSERR;
1662 while (offset < (filesize - 1) && str_cnt < limit)
1665 if (((data[offset] == '\n')) && (buf != &data[offset]))
1667 data[offset] = '\0';
1669 buf = &data[offset + 1];
1671 else if ((data[offset] == '\n') || (data[offset] == '\0'))
1672 buf = &data[offset + 1];
1674 *strings = GNUNET_malloc (sizeof (char *) * str_cnt);
1676 for (i = 0; i < str_cnt; i++)
1678 GNUNET_asprintf (&(*strings)[i], "%s%s", regex_prefix, &data[offset]);
1679 offset += strlen (&data[offset]) + 1;
1687 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
1688 * inform whether the given host is habitable or not. The Handle returned by
1689 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
1692 * @param host the host whose status is being reported; will be NULL if the host
1693 * given to GNUNET_TESTBED_is_host_habitable() is NULL
1694 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
1697 host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status)
1699 struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handle = cls;
1700 static unsigned int hosts_checked;
1703 if (GNUNET_NO == status)
1705 if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host)))
1706 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"),
1707 GNUNET_TESTBED_host_get_hostname (host));
1709 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Testbed cannot be started on localhost\n"));
1710 GNUNET_SCHEDULER_cancel (abort_task);
1711 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1715 /* printf (_("\rChecked %u hosts"), hosts_checked); */
1716 /* fflush (stdout); */
1717 if (hosts_checked < num_hosts)
1719 /* printf (_("\nAll hosts can start testbed. Creating peers\n")); */
1720 GNUNET_free (hc_handles);
1723 GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname
1733 * Main function that will be run by the scheduler.
1735 * @param cls closure
1736 * @param args remaining command-line arguments
1737 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1738 * @param config configuration
1741 run (void *cls, char *const *args, const char *cfgfile,
1742 const struct GNUNET_CONFIGURATION_Handle *config)
1745 unsigned int nsearchstrs;
1747 if (NULL == args[0])
1749 fprintf (stderr, _("No hosts-file specified on command line. Exiting.\n"));
1752 if (NULL == args[1])
1754 fprintf (stderr, _("No policy directory specified on command line. Exiting.\n"));
1757 num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
1760 fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
1763 printf (_("Checking whether given hosts can start testbed. Please wait\n"));
1764 hc_handles = GNUNET_malloc (sizeof (struct
1765 GNUNET_TESTBED_HostHabitableCheckHandle *)
1767 for (nhost = 0; nhost < num_hosts; nhost++)
1769 if (NULL == (hc_handles[nhost] = GNUNET_TESTBED_is_host_habitable (hosts[nhost], config,
1771 &hc_handles[nhost])))
1774 for (nhost = 0; nhost < num_hosts; nhost++)
1775 if (NULL != hc_handles[nhost])
1776 GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[nhost]);
1777 GNUNET_free (hc_handles);
1782 if (num_hosts != nhost)
1784 fprintf (stderr, _("Exiting\n"));
1785 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1790 fprintf (stderr, _("No configuration file given. Exiting\n"));
1791 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1796 GNUNET_CONFIGURATION_get_value_string (config, "REGEXPROFILER", "REGEX_PREFIX",
1799 fprintf (stderr, _("Configuration option (regex_prefix) missing. Exiting\n"));
1800 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1804 if ( (NULL != data_filename) &&
1805 (NULL == (data_file =
1806 GNUNET_DISK_file_open (data_filename,
1807 GNUNET_DISK_OPEN_READWRITE |
1808 GNUNET_DISK_OPEN_TRUNCATE |
1809 GNUNET_DISK_OPEN_CREATE,
1810 GNUNET_DISK_PERM_USER_READ |
1811 GNUNET_DISK_PERM_USER_WRITE))) )
1812 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1815 if (GNUNET_YES != GNUNET_DISK_directory_test (args[1], GNUNET_YES))
1817 fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n"));
1818 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1821 policy_dir = args[1];
1822 if (GNUNET_YES != GNUNET_DISK_file_test (args[2]))
1824 fprintf (stderr, _("No search strings file given. Exiting.\n"));
1825 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1828 nsearchstrs = load_search_strings (args[2], &search_strings, num_search_strings);
1829 if (num_search_strings != nsearchstrs)
1831 num_search_strings = nsearchstrs;
1832 fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n"));
1833 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1836 if (0 >= num_search_strings || NULL == search_strings)
1838 fprintf (stderr, _("Error loading search strings. Exiting.\n"));
1839 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1843 for (i = 0; i < num_search_strings; i++)
1844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "search string: %s\n", search_strings[i]);
1845 cfg = GNUNET_CONFIGURATION_dup (config);
1847 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1848 (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
1856 * @param argc argument count
1857 * @param argv argument values
1858 * @return 0 on success
1861 main (int argc, char *const *argv)
1863 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1864 {'d', "details", "FILENAME",
1865 gettext_noop ("name of the file for writing statistics"),
1866 1, &GNUNET_GETOPT_set_string, &data_filename},
1867 {'n', "num-links", "COUNT",
1868 gettext_noop ("create COUNT number of random links between peers"),
1869 GNUNET_YES, &GNUNET_GETOPT_set_uint, &linking_factor },
1870 {'t', "matching-timeout", "TIMEOUT",
1871 gettext_noop ("wait TIMEOUT before considering a string match as failed"),
1872 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout },
1873 {'s', "search-delay", "DELAY",
1874 gettext_noop ("wait DELAY before starting string search"),
1875 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay },
1876 {'a', "num-search-strings", "COUNT",
1877 gettext_noop ("number of search strings to read from search strings file"),
1878 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_search_strings },
1879 {'p', "max-path-compression", "MAX_PATH_COMPRESSION",
1880 gettext_noop ("maximum path compression length"),
1881 1, &GNUNET_GETOPT_set_uint, &max_path_compression},
1882 {'i', "no-distributed-search", "",
1883 gettext_noop ("if this option is set, only one peer is responsible for searching all strings"),
1884 0, &GNUNET_GETOPT_set_one, &no_distributed_search},
1885 GNUNET_GETOPT_OPTION_END
1889 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1892 result = GNUNET_SYSERR;
1894 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir search-strings-file",
1895 _("Profiler for regex/mesh"),
1896 options, &run, NULL);
1898 if (GNUNET_OK != ret)
1900 if (GNUNET_OK != result)