2 This file is part of GNUnet.
3 (C) 2011 - 2013 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.
24 * @author Bartlomiej Polot
25 * @author Maximilian Szengel
32 #include "gnunet_applications.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_regex_lib.h"
35 #include "gnunet_dht_service.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;
154 struct GNUNET_DHT_Handle *dht_handle;
157 * Handle to a running regex search.
159 struct GNUNET_REGEX_search_handle *search_handle;
162 * Testbed operation handle for the dht service.
164 struct GNUNET_TESTBED_Operation *dht_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 * Search callback function.
387 * @param cls Closure provided in GNUNET_REGEX_search.
388 * @param id Peer providing a regex that matches the string.
389 * @param get_path Path of the get request.
390 * @param get_path_length Lenght of get_path.
391 * @param put_path Path of the put request.
392 * @param put_path_length Length of the put_path.
395 regex_found_handler (void *cls,
396 const struct GNUNET_PeerIdentity *id,
397 const struct GNUNET_PeerIdentity *get_path,
398 unsigned int get_path_length,
399 const struct GNUNET_PeerIdentity *put_path,
400 unsigned int put_path_length);
404 * DHT connect callback.
406 * @param cls internal peer id.
407 * @param op operation handle.
408 * @param ca_result connect adapter result.
409 * @param emsg error message.
412 dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
413 void *ca_result, const char *emsg);
416 * DHT connect adapter.
418 * @param cls not used.
419 * @param cfg configuration handle.
424 dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
428 * Adapter function called to destroy a connection to
432 * @param op_result service handle returned from the connect adapter
435 dht_da (void *cls, void *op_result);
439 * Function called by testbed once we are connected to stats
440 * service. Get the statistics for the services of interest.
442 * @param cls the 'struct RegexPeer' for which we connected to stats
443 * @param op connect operation handle
444 * @param ca_result handle to stats service
445 * @param emsg error message on failure
448 stats_connect_cb (void *cls,
449 struct GNUNET_TESTBED_Operation *op,
455 * Task to collect all statistics from all peers, will shutdown the
456 * profiler, when done.
459 * @param tc the task context
462 do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
465 /******************************************************************************/
466 /******************************** SHUTDOWN **********************************/
467 /******************************************************************************/
474 * @param tc the task context
477 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
479 struct DLLOperation *dll_op;
480 struct RegexPeer *peer;
482 unsigned int peer_cnt;
483 unsigned int search_str_cnt;
484 char output_buffer[512];
487 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
488 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
489 GNUNET_SCHEDULER_cancel (abort_task);
490 if (NULL != hc_handles)
492 for (nhost = 0; nhost < num_hosts; nhost++)
493 if (NULL != hc_handles[nhost])
494 GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[nhost]);
495 GNUNET_free (hc_handles);
498 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
499 GNUNET_SCHEDULER_cancel (register_hosts_task);
501 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
503 peer = &peers[peer_cnt];
505 if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
507 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
509 GNUNET_snprintf (output_buffer,
510 sizeof (output_buffer),
511 "%p Search string not found: %s (%d)\n%p On peer: %u (%p)\n%p With policy file: %s\n%p After: %s\n",
512 peer, peer->search_str, peer->search_str_matched,
513 peer, peer->id, peer,
514 peer, peer->policy_file,
516 GNUNET_STRINGS_relative_time_to_string (prof_time,
518 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
519 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
522 if (NULL != peers[peer_cnt].dht_op_handle)
523 GNUNET_TESTBED_operation_done (peers[peer_cnt].dht_op_handle);
524 if (NULL != peers[peer_cnt].stats_op_handle)
525 GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle);
528 if (NULL != data_file)
529 GNUNET_DISK_file_close (data_file);
531 for (search_str_cnt = 0;
532 search_str_cnt < num_search_strings && NULL != search_strings;
535 GNUNET_free_non_null (search_strings[search_str_cnt]);
537 GNUNET_free_non_null (search_strings);
539 if (NULL != reg_handle)
540 GNUNET_TESTBED_cancel_registration (reg_handle);
541 if (NULL != topology_op)
542 GNUNET_TESTBED_operation_done (topology_op);
543 for (nhost = 0; nhost < num_hosts; nhost++)
544 if (NULL != hosts[nhost])
545 GNUNET_TESTBED_host_destroy (hosts[nhost]);
546 GNUNET_free_non_null (hosts);
548 while (NULL != (dll_op = dll_op_head))
550 GNUNET_TESTBED_operation_done (dll_op->op);
551 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
552 GNUNET_free (dll_op);
555 GNUNET_TESTBED_controller_disconnect (mc);
557 GNUNET_TESTBED_controller_stop (mc_proc);
559 GNUNET_CONFIGURATION_destroy (cfg);
561 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
566 * abort task to run on test timed out
569 * @param tc the task context
572 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
574 unsigned long i = (unsigned long) cls;
576 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting %lu...\n", i);
577 abort_task = GNUNET_SCHEDULER_NO_TASK;
578 result = GNUNET_SYSERR;
579 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
580 GNUNET_SCHEDULER_cancel (shutdown_task);
581 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
585 /******************************************************************************/
586 /********************* STATISTICS SERVICE CONNECTIONS ***********************/
587 /******************************************************************************/
590 * Adapter function called to establish a connection to
591 * statistics service.
594 * @param cfg configuration of the peer to connect to; will be available until
595 * GNUNET_TESTBED_operation_done() is called on the operation returned
596 * from GNUNET_TESTBED_service_connect()
597 * @return service handle to return in 'op_result', NULL on error
600 stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
602 return GNUNET_STATISTICS_create ("<driver>", cfg);
607 * Adapter function called to destroy a connection to
608 * statistics service.
611 * @param op_result service handle returned from the connect adapter
614 stats_da (void *cls, void *op_result)
616 struct RegexPeer *peer = cls;
618 GNUNET_assert (op_result == peer->stats_handle);
620 GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
621 peer->stats_handle = NULL;
626 * Process statistic values. Write all values to global 'data_file', if present.
629 * @param subsystem name of subsystem that created the statistic
630 * @param name the name of the datum
631 * @param value the current value
632 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
633 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
636 stats_iterator (void *cls, const char *subsystem, const char *name,
637 uint64_t value, int is_persistent)
639 struct RegexPeer *peer = cls;
640 char output_buffer[512];
643 if (NULL == data_file)
645 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
646 "%p -> %s [%s]: %llu\n",
647 peer, subsystem, name, value);
651 GNUNET_snprintf (output_buffer,
652 sizeof (output_buffer),
655 subsystem, value, name);
656 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
657 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
664 * Stats callback. Finish the stats testbed operation and when all stats have
665 * been iterated, shutdown the profiler.
668 * @param success GNUNET_OK if statistics were
669 * successfully obtained, GNUNET_SYSERR if not.
675 static unsigned int peer_cnt;
676 struct RegexPeer *peer = cls;
678 if (GNUNET_OK != success)
680 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
681 "Getting statistics for peer %u failed!\n",
686 GNUNET_assert (NULL != peer->stats_op_handle);
688 GNUNET_TESTBED_operation_done (peer->stats_op_handle);
689 peer->stats_op_handle = NULL;
692 peer = &peers[peer_cnt];
694 if (peer_cnt == num_peers)
696 struct GNUNET_TIME_Relative delay = { 100 };
697 shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
701 peer->stats_op_handle =
702 GNUNET_TESTBED_service_connect (NULL,
715 * Function called by testbed once we are connected to stats
716 * service. Get the statistics for the services of interest.
718 * @param cls the 'struct RegexPeer' for which we connected to stats
719 * @param op connect operation handle
720 * @param ca_result handle to stats service
721 * @param emsg error message on failure
724 stats_connect_cb (void *cls,
725 struct GNUNET_TESTBED_Operation *op,
729 struct RegexPeer *peer = cls;
731 if (NULL == ca_result || NULL != emsg)
733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
734 "Failed to connect to statistics service on peer %u: %s\n",
737 peer->stats_handle = NULL;
741 peer->stats_handle = ca_result;
743 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL,
744 GNUNET_TIME_UNIT_FOREVER_REL,
746 &stats_iterator, peer))
748 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
749 "Could not get statistics of peer %u!\n", peer->id);
755 * Task to collect all statistics from all peers, will shutdown the
756 * profiler, when done.
759 * @param tc the task context
762 do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
764 struct RegexPeer *peer = &peers[0];
766 GNUNET_assert (NULL != peer->peer_handle);
768 peer->stats_op_handle =
769 GNUNET_TESTBED_service_connect (NULL,
780 /******************************************************************************/
781 /************************ MESH SERVICE CONNECTIONS **************************/
782 /******************************************************************************/
785 * Method called when we've found a peer that announced a regex
786 * that matches our search string. Now get the statistics.
788 * @param cls Closure provided in GNUNET_REGEX_search.
789 * @param id Peer providing a regex that matches the string.
790 * @param get_path Path of the get request.
791 * @param get_path_length Lenght of get_path.
792 * @param put_path Path of the put request.
793 * @param put_path_length Length of the put_path.
796 regex_found_handler (void *cls,
797 const struct GNUNET_PeerIdentity *id,
798 const struct GNUNET_PeerIdentity *get_path,
799 unsigned int get_path_length,
800 const struct GNUNET_PeerIdentity *put_path,
801 unsigned int put_path_length)
803 struct RegexPeer *peer = cls;
804 char output_buffer[512];
807 if (GNUNET_YES == peer->search_str_matched)
809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
810 "String %s on peer %u already matched!\n",
811 peer->search_str, peer->id);
819 // FIXME not possible right now
820 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
821 "String matching timed out for string %s on peer %u (%i/%i)\n",
822 peer->search_str, peer->id, peers_found, num_search_strings);
824 printf ("String matching timed out for string %s on peer %u (%i/%i)\n",
825 peer->search_str, peer->id, peers_found, num_search_strings);
827 peer->search_str_matched = GNUNET_SYSERR;
831 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
832 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
833 "String %s successfully matched on peer %u after %s (%i/%i)\n",
834 peer->search_str, peer->id, GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
835 peers_found, num_search_strings);
837 printf ("String %s successfully matched on peer %u after %s (%i/%i)\n",
838 peer->search_str, peer->id, GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
839 peers_found, num_search_strings);
842 peer->search_str_matched = GNUNET_YES;
844 if (NULL != data_file)
847 GNUNET_snprintf (output_buffer,
848 sizeof (output_buffer),
849 "%p Peer: %u\n%p Host: %s\n%p Policy file: %s\n"
850 "%p Search string: %s\n%p Search duration: %s\n\n",
853 GNUNET_TESTBED_host_get_hostname (peer->host_handle),
854 peer, peer->policy_file,
855 peer, peer->search_str,
857 GNUNET_STRINGS_relative_time_to_string (prof_time,
860 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
861 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
865 GNUNET_TESTBED_operation_done (peer->dht_op_handle);
866 peer->dht_op_handle = NULL;
868 if (peers_found == num_search_strings)
870 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
871 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
872 "All strings successfully matched in %s\n",
873 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
874 printf ("All strings successfully matched.\n");
877 if (GNUNET_SCHEDULER_NO_TASK != search_timeout_task)
878 GNUNET_SCHEDULER_cancel (search_timeout_task);
880 printf ("Collecting stats and shutting down.\n");
881 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
887 * Connect by string timeout task. This will cancel the profiler after the
888 * specified timeout 'search_timeout'.
891 * @param tc the task context
894 do_connect_by_string_timeout (void *cls,
895 const struct GNUNET_SCHEDULER_TaskContext * tc)
897 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
898 "Finding matches to all strings did not succeed after %s.\n",
899 GNUNET_STRINGS_relative_time_to_string (search_timeout, GNUNET_NO));
900 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
901 "Found %i of %i strings\n", peers_found, num_search_strings);
903 printf ("Search timed out after %s. Collecting stats and shutting down.\n",
904 GNUNET_STRINGS_relative_time_to_string (search_timeout, GNUNET_NO));
907 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
912 * Connect by string task that is run to search for a string in the
913 * NFA. It first connects to the mesh service and when a connection is
914 * established it starts to search for the string.
917 * @param tc the task context
920 do_connect_by_string (void *cls,
921 const struct GNUNET_SCHEDULER_TaskContext * tc)
923 printf ("Starting string search.\n");
926 peers[0].search_str = search_strings[0];
927 peers[0].search_str_matched = GNUNET_NO;
929 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
930 "Searching for string \"%s\" on peer %d with file %s\n",
931 peers[0].search_str, 0, peers[0].policy_file);
933 /* First connect to mesh service, then search for string. Next
934 connect will be in mesh_connect_cb */
935 peers[0].dht_op_handle =
936 GNUNET_TESTBED_service_connect (NULL,
937 peers[0].peer_handle,
945 search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout,
946 &do_connect_by_string_timeout, NULL);
951 * DHT connect callback. Called when we are connected to the dht service for
952 * the peer in 'cls'. If successfull we connect to the stats service of this
953 * peer and then try to match the search string of this peer.
955 * @param cls internal peer id.
956 * @param op operation handle.
957 * @param ca_result connect adapter result.
958 * @param emsg error message.
961 dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
962 void *ca_result, const char *emsg)
964 struct RegexPeer *peer = (struct RegexPeer *) cls;
965 static unsigned int peer_cnt;
968 if (NULL != emsg || NULL == op || NULL == ca_result)
970 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg);
974 GNUNET_assert (NULL != peer->dht_handle);
975 GNUNET_assert (peer->dht_op_handle == op);
976 GNUNET_assert (peer->dht_handle == ca_result);
978 peer->search_str_matched = GNUNET_NO;
979 peer->search_handle = GNUNET_REGEX_search (peer->dht_handle,
981 ®ex_found_handler, NULL,
983 peer->prof_start_time = GNUNET_TIME_absolute_get ();
985 if (peer_cnt < (num_search_strings - 1))
987 if (GNUNET_YES == no_distributed_search)
990 next_p = (++peer_cnt % num_peers);
992 peers[next_p].search_str = search_strings[next_p];
993 peers[next_p].search_str_matched = GNUNET_NO;
995 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
996 "Searching for string \"%s\" on peer %d with file %s\n",
997 peers[next_p].search_str, next_p, peers[next_p].policy_file);
1000 * dont connect to a new dht for each peer, we might want to seach for n
1001 * strings on m peers where n > m
1003 peers[next_p].dht_op_handle =
1004 GNUNET_TESTBED_service_connect (NULL,
1005 peers[next_p].peer_handle,
1017 * DHT connect adapter. Opens a connection to the dht service.
1019 * @param cls Closure (peer).
1020 * @param cfg Configuration handle.
1025 dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1027 struct RegexPeer *peer = cls;
1029 peer->dht_handle = GNUNET_DHT_connect (cfg, 32);
1031 return peer->dht_handle;
1036 * Adapter function called to destroy a connection to the dht service.
1038 * @param cls Closure (peer).
1039 * @param op_result Service handle returned from the connect adapter.
1042 dht_da (void *cls, void *op_result)
1044 struct RegexPeer *peer = (struct RegexPeer *) cls;
1046 GNUNET_assert (peer->dht_handle == op_result);
1048 if (NULL != peer->search_handle)
1050 GNUNET_REGEX_search_cancel (peer->search_handle);
1051 peer->search_handle = NULL;
1054 if (NULL != peer->dht_handle)
1056 GNUNET_DHT_disconnect (peer->dht_handle);
1057 peer->dht_handle = NULL;
1062 /******************************************************************************/
1063 /*************************** TESTBED PEER SETUP *****************************/
1064 /******************************************************************************/
1068 * Configure the peer overlay topology.
1071 * @param tc the task context
1074 do_configure_topology (void *cls,
1075 const struct GNUNET_SCHEDULER_TaskContext * tc)
1078 if (0 == linking_factor)
1080 num_links = linking_factor * num_peers;
1082 /* num_links = num_peers - 1; */
1083 num_links = linking_factor;
1085 /* Do overlay connect */
1086 prof_start_time = GNUNET_TIME_absolute_get ();
1088 GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peer_handles,
1090 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
1092 GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY,
1093 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
1094 if (NULL == topology_op)
1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1097 "Cannot create topology, op handle was NULL\n");
1104 * Functions of this signature are called when a peer has been successfully
1105 * started or stopped.
1107 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
1108 * @param emsg NULL on success; otherwise an error description
1111 peer_churn_cb (void *cls, const char *emsg)
1113 struct DLLOperation *dll_op = cls;
1114 struct GNUNET_TESTBED_Operation *op;
1115 static unsigned int started_peers;
1116 unsigned int peer_cnt;
1119 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1120 GNUNET_free (dll_op);
1123 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1124 _("An operation has failed while starting peers\n"));
1125 GNUNET_TESTBED_operation_done (op);
1126 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1127 GNUNET_SCHEDULER_cancel (abort_task);
1128 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1131 GNUNET_TESTBED_operation_done (op);
1132 if (++started_peers == num_peers)
1134 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1135 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1136 "All peers started successfully in %s\n",
1137 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1140 peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * num_peers);
1141 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1142 peer_handles[peer_cnt] = peers[peer_cnt].peer_handle;
1144 state = STATE_PEERS_LINKING;
1145 GNUNET_SCHEDULER_add_now (&do_configure_topology, NULL);
1151 * Functions of this signature are called when a peer has been successfully
1154 * @param cls the closure from GNUNET_TESTBED_peer_create()
1155 * @param peer the handle for the created peer; NULL on any error during
1157 * @param emsg NULL if peer is not NULL; else MAY contain the error description
1160 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
1162 struct DLLOperation *dll_op = cls;
1163 struct RegexPeer *peer_ptr;
1164 static unsigned int created_peers;
1165 unsigned int peer_cnt;
1169 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1170 _("Creating a peer failed. Error: %s\n"), emsg);
1171 GNUNET_TESTBED_operation_done (dll_op->op);
1172 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1173 GNUNET_free (dll_op);
1174 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1175 GNUNET_SCHEDULER_cancel (abort_task);
1176 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1180 peer_ptr = dll_op->cls;
1181 GNUNET_assert (NULL == peer_ptr->peer_handle);
1182 GNUNET_CONFIGURATION_destroy (peer_ptr->cfg);
1183 peer_ptr->cfg = NULL;
1184 peer_ptr->peer_handle = peer;
1185 GNUNET_TESTBED_operation_done (dll_op->op);
1186 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1187 GNUNET_free (dll_op);
1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n",
1191 GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle));
1193 if (++created_peers == num_peers)
1195 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1196 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1197 "All peers created successfully in %s\n",
1198 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1199 /* Now peers are to be started */
1200 state = STATE_PEERS_STARTING;
1201 prof_start_time = GNUNET_TIME_absolute_get ();
1202 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1204 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
1205 dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt].peer_handle,
1206 &peer_churn_cb, dll_op);
1207 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
1214 * Function called with a filename for each file in the policy directory. Create
1215 * a peer for each filename and update the peer's configuration to include the
1216 * max_path_compression specified as a command line argument as well as the
1217 * policy_file for this peer. The gnunet-service-regexprofiler service is
1218 * automatically started on this peer. The service reads the configurration and
1219 * announces the regexes stored in the policy file 'filename'.
1221 * @param cls closure
1222 * @param filename complete filename (absolute path)
1223 * @return GNUNET_OK to continue to iterate,
1224 * GNUNET_SYSERR to abort iteration with error!
1227 policy_filename_cb (void *cls, const char *filename)
1229 static unsigned int peer_cnt;
1230 struct DLLOperation *dll_op;
1231 struct RegexPeer *peer = &peers[peer_cnt];
1233 GNUNET_assert (NULL != peer);
1235 peer->policy_file = GNUNET_strdup (filename);
1237 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating peer %i on host %s for policy file %s\n",
1239 GNUNET_TESTBED_host_get_hostname (peer->host_handle),
1242 /* Set configuration options specific for this peer
1243 (max_path_compression and policy_file */
1244 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1245 GNUNET_CONFIGURATION_set_value_number (peer->cfg, "REGEXPROFILER",
1246 "MAX_PATH_COMPRESSION",
1247 (unsigned long long)max_path_compression);
1248 GNUNET_CONFIGURATION_set_value_string (peer->cfg, "REGEXPROFILER",
1249 "POLICY_FILE", filename);
1251 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
1252 dll_op->cls = &peers[peer_cnt];
1253 dll_op->op = GNUNET_TESTBED_peer_create (mc,
1258 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
1267 * Controller event callback.
1270 * @param event the controller event
1273 controller_event_cb (void *cls,
1274 const struct GNUNET_TESTBED_EventInformation *event)
1276 struct DLLOperation *dll_op;
1277 struct GNUNET_TESTBED_Operation *op;
1282 case STATE_SLAVES_STARTING:
1283 switch (event->type)
1285 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1287 static unsigned int slaves_started;
1288 unsigned int peer_cnt;
1290 dll_op = event->details.operation_finished.op_cls;
1291 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
1292 GNUNET_free (dll_op);
1293 op = event->details.operation_finished.operation;
1294 if (NULL != event->details.operation_finished.emsg)
1296 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1297 _("An operation has failed while starting slaves\n"));
1298 GNUNET_TESTBED_operation_done (op);
1299 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1300 GNUNET_SCHEDULER_cancel (abort_task);
1301 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1304 GNUNET_TESTBED_operation_done (op);
1305 /* Proceed to start peers */
1306 if (++slaves_started == num_hosts - 1)
1308 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1309 "All slaves started successfully\n");
1311 state = STATE_PEERS_CREATING;
1312 prof_start_time = GNUNET_TIME_absolute_get ();
1314 if (-1 == (ret = GNUNET_DISK_directory_scan (policy_dir,
1318 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1319 _("No files found in `%s'\n"),
1321 GNUNET_SCHEDULER_shutdown ();
1324 num_peers = (unsigned int) ret;
1325 peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers);
1327 /* Initialize peers */
1328 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1330 struct RegexPeer *peer = &peers[peer_cnt];
1331 peer->id = peer_cnt;
1332 peer->policy_file = NULL;
1333 /* Do not start peers on hosts[0] (master controller) */
1334 peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))];
1335 peer->dht_handle = NULL;
1336 peer->search_handle = NULL;
1337 peer->stats_handle = NULL;
1338 peer->stats_op_handle = NULL;
1339 peer->search_str = NULL;
1340 peer->search_str_matched = GNUNET_NO;
1343 GNUNET_DISK_directory_scan (policy_dir,
1344 &policy_filename_cb,
1353 case STATE_PEERS_STARTING:
1354 switch (event->type)
1356 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1357 /* Control reaches here when peer start fails */
1358 case GNUNET_TESTBED_ET_PEER_START:
1359 /* we handle peer starts in peer_churn_cb */
1365 case STATE_PEERS_LINKING:
1366 switch (event->type)
1368 static unsigned int established_links;
1369 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1370 /* Control reaches here when a peer linking operation fails */
1371 if (NULL != event->details.operation_finished.emsg)
1373 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1374 _("An operation has failed while linking\n"));
1379 /* We do no retries, consider this link as established */
1381 case GNUNET_TESTBED_ET_CONNECT:
1383 char output_buffer[512];
1386 if (0 == established_links)
1387 printf ("Establishing links .");
1393 if (++established_links == num_links)
1396 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1397 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1398 "%u links established in %s\n",
1400 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1402 GNUNET_free (peer_handles);
1404 if (NULL != data_file)
1407 GNUNET_snprintf (output_buffer,
1408 sizeof (output_buffer),
1409 "# of peers: %u\n# of links established: %u\n"
1410 "Time to establish links: %s\nLinking failures: %u\n"
1411 "path compression length: %u\n# of search strings: %u\n",
1413 (established_links - cont_fails),
1414 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
1416 max_path_compression,
1417 num_search_strings);
1419 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
1420 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
1423 printf ("\nWaiting %s before starting to search.\n",
1424 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
1427 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1428 "Waiting %s before starting to search.\n",
1429 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_NO));
1431 state = STATE_SEARCH_REGEX;
1433 search_task = GNUNET_SCHEDULER_add_delayed (search_delay,
1434 &do_connect_by_string, NULL);
1442 case STATE_SEARCH_REGEX:
1444 /* Handled in service connect callback */
1450 case STATE_PEERS_CREATING:
1451 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create peer\n");
1454 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1455 "Unexpected controller_cb with state %i!\n", state);
1463 * Task to register all hosts available in the global host list.
1466 * @param tc the scheduler task context
1469 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1473 * Callback which will be called to after a host registration succeeded or failed
1475 * @param cls the closure
1476 * @param emsg the error message; NULL if host registration is successful
1479 host_registration_completion (void *cls, const char *emsg)
1484 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1485 _("Host registration failed for a host. Error: %s\n"), emsg);
1486 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1487 GNUNET_SCHEDULER_cancel (abort_task);
1488 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1491 register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
1496 * Task to register all hosts available in the global host list.
1499 * @param tc the scheduler task context
1502 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1504 struct DLLOperation *dll_op;
1505 static unsigned int reg_host;
1508 register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
1509 if (reg_host == num_hosts - 1)
1511 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1512 "All hosts successfully registered\n");
1514 state = STATE_SLAVES_STARTING;
1515 for (slave = 1; slave < num_hosts; slave++)
1517 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
1518 dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
1524 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
1528 reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],
1529 host_registration_completion,
1535 * Callback to signal successfull startup of the controller process.
1537 * @param cls the closure from GNUNET_TESTBED_controller_start()
1538 * @param config the configuration with which the controller has been started;
1539 * NULL if status is not GNUNET_OK
1540 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1541 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1544 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
1546 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
1547 GNUNET_SCHEDULER_cancel (abort_task);
1548 if (GNUNET_OK != status)
1552 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1556 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
1557 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
1558 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1559 event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
1560 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1561 mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
1562 &controller_event_cb, NULL);
1565 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1566 _("Unable to connect to master controller -- Check config\n"));
1567 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1570 register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
1571 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1572 &do_abort, (void*) __LINE__);
1577 * Load search strings from given filename. One search string per line.
1579 * @param filename filename of the file containing the search strings.
1580 * @param strings set of strings loaded from file. Caller needs to free this
1581 * if number returned is greater than zero.
1582 * @param limit upper limit on the number of strings read from the file
1583 * @return number of strings found in the file. GNUNET_SYSERR on error.
1586 load_search_strings (const char *filename, char ***strings, unsigned int limit)
1591 unsigned int offset;
1595 if (NULL == filename)
1597 return GNUNET_SYSERR;
1600 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1602 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1603 "Could not find search strings file %s\n", filename);
1604 return GNUNET_SYSERR;
1606 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES))
1610 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Search strings file %s is empty.\n", filename);
1611 return GNUNET_SYSERR;
1613 data = GNUNET_malloc (filesize);
1614 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
1617 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read search strings file %s.\n",
1619 return GNUNET_SYSERR;
1624 while (offset < (filesize - 1) && str_cnt < limit)
1627 if (((data[offset] == '\n')) && (buf != &data[offset]))
1629 data[offset] = '\0';
1631 buf = &data[offset + 1];
1633 else if ((data[offset] == '\n') || (data[offset] == '\0'))
1634 buf = &data[offset + 1];
1636 *strings = GNUNET_malloc (sizeof (char *) * str_cnt);
1638 for (i = 0; i < str_cnt; i++)
1640 GNUNET_asprintf (&(*strings)[i], "%s%s", regex_prefix, &data[offset]);
1641 offset += strlen (&data[offset]) + 1;
1649 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
1650 * inform whether the given host is habitable or not. The Handle returned by
1651 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
1654 * @param host the host whose status is being reported; will be NULL if the host
1655 * given to GNUNET_TESTBED_is_host_habitable() is NULL
1656 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
1659 host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status)
1661 struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handle = cls;
1662 static unsigned int hosts_checked;
1665 if (GNUNET_NO == status)
1667 if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host)))
1668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"),
1669 GNUNET_TESTBED_host_get_hostname (host));
1671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Testbed cannot be started on localhost\n"));
1672 GNUNET_SCHEDULER_cancel (abort_task);
1673 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, (void*) __LINE__);
1677 /* printf (_("\rChecked %u hosts"), hosts_checked); */
1678 /* fflush (stdout); */
1679 if (hosts_checked < num_hosts)
1681 /* printf (_("\nAll hosts can start testbed. Creating peers\n")); */
1682 GNUNET_free (hc_handles);
1685 GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname
1695 * Main function that will be run by the scheduler.
1697 * @param cls closure
1698 * @param args remaining command-line arguments
1699 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1700 * @param config configuration
1703 run (void *cls, char *const *args, const char *cfgfile,
1704 const struct GNUNET_CONFIGURATION_Handle *config)
1707 unsigned int nsearchstrs;
1709 if (NULL == args[0])
1711 fprintf (stderr, _("No hosts-file specified on command line. Exiting.\n"));
1714 if (NULL == args[1])
1716 fprintf (stderr, _("No policy directory specified on command line. Exiting.\n"));
1719 num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
1722 fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
1725 printf (_("Checking whether given hosts can start testbed. Please wait\n"));
1726 hc_handles = GNUNET_malloc (sizeof (struct
1727 GNUNET_TESTBED_HostHabitableCheckHandle *)
1729 for (nhost = 0; nhost < num_hosts; nhost++)
1731 if (NULL == (hc_handles[nhost] = GNUNET_TESTBED_is_host_habitable (hosts[nhost], config,
1733 &hc_handles[nhost])))
1736 for (nhost = 0; nhost < num_hosts; nhost++)
1737 if (NULL != hc_handles[nhost])
1738 GNUNET_TESTBED_is_host_habitable_cancel (hc_handles[nhost]);
1739 GNUNET_free (hc_handles);
1744 if (num_hosts != nhost)
1746 fprintf (stderr, _("Exiting\n"));
1747 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1752 fprintf (stderr, _("No configuration file given. Exiting\n"));
1753 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1758 GNUNET_CONFIGURATION_get_value_string (config, "REGEXPROFILER", "REGEX_PREFIX",
1761 fprintf (stderr, _("Configuration option (regex_prefix) missing. Exiting\n"));
1762 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1766 if ( (NULL != data_filename) &&
1767 (NULL == (data_file =
1768 GNUNET_DISK_file_open (data_filename,
1769 GNUNET_DISK_OPEN_READWRITE |
1770 GNUNET_DISK_OPEN_TRUNCATE |
1771 GNUNET_DISK_OPEN_CREATE,
1772 GNUNET_DISK_PERM_USER_READ |
1773 GNUNET_DISK_PERM_USER_WRITE))) )
1774 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1777 if (GNUNET_YES != GNUNET_DISK_directory_test (args[1], GNUNET_YES))
1779 fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n"));
1780 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1783 policy_dir = args[1];
1784 if (GNUNET_YES != GNUNET_DISK_file_test (args[2]))
1786 fprintf (stderr, _("No search strings file given. Exiting.\n"));
1787 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1790 nsearchstrs = load_search_strings (args[2], &search_strings, num_search_strings);
1791 if (num_search_strings != nsearchstrs)
1793 num_search_strings = nsearchstrs;
1794 fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n"));
1795 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1798 if (0 >= num_search_strings || NULL == search_strings)
1800 fprintf (stderr, _("Error loading search strings. Exiting.\n"));
1801 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1805 for (i = 0; i < num_search_strings; i++)
1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "search string: %s\n", search_strings[i]);
1807 cfg = GNUNET_CONFIGURATION_dup (config);
1809 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1810 (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
1818 * @param argc argument count
1819 * @param argv argument values
1820 * @return 0 on success
1823 main (int argc, char *const *argv)
1825 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1826 {'d', "details", "FILENAME",
1827 gettext_noop ("name of the file for writing statistics"),
1828 1, &GNUNET_GETOPT_set_string, &data_filename},
1829 {'n', "num-links", "COUNT",
1830 gettext_noop ("create COUNT number of random links between peers"),
1831 GNUNET_YES, &GNUNET_GETOPT_set_uint, &linking_factor },
1832 {'t', "matching-timeout", "TIMEOUT",
1833 gettext_noop ("wait TIMEOUT before considering a string match as failed"),
1834 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout },
1835 {'s', "search-delay", "DELAY",
1836 gettext_noop ("wait DELAY before starting string search"),
1837 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay },
1838 {'a', "num-search-strings", "COUNT",
1839 gettext_noop ("number of search strings to read from search strings file"),
1840 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_search_strings },
1841 {'p', "max-path-compression", "MAX_PATH_COMPRESSION",
1842 gettext_noop ("maximum path compression length"),
1843 1, &GNUNET_GETOPT_set_uint, &max_path_compression},
1844 {'i', "no-distributed-search", "",
1845 gettext_noop ("if this option is set, only one peer is responsible for searching all strings"),
1846 0, &GNUNET_GETOPT_set_one, &no_distributed_search},
1847 GNUNET_GETOPT_OPTION_END
1851 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1854 result = GNUNET_SYSERR;
1856 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir search-strings-file",
1857 _("Profiler for regex/mesh"),
1858 options, &run, NULL);
1860 if (GNUNET_OK != ret)
1862 if (GNUNET_OK != result)