aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_integration.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/test_regex_integration.c
parent5ae8ee063302cc6c1fc7b74328af46a11cb02cdc (diff)
downloadgnunet-7f72b05249f6ac663cee7a033f3cac5d9400ede7.tar.gz
gnunet-7f72b05249f6ac663cee7a033f3cac5d9400ede7.zip
BUILD: Move regex/dns to service
Diffstat (limited to 'src/regex/test_regex_integration.c')
-rw-r--r--src/regex/test_regex_integration.c211
1 files changed, 0 insertions, 211 deletions
diff --git a/src/regex/test_regex_integration.c b/src/regex/test_regex_integration.c
deleted file mode 100644
index 1f422e5a3..000000000
--- a/src/regex/test_regex_integration.c
+++ /dev/null
@@ -1,211 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013, 2015 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 * @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
26 */
27#include "platform.h"
28#include "gnunet_applications.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h"
31#include "gnunet_regex_service.h"
32
33
34/**
35 * How long until we really give up on a particular testcase portion?
36 */
37#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
38 600)
39
40/**
41 * How long until we give up on any particular operation (and retry)?
42 */
43#define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
44
45
46static struct GNUNET_REGEX_Announcement *a4;
47
48static struct GNUNET_REGEX_Search *s4;
49
50static struct GNUNET_REGEX_Announcement *a6;
51
52static struct GNUNET_REGEX_Search *s6;
53
54static int ok = 1;
55
56static struct GNUNET_SCHEDULER_Task *die_task;
57
58
59static void
60end (void *cls)
61{
62 die_task = NULL;
63 GNUNET_REGEX_announce_cancel (a4);
64 a4 = NULL;
65 GNUNET_REGEX_search_cancel (s4);
66 s4 = NULL;
67 GNUNET_REGEX_announce_cancel (a6);
68 a6 = NULL;
69 GNUNET_REGEX_search_cancel (s6);
70 s6 = NULL;
71 ok = 0;
72}
73
74
75static void
76end_badly ()
77{
78 fprintf (stderr, "%s", "Testcase failed (timeout).\n");
79 end (NULL);
80 ok = 1;
81}
82
83
84/**
85 * Search callback function, invoked for every result that was found.
86 *
87 * @param cls Closure provided in #GNUNET_REGEX_search().
88 * @param id Peer providing a regex that matches the string.
89 * @param get_path Path of the get request.
90 * @param get_path_length Length of @a get_path.
91 * @param put_path Path of the put request.
92 * @param put_path_length Length of the @a put_path.
93 */
94static void
95found_cb (void *cls,
96 const struct GNUNET_PeerIdentity *id,
97 const struct GNUNET_PeerIdentity *get_path,
98 unsigned int get_path_length,
99 const struct GNUNET_PeerIdentity *put_path,
100 unsigned int put_path_length)
101{
102 const char *str = cls;
103 static int found;
104
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
106 "IPv%s-exit found\n",
107 str);
108 if (0 == strcmp (str, "4"))
109 found |= 4;
110 if (0 == strcmp (str, "6"))
111 found |= 2;
112 if ((4 | 2) == found)
113 {
114 GNUNET_SCHEDULER_cancel (die_task);
115 die_task =
116 GNUNET_SCHEDULER_add_now (&end, NULL);
117 }
118}
119
120
121static void
122run (void *cls,
123 const struct GNUNET_CONFIGURATION_Handle *cfg,
124 struct GNUNET_TESTING_Peer *peer)
125{
126 char rxstr4[GNUNET_TUN_IPV4_REGEXLEN];
127 char rxstr6[GNUNET_TUN_IPV6_REGEXLEN];
128 char *p4r;
129 char *p6r;
130 char *p4;
131 char *p6;
132 char *ss4;
133 char *ss6;
134 struct in_addr i4;
135 struct in6_addr i6;
136
137 die_task =
138 GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
139 &end_badly, NULL);
140 GNUNET_assert (1 ==
141 inet_pton (AF_INET,
142 "127.0.0.1",
143 &i4));
144 GNUNET_assert (1 ==
145 inet_pton (AF_INET6,
146 "::1:5",
147 &i6));
148 GNUNET_TUN_ipv4toregexsearch (&i4,
149 8080,
150 rxstr4);
151 GNUNET_TUN_ipv6toregexsearch (&i6,
152 8686,
153 rxstr6);
154 GNUNET_asprintf (&ss4,
155 "%s%s",
156 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
157 rxstr4);
158 GNUNET_asprintf (&ss6,
159 "%s%s",
160 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
161 rxstr6);
162 p4r = GNUNET_TUN_ipv4policy2regex ("0.0.0.0/0:!25;");
163 p6r = GNUNET_TUN_ipv6policy2regex ("::/0:!25;");
164 GNUNET_asprintf (&p4,
165 "%s%s",
166 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
167 p4r);
168 GNUNET_asprintf (&p6,
169 "%s%s",
170 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
171 p6r);
172 GNUNET_free (p4r);
173 GNUNET_free (p6r);
174 a4 = GNUNET_REGEX_announce (cfg,
175 p4,
176 GNUNET_TIME_relative_multiply (
177 GNUNET_TIME_UNIT_SECONDS,
178 5),
179 1);
180 a6 = GNUNET_REGEX_announce (cfg,
181 p6,
182 GNUNET_TIME_relative_multiply (
183 GNUNET_TIME_UNIT_SECONDS,
184 5),
185 1);
186 GNUNET_free (p4);
187 GNUNET_free (p6);
188
189 s4 = GNUNET_REGEX_search (cfg,
190 ss4,
191 &found_cb, "4");
192 s6 = GNUNET_REGEX_search (cfg,
193 ss6,
194 &found_cb, "6");
195 GNUNET_free (ss4);
196 GNUNET_free (ss6);
197}
198
199
200int
201main (int argc, char *argv[])
202{
203 if (0 != GNUNET_TESTING_peer_run ("test-regex-integration",
204 "test_regex_api_data.conf",
205 &run, NULL))
206 return 1;
207 return ok;
208}
209
210
211/* end of test_regex_integration.c */