aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_monitoring_existing.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 09:37:26 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 09:37:26 +0200
commitb7a1d4379ebcff1c878d068cbd8df34fd16d81d4 (patch)
treef7f1c37fb5f106ca165a79a5c5fb4f3e13abbdc2 /src/namestore/test_namestore_api_monitoring_existing.c
parent54a37c4239d34fc3b681df78a5a8b4d6a7bde902 (diff)
downloadgnunet-b7a1d4379ebcff1c878d068cbd8df34fd16d81d4.tar.gz
gnunet-b7a1d4379ebcff1c878d068cbd8df34fd16d81d4.zip
BUILD: Move namestore to service
Diffstat (limited to 'src/namestore/test_namestore_api_monitoring_existing.c')
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c393
1 files changed, 0 insertions, 393 deletions
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
deleted file mode 100644
index fe17833c8..000000000
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ /dev/null
@@ -1,393 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013, 2018 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 namestore/test_namestore_api_monitoring_existing.c
22 * @brief testcase for zone monitoring functionality: add records first, then monitor
23 */
24#include "platform.h"
25#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h"
27#include "namestore.h"
28
29#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
30
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33
34static const struct GNUNET_CONFIGURATION_Handle *cfg;
35
36static struct GNUNET_NAMESTORE_Handle *nsh;
37
38static struct GNUNET_SCHEDULER_Task *endbadly_task;
39
40static struct GNUNET_CRYPTO_PrivateKey privkey;
41
42static struct GNUNET_CRYPTO_PrivateKey privkey2;
43
44static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
45
46static int res;
47
48static const char *s_name_1;
49
50static struct GNUNET_GNSRECORD_Data *s_rd_1;
51
52static const char *s_name_2;
53
54static struct GNUNET_GNSRECORD_Data *s_rd_2;
55
56static const char *s_name_3;
57
58static struct GNUNET_GNSRECORD_Data *s_rd_3;
59
60struct GNUNET_NAMESTORE_QueueEntry *ns_ops[3];
61
62
63/**
64 * Re-establish the connection to the service.
65 *
66 * @param cls handle to use to re-connect.
67 */
68static void
69endbadly (void *cls)
70{
71 endbadly_task = NULL;
72 GNUNET_break (0);
73 GNUNET_SCHEDULER_shutdown ();
74 res = 1;
75}
76
77
78static void
79end (void *cls)
80{
81 if (NULL != zm)
82 {
83 GNUNET_NAMESTORE_zone_monitor_stop (zm);
84 zm = NULL;
85 }
86 if (NULL != ns_ops[0])
87 {
88 GNUNET_NAMESTORE_cancel (ns_ops[0]);
89 ns_ops[0] = NULL;
90 }
91 if (NULL != ns_ops[1])
92 {
93 GNUNET_NAMESTORE_cancel (ns_ops[1]);
94 ns_ops[1] = NULL;
95 }
96 if (NULL != ns_ops[2])
97 {
98 GNUNET_NAMESTORE_cancel (ns_ops[2]);
99 ns_ops[2] = NULL;
100 }
101 if (NULL != endbadly_task)
102 {
103 GNUNET_SCHEDULER_cancel (endbadly_task);
104 endbadly_task = NULL;
105 }
106 if (NULL != nsh)
107 {
108 GNUNET_NAMESTORE_disconnect (nsh);
109 nsh = NULL;
110 }
111 if (NULL != s_rd_1)
112 {
113 GNUNET_free_nz ((void *) s_rd_1->data);
114 GNUNET_free (s_rd_1);
115 }
116 if (NULL != s_rd_2)
117 {
118 GNUNET_free_nz ((void *) s_rd_2->data);
119 GNUNET_free (s_rd_2);
120 }
121 if (NULL != s_rd_3)
122 {
123 GNUNET_free_nz ((void *) s_rd_3->data);
124 GNUNET_free (s_rd_3);
125 }
126}
127
128
129static void
130zone_proc (void *cls,
131 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
132 const char *name,
133 unsigned int rd_count,
134 const struct GNUNET_GNSRECORD_Data *rd)
135{
136 static int returned_records;
137 static int fail = GNUNET_NO;
138
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "Comparing results name %s\n",
141 name);
142 if (0 != GNUNET_memcmp (zone_key,
143 &privkey))
144 {
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "Monitoring returned wrong zone key\n");
147 GNUNET_break (0);
148 GNUNET_SCHEDULER_shutdown ();
149 return;
150 }
151
152 if (0 == strcmp (name,
153 s_name_1))
154 {
155 if (GNUNET_YES !=
156 GNUNET_GNSRECORD_records_cmp (rd,
157 s_rd_1))
158 {
159 GNUNET_break (0);
160 fail = GNUNET_YES;
161 }
162 }
163 else if (0 == strcmp (name,
164 s_name_2))
165 {
166 if (GNUNET_YES !=
167 GNUNET_GNSRECORD_records_cmp (rd,
168 s_rd_2))
169 {
170 GNUNET_break (0);
171 fail = GNUNET_YES;
172 }
173 }
174 else
175 {
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
177 "Invalid name %s\n",
178 name);
179 GNUNET_break (0);
180 fail = GNUNET_YES;
181 }
182 GNUNET_NAMESTORE_zone_monitor_next (zm,
183 1);
184 if (2 == ++returned_records)
185 {
186 GNUNET_SCHEDULER_shutdown ();
187 if (GNUNET_YES == fail)
188 {
189 GNUNET_break (0);
190 res = 1;
191 }
192 else
193 {
194 res = 0;
195 }
196 }
197}
198
199
200static void
201fail_cb (void *cls)
202{
203 GNUNET_assert (0);
204}
205
206
207static void
208sync_cb (void *cls)
209{
210 /* do nothing */
211}
212
213
214static void
215put_cont (void *cls,
216 enum GNUNET_ErrorCode ec)
217{
218 static int c = 0;
219 const char *label = cls;
220
221 if (0 == strcmp (label,
222 s_name_1))
223 ns_ops[0] = NULL;
224 else if (0 == strcmp (label,
225 s_name_2))
226 ns_ops[1] = NULL;
227 else if (0 == strcmp (label,
228 s_name_3))
229 ns_ops[2] = NULL;
230
231 if (GNUNET_EC_NONE == ec)
232 {
233 c++;
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "Created record %u: `%s'\n",
236 c,
237 label);
238 }
239 else
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
242 "Failed to created records\n");
243 GNUNET_break (0);
244 res = 1;
245 GNUNET_SCHEDULER_shutdown ();
246 return;
247 }
248
249}
250
251
252static struct GNUNET_GNSRECORD_Data *
253create_record (unsigned int count)
254{
255 struct GNUNET_GNSRECORD_Data *rd;
256
257 rd = GNUNET_new_array (count,
258 struct GNUNET_GNSRECORD_Data);
259 for (unsigned int c = 0; c < count; c++)
260 {
261 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (
262 GNUNET_TIME_UNIT_HOURS).abs_value_us;
263 rd[c].record_type = TEST_RECORD_TYPE;
264 rd[c].data_size = 50;
265 rd[c].data = GNUNET_malloc (50);
266 rd[c].flags = 0;
267 memset ((char *) rd[c].data,
268 'a',
269 50);
270 }
271 return rd;
272}
273
274
275static void
276run (void *cls,
277 const struct GNUNET_CONFIGURATION_Handle *mycfg,
278 struct GNUNET_TESTING_Peer *peer)
279{
280 res = 1;
281 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
282 privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
283 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key);
284 GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key);
285
286 cfg = mycfg;
287 GNUNET_SCHEDULER_add_shutdown (&end,
288 NULL);
289 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
290 &endbadly,
291 NULL);
292 /* Connect to namestore */
293 nsh = GNUNET_NAMESTORE_connect (cfg);
294 if (NULL == nsh)
295 {
296 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
297 "Connect to namestore failed\n");
298 GNUNET_break (0);
299 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
300 NULL);
301 return;
302 }
303 /* Start monitoring */
304 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
305 &privkey,
306 GNUNET_YES,
307 &fail_cb,
308 NULL,
309 &zone_proc,
310 NULL,
311 &sync_cb,
312 NULL);
313 if (NULL == zm)
314 {
315 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
316 "Failed to create zone monitor\n");
317 GNUNET_break (0);
318 res = 1;
319 GNUNET_SCHEDULER_shutdown ();
320 return;
321 }
322
323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
324 "Created record 3\n");
325 /* name in different zone */
326 s_name_3 = "dummy3";
327 s_rd_3 = create_record (1);
328 GNUNET_assert (NULL != (ns_ops[2] =
329 GNUNET_NAMESTORE_records_store (nsh,
330 &privkey2,
331 s_name_3,
332 1,
333 s_rd_3,
334 &put_cont,
335 (void *) s_name_3)));
336
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "Created record 1\n");
339 s_name_1 = "dummy1";
340 s_rd_1 = create_record (1);
341 GNUNET_assert (NULL != (ns_ops[0] =
342 GNUNET_NAMESTORE_records_store (nsh,
343 &privkey,
344 s_name_1,
345 1,
346 s_rd_1,
347 &put_cont,
348 (void *) s_name_1)));
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "Created record 2 \n");
351 s_name_2 = "dummy2";
352 s_rd_2 = create_record (1);
353 GNUNET_assert (NULL != (ns_ops[1] =
354 GNUNET_NAMESTORE_records_store (nsh,
355 &privkey,
356 s_name_2,
357 1,
358 s_rd_2,
359 &put_cont,
360 (void *) s_name_2)));
361}
362
363
364#include "test_common.c"
365
366
367int
368main (int argc,
369 char *argv[])
370{
371 const char *plugin_name;
372 char *cfg_name;
373
374 SETUP_CFG (plugin_name, cfg_name);
375 res = 1;
376 if (0 !=
377 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
378 cfg_name,
379 &run,
380 NULL))
381 {
382 GNUNET_break (0);
383 res = 1;
384 }
385 GNUNET_DISK_purge_cfg_dir (cfg_name,
386 "GNUNET_TEST_HOME");
387 GNUNET_free (plugin_name);
388 GNUNET_free (cfg_name);
389 return res;
390}
391
392
393/* end of test_namestore_api_monitoring_existing.c */