making GNUNET_SCHEDULER_cancel() perform in O(1) instead of O(n) to help or even...
[oweals/gnunet.git] / src / regex / gnunet-regex-profiler.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011 - 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file regex/gnunet-regex-profiler.c
23  * @brief Regex profiler for testing distributed regex use.
24  * @author Bartlomiej Polot
25  * @author Maximilian Szengel
26  *
27  */
28
29 #include <string.h>
30
31 #include "platform.h"
32 #include "gnunet_applications.h"
33 #include "gnunet_util_lib.h"
34 #include "regex_internal_lib.h"
35 #include "gnunet_arm_service.h"
36 #include "gnunet_dht_service.h"
37 #include "gnunet_testbed_service.h"
38
39 #define FIND_TIMEOUT \
40         GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
41
42 /**
43  * DLL of operations
44  */
45 struct DLLOperation
46 {
47   /**
48    * The testbed operation handle
49    */
50   struct GNUNET_TESTBED_Operation *op;
51
52   /**
53    * Closure
54    */
55   void *cls;
56
57   /**
58    * The next pointer for DLL
59    */
60   struct DLLOperation *next;
61
62   /**
63    * The prev pointer for DLL
64    */
65   struct DLLOperation *prev;
66 };
67
68
69 /**
70  * Available states during profiling
71  */
72 enum State
73 {
74   /**
75    * Initial state
76    */
77   STATE_INIT = 0,
78
79   /**
80    * Starting slaves
81    */
82   STATE_SLAVES_STARTING,
83
84   /**
85    * Creating peers
86    */
87   STATE_PEERS_CREATING,
88
89   /**
90    * Starting peers
91    */
92   STATE_PEERS_STARTING,
93
94   /**
95    * Linking peers
96    */
97   STATE_PEERS_LINKING,
98
99   /**
100    * Matching strings against announced regexes
101    */
102   STATE_SEARCH_REGEX,
103
104   /**
105    * Destroying peers; we can do this as the controller takes care of stopping a
106    * peer if it is running
107    */
108   STATE_PEERS_DESTROYING
109 };
110
111
112 /**
113  * Peer handles.
114  */
115 struct RegexPeer
116 {
117   /**
118    * Peer id.
119    */
120   unsigned int id;
121
122   /**
123    * Peer configuration handle.
124    */
125   struct GNUNET_CONFIGURATION_Handle *cfg;
126
127   /**
128    * The actual testbed peer handle.
129    */
130   struct GNUNET_TESTBED_Peer *peer_handle;
131
132   /**
133    * Peer's search string.
134    */
135   const char *search_str;
136
137   /**
138    * Set to GNUNET_YES if the peer successfully matched the above
139    * search string. GNUNET_NO if the string could not be matched
140    * during the profiler run. GNUNET_SYSERR if the string matching
141    * timed out. Undefined if search_str is NULL
142    */
143   int search_str_matched;
144
145   /**
146    * Peer's DHT handle.
147    */
148   struct GNUNET_DHT_Handle *dht_handle;
149
150   /**
151    * Handle to a running regex search.
152    */
153    struct REGEX_INTERNAL_Search *search_handle;
154
155   /**
156    * Testbed operation handle for DHT.
157    */
158   struct GNUNET_TESTBED_Operation *op_handle;
159
160   /**
161    * Peers's statistics handle.
162    */
163   struct GNUNET_STATISTICS_Handle *stats_handle;
164
165   /**
166    * The starting time of a profiling step.
167    */
168   struct GNUNET_TIME_Absolute prof_start_time;
169
170   /**
171    * Operation timeout
172    */
173   struct GNUNET_SCHEDULER_Task * timeout;
174
175   /**
176    * Deamon start
177    */
178   struct GNUNET_TESTBED_Operation *daemon_op;
179 };
180
181 /**
182  * Set when shutting down to avoid making more queries.
183  */
184 static int in_shutdown;
185
186 /**
187  * The array of peers; we fill this as the peers are given to us by the testbed
188  */
189 static struct RegexPeer *peers;
190
191 /**
192  * Host registration handle
193  */
194 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
195
196 /**
197  * Handle to the master controller process
198  */
199 static struct GNUNET_TESTBED_ControllerProc *mc_proc;
200
201 /**
202  * Handle to the master controller
203  */
204 static struct GNUNET_TESTBED_Controller *mc;
205
206 /**
207  * Handle to global configuration
208  */
209 static struct GNUNET_CONFIGURATION_Handle *cfg;
210
211 /**
212  * Abort task identifier
213  */
214 static struct GNUNET_SCHEDULER_Task * abort_task;
215
216 /**
217  * Shutdown task identifier
218  */
219 static struct GNUNET_SCHEDULER_Task * shutdown_task;
220
221 /**
222  * Host registration task identifier
223  */
224 static struct GNUNET_SCHEDULER_Task * register_hosts_task;
225
226 /**
227  * Global event mask for all testbed events
228  */
229 static uint64_t event_mask;
230
231 /**
232  * The starting time of a profiling step
233  */
234 static struct GNUNET_TIME_Absolute prof_start_time;
235
236 /**
237  * Duration profiling step has taken
238  */
239 static struct GNUNET_TIME_Relative prof_time;
240
241 /**
242  * Number of peers to be started by the profiler
243  */
244 static unsigned int num_peers;
245
246 /**
247  * Global testing status
248  */
249 static int result;
250
251 /**
252  * current state of profiling
253  */
254 enum State state;
255
256 /**
257  * Folder where policy files are stored.
258  */
259 static char * policy_dir;
260
261 /**
262  * File with hostnames where to execute the test.
263  */
264 static char *hosts_file;
265
266 /**
267  * File with the strings to look for.
268  */
269 static char *strings_file;
270
271 /**
272  * Search strings (num_peers of them).
273  */
274 static char **search_strings;
275
276 /**
277  * How many searches are we going to start in parallel
278  */
279 static long long unsigned int init_parallel_searches;
280
281 /**
282  * How many searches are running in parallel
283  */
284 static unsigned int parallel_searches;
285
286 /**
287  * Number of strings found in the published regexes.
288  */
289 static unsigned int strings_found;
290
291 /**
292  * Index of peer to start next announce/search.
293  */
294 static unsigned int next_search;
295
296 /**
297  * Search timeout task identifier.
298  */
299 static struct GNUNET_SCHEDULER_Task * search_timeout_task;
300
301 /**
302  * Search timeout in seconds.
303  */
304 static struct GNUNET_TIME_Relative search_timeout_time = { 60000 };
305
306 /**
307  * File to log statistics to.
308  */
309 static struct GNUNET_DISK_FileHandle *data_file;
310
311 /**
312  * Filename to log statistics to.
313  */
314 static char *data_filename;
315
316 /**
317  * Prefix used for regex announcing. We need to prefix the search
318  * strings with it, in order to find something.
319  */
320 static char * regex_prefix;
321
322 /**
323  * What's the maximum regex reannounce period.
324  */
325 static struct GNUNET_TIME_Relative reannounce_period_max;
326
327
328 /******************************************************************************/
329 /******************************  DECLARATIONS  ********************************/
330 /******************************************************************************/
331
332 /**
333  * DHT connect callback.
334  *
335  * @param cls internal peer id.
336  * @param op operation handle.
337  * @param ca_result connect adapter result.
338  * @param emsg error message.
339  */
340 static void
341 dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
342                 void *ca_result, const char *emsg);
343
344 /**
345  * DHT connect adapter.
346  *
347  * @param cls not used.
348  * @param cfg configuration handle.
349  *
350  * @return
351  */
352 static void *
353 dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
354
355
356 /**
357  * Adapter function called to destroy a connection to
358  * the DHT service
359  *
360  * @param cls closure
361  * @param op_result service handle returned from the connect adapter
362  */
363 static void
364 dht_da (void *cls, void *op_result);
365
366
367 /**
368  * Function called by testbed once we are connected to stats
369  * service. Get the statistics for the services of interest.
370  *
371  * @param cls the 'struct RegexPeer' for which we connected to stats
372  * @param op connect operation handle
373  * @param ca_result handle to stats service
374  * @param emsg error message on failure
375  */
376 static void
377 stats_connect_cb (void *cls,
378                   struct GNUNET_TESTBED_Operation *op,
379                   void *ca_result,
380                   const char *emsg);
381
382
383 /**
384  * Start announcing the next regex in the DHT.
385  *
386  * @param cls Index of the next peer in the peers array.
387  * @param tc TaskContext.
388  */
389 static void
390 announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
391
392
393 /******************************************************************************/
394 /********************************  SHUTDOWN  **********************************/
395 /******************************************************************************/
396
397
398 /**
399  * Shutdown nicely
400  *
401  * @param cls NULL
402  * @param tc the task context
403  */
404 static void
405 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
406 {
407   struct RegexPeer *peer;
408   unsigned int peer_cnt;
409   unsigned int search_str_cnt;
410   char output_buffer[512];
411   size_t size;
412
413   shutdown_task = NULL;
414   if (NULL != abort_task)
415     GNUNET_SCHEDULER_cancel (abort_task);
416   if (NULL != register_hosts_task)
417     GNUNET_SCHEDULER_cancel (register_hosts_task);
418
419   for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
420   {
421     peer = &peers[peer_cnt];
422
423     if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
424     {
425       prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
426       size =
427         GNUNET_snprintf (output_buffer,
428                          sizeof (output_buffer),
429                          "%p Search string not found: %s (%d)\n"
430                          "%p On peer: %u (%p)\n"
431                          "%p After: %s\n",
432                          peer, peer->search_str, peer->search_str_matched,
433                          peer, peer->id, peer,
434                          peer,
435                          GNUNET_STRINGS_relative_time_to_string (prof_time,
436                                                                  GNUNET_NO));
437       if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
438         GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
439     }
440
441     if (NULL != peers[peer_cnt].op_handle)
442       GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle);
443   }
444
445   if (NULL != data_file)
446     GNUNET_DISK_file_close (data_file);
447
448   for (search_str_cnt = 0;
449        search_str_cnt < num_peers && NULL != search_strings;
450        search_str_cnt++)
451   {
452     GNUNET_free_non_null (search_strings[search_str_cnt]);
453   }
454   GNUNET_free_non_null (search_strings);
455
456   if (NULL != reg_handle)
457     GNUNET_TESTBED_cancel_registration (reg_handle);
458
459   if (NULL != mc)
460     GNUNET_TESTBED_controller_disconnect (mc);
461   if (NULL != mc_proc)
462     GNUNET_TESTBED_controller_stop (mc_proc);
463   if (NULL != cfg)
464     GNUNET_CONFIGURATION_destroy (cfg);
465
466   GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
467 }
468
469
470 /**
471  * abort task to run on test timed out
472  *
473  * @param cls NULL
474  * @param tc the task context
475  */
476 static void
477 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
478 {
479   unsigned long i = (unsigned long) cls;
480
481   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting from line %lu...\n", i);
482   abort_task = NULL;
483   result = GNUNET_SYSERR;
484   if (NULL != shutdown_task)
485     GNUNET_SCHEDULER_cancel (shutdown_task);
486   shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
487 }
488
489
490 /******************************************************************************/
491 /*********************  STATISTICS SERVICE CONNECTIONS  ***********************/
492 /******************************************************************************/
493
494 /**
495  * Adapter function called to establish a connection to
496  * statistics service.
497  *
498  * @param cls closure
499  * @param cfg configuration of the peer to connect to; will be available until
500  *          GNUNET_TESTBED_operation_done() is called on the operation returned
501  *          from GNUNET_TESTBED_service_connect()
502  * @return service handle to return in 'op_result', NULL on error
503  */
504 static void *
505 stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
506 {
507   return GNUNET_STATISTICS_create ("<driver>", cfg);
508 }
509
510
511 /**
512  * Adapter function called to destroy a connection to
513  * statistics service.
514  *
515  * @param cls closure
516  * @param op_result service handle returned from the connect adapter
517  */
518 static void
519 stats_da (void *cls, void *op_result)
520 {
521   struct RegexPeer *peer = cls;
522
523   GNUNET_assert (op_result == peer->stats_handle);
524
525   GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
526   peer->stats_handle = NULL;
527 }
528
529
530 /**
531  * Process statistic values. Write all values to global 'data_file', if present.
532  *
533  * @param cls closure
534  * @param subsystem name of subsystem that created the statistic
535  * @param name the name of the datum
536  * @param value the current value
537  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
538  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
539  */
540 static int
541 stats_iterator (void *cls, const char *subsystem, const char *name,
542                 uint64_t value, int is_persistent)
543 {
544   struct RegexPeer *peer = cls;
545   char output_buffer[512];
546   size_t size;
547
548   if (NULL == data_file)
549   {
550     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
551                 "%p -> %s [%s]: %llu\n",
552                 peer, subsystem, name, value);
553     return GNUNET_OK;
554   }
555   size =
556     GNUNET_snprintf (output_buffer,
557                      sizeof (output_buffer),
558                      "%p [%s] %llu %s\n",
559                      peer,
560                      subsystem, value, name);
561   if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
562     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
563
564   return GNUNET_OK;
565 }
566
567
568 /**
569  * Stats callback. Finish the stats testbed operation and when all stats have
570  * been iterated, shutdown the profiler.
571  *
572  * @param cls closure
573  * @param success GNUNET_OK if statistics were
574  *        successfully obtained, GNUNET_SYSERR if not.
575  */
576 static void
577 stats_cb (void *cls,
578           int success)
579 {
580   static unsigned int peer_cnt;
581   struct RegexPeer *peer = cls;
582
583   if (GNUNET_OK != success)
584   {
585     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
586                 "Getting statistics for peer %u failed!\n",
587                 peer->id);
588     return;
589   }
590
591   GNUNET_assert (NULL != peer->op_handle);
592
593   GNUNET_TESTBED_operation_done (peer->op_handle);
594   peer->op_handle = NULL;
595
596   peer_cnt++;
597   peer = &peers[peer_cnt];
598
599   fprintf (stderr, "s");
600   if (peer_cnt == num_peers)
601   {
602     struct GNUNET_TIME_Relative delay = { 100 };
603     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\nCollecting stats finished. Shutting down.\n");
604     shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
605     result = GNUNET_OK;
606   }
607   else
608   {
609     peer->op_handle =
610       GNUNET_TESTBED_service_connect (NULL,
611                                       peer->peer_handle,
612                                       "statistics",
613                                       &stats_connect_cb,
614                                       peer,
615                                       &stats_ca,
616                                       &stats_da,
617                                       peer);
618   }
619 }
620
621
622 /**
623  * Function called by testbed once we are connected to stats
624  * service. Get the statistics for the services of interest.
625  *
626  * @param cls the 'struct RegexPeer' for which we connected to stats
627  * @param op connect operation handle
628  * @param ca_result handle to stats service
629  * @param emsg error message on failure
630  */
631 static void
632 stats_connect_cb (void *cls,
633                   struct GNUNET_TESTBED_Operation *op,
634                   void *ca_result,
635                   const char *emsg)
636 {
637   struct RegexPeer *peer = cls;
638
639   if (NULL == ca_result || NULL != emsg)
640   {
641     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
642                 "Failed to connect to statistics service on peer %u: %s\n",
643                 peer->id, emsg);
644
645     peer->stats_handle = NULL;
646     return;
647   }
648
649   peer->stats_handle = ca_result;
650
651   if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL,
652                                      GNUNET_TIME_UNIT_FOREVER_REL,
653                                      &stats_cb,
654                                      &stats_iterator, peer))
655   {
656     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
657                 "Could not get statistics of peer %u!\n", peer->id);
658   }
659 }
660
661
662 /**
663  * Task to collect all statistics from all peers, will shutdown the
664  * profiler, when done.
665  *
666  * @param cls NULL
667  * @param tc the task context
668  */
669 static void
670 do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
671 {
672   struct RegexPeer *peer = &peers[0];
673
674   GNUNET_assert (NULL != peer->peer_handle);
675
676   peer->op_handle =
677     GNUNET_TESTBED_service_connect (NULL,
678                                     peer->peer_handle,
679                                     "statistics",
680                                     &stats_connect_cb,
681                                     peer,
682                                     &stats_ca,
683                                     &stats_da,
684                                     peer);
685 }
686
687
688 /******************************************************************************/
689 /************************   REGEX FIND CONNECTIONS   **************************/
690 /******************************************************************************/
691
692
693 /**
694  * Start searching for the next string in the DHT.
695  *
696  * @param cls Index of the next peer in the peers array.
697  * @param tc TaskContext.
698  */
699 static void
700 find_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
701
702
703 /**
704  * Method called when we've found a peer that announced a regex
705  * that matches our search string. Now get the statistics.
706  *
707  * @param cls Closure provided in REGEX_INTERNAL_search.
708  * @param id Peer providing a regex that matches the string.
709  * @param get_path Path of the get request.
710  * @param get_path_length Lenght of get_path.
711  * @param put_path Path of the put request.
712  * @param put_path_length Length of the put_path.
713  */
714 static void
715 regex_found_handler (void *cls,
716                      const struct GNUNET_PeerIdentity *id,
717                      const struct GNUNET_PeerIdentity *get_path,
718                      unsigned int get_path_length,
719                      const struct GNUNET_PeerIdentity *put_path,
720                      unsigned int put_path_length)
721 {
722   struct RegexPeer *peer = cls;
723   char output_buffer[512];
724   size_t size;
725
726   if (GNUNET_YES == peer->search_str_matched)
727   {
728     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
729                 "String %s on peer %u already matched!\n",
730                 peer->search_str, peer->id);
731     return;
732   }
733
734   strings_found++;
735   parallel_searches--;
736
737   if (NULL != peer->timeout)
738   {
739     GNUNET_SCHEDULER_cancel (peer->timeout);
740     peer->timeout = NULL;
741     if (GNUNET_NO == in_shutdown)
742       GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
743   }
744
745   if (NULL == id)
746   {
747     // FIXME not possible right now
748     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
749                 "String matching timed out for string %s on peer %u (%i/%i)\n",
750                 peer->search_str, peer->id, strings_found, num_peers);
751     peer->search_str_matched = GNUNET_SYSERR;
752   }
753   else
754   {
755     prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
756
757     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
758                 "String %s found on peer %u after %s (%i/%i) (%u||)\n",
759                 peer->search_str, peer->id,
760                 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
761                 strings_found, num_peers, parallel_searches);
762
763     peer->search_str_matched = GNUNET_YES;
764
765     if (NULL != data_file)
766     {
767       size =
768         GNUNET_snprintf (output_buffer,
769                          sizeof (output_buffer),
770                          "%p Peer: %u\n"
771                          "%p Search string: %s\n"
772                          "%p Search duration: %s\n\n",
773                          peer, peer->id,
774                          peer, peer->search_str,
775                          peer,
776                          GNUNET_STRINGS_relative_time_to_string (prof_time,
777                                                                  GNUNET_NO));
778
779       if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
780         GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
781     }
782   }
783
784   GNUNET_TESTBED_operation_done (peer->op_handle);
785   peer->op_handle = NULL;
786
787   if (strings_found == num_peers)
788   {
789     prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
790     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
791                 "All strings successfully matched in %s\n",
792                 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
793
794     if (NULL != search_timeout_task)
795     {
796       GNUNET_SCHEDULER_cancel (search_timeout_task);
797       search_timeout_task = NULL;
798     }
799
800     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n");
801     GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
802   }
803 }
804
805
806 /**
807  * Connect by string timeout task. This will cancel the profiler after the
808  * specified timeout 'search_timeout'.
809  *
810  * @param cls NULL
811  * @param tc the task context
812  */
813 static void
814 search_timed_out (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
815 {
816   unsigned int i;
817
818   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
819               "Finding matches to all strings did not succeed after %s.\n",
820               GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
821                                                       GNUNET_NO));
822   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
823               "Found %i of %i strings\n", strings_found, num_peers);
824
825   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
826               "Search timed out after %s."
827               "Collecting stats and shutting down.\n",
828               GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
829                                                       GNUNET_NO));
830
831   in_shutdown = GNUNET_YES;
832   for (i = 0; i < num_peers; i++)
833   {
834     if (NULL != peers[i].op_handle)
835     {
836       GNUNET_TESTBED_operation_done (peers[i].op_handle);
837       peers[i].op_handle = NULL;
838     }
839   }
840   GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
841 }
842
843
844 /**
845  * Search timed out. It might still complete in the future,
846  * but we should start another one.
847  *
848  * @param cls Index of the next peer in the peers array.
849  * @param tc TaskContext.
850  */
851 static void
852 find_timed_out (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
853 {
854   struct RegexPeer *p = cls;
855
856   p->timeout = NULL;
857
858   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
859     return;
860   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
861               "Searching for string \"%s\" on peer %d timed out.\n",
862               p->search_str,
863               p->id);
864   if (GNUNET_NO == in_shutdown)
865     GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
866 }
867
868
869 /**
870  * Start searching for a string in the DHT.
871  *
872  * @param cls Index of the next peer in the peers array.
873  * @param tc TaskContext.
874  */
875 static void
876 find_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
877 {
878   unsigned int search_peer = (unsigned int) (long) cls;
879
880   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) ||
881       search_peer >= num_peers ||
882       GNUNET_YES == in_shutdown)
883     return;
884
885   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
886               "Searching for string \"%s\" on peer %d (%u||)\n",
887               peers[search_peer].search_str,
888               search_peer,
889               parallel_searches);
890
891   peers[search_peer].op_handle =
892     GNUNET_TESTBED_service_connect (NULL,
893                                     peers[search_peer].peer_handle,
894                                     "dht",
895                                     &dht_connect_cb,
896                                     &peers[search_peer],
897                                     &dht_ca,
898                                     &dht_da,
899                                     &peers[search_peer]);
900   GNUNET_assert (NULL != peers[search_peer].op_handle);
901   peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
902                                                           &find_timed_out,
903                                                           &peers[search_peer]);
904 }
905
906
907
908
909 /**
910  * Callback called when testbed has started the daemon we asked for.
911  *
912  * @param cls NULL
913  * @param op the operation handle
914  * @param emsg NULL on success; otherwise an error description
915  */
916 static void
917 daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op,
918                 const char *emsg)
919 {
920   struct RegexPeer *peer = (struct RegexPeer *) cls;
921   unsigned long search_peer;
922   unsigned int i;
923
924   GNUNET_TESTBED_operation_done (peer->daemon_op);
925   peer->daemon_op = NULL;
926   if (NULL != emsg)
927   {
928     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
929                 "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg);
930     GNUNET_abort ();
931   }
932   else
933   {
934     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
935                 "Deamon %u started successfully\n", peer->id);
936   }
937
938   /* Find a peer to look for a string matching the regex announced */
939   search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
940                                           num_peers);
941   for (i = 0; peers[search_peer].search_str != NULL; i++)
942   {
943     search_peer = (search_peer + 1) % num_peers;
944     if (i > num_peers)
945       GNUNET_abort (); /* we ran out of peers, must be a bug */
946   }
947   peers[search_peer].search_str = search_strings[peer->id];
948   peers[search_peer].search_str_matched = GNUNET_NO;
949   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
950                                   reannounce_period_max,
951                                   2),
952                                 &find_string,
953                                 (void *) search_peer);
954 }
955
956
957 /**
958  * Task to start the daemons on each peer so that the regexes are announced
959  * into the DHT.
960  *
961  * @param cls NULL
962  * @param tc the task context
963  */
964 static void
965 do_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
966 {
967   unsigned int i;
968
969   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting announce.\n");
970
971   for (i = 0; i < init_parallel_searches; i++)
972   {
973     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
974                 "  scheduling announce %u\n",
975                 i);
976     (void) GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
977   }
978 }
979
980
981 /**
982  * Start announcing the next regex in the DHT.
983  *
984  * @param cls Closure (unused).
985  * @param tc TaskContext.
986  */
987 static void
988 announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
989 {
990   struct RegexPeer *peer;
991
992   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
993     return;
994   if (next_search >= num_peers)
995   {
996     if (strings_found != num_peers)
997     {
998       struct GNUNET_TIME_Relative new_delay;
999       if (NULL != search_timeout_task)
1000         GNUNET_SCHEDULER_cancel (search_timeout_task);
1001       new_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
1002       search_timeout_task = GNUNET_SCHEDULER_add_delayed (new_delay,
1003                                                           &search_timed_out,
1004                                                           NULL);
1005     }
1006     return;
1007   }
1008
1009   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search);
1010   peer = &peers[next_search];
1011   peer->daemon_op =
1012   GNUNET_TESTBED_peer_manage_service (NULL,
1013                                       peer->peer_handle,
1014                                       "regexprofiler",
1015                                       &daemon_started,
1016                                       peer,
1017                                       1);
1018   next_search++;
1019   parallel_searches++;
1020 }
1021
1022 /**
1023  * DHT connect callback. Called when we are connected to the dht service for
1024  * the peer in 'cls'. If successfull we connect to the stats service of this
1025  * peer and then try to match the search string of this peer.
1026  *
1027  * @param cls internal peer id.
1028  * @param op operation handle.
1029  * @param ca_result connect adapter result.
1030  * @param emsg error message.
1031  */
1032 static void
1033 dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1034                 void *ca_result, const char *emsg)
1035 {
1036   struct RegexPeer *peer = (struct RegexPeer *) cls;
1037
1038   if (NULL != emsg || NULL == op || NULL == ca_result)
1039   {
1040     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg);
1041     GNUNET_abort ();
1042   }
1043
1044   GNUNET_assert (NULL != peer->dht_handle);
1045   GNUNET_assert (peer->op_handle == op);
1046   GNUNET_assert (peer->dht_handle == ca_result);
1047
1048   peer->search_str_matched = GNUNET_NO;
1049   peer->search_handle = REGEX_INTERNAL_search (peer->dht_handle,
1050                                              peer->search_str,
1051                                              &regex_found_handler, peer,
1052                                              NULL);
1053   peer->prof_start_time = GNUNET_TIME_absolute_get ();
1054 }
1055
1056
1057 /**
1058  * DHT connect adapter. Opens a connection to the dht service.
1059  *
1060  * @param cls Closure (peer).
1061  * @param cfg Configuration handle.
1062  *
1063  * @return
1064  */
1065 static void *
1066 dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1067 {
1068   struct RegexPeer *peer = cls;
1069
1070   peer->dht_handle = GNUNET_DHT_connect (cfg, 32);
1071
1072   return peer->dht_handle;
1073 }
1074
1075
1076 /**
1077  * Adapter function called to destroy a connection to the dht service.
1078  *
1079  * @param cls Closure (peer).
1080  * @param op_result Service handle returned from the connect adapter.
1081  */
1082 static void
1083 dht_da (void *cls, void *op_result)
1084 {
1085   struct RegexPeer *peer = (struct RegexPeer *) cls;
1086
1087   GNUNET_assert (peer->dht_handle == op_result);
1088
1089   if (NULL != peer->search_handle)
1090   {
1091     REGEX_INTERNAL_search_cancel (peer->search_handle);
1092     peer->search_handle = NULL;
1093   }
1094
1095   if (NULL != peer->dht_handle)
1096   {
1097     GNUNET_DHT_disconnect (peer->dht_handle);
1098     peer->dht_handle = NULL;
1099   }
1100 }
1101
1102
1103 /**
1104  * Signature of a main function for a testcase.
1105  *
1106  * @param cls NULL
1107  * @param h the run handle
1108  * @param num_peers_ number of peers in 'peers'
1109  * @param testbed_peers handle to peers run in the testbed.  NULL upon timeout (see
1110  *          GNUNET_TESTBED_test_run()).
1111  * @param links_succeeded the number of overlay link connection attempts that
1112  *          succeeded
1113  * @param links_failed the number of overlay link connection attempts that
1114  *          failed
1115  */
1116 static void
1117 test_master (void *cls,
1118              struct GNUNET_TESTBED_RunHandle *h,
1119              unsigned int num_peers_,
1120              struct GNUNET_TESTBED_Peer **testbed_peers,
1121              unsigned int links_succeeded,
1122              unsigned int links_failed)
1123 {
1124   unsigned int i;
1125
1126   GNUNET_assert (num_peers_ == num_peers);
1127
1128   prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1129   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1130               "Testbed started in %s\n",
1131               GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1132
1133   if (NULL != abort_task)
1134   {
1135     GNUNET_SCHEDULER_cancel (abort_task);
1136     abort_task = NULL;
1137   }
1138
1139   for (i = 0; i < num_peers; i++)
1140   {
1141     peers[i].peer_handle = testbed_peers[i];
1142   }
1143   if (GNUNET_NO ==
1144       GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", "DISABLE_TRY_CONNECT"))
1145   {
1146     struct GNUNET_TIME_Relative settle_time;
1147
1148     settle_time =
1149       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1150                                      10 * num_peers);
1151     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1152                 "Waiting for DHT for %s to settle new connections.\n\n",
1153                 GNUNET_STRINGS_relative_time_to_string(settle_time, GNUNET_NO));
1154     GNUNET_SCHEDULER_add_delayed (settle_time, &do_announce, NULL);
1155   }
1156   else
1157   {
1158     GNUNET_SCHEDULER_add_now (&do_announce, NULL);
1159   }
1160   search_timeout_task =
1161       GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timed_out, NULL);
1162 }
1163
1164 /**
1165  * Function that will be called whenever something in the testbed changes.
1166  *
1167  * @param cls closure, NULL
1168  * @param event information on what is happening
1169  */
1170 static void
1171 master_controller_cb (void *cls,
1172                       const struct GNUNET_TESTBED_EventInformation *event)
1173 {
1174   switch (event->type)
1175   {
1176   case GNUNET_TESTBED_ET_CONNECT:
1177     printf(".");
1178     break;
1179   case GNUNET_TESTBED_ET_PEER_START:
1180     printf("#");
1181     break;
1182   default:
1183     break;
1184   }
1185   fflush(stdout);
1186 }
1187
1188
1189 /******************************************************************************/
1190 /***************************  TESTBED PEER SETUP  *****************************/
1191 /******************************************************************************/
1192
1193
1194 /**
1195  * Load search strings from given filename. One search string per line.
1196  *
1197  * @param filename filename of the file containing the search strings.
1198  * @param strings set of strings loaded from file. Caller needs to free this
1199  *                if number returned is greater than zero.
1200  * @param limit upper limit on the number of strings read from the file
1201  * @return number of strings found in the file. GNUNET_SYSERR on error.
1202  */
1203 static int
1204 load_search_strings (const char *filename, char ***strings, unsigned int limit)
1205 {
1206   char *data;
1207   char *buf;
1208   uint64_t filesize;
1209   unsigned int offset;
1210   int str_cnt;
1211   unsigned int i;
1212
1213   if (NULL == filename)
1214   {
1215     return GNUNET_SYSERR;
1216   }
1217
1218   if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1219   {
1220     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1221                 "Could not find search strings file %s\n", filename);
1222     return GNUNET_SYSERR;
1223   }
1224   if (GNUNET_OK != GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES))
1225     filesize = 0;
1226   if (0 == filesize)
1227   {
1228     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Search strings file %s is empty.\n", filename);
1229     return GNUNET_SYSERR;
1230   }
1231   data = GNUNET_malloc (filesize);
1232   if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
1233   {
1234     GNUNET_free (data);
1235     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read search strings file %s.\n",
1236          filename);
1237     return GNUNET_SYSERR;
1238   }
1239   buf = data;
1240   offset = 0;
1241   str_cnt = 0;
1242   while (offset < (filesize - 1) && str_cnt < limit)
1243   {
1244     offset++;
1245     if (((data[offset] == '\n')) && (buf != &data[offset]))
1246     {
1247       data[offset] = '\0';
1248       str_cnt++;
1249       buf = &data[offset + 1];
1250     }
1251     else if ((data[offset] == '\n') || (data[offset] == '\0'))
1252       buf = &data[offset + 1];
1253   }
1254   *strings = GNUNET_malloc (sizeof (char *) * str_cnt);
1255   offset = 0;
1256   for (i = 0; i < str_cnt; i++)
1257   {
1258     GNUNET_asprintf (&(*strings)[i], "%s%s", regex_prefix, &data[offset]);
1259     offset += strlen (&data[offset]) + 1;
1260   }
1261   GNUNET_free (data);
1262   return str_cnt;
1263 }
1264
1265
1266 /**
1267  * Main function that will be run by the scheduler.
1268  *
1269  * @param cls closure
1270  * @param args remaining command-line arguments
1271  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1272  * @param config configuration
1273  */
1274 static void
1275 run (void *cls, char *const *args, const char *cfgfile,
1276      const struct GNUNET_CONFIGURATION_Handle *config)
1277 {
1278   unsigned int nsearchstrs;
1279   unsigned int i;
1280   struct GNUNET_TIME_Relative abort_time;
1281
1282   in_shutdown = GNUNET_NO;
1283
1284   /* Check config */
1285   if (NULL == config)
1286   {
1287     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1288                 _("No configuration file given. Exiting\n"));
1289     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1290     return;
1291   }
1292   cfg = GNUNET_CONFIGURATION_dup (config);
1293   if (GNUNET_OK !=
1294       GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER",
1295                                              "REGEX_PREFIX",
1296                                              &regex_prefix))
1297   {
1298     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1299                 _("Configuration option \"regex_prefix\" missing. Exiting\n"));
1300     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1301     return;
1302   }
1303   if (GNUNET_OK !=
1304       GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER",
1305                                              "PARALLEL_SEARCHES",
1306                                              &init_parallel_searches))
1307   {
1308     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1309                 "Configuration option \"PARALLEL_SEARCHES\" missing."
1310                 " Using default (%d)\n", 10);
1311     init_parallel_searches = 10;
1312   }
1313   if (GNUNET_OK !=
1314       GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER",
1315                                            "REANNOUNCE_PERIOD_MAX",
1316                                            &reannounce_period_max))
1317   {
1318     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1319                 "reannounce_period_max not given. Using 10 minutes.\n");
1320     reannounce_period_max =
1321       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10);
1322   }
1323
1324   /* Check arguments */
1325   if (NULL == policy_dir)
1326   {
1327     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1328                 _("No policy directory specified on command line. Exiting.\n"));
1329     return;
1330   }
1331   if (GNUNET_YES != GNUNET_DISK_directory_test (policy_dir, GNUNET_YES))
1332   {
1333     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1334                 _("Specified policies directory does not exist. Exiting.\n"));
1335     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1336     return;
1337   }
1338   if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL)))
1339   {
1340     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1341                 _("No files found in `%s'\n"),
1342                 policy_dir);
1343     return;
1344   }
1345   GNUNET_CONFIGURATION_set_value_string (cfg, "REGEXPROFILER",
1346                                          "POLICY_DIR", policy_dir);
1347   if (GNUNET_YES != GNUNET_DISK_file_test (strings_file))
1348   {
1349     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1350                 _("No search strings file given. Exiting.\n"));
1351     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1352     return;
1353   }
1354   nsearchstrs = load_search_strings (strings_file,
1355                                      &search_strings,
1356                                      num_peers);
1357   if (num_peers != nsearchstrs)
1358   {
1359     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1360                 "Error loading search strings.\n");
1361     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1362                 "File (%s) does not contain enough strings (%u/%u).\n",
1363                 strings_file, nsearchstrs, num_peers);
1364     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1365     return;
1366   }
1367   if ( (0 == num_peers) || (NULL == search_strings))
1368   {
1369     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1370                 _("Error loading search strings. Exiting.\n"));
1371     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1372     return;
1373   }
1374   for (i = 0; i < num_peers; i++)
1375     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1376                 "search string: %s\n",
1377                 search_strings[i]);
1378
1379   /* Check logfile */
1380   if ( (NULL != data_filename) &&
1381        (NULL == (data_file =
1382                  GNUNET_DISK_file_open (data_filename,
1383                                         GNUNET_DISK_OPEN_READWRITE |
1384                                         GNUNET_DISK_OPEN_TRUNCATE |
1385                                         GNUNET_DISK_OPEN_CREATE,
1386                                         GNUNET_DISK_PERM_USER_READ |
1387                                         GNUNET_DISK_PERM_USER_WRITE))) )
1388   {
1389     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1390                               "open",
1391                               data_filename);
1392     return;
1393   }
1394
1395   /* Initialize peers */
1396   peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers);
1397   for (i = 0; i < num_peers; i++)
1398     peers[i].id = i;
1399
1400   GNUNET_CONFIGURATION_set_value_number (cfg,
1401                                          "TESTBED", "OVERLAY_RANDOM_LINKS",
1402                                          num_peers * 20);
1403   GNUNET_CONFIGURATION_set_value_number (cfg,
1404                                          "DHT", "FORCE_NSE",
1405                                          (long long unsigned)
1406                                          (log (num_peers) / log (2.0)));
1407   event_mask = 0LL;
1408 /* For feedback about the start process activate these and pass master_cb */
1409   event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
1410 //   event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
1411   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1412 //   event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
1413   prof_start_time = GNUNET_TIME_absolute_get ();
1414   GNUNET_TESTBED_run (hosts_file,
1415                       cfg,
1416                       num_peers,
1417                       event_mask,
1418                       &master_controller_cb,
1419                       NULL,     /* master_controller_cb cls */
1420                       &test_master,
1421                       NULL);    /* test_master cls */
1422   if (GNUNET_OK !=
1423       GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
1424                                            "SETUP_TIMEOUT",
1425                                            &abort_time))
1426   {
1427     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1428                 "SETUP_TIMEOUT not given. Using 15 minutes.\n");
1429     abort_time =
1430       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
1431   }
1432   abort_time = GNUNET_TIME_relative_add (abort_time, GNUNET_TIME_UNIT_MINUTES);
1433   abort_task =
1434       GNUNET_SCHEDULER_add_delayed (abort_time,
1435                                     &do_abort,
1436                                     (void*) __LINE__);
1437   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1438               "setup_timeout: %s\n",
1439               GNUNET_STRINGS_relative_time_to_string (abort_time, GNUNET_YES));
1440 }
1441
1442
1443 /**
1444  * Main function.
1445  *
1446  * @param argc argument count
1447  * @param argv argument values
1448  * @return 0 on success
1449  */
1450 int
1451 main (int argc, char *const *argv)
1452 {
1453   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1454     {'o', "output-file", "FILENAME",
1455      gettext_noop ("name of the file for writing statistics"),
1456      GNUNET_YES, &GNUNET_GETOPT_set_string, &data_filename},
1457     {'t', "matching-timeout", "TIMEOUT",
1458       gettext_noop ("wait TIMEOUT before ending the experiment"),
1459       GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout_time},
1460     {'p', "policy-dir", "DIRECTORY",
1461       gettext_noop ("directory with policy files"),
1462       GNUNET_YES, &GNUNET_GETOPT_set_filename, &policy_dir},
1463     {'s', "strings-file", "FILENAME",
1464       gettext_noop ("name of file with input strings"),
1465       GNUNET_YES, &GNUNET_GETOPT_set_filename, &strings_file},
1466     {'H', "hosts-file", "FILENAME",
1467       gettext_noop ("name of file with hosts' names"),
1468       GNUNET_YES, &GNUNET_GETOPT_set_filename, &hosts_file},
1469     GNUNET_GETOPT_OPTION_END
1470   };
1471   int ret;
1472
1473   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1474     return 2;
1475   result = GNUNET_SYSERR;
1476   ret =
1477       GNUNET_PROGRAM_run (argc, argv,
1478                           "gnunet-regex-profiler",
1479                           _("Profiler for regex"),
1480                           options, &run, NULL);
1481   if (GNUNET_OK != ret)
1482     return ret;
1483   if (GNUNET_OK != result)
1484     return 1;
1485   return 0;
1486 }