aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-regex-profiler.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 09:03:33 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 09:03:33 +0200
commit7f72b05249f6ac663cee7a033f3cac5d9400ede7 (patch)
treed15cec717aa9568adc1876ec1b717cf18596e1f6 /src/regex/gnunet-regex-profiler.c
parent5ae8ee063302cc6c1fc7b74328af46a11cb02cdc (diff)
downloadgnunet-7f72b05249f6ac663cee7a033f3cac5d9400ede7.tar.gz
gnunet-7f72b05249f6ac663cee7a033f3cac5d9400ede7.zip
BUILD: Move regex/dns to service
Diffstat (limited to 'src/regex/gnunet-regex-profiler.c')
-rw-r--r--src/regex/gnunet-regex-profiler.c1589
1 files changed, 0 insertions, 1589 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c
deleted file mode 100644
index 8238ad3df..000000000
--- a/src/regex/gnunet-regex-profiler.c
+++ /dev/null
@@ -1,1589 +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. Called when we are connected to the dht service for
325 * the peer in 'cls'. If successful we connect to the stats service of this
326 * peer and then try to match the search string of this peer.
327 *
328 * @param cls internal peer id.
329 * @param op operation handle.
330 * @param ca_result connect adapter result.
331 * @param emsg error message.
332 */
333static void
334dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
335 void *ca_result, const char *emsg);
336
337/**
338 * DHT connect adapter. Opens a connection to the DHT service.
339 *
340 * @param cls Closure (peer).
341 * @param cfg Configuration handle.
342 *
343 * @return
344 */
345static void *
346dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
347
348
349/**
350 * Adapter function called to destroy a connection to
351 * the DHT service.
352 *
353 * @param cls Closure
354 * @param op_result Service handle returned from the connect adapter.
355 */
356static void
357dht_da (void *cls, void *op_result);
358
359
360/**
361 * Function called by testbed once we are connected to stats
362 * service. Get the statistics for the services of interest.
363 *
364 * @param cls the 'struct RegexPeer' for which we connected to stats
365 * @param op connect operation handle
366 * @param ca_result handle to stats service
367 * @param emsg error message on failure
368 */
369static void
370stats_connect_cb (void *cls,
371 struct GNUNET_TESTBED_Operation *op,
372 void *ca_result,
373 const char *emsg);
374
375
376/**
377 * Start announcing the next regex in the DHT.
378 *
379 * @param cls Index of the next peer in the peers array.
380 */
381static void
382announce_next_regex (void *cls);
383
384
385/******************************************************************************/
386/******************************** SHUTDOWN **********************************/
387/******************************************************************************/
388
389
390/**
391 * Shutdown nicely
392 *
393 * @param cls NULL
394 */
395static void
396do_shutdown (void *cls)
397{
398 struct RegexPeer *peer;
399 unsigned int peer_cnt;
400 unsigned int search_str_cnt;
401 char output_buffer[512];
402 size_t size;
403
404 if (NULL != abort_task)
405 {
406 GNUNET_SCHEDULER_cancel (abort_task);
407 abort_task = NULL;
408 }
409 if (NULL != register_hosts_task)
410 {
411 GNUNET_SCHEDULER_cancel (register_hosts_task);
412 register_hosts_task = NULL;
413 }
414 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
415 {
416 peer = &peers[peer_cnt];
417
418 if ((GNUNET_YES != peer->search_str_matched) && (NULL != data_file) )
419 {
420 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
421 size =
422 GNUNET_snprintf (output_buffer,
423 sizeof(output_buffer),
424 "%p Search string not found: %s (%d)\n"
425 "%p On peer: %u (%p)\n"
426 "%p After: %s\n",
427 peer, peer->search_str, peer->search_str_matched,
428 peer, peer->id, peer,
429 peer,
430 GNUNET_STRINGS_relative_time_to_string (prof_time,
431 GNUNET_NO));
432 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
434 }
435
436 if (NULL != peers[peer_cnt].op_handle)
437 GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle);
438 }
439
440 if (NULL != data_file)
441 {
442 GNUNET_DISK_file_close (data_file);
443 data_file = NULL;
444 }
445 for (search_str_cnt = 0;
446 search_str_cnt < num_peers && NULL != search_strings;
447 search_str_cnt++)
448 {
449 GNUNET_free (search_strings[search_str_cnt]);
450 }
451 GNUNET_free (search_strings);
452 search_strings = NULL;
453
454 if (NULL != reg_handle)
455 {
456 GNUNET_TESTBED_cancel_registration (reg_handle);
457 reg_handle = NULL;
458 }
459 if (NULL != mc)
460 {
461 GNUNET_TESTBED_controller_disconnect (mc);
462 mc = NULL;
463 }
464 if (NULL != mc_proc)
465 {
466 GNUNET_TESTBED_controller_stop (mc_proc);
467 mc_proc = NULL;
468 }
469 if (NULL != cfg)
470 {
471 GNUNET_CONFIGURATION_destroy (cfg);
472 cfg = NULL;
473 }
474}
475
476
477/**
478 * abort task to run on test timed out
479 *
480 * @param cls NULL
481 */
482static void
483do_abort (void *cls)
484{
485 unsigned long i = (unsigned long) cls;
486
487 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
488 "Aborting from line %lu...\n", i);
489 abort_task = NULL;
490 result = GNUNET_SYSERR;
491 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
492}
493
494
495/******************************************************************************/
496/********************* STATISTICS SERVICE CONNECTIONS ***********************/
497/******************************************************************************/
498
499/**
500 * Adapter function called to establish a connection to
501 * statistics service.
502 *
503 * @param cls closure
504 * @param cfg configuration of the peer to connect to; will be available until
505 * GNUNET_TESTBED_operation_done() is called on the operation returned
506 * from GNUNET_TESTBED_service_connect()
507 * @return service handle to return in 'op_result', NULL on error
508 */
509static void *
510stats_ca (void *cls,
511 const struct GNUNET_CONFIGURATION_Handle *cfg)
512{
513 return GNUNET_STATISTICS_create ("<driver>", cfg);
514}
515
516
517/**
518 * Adapter function called to destroy a connection to
519 * statistics service.
520 *
521 * @param cls closure
522 * @param op_result service handle returned from the connect adapter
523 */
524static void
525stats_da (void *cls, void *op_result)
526{
527 struct RegexPeer *peer = cls;
528
529 GNUNET_assert (op_result == peer->stats_handle);
530
531 GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
532 peer->stats_handle = NULL;
533}
534
535
536/**
537 * Process statistic values. Write all values to global 'data_file', if present.
538 *
539 * @param cls closure
540 * @param subsystem name of subsystem that created the statistic
541 * @param name the name of the datum
542 * @param value the current value
543 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
544 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
545 */
546static int
547stats_iterator (void *cls,
548 const char *subsystem,
549 const char *name,
550 uint64_t value, int is_persistent)
551{
552 struct RegexPeer *peer = cls;
553 char output_buffer[512];
554 size_t size;
555
556 if (NULL == data_file)
557 {
558 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
559 "%p -> %s [%s]: %llu\n",
560 peer,
561 subsystem,
562 name,
563 (unsigned long long) value);
564 return GNUNET_OK;
565 }
566 size =
567 GNUNET_snprintf (output_buffer,
568 sizeof(output_buffer),
569 "%p [%s] %llu %s\n",
570 peer,
571 subsystem,
572 (unsigned long long) value,
573 name);
574 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
576 "Unable to write to file!\n");
577
578 return GNUNET_OK;
579}
580
581
582/**
583 * Stats callback. Finish the stats testbed operation and when all stats have
584 * been iterated, shutdown the profiler.
585 *
586 * @param cls closure
587 * @param success GNUNET_OK if statistics were
588 * successfully obtained, GNUNET_SYSERR if not.
589 */
590static void
591stats_cb (void *cls,
592 int success)
593{
594 static unsigned int peer_cnt;
595 struct RegexPeer *peer = cls;
596
597 if (GNUNET_OK != success)
598 {
599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
600 "Getting statistics for peer %u failed!\n",
601 peer->id);
602 return;
603 }
604
605 GNUNET_assert (NULL != peer->op_handle);
606
607 GNUNET_TESTBED_operation_done (peer->op_handle);
608 peer->op_handle = NULL;
609
610 peer_cnt++;
611 peer = &peers[peer_cnt];
612
613 fprintf (stderr, "s");
614 if (peer_cnt == num_peers)
615 {
616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
617 "\nCollecting stats finished. Shutting down.\n");
618 GNUNET_SCHEDULER_shutdown ();
619 result = GNUNET_OK;
620 }
621 else
622 {
623 peer->op_handle =
624 GNUNET_TESTBED_service_connect (NULL,
625 peer->peer_handle,
626 "statistics",
627 &stats_connect_cb,
628 peer,
629 &stats_ca,
630 &stats_da,
631 peer);
632 }
633}
634
635
636/**
637 * Function called by testbed once we are connected to stats
638 * service. Get the statistics for the services of interest.
639 *
640 * @param cls the 'struct RegexPeer' for which we connected to stats
641 * @param op connect operation handle
642 * @param ca_result handle to stats service
643 * @param emsg error message on failure
644 */
645static void
646stats_connect_cb (void *cls,
647 struct GNUNET_TESTBED_Operation *op,
648 void *ca_result,
649 const char *emsg)
650{
651 struct RegexPeer *peer = cls;
652
653 if ((NULL == ca_result) || (NULL != emsg))
654 {
655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
656 "Failed to connect to statistics service on peer %u: %s\n",
657 peer->id, emsg);
658
659 peer->stats_handle = NULL;
660 return;
661 }
662
663 peer->stats_handle = ca_result;
664
665 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL,
666 &stats_cb,
667 &stats_iterator, peer))
668 {
669 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
670 "Could not get statistics of peer %u!\n", peer->id);
671 }
672}
673
674
675/**
676 * Task to collect all statistics from all peers, will shutdown the
677 * profiler, when done.
678 *
679 * @param cls NULL
680 */
681static void
682do_collect_stats (void *cls)
683{
684 struct RegexPeer *peer = &peers[0];
685
686 GNUNET_assert (NULL != peer->peer_handle);
687
688 peer->op_handle =
689 GNUNET_TESTBED_service_connect (NULL,
690 peer->peer_handle,
691 "statistics",
692 &stats_connect_cb,
693 peer,
694 &stats_ca,
695 &stats_da,
696 peer);
697}
698
699
700/******************************************************************************/
701/************************ REGEX FIND CONNECTIONS **************************/
702/******************************************************************************/
703
704
705/**
706 * Start searching for the next string in the DHT.
707 *
708 * @param cls Index of the next peer in the peers array.
709 */
710static void
711find_string (void *cls);
712
713
714/**
715 * Method called when we've found a peer that announced a regex
716 * that matches our search string. Now get the statistics.
717 *
718 * @param cls Closure provided in REGEX_INTERNAL_search.
719 * @param id Peer providing a regex that matches the string.
720 * @param get_path Path of the get request.
721 * @param get_path_length Length of get_path.
722 * @param put_path Path of the put request.
723 * @param put_path_length Length of the put_path.
724 */
725static void
726regex_found_handler (void *cls,
727 const struct GNUNET_PeerIdentity *id,
728 const struct GNUNET_DHT_PathElement *get_path,
729 unsigned int get_path_length,
730 const struct GNUNET_DHT_PathElement *put_path,
731 unsigned int put_path_length)
732{
733 struct RegexPeer *peer = cls;
734 char output_buffer[512];
735 size_t size;
736
737 if (GNUNET_YES == peer->search_str_matched)
738 {
739 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
740 "String %s on peer %u already matched!\n",
741 peer->search_str, peer->id);
742 return;
743 }
744
745 strings_found++;
746 parallel_searches--;
747
748 if (NULL != peer->timeout)
749 {
750 GNUNET_SCHEDULER_cancel (peer->timeout);
751 peer->timeout = NULL;
752 if (GNUNET_NO == in_shutdown)
753 GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
754 }
755
756 if (NULL == id)
757 {
758 // FIXME not possible right now
759 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
760 "String matching timed out for string %s on peer %u (%i/%i)\n",
761 peer->search_str, peer->id, strings_found, num_peers);
762 peer->search_str_matched = GNUNET_SYSERR;
763 }
764 else
765 {
766 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
767
768 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
769 "String %s found on peer %u after %s (%i/%i) (%u||)\n",
770 peer->search_str, peer->id,
771 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
772 strings_found, num_peers, parallel_searches);
773
774 peer->search_str_matched = GNUNET_YES;
775
776 if (NULL != data_file)
777 {
778 size =
779 GNUNET_snprintf (output_buffer,
780 sizeof(output_buffer),
781 "%p Peer: %u\n"
782 "%p Search string: %s\n"
783 "%p Search duration: %s\n\n",
784 peer, peer->id,
785 peer, peer->search_str,
786 peer,
787 GNUNET_STRINGS_relative_time_to_string (prof_time,
788 GNUNET_NO));
789
790 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
791 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
792 }
793 }
794
795 GNUNET_TESTBED_operation_done (peer->op_handle);
796 peer->op_handle = NULL;
797
798 if (strings_found == num_peers)
799 {
800 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
801 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
802 "All strings successfully matched in %s\n",
803 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
804
805 if (NULL != search_timeout_task)
806 {
807 GNUNET_SCHEDULER_cancel (search_timeout_task);
808 search_timeout_task = NULL;
809 }
810
811 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n");
812 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
813 }
814}
815
816
817/**
818 * Connect by string timeout task. This will cancel the profiler after the
819 * specified timeout 'search_timeout'.
820 *
821 * @param cls NULL
822 */
823static void
824search_timed_out (void *cls)
825{
826 unsigned int i;
827
828 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
829 "Finding matches to all strings did not succeed after %s.\n",
830 GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
831 GNUNET_NO));
832 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
833 "Found %i of %i strings\n", strings_found, num_peers);
834
835 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
836 "Search timed out after %s."
837 "Collecting stats and shutting down.\n",
838 GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
839 GNUNET_NO));
840
841 in_shutdown = GNUNET_YES;
842 for (i = 0; i < num_peers; i++)
843 {
844 if (NULL != peers[i].op_handle)
845 {
846 GNUNET_TESTBED_operation_done (peers[i].op_handle);
847 peers[i].op_handle = NULL;
848 }
849 }
850 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
851}
852
853
854/**
855 * Search timed out. It might still complete in the future,
856 * but we should start another one.
857 *
858 * @param cls Index of the next peer in the peers array.
859 */
860static void
861find_timed_out (void *cls)
862{
863 struct RegexPeer *p = cls;
864
865 p->timeout = NULL;
866 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
867 "Searching for string \"%s\" on peer %d timed out.\n",
868 p->search_str,
869 p->id);
870 if (GNUNET_NO == in_shutdown)
871 GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
872}
873
874
875/**
876 * Start searching for a string in the DHT.
877 *
878 * @param cls Index of the next peer in the peers array.
879 */
880static void
881find_string (void *cls)
882{
883 unsigned int search_peer = (unsigned int) (long) cls;
884
885 if ((search_peer >= num_peers) ||
886 (GNUNET_YES == in_shutdown))
887 return;
888
889 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
890 "Searching for string \"%s\" on peer %d (%u||)\n",
891 peers[search_peer].search_str,
892 search_peer,
893 parallel_searches);
894
895 peers[search_peer].op_handle =
896 GNUNET_TESTBED_service_connect (NULL,
897 peers[search_peer].peer_handle,
898 "dht",
899 &dht_connect_cb,
900 &peers[search_peer],
901 &dht_ca,
902 &dht_da,
903 &peers[search_peer]);
904 GNUNET_assert (NULL != peers[search_peer].op_handle);
905 peers[search_peer].timeout
906 = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
907 &find_timed_out,
908 &peers[search_peer]);
909}
910
911
912/**
913 * Callback called when testbed has started the daemon we asked for.
914 *
915 * @param cls NULL
916 * @param op the operation handle
917 * @param emsg NULL on success; otherwise an error description
918 */
919static void
920daemon_started (void *cls,
921 struct GNUNET_TESTBED_Operation *op,
922 const char *emsg)
923{
924 struct RegexPeer *peer = (struct RegexPeer *) cls;
925 unsigned long search_peer;
926 unsigned int i;
927
928 GNUNET_TESTBED_operation_done (peer->daemon_op);
929 peer->daemon_op = NULL;
930 if (NULL != emsg)
931 {
932 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
933 "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg);
934 GNUNET_assert (0);
935 }
936 else
937 {
938 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
939 "Daemon %u started successfully\n", peer->id);
940 }
941
942 /* Find a peer to look for a string matching the regex announced */
943 search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
944 num_peers);
945 for (i = 0; peers[search_peer].search_str != NULL; i++)
946 {
947 search_peer = (search_peer + 1) % num_peers;
948 if (i > num_peers)
949 GNUNET_assert (0); /* we ran out of peers, must be a bug */
950 }
951 peers[search_peer].search_str = search_strings[peer->id];
952 peers[search_peer].search_str_matched = GNUNET_NO;
953 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_saturating_multiply (
954 reannounce_period_max,
955 2),
956 &find_string,
957 (void *) search_peer);
958}
959
960
961/**
962 * Task to start the daemons on each peer so that the regexes are announced
963 * into the DHT.
964 *
965 * @param cls NULL
966 */
967static void
968do_announce (void *cls)
969{
970 unsigned int i;
971
972 if (GNUNET_YES == in_shutdown)
973 return;
974 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
975 "Starting announce.\n");
976 for (i = 0; i < init_parallel_searches; i++)
977 {
978 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
979 " scheduling announce %u\n",
980 i);
981 (void) GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
982 }
983}
984
985
986/**
987 * Start announcing the next regex in the DHT.
988 *
989 * @param cls Closure (unused).
990 */
991static void
992announce_next_regex (void *cls)
993{
994 struct RegexPeer *peer;
995
996 if (GNUNET_YES == in_shutdown)
997 return;
998 if (next_search >= num_peers)
999 {
1000 if (strings_found != num_peers)
1001 {
1002 struct GNUNET_TIME_Relative new_delay;
1003 if (NULL != search_timeout_task)
1004 GNUNET_SCHEDULER_cancel (search_timeout_task);
1005 new_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
1006 search_timeout_task = GNUNET_SCHEDULER_add_delayed (new_delay,
1007 &search_timed_out,
1008 NULL);
1009 }
1010 return;
1011 }
1012
1013 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search);
1014 peer = &peers[next_search];
1015 peer->daemon_op =
1016 GNUNET_TESTBED_peer_manage_service (NULL,
1017 peer->peer_handle,
1018 "regexprofiler",
1019 &daemon_started,
1020 peer,
1021 1);
1022 next_search++;
1023 parallel_searches++;
1024}
1025
1026
1027static void
1028dht_connect_cb (void *cls,
1029 struct GNUNET_TESTBED_Operation *op,
1030 void *ca_result,
1031 const char *emsg)
1032{
1033 struct RegexPeer *peer = (struct RegexPeer *) cls;
1034
1035 if ((NULL != emsg) || (NULL == op) || (NULL == ca_result))
1036 {
1037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg);
1038 GNUNET_assert (0);
1039 }
1040
1041 GNUNET_assert (NULL != peer->dht_handle);
1042 GNUNET_assert (peer->op_handle == op);
1043 GNUNET_assert (peer->dht_handle == ca_result);
1044
1045 peer->search_str_matched = GNUNET_NO;
1046 peer->search_handle = REGEX_INTERNAL_search (peer->dht_handle,
1047 peer->search_str,
1048 &regex_found_handler, peer,
1049 NULL);
1050 peer->prof_start_time = GNUNET_TIME_absolute_get ();
1051}
1052
1053
1054static void *
1055dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1056{
1057 struct RegexPeer *peer = cls;
1058
1059 peer->dht_handle = GNUNET_DHT_connect (cfg, 32);
1060
1061 return peer->dht_handle;
1062}
1063
1064
1065static void
1066dht_da (void *cls, void *op_result)
1067{
1068 struct RegexPeer *peer = (struct RegexPeer *) cls;
1069
1070 GNUNET_assert (peer->dht_handle == op_result);
1071
1072 if (NULL != peer->search_handle)
1073 {
1074 REGEX_INTERNAL_search_cancel (peer->search_handle);
1075 peer->search_handle = NULL;
1076 }
1077
1078 if (NULL != peer->dht_handle)
1079 {
1080 GNUNET_DHT_disconnect (peer->dht_handle);
1081 peer->dht_handle = NULL;
1082 }
1083}
1084
1085
1086/**
1087 * Signature of a main function for a testcase.
1088 *
1089 * @param cls NULL
1090 * @param h the run handle
1091 * @param num_peers_ number of peers in 'peers'
1092 * @param testbed_peers handle to peers run in the testbed. NULL upon timeout (see
1093 * GNUNET_TESTBED_test_run()).
1094 * @param links_succeeded the number of overlay link connection attempts that
1095 * succeeded
1096 * @param links_failed the number of overlay link connection attempts that
1097 * failed
1098 */
1099static void
1100test_master (void *cls,
1101 struct GNUNET_TESTBED_RunHandle *h,
1102 unsigned int num_peers_,
1103 struct GNUNET_TESTBED_Peer **testbed_peers,
1104 unsigned int links_succeeded,
1105 unsigned int links_failed)
1106{
1107 unsigned int i;
1108
1109 GNUNET_assert (num_peers_ == num_peers);
1110
1111 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1112 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1113 "Testbed started in %s\n",
1114 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1115
1116 if (NULL != abort_task)
1117 {
1118 GNUNET_SCHEDULER_cancel (abort_task);
1119 abort_task = NULL;
1120 }
1121
1122 for (i = 0; i < num_peers; i++)
1123 {
1124 peers[i].peer_handle = testbed_peers[i];
1125 }
1126 if (GNUNET_NO ==
1127 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", "DISABLE_TRY_CONNECT"))
1128 {
1129 struct GNUNET_TIME_Relative settle_time;
1130
1131 settle_time =
1132 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1133 10 * num_peers);
1134 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1135 "Waiting for DHT for %s to settle new connections.\n\n",
1136 GNUNET_STRINGS_relative_time_to_string (settle_time,
1137 GNUNET_NO));
1138 GNUNET_SCHEDULER_add_delayed (settle_time, &do_announce, NULL);
1139 }
1140 else
1141 {
1142 GNUNET_SCHEDULER_add_now (&do_announce, NULL);
1143 }
1144 search_timeout_task =
1145 GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timed_out, NULL);
1146}
1147
1148
1149/**
1150 * Function that will be called whenever something in the testbed changes.
1151 *
1152 * @param cls closure, NULL
1153 * @param event information on what is happening
1154 */
1155static void
1156master_controller_cb (void *cls,
1157 const struct GNUNET_TESTBED_EventInformation *event)
1158{
1159 switch (event->type)
1160 {
1161 case GNUNET_TESTBED_ET_CONNECT:
1162 printf (".");
1163 break;
1164
1165 case GNUNET_TESTBED_ET_PEER_START:
1166 printf ("#");
1167 break;
1168
1169 default:
1170 break;
1171 }
1172 fflush (stdout);
1173}
1174
1175
1176/******************************************************************************/
1177/*************************** TESTBED PEER SETUP *****************************/
1178/******************************************************************************/
1179
1180/**
1181 * Process the text buffer counting the non-empty lines and separating them
1182 * with NULL characters, for later ease of copy using (as)printf.
1183 *
1184 * @param data Memory buffer with strings.
1185 * @param data_size Size of the @a data buffer in bytes.
1186 * @param str_max Maximum number of strings to return.
1187 * @return Positive number of lines found in the buffer,
1188 * #GNUNET_SYSERR otherwise.
1189 */
1190static int
1191count_and_separate_strings (char *data,
1192 uint64_t data_size,
1193 unsigned int str_max)
1194{
1195 char *buf; // Keep track of last string to skip blank lines
1196 unsigned int offset;
1197 unsigned int str_cnt;
1198
1199 buf = data;
1200 offset = 0;
1201 str_cnt = 0;
1202 while ((offset < (data_size - 1)) && (str_cnt < str_max))
1203 {
1204 offset++;
1205 if (((data[offset] == '\n')) &&
1206 (buf != &data[offset]))
1207 {
1208 data[offset] = '\0';
1209 str_cnt++;
1210 buf = &data[offset + 1];
1211 }
1212 else if ((data[offset] == '\n') ||
1213 (data[offset] == '\0'))
1214 buf = &data[offset + 1];
1215 }
1216 return str_cnt;
1217}
1218
1219
1220/**
1221 * Allocate a string array and fill it with the prefixed strings
1222 * from a pre-processed, NULL-separated memory region.
1223 *
1224 * @param data Preprocessed memory with strings
1225 * @param data_size Size of the @a data buffer in bytes.
1226 * @param strings Address of the string array to be created.
1227 * Must be freed by caller if function end in success.
1228 * @param str_cnt String count. The @a data buffer should contain
1229 * at least this many NULL-separated strings.
1230 * @return #GNUNET_OK in ase of success, #GNUNET_SYSERR otherwise.
1231 * In case of error @a strings must not be freed.
1232 */
1233static int
1234create_string_array (char *data, uint64_t data_size,
1235 char ***strings, unsigned int str_cnt)
1236{
1237 uint64_t offset;
1238 uint64_t len;
1239 unsigned int i;
1240
1241 *strings = GNUNET_malloc (sizeof(char *) * str_cnt);
1242 offset = 0;
1243 for (i = 0; i < str_cnt; i++)
1244 {
1245 len = strlen (&data[offset]);
1246 if (offset + len >= data_size)
1247 {
1248 GNUNET_free (*strings);
1249 *strings = NULL;
1250 return GNUNET_SYSERR;
1251 }
1252 if (0 == len) // empty line
1253 {
1254 offset++;
1255 i--;
1256 continue;
1257 }
1258
1259 GNUNET_asprintf (&(*strings)[i],
1260 "%s%s",
1261 regex_prefix,
1262 &data[offset]);
1263 offset += len + 1;
1264 }
1265 return GNUNET_OK;
1266}
1267
1268
1269/**
1270 * Load search strings from given filename. One search string per line.
1271 *
1272 * @param filename filename of the file containing the search strings.
1273 * @param strings set of strings loaded from file. Caller needs to free this
1274 * if number returned is greater than zero.
1275 * @param limit upper limit on the number of strings read from the file
1276 * @return number of strings found in the file. #GNUNET_SYSERR on error.
1277 */
1278static int
1279load_search_strings (const char *filename,
1280 char ***strings,
1281 unsigned int limit)
1282{
1283 char *data;
1284 uint64_t filesize;
1285 int str_cnt;
1286
1287 /* Sanity checks */
1288 if (NULL == filename)
1289 {
1290 return GNUNET_SYSERR;
1291 }
1292 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1293 {
1294 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1295 "Could not find search strings file %s\n", filename);
1296 return GNUNET_SYSERR;
1297 }
1298 if (GNUNET_OK !=
1299 GNUNET_DISK_file_size (filename,
1300 &filesize,
1301 GNUNET_YES,
1302 GNUNET_YES))
1303 {
1304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1305 "Search strings file %s cannot be read.\n",
1306 filename);
1307 return GNUNET_SYSERR;
1308 }
1309 if (0 == filesize)
1310 {
1311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1312 "Search strings file %s is empty.\n",
1313 filename);
1314 return GNUNET_SYSERR;
1315 }
1316
1317 /* Read data into memory */
1318 data = GNUNET_malloc (filesize + 1);
1319 if (filesize != GNUNET_DISK_fn_read (filename,
1320 data,
1321 filesize))
1322 {
1323 GNUNET_free (data);
1324 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1325 "Could not read search strings file %s.\n",
1326 filename);
1327 return GNUNET_SYSERR;
1328 }
1329
1330 /* Process buffer and build array */
1331 str_cnt = count_and_separate_strings (data, filesize, limit);
1332 if (GNUNET_OK != create_string_array (data, filesize, strings, str_cnt))
1333 {
1334 str_cnt = GNUNET_SYSERR;
1335 }
1336 GNUNET_free (data);
1337 return str_cnt;
1338}
1339
1340
1341/**
1342 * Main function that will be run by the scheduler.
1343 *
1344 * @param cls closure
1345 * @param args remaining command-line arguments
1346 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1347 * @param config configuration
1348 */
1349static void
1350run (void *cls,
1351 char *const *args,
1352 const char *cfgfile,
1353 const struct GNUNET_CONFIGURATION_Handle *config)
1354{
1355 unsigned int nsearchstrs;
1356 unsigned int i;
1357 struct GNUNET_TIME_Relative abort_time;
1358
1359 in_shutdown = GNUNET_NO;
1360
1361 /* Check config */
1362 if (NULL == config)
1363 {
1364 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1365 _ ("No configuration file given. Exiting\n"));
1366 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1367 return;
1368 }
1369 cfg = GNUNET_CONFIGURATION_dup (config);
1370 if (GNUNET_OK !=
1371 GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER",
1372 "REGEX_PREFIX",
1373 &regex_prefix))
1374 {
1375 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1376 "regexprofiler",
1377 "regex_prefix");
1378 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1379 return;
1380 }
1381 if (GNUNET_OK !=
1382 GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER",
1383 "PARALLEL_SEARCHES",
1384 &init_parallel_searches))
1385 {
1386 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1387 "Configuration option \"PARALLEL_SEARCHES\" missing."
1388 " Using default (%d)\n", 10);
1389 init_parallel_searches = 10;
1390 }
1391 if (GNUNET_OK !=
1392 GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER",
1393 "REANNOUNCE_PERIOD_MAX",
1394 &reannounce_period_max))
1395 {
1396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1397 "reannounce_period_max not given. Using 10 minutes.\n");
1398 reannounce_period_max =
1399 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10);
1400 }
1401
1402 /* Check arguments */
1403 if (NULL == policy_dir)
1404 {
1405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1406 _ (
1407 "No policy directory specified on command line. Exiting.\n"));
1408 return;
1409 }
1410 if (GNUNET_YES != GNUNET_DISK_directory_test (policy_dir, GNUNET_YES))
1411 {
1412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1413 _ ("Specified policies directory does not exist. Exiting.\n"));
1414 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1415 return;
1416 }
1417 if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL,
1418 NULL)))
1419 {
1420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1421 _ ("No files found in `%s'\n"),
1422 policy_dir);
1423 return;
1424 }
1425 GNUNET_CONFIGURATION_set_value_string (cfg, "REGEXPROFILER",
1426 "POLICY_DIR", policy_dir);
1427 if (GNUNET_YES != GNUNET_DISK_file_test (strings_file))
1428 {
1429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1430 _ ("No search strings file given. Exiting.\n"));
1431 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1432 return;
1433 }
1434 nsearchstrs = load_search_strings (strings_file,
1435 &search_strings,
1436 num_peers);
1437 if (num_peers != nsearchstrs)
1438 {
1439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1440 "Error loading search strings.\n");
1441 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1442 "File (%s) does not contain enough strings (%u/%u).\n",
1443 strings_file, nsearchstrs, num_peers);
1444 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1445 return;
1446 }
1447 if ((0 == num_peers) || (NULL == search_strings))
1448 {
1449 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1450 _ ("Error loading search strings. Exiting.\n"));
1451 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1452 return;
1453 }
1454 for (i = 0; i < num_peers; i++)
1455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1456 "search string: %s\n",
1457 search_strings[i]);
1458
1459 /* Check logfile */
1460 if ((NULL != data_filename) &&
1461 (NULL == (data_file =
1462 GNUNET_DISK_file_open (data_filename,
1463 GNUNET_DISK_OPEN_READWRITE
1464 | GNUNET_DISK_OPEN_TRUNCATE
1465 | GNUNET_DISK_OPEN_CREATE,
1466 GNUNET_DISK_PERM_USER_READ
1467 | GNUNET_DISK_PERM_USER_WRITE))))
1468 {
1469 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1470 "open",
1471 data_filename);
1472 return;
1473 }
1474
1475 /* Initialize peers */
1476 peers = GNUNET_malloc (sizeof(struct RegexPeer) * num_peers);
1477 for (i = 0; i < num_peers; i++)
1478 peers[i].id = i;
1479
1480 GNUNET_CONFIGURATION_set_value_number (cfg,
1481 "TESTBED", "OVERLAY_RANDOM_LINKS",
1482 num_peers * 20);
1483 GNUNET_CONFIGURATION_set_value_number (cfg,
1484 "DHT", "FORCE_NSE",
1485 (long long unsigned)
1486 (log (num_peers) / log (2.0)));
1487 event_mask = 0LL;
1488/* For feedback about the start process activate these and pass master_cb */
1489 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
1490// event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
1491 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1492// event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
1493 prof_start_time = GNUNET_TIME_absolute_get ();
1494 GNUNET_TESTBED_run (hosts_file,
1495 cfg,
1496 num_peers,
1497 event_mask,
1498 &master_controller_cb,
1499 NULL, /* master_controller_cb cls */
1500 &test_master,
1501 NULL); /* test_master cls */
1502 if (GNUNET_OK !=
1503 GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
1504 "SETUP_TIMEOUT",
1505 &abort_time))
1506 {
1507 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1508 "SETUP_TIMEOUT not given. Using 15 minutes.\n");
1509 abort_time =
1510 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
1511 }
1512 abort_time = GNUNET_TIME_relative_add (abort_time, GNUNET_TIME_UNIT_MINUTES);
1513 abort_task =
1514 GNUNET_SCHEDULER_add_delayed (abort_time,
1515 &do_abort,
1516 (void *) __LINE__);
1517 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1518 "setup_timeout: %s\n",
1519 GNUNET_STRINGS_relative_time_to_string (abort_time, GNUNET_YES));
1520}
1521
1522
1523/**
1524 * Main function.
1525 *
1526 * @param argc argument count
1527 * @param argv argument values
1528 * @return 0 on success
1529 */
1530int
1531main (int argc, char *const *argv)
1532{
1533 struct GNUNET_GETOPT_CommandLineOption options[] = {
1534 GNUNET_GETOPT_option_filename (
1535 'o',
1536 "output-file",
1537 "FILENAME",
1538 gettext_noop (
1539 "name of the file for writing statistics"),
1540 &data_filename),
1541 GNUNET_GETOPT_option_relative_time (
1542 't',
1543 "matching-timeout",
1544 "TIMEOUT",
1545 gettext_noop (
1546 "wait TIMEOUT before ending the experiment"),
1547 &search_timeout_time),
1548 GNUNET_GETOPT_option_filename (
1549 'p',
1550 "policy-dir",
1551 "DIRECTORY",
1552 gettext_noop ("directory with policy files"),
1553 &policy_dir),
1554 GNUNET_GETOPT_option_filename (
1555 's',
1556 "strings-file",
1557 "FILENAME",
1558 gettext_noop (
1559 "name of file with input strings"),
1560 &strings_file),
1561 GNUNET_GETOPT_option_filename (
1562 'H',
1563 "hosts-file",
1564 "FILENAME",
1565 gettext_noop (
1566 "name of file with hosts' names"),
1567 &hosts_file),
1568
1569 GNUNET_GETOPT_OPTION_END
1570 };
1571 int ret;
1572
1573 if (GNUNET_OK !=
1574 GNUNET_STRINGS_get_utf8_args (argc, argv,
1575 &argc, &argv))
1576 return 2;
1577 result = GNUNET_SYSERR;
1578 ret =
1579 GNUNET_PROGRAM_run (argc, argv,
1580 "gnunet-regex-profiler",
1581 _ ("Profiler for regex"),
1582 options,
1583 &run, NULL);
1584 if (GNUNET_OK != ret)
1585 return ret;
1586 if (GNUNET_OK != result)
1587 return 1;
1588 return 0;
1589}