aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_lookup_shadow.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_lookup_shadow.c')
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow.c288
1 files changed, 0 insertions, 288 deletions
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c
deleted file mode 100644
index 79fa4c9c6..000000000
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ /dev/null
@@ -1,288 +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_shadow.c
22 * @brief testcase for namestore_api.c: store a shadow record and perform a lookup
23 * test passes if test returns the record but without the shadow flag since no
24 * other valid record is available
25 */
26#include "platform.h"
27#include "gnunet_namecache_service.h"
28#include "gnunet_namestore_service.h"
29#include "gnunet_testing_lib.h"
30#include "gnunet_dnsparser_lib.h"
31
32#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
33
34#define TEST_RECORD_DATALEN 123
35
36#define TEST_RECORD_DATA 'a'
37
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
39
40
41static struct GNUNET_NAMESTORE_Handle *nsh;
42
43static struct GNUNET_NAMECACHE_Handle *nch;
44
45static struct GNUNET_SCHEDULER_Task *endbadly_task;
46
47static struct GNUNET_IDENTITY_PrivateKey privkey;
48
49static struct GNUNET_IDENTITY_PublicKey pubkey;
50
51static int res;
52
53static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
54
55static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
56
57
58static void
59cleanup ()
60{
61 if (NULL != nsh)
62 {
63 GNUNET_NAMESTORE_disconnect (nsh);
64 nsh = NULL;
65 }
66 if (NULL != nch)
67 {
68 GNUNET_NAMECACHE_disconnect (nch);
69 nch = NULL;
70 }
71 GNUNET_SCHEDULER_shutdown ();
72}
73
74
75/**
76 * Re-establish the connection to the service.
77 *
78 * @param cls handle to use to re-connect.
79 */
80static void
81endbadly (void *cls)
82{
83 if (NULL != nsqe)
84 {
85 GNUNET_NAMESTORE_cancel (nsqe);
86 nsqe = NULL;
87 }
88 if (NULL != ncqe)
89 {
90 GNUNET_NAMECACHE_cancel (ncqe);
91 ncqe = NULL;
92 }
93 cleanup ();
94 res = 1;
95}
96
97
98static void
99end (void *cls)
100{
101 cleanup ();
102 res = 0;
103}
104
105
106static void
107rd_decrypt_cb (void *cls,
108 unsigned int rd_count,
109 const struct GNUNET_GNSRECORD_Data *rd)
110{
111 char rd_cmp_data[TEST_RECORD_DATALEN];
112
113 if (1 != rd_count)
114 {
115 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
116 GNUNET_break (0);
117 return;
118 }
119 if (NULL == rd)
120 {
121 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
122 GNUNET_break (0);
123 return;
124 }
125 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN);
126
127 if (TEST_RECORD_TYPE != rd[0].record_type)
128 {
129 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
130 GNUNET_break (0);
131 return;
132 }
133 if (TEST_RECORD_DATALEN != rd[0].data_size)
134 {
135 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
136 GNUNET_break (0);
137 return;
138 }
139 if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
140 {
141 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
142 GNUNET_break (0);
143 return;
144 }
145 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
146 {
147 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
148 GNUNET_break (0);
149 return;
150 }
151
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Block was decrypted successfully \n");
154
155 GNUNET_SCHEDULER_add_now (&end, NULL);
156}
157
158
159static void
160name_lookup_proc (void *cls,
161 const struct GNUNET_GNSRECORD_Block *block)
162{
163 const char *name = cls;
164
165 ncqe = NULL;
166 GNUNET_assert (NULL != cls);
167
168 if (endbadly_task != NULL)
169 {
170 GNUNET_SCHEDULER_cancel (endbadly_task);
171 endbadly_task = NULL;
172 }
173
174 if (NULL == block)
175 {
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
177 _ ("Namestore returned no block\n"));
178 if (endbadly_task != NULL)
179 GNUNET_SCHEDULER_cancel (endbadly_task);
180 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
181 return;
182 }
183
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 "Namestore returned block, decrypting \n");
186 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block,
187 &pubkey, name,
188 &rd_decrypt_cb,
189 (void *) name));
190}
191
192
193static void
194put_cont (void *cls, int32_t success, const char *emsg)
195{
196 const char *name = cls;
197 struct GNUNET_HashCode derived_hash;
198 struct GNUNET_IDENTITY_PublicKey pubkey;
199
200 nsqe = NULL;
201 GNUNET_assert (NULL != cls);
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Name store added record for `%s': %s\n",
204 name,
205 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
206
207 /* Create derived hash */
208 GNUNET_IDENTITY_key_get_public (&privkey,
209 &pubkey);
210 GNUNET_GNSRECORD_query_from_public_key (&pubkey,
211 name,
212 &derived_hash);
213
214 ncqe = GNUNET_NAMECACHE_lookup_block (nch,
215 &derived_hash,
216 &name_lookup_proc, (void *) name);
217}
218
219
220static void
221run (void *cls,
222 const struct GNUNET_CONFIGURATION_Handle *cfg,
223 struct GNUNET_TESTING_Peer *peer)
224{
225 struct GNUNET_GNSRECORD_Data rd;
226 const char *name = "dummy.dummy.gnunet";
227
228 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
229 &endbadly,
230 NULL);
231 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
232 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key);
233 GNUNET_IDENTITY_key_get_public (&privkey,
234 &pubkey);
235 rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000;
236 rd.record_type = TEST_RECORD_TYPE;
237 rd.data_size = TEST_RECORD_DATALEN;
238 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
239 rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
240 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
241
242 nsh = GNUNET_NAMESTORE_connect (cfg);
243 nch = GNUNET_NAMECACHE_connect (cfg);
244 GNUNET_break (NULL != nsh);
245 GNUNET_break (NULL != nch);
246 nsqe = GNUNET_NAMESTORE_records_store (nsh,
247 &privkey,
248 name,
249 1,
250 &rd,
251 &put_cont,
252 (void *) name);
253 if (NULL == nsqe)
254 {
255 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
256 _ ("Namestore cannot store no block\n"));
257 }
258 GNUNET_free_nz ((void *) rd.data);
259}
260
261
262#include "test_common.c"
263
264
265int
266main (int argc, char *argv[])
267{
268 const char *plugin_name;
269 char *cfg_name;
270
271 SETUP_CFG (plugin_name, cfg_name);
272 res = 1;
273 if (0 !=
274 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
275 cfg_name,
276 &run,
277 NULL))
278 {
279 res = 1;
280 }
281 GNUNET_DISK_purge_cfg_dir (cfg_name,
282 "GNUNET_TEST_HOME");
283 GNUNET_free (cfg_name);
284 return res;
285}
286
287
288/* end of test_namestore_api_lookup_shadow.c */