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