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