2 This file is part of GNUnet.
3 Copyright (C) 2013, 2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file regex/test_regex_integration.c
22 * @brief base test case for regex integration with VPN;
23 * tests that the regexes generated by the TUN API
24 * for IP addresses work (for some simple cases)
25 * @author Christian Grothoff
28 #include "gnunet_applications.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_tun_lib.h"
31 #include "gnunet_testing_lib.h"
32 #include "gnunet_regex_service.h"
36 * How long until we really give up on a particular testcase portion?
38 #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
41 * How long until we give up on any particular operation (and retry)?
43 #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
46 static struct GNUNET_REGEX_Announcement *a4;
48 static struct GNUNET_REGEX_Search *s4;
50 static struct GNUNET_REGEX_Announcement *a6;
52 static struct GNUNET_REGEX_Search *s6;
56 static struct GNUNET_SCHEDULER_Task *die_task;
61 const struct GNUNET_SCHEDULER_TaskContext *tc)
64 GNUNET_REGEX_announce_cancel (a4);
66 GNUNET_REGEX_search_cancel (s4);
68 GNUNET_REGEX_announce_cancel (a6);
70 GNUNET_REGEX_search_cancel (s6);
79 FPRINTF (stderr, "%s", "Testcase failed (timeout).\n");
86 * Search callback function, invoked for every result that was found.
88 * @param cls Closure provided in #GNUNET_REGEX_search().
89 * @param id Peer providing a regex that matches the string.
90 * @param get_path Path of the get request.
91 * @param get_path_length Length of @a get_path.
92 * @param put_path Path of the put request.
93 * @param put_path_length Length of the @a put_path.
97 const struct GNUNET_PeerIdentity *id,
98 const struct GNUNET_PeerIdentity *get_path,
99 unsigned int get_path_length,
100 const struct GNUNET_PeerIdentity *put_path,
101 unsigned int put_path_length)
103 const char *str = cls;
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
107 "IPv%s-exit found\n",
109 if (0 == strcmp (str, "4"))
111 if (0 == strcmp (str, "6"))
115 GNUNET_SCHEDULER_cancel (die_task);
117 GNUNET_SCHEDULER_add_now (&end, NULL);
124 const struct GNUNET_CONFIGURATION_Handle *cfg,
125 struct GNUNET_TESTING_Peer *peer)
127 char rxstr4[GNUNET_TUN_IPV4_REGEXLEN];
128 char rxstr6[GNUNET_TUN_IPV6_REGEXLEN];
139 GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
149 GNUNET_TUN_ipv4toregexsearch (&i4,
152 GNUNET_TUN_ipv6toregexsearch (&i6,
155 GNUNET_asprintf (&ss4,
157 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
159 GNUNET_asprintf (&ss6,
161 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
163 p4r = GNUNET_TUN_ipv4policy2regex ("0.0.0.0/0:!25;");
164 p6r = GNUNET_TUN_ipv6policy2regex ("::/0:!25;");
165 GNUNET_asprintf (&p4,
167 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
169 GNUNET_asprintf (&p6,
171 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
175 a4 = GNUNET_REGEX_announce (cfg,
177 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
180 a6 = GNUNET_REGEX_announce (cfg,
182 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
188 s4 = GNUNET_REGEX_search (cfg,
191 s6 = GNUNET_REGEX_search (cfg,
200 main (int argc, char *argv[])
202 if (0 != GNUNET_TESTING_peer_run ("test-regex-integration",
203 "test_regex_api_data.conf",
209 /* end of test_regex_integration.c */