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