aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_zone_iteration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_zone_iteration.c')
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c200
1 files changed, 173 insertions, 27 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 95755ceee..e70a3baf0 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -24,6 +24,7 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
27#include "namestore.h"
27 28
28#define VERBOSE GNUNET_NO 29#define VERBOSE GNUNET_NO
29 30
@@ -42,6 +43,14 @@ static GNUNET_HashCode zone;
42static struct GNUNET_NAMESTORE_ZoneIterator *zi; 43static struct GNUNET_NAMESTORE_ZoneIterator *zi;
43static int res; 44static int res;
44 45
46struct GNUNET_CRYPTO_RsaSignature *sig_1;
47char * s_name_1;
48struct GNUNET_NAMESTORE_RecordData *s_rd_1;
49
50struct GNUNET_CRYPTO_RsaSignature *sig_2;
51char * s_name_2;
52struct GNUNET_NAMESTORE_RecordData *s_rd_2;
53
45static void 54static void
46start_arm (const char *cfgname) 55start_arm (const char *cfgname)
47{ 56{
@@ -87,6 +96,21 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 96 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
88 nsh = NULL; 97 nsh = NULL;
89 98
99 GNUNET_free_non_null(sig_1);
100 GNUNET_free_non_null(sig_2);
101 GNUNET_free_non_null(s_name_1);
102 GNUNET_free_non_null(s_name_2);
103 if (s_rd_1 != NULL)
104 {
105 GNUNET_free ((void *)s_rd_1->data);
106 GNUNET_free (s_rd_1);
107 }
108 if (s_rd_2 != NULL)
109 {
110 GNUNET_free ((void *)s_rd_2->data);
111 GNUNET_free (s_rd_2);
112 }
113
90 if (privkey != NULL) 114 if (privkey != NULL)
91 GNUNET_CRYPTO_rsa_key_free (privkey); 115 GNUNET_CRYPTO_rsa_key_free (privkey);
92 privkey = NULL; 116 privkey = NULL;
@@ -118,6 +142,21 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 GNUNET_CRYPTO_rsa_key_free (privkey); 142 GNUNET_CRYPTO_rsa_key_free (privkey);
119 privkey = NULL; 143 privkey = NULL;
120 144
145 GNUNET_free_non_null(sig_1);
146 GNUNET_free_non_null(sig_2);
147 GNUNET_free_non_null(s_name_1);
148 GNUNET_free_non_null(s_name_2);
149 if (s_rd_1 != NULL)
150 {
151 GNUNET_free ((void *)s_rd_1->data);
152 GNUNET_free (s_rd_1);
153 }
154 if (s_rd_2 != NULL)
155 {
156 GNUNET_free ((void *)s_rd_2->data);
157 GNUNET_free (s_rd_2);
158 }
159
121 if (nsh != NULL) 160 if (nsh != NULL)
122 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 161 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
123 nsh = NULL; 162 nsh = NULL;
@@ -129,17 +168,6 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
129 res = 0; 168 res = 0;
130} 169}
131 170
132static void
133stop_iteration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
134{
135 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
136
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping iteration for zone `%s'\n", GNUNET_h2s (&zone));
138 GNUNET_NAMESTORE_zone_iteration_stop (zi);
139
140 GNUNET_SCHEDULER_add_now (&end, NULL);
141}
142
143void zone_proc (void *cls, 171void zone_proc (void *cls,
144 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 172 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
145 struct GNUNET_TIME_Absolute expire, 173 struct GNUNET_TIME_Absolute expire,
@@ -148,9 +176,77 @@ void zone_proc (void *cls,
148 const struct GNUNET_NAMESTORE_RecordData *rd, 176 const struct GNUNET_NAMESTORE_RecordData *rd,
149 const struct GNUNET_CRYPTO_RsaSignature *signature) 177 const struct GNUNET_CRYPTO_RsaSignature *signature)
150{ 178{
179 int failed = GNUNET_NO;
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone)); 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
152 181 if ((zone_key == NULL) && (name == NULL))
153 stopiteration_task = GNUNET_SCHEDULER_add_now (&stop_iteration, NULL); 182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n");
184 GNUNET_SCHEDULER_add_now (&end, NULL);
185 }
186 else
187 {
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing results name %s \n", name);
189 if (0 == strcmp (name, s_name_1))
190 {
191 if (rd_count == 1)
192 {
193 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
194 {
195 failed = GNUNET_YES;
196 GNUNET_break (0);
197 }
198 }
199 else
200 {
201 failed = GNUNET_YES;
202 GNUNET_break (0);
203 }
204 if (0 != memcmp (signature, sig_1, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
205 {
206 failed = GNUNET_YES;
207 GNUNET_break (0);
208 }
209 }
210 else if (0 == strcmp (name, s_name_2))
211 {
212 if (rd_count == 1)
213 {
214 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
215 {
216 failed = GNUNET_YES;
217 GNUNET_break (0);
218 }
219 }
220 else
221 {
222 failed = GNUNET_YES;
223 GNUNET_break (0);
224 }
225 if (0 != memcmp (signature, sig_2, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
226 {
227 failed = GNUNET_YES;
228 GNUNET_break (0);
229 }
230
231 }
232 else
233 {
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name);
235 GNUNET_break (0);
236 GNUNET_SCHEDULER_add_now (&end, NULL);
237 }
238
239 if (failed == GNUNET_NO)
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
242 GNUNET_NAMESTORE_zone_iterator_next (zi);
243 }
244 else
245 {
246 GNUNET_break (0);
247 GNUNET_SCHEDULER_add_now (&end, NULL);
248 }
249 }
154} 250}
155 251
156void 252void
@@ -171,6 +267,53 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
171 267
172} 268}
173 269
270void
271put_cont (void *cls, int32_t success, const char *emsg)
272{
273 static int c = 0;
274
275 if (success == GNUNET_OK)
276 {
277 c++;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
279
280 }
281
282 if (c == 2)
283 {
284 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
285 NULL,
286 GNUNET_NAMESTORE_RF_NONE,
287 GNUNET_NAMESTORE_RF_NONE,
288 zone_proc,
289 &zone);
290 if (zi == NULL)
291 {
292 GNUNET_break (0);
293 GNUNET_SCHEDULER_cancel (endbadly_task);
294 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
295 }
296 }
297}
298
299static struct GNUNET_NAMESTORE_RecordData *
300create_record (int count)
301{
302 int c;
303 struct GNUNET_NAMESTORE_RecordData * rd;
304 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
305
306 for (c = 0; c < count; c++)
307 {
308 rd[c].expiration = GNUNET_TIME_absolute_get();
309 rd[c].record_type = 1111;
310 rd[c].data_size = 50;
311 rd[c].data = GNUNET_malloc(50);
312 memset ((char *) rd[c].data, 'a', 50);
313 }
314 return rd;
315}
316
174static void 317static void
175run (void *cls, char *const *args, const char *cfgfile, 318run (void *cls, char *const *args, const char *cfgfile,
176 const struct GNUNET_CONFIGURATION_Handle *cfg) 319 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -181,8 +324,7 @@ run (void *cls, char *const *args, const char *cfgfile,
181 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); 324 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
182 GNUNET_assert (privkey != NULL); 325 GNUNET_assert (privkey != NULL);
183 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 326 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
184 327 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
185 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone);
186 328
187 start_arm (cfgfile); 329 start_arm (cfgfile);
188 GNUNET_assert (arm != NULL); 330 GNUNET_assert (arm != NULL);
@@ -190,18 +332,22 @@ run (void *cls, char *const *args, const char *cfgfile,
190 nsh = GNUNET_NAMESTORE_connect (cfg); 332 nsh = GNUNET_NAMESTORE_connect (cfg);
191 GNUNET_break (NULL != nsh); 333 GNUNET_break (NULL != nsh);
192 334
193 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
194 &zone, 336
195 GNUNET_NAMESTORE_RF_NONE, 337
196 GNUNET_NAMESTORE_RF_NONE, 338
197 zone_proc, 339 GNUNET_asprintf(&s_name_1, "dummy1");
198 &zone); 340 s_rd_1 = create_record(1);
199 if (zi == NULL) 341 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
200 { 342 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
201 GNUNET_break (0); 343
202 GNUNET_SCHEDULER_cancel (endbadly_task); 344
203 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
204 } 346 GNUNET_asprintf(&s_name_2, "dummy2");
347 s_rd_2 = create_record(1);
348
349 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
350 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
205} 351}
206 352
207static int 353static int