aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_lookup_nick.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_lookup_nick.c')
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c347
1 files changed, 0 insertions, 347 deletions
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c
deleted file mode 100644
index 7decf39f8..000000000
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ /dev/null
@@ -1,347 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012 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_lookup_nick.c
22 * @brief testcase for namestore_api.c: NICK records
23 */
24#include "platform.h"
25#include "gnunet_namestore_service.h"
26#include "gnunet_gns_service.h"
27#include "gnunet_testing_lib.h"
28#include "gnunet_dnsparser_lib.h"
29
30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31
32#define TEST_RECORD_DATALEN 123
33
34#define TEST_NICK "gnunettestnick"
35
36#define TEST_RECORD_DATA 'a'
37
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
39
40static struct GNUNET_NAMESTORE_Handle *nsh;
41
42static struct GNUNET_SCHEDULER_Task *endbadly_task;
43
44static struct GNUNET_IDENTITY_PrivateKey privkey;
45
46static struct GNUNET_IDENTITY_PublicKey pubkey;
47
48static int res;
49
50static struct GNUNET_GNSRECORD_Data rd_orig;
51
52static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
53
54// static const char * name = "dummy.dummy.gnunet";
55static const char *name = "d";
56
57static char *record_data;
58
59static void
60cleanup ()
61{
62 GNUNET_free (record_data);
63 if (NULL != nsh)
64 {
65 GNUNET_NAMESTORE_disconnect (nsh);
66 nsh = NULL;
67 }
68 GNUNET_SCHEDULER_shutdown ();
69}
70
71
72/**
73 * Re-establish the connection to the service.
74 *
75 * @param cls handle to use to re-connect.
76 * @param tc scheduler context
77 */
78static void
79endbadly (void *cls)
80{
81 if (NULL != nsqe)
82 {
83 GNUNET_NAMESTORE_cancel (nsqe);
84 nsqe = NULL;
85 }
86 cleanup ();
87 res = 1;
88}
89
90
91static void
92end (void *cls)
93{
94 cleanup ();
95 res = 0;
96}
97
98
99static void
100lookup_it (void *cls,
101 const struct GNUNET_IDENTITY_PrivateKey *zone,
102 const char *label,
103 unsigned int rd_count,
104 const struct GNUNET_GNSRECORD_Data *rd)
105{
106 nsqe = NULL;
107 int c;
108 int found_record = GNUNET_NO;
109 int found_nick = GNUNET_NO;
110
111 if (0 != GNUNET_memcmp (&privkey, zone))
112 {
113 GNUNET_break (0);
114 GNUNET_SCHEDULER_cancel (endbadly_task);
115 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
116 return;
117 }
118
119 if (NULL == label)
120 {
121 GNUNET_break (0);
122 GNUNET_SCHEDULER_cancel (endbadly_task);
123 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
124 return;
125 }
126
127 if (0 != strcmp (label, name))
128 {
129 GNUNET_break (0);
130 GNUNET_SCHEDULER_cancel (endbadly_task);
131 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
132 return;
133 }
134
135 if (2 != rd_count)
136 {
137 GNUNET_break (0);
138 GNUNET_SCHEDULER_cancel (endbadly_task);
139 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
140 return;
141 }
142
143 for (c = 0; c < rd_count; c++)
144 {
145 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
146 {
147 if (rd[c].data_size != strlen (TEST_NICK) + 1)
148 {
149 GNUNET_break (0);
150 GNUNET_SCHEDULER_cancel (endbadly_task);
151 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
152 return;
153 }
154 if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE))
155 {
156 GNUNET_break (0);
157 GNUNET_SCHEDULER_cancel (endbadly_task);
158 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
159 return;
160 }
161 if (0 != strcmp (rd[c].data, TEST_NICK))
162 {
163 GNUNET_SCHEDULER_cancel (endbadly_task);
164 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
165 return;
166 }
167 found_nick = GNUNET_YES;
168 }
169 else
170 {
171 if (rd[c].record_type != TEST_RECORD_TYPE)
172 {
173 GNUNET_break (0);
174 GNUNET_SCHEDULER_cancel (endbadly_task);
175 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
176 return;
177 }
178 if (rd[c].data_size != TEST_RECORD_DATALEN)
179 {
180 GNUNET_break (0);
181 GNUNET_SCHEDULER_cancel (endbadly_task);
182 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
183 return;
184 }
185 if (0 != memcmp (rd[c].data, rd_orig.data, TEST_RECORD_DATALEN))
186 {
187 GNUNET_break (0);
188 GNUNET_SCHEDULER_cancel (endbadly_task);
189 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
190 return;
191 }
192 if (rd[c].flags != rd->flags)
193 {
194 GNUNET_break (0);
195 GNUNET_SCHEDULER_cancel (endbadly_task);
196 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
197 return;
198 }
199 found_record = GNUNET_YES;
200 }
201 }
202
203 /* Done */
204 if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record))
205 {
206 GNUNET_SCHEDULER_cancel (endbadly_task);
207 endbadly_task = NULL;
208 GNUNET_SCHEDULER_add_now (&end, NULL);
209 }
210 else
211 {
212 GNUNET_break (0);
213 GNUNET_SCHEDULER_cancel (endbadly_task);
214 endbadly_task = NULL;
215 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
216 }
217}
218
219
220static void
221fail_cb (void *cls)
222{
223 GNUNET_assert (0);
224}
225
226
227static void
228put_cont (void *cls, int32_t success, const char *emsg)
229{
230 const char *name = cls;
231
232 nsqe = NULL;
233 GNUNET_assert (NULL != cls);
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "Name store added record for `%s': %s\n",
236 name,
237 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
238
239 if (GNUNET_OK != success)
240 {
241 GNUNET_SCHEDULER_cancel (endbadly_task);
242 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
243 return;
244 }
245 /* Lookup */
246 nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
247 &privkey,
248 name,
249 &fail_cb,
250 NULL,
251 &lookup_it,
252 NULL);
253}
254
255
256static void
257nick_cont (void *cls, int32_t success, const char *emsg)
258{
259 const char *name = cls;
260
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Nick added : %s\n",
263 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
264
265 rd_orig.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us;
266 rd_orig.record_type = TEST_RECORD_TYPE;
267 rd_orig.data_size = TEST_RECORD_DATALEN;
268 record_data = GNUNET_malloc (TEST_RECORD_DATALEN);
269 rd_orig.data = record_data;
270 rd_orig.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
271 memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN);
272
273 nsqe = GNUNET_NAMESTORE_records_store (nsh, &privkey,
274 name,
275 1,
276 &rd_orig,
277 &put_cont, (void *) name);
278}
279
280
281static void
282run (void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer)
285{
286 struct GNUNET_GNSRECORD_Data rd;
287
288 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
289 &endbadly,
290 NULL);
291 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
292 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key);
293 GNUNET_IDENTITY_key_get_public (&privkey,
294 &pubkey);
295
296 nsh = GNUNET_NAMESTORE_connect (cfg);
297 GNUNET_break (NULL != nsh);
298
299 memset (&rd, 0, sizeof(rd));
300 rd.data = TEST_NICK;
301 rd.data_size = strlen (TEST_NICK) + 1;
302 rd.record_type = GNUNET_GNSRECORD_TYPE_NICK;
303 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
304 rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
305 nsqe = GNUNET_NAMESTORE_records_store (nsh,
306 &privkey,
307 GNUNET_GNS_EMPTY_LABEL_AT,
308 1,
309 &rd,
310 &nick_cont,
311 (void *) name);
312
313 if (NULL == nsqe)
314 {
315 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
316 _ ("Namestore cannot store no block\n"));
317 }
318}
319
320
321#include "test_common.c"
322
323
324int
325main (int argc, char *argv[])
326{
327 const char *plugin_name;
328 char *cfg_name;
329
330 SETUP_CFG (plugin_name, cfg_name);
331 res = 1;
332 if (0 !=
333 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
334 cfg_name,
335 &run,
336 NULL))
337 {
338 res = 1;
339 }
340 GNUNET_DISK_purge_cfg_dir (cfg_name,
341 "GNUNET_TEST_HOME");
342 GNUNET_free (cfg_name);
343 return res;
344}
345
346
347/* end of test_namestore_api_store.c */