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.c444
1 files changed, 222 insertions, 222 deletions
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index e54046c85..97432b2a2 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_monitoring_existing.c 21 * @file namestore/test_namestore_api_monitoring_existing.c
22 * @brief testcase for zone monitoring functionality: add records first, then monitor 22 * @brief testcase for zone monitoring functionality: add records first, then monitor
@@ -30,7 +30,7 @@
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
@@ -67,311 +67,311 @@ 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 {
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
157 "Monitoring returned wrong zone key\n");
158 GNUNET_break (0);
159 GNUNET_SCHEDULER_shutdown ();
160 return;
161 }
162
163 if (0 == strcmp (name,
164 s_name_1))
165 {
166 if (GNUNET_YES !=
167 GNUNET_GNSRECORD_records_cmp (rd,
168 s_rd_1))
169 { 155 {
170 GNUNET_break (0); 156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
171 fail = GNUNET_YES; 157 "Monitoring returned wrong zone key\n");
158 GNUNET_break(0);
159 GNUNET_SCHEDULER_shutdown();
160 return;
172 } 161 }
173 } 162
174 else if (0 == strcmp (name, 163 if (0 == strcmp(name,
175 s_name_2)) 164 s_name_1))
176 {
177 if (GNUNET_YES !=
178 GNUNET_GNSRECORD_records_cmp (rd,
179 s_rd_2))
180 { 165 {
181 GNUNET_break (0); 166 if (GNUNET_YES !=
182 fail = GNUNET_YES; 167 GNUNET_GNSRECORD_records_cmp(rd,
168 s_rd_1))
169 {
170 GNUNET_break(0);
171 fail = GNUNET_YES;
172 }
173 }
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))
180 {
181 GNUNET_break(0);
182 fail = GNUNET_YES;
183 }
183 } 184 }
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)
199 { 186 {
200 GNUNET_break (0); 187 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
201 res = 1; 188 "Invalid name %s\n",
189 name);
190 GNUNET_break(0);
191 fail = GNUNET_YES;
202 } 192 }
203 else 193 GNUNET_NAMESTORE_zone_monitor_next(zm,
194 1);
195 if (2 == ++returned_records)
204 { 196 {
205 res = 0; 197 GNUNET_SCHEDULER_shutdown();
198 if (GNUNET_YES == fail)
199 {
200 GNUNET_break(0);
201 res = 1;
202 }
203 else
204 {
205 res = 0;
206 }
206 } 207 }
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 {
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 "Failed to created records\n");
255 GNUNET_break (0);
256 res = 1;
257 GNUNET_SCHEDULER_shutdown ();
258 return;
259 }
260
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)
274 { 252 {
275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 253 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
276 "Failed to create zone monitor\n"); 254 "Failed to created records\n");
277 GNUNET_break (0); 255 GNUNET_break(0);
278 res = 1; 256 res = 1;
279 GNUNET_SCHEDULER_shutdown (); 257 GNUNET_SCHEDULER_shutdown();
280 return; 258 return;
281 } 259 }
282 } 260
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)
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 }
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(GNUNET_TIME_UNIT_HOURS).abs_value_us;
296 rd[c].record_type = TEST_RECORD_TYPE; 296 rd[c].record_type = TEST_RECORD_TYPE;
297 rd[c].data_size = 50; 297 rd[c].data_size = 50;
298 rd[c].data = GNUNET_malloc(50); 298 rd[c].data = GNUNET_malloc(50);
299 rd[c].flags = 0; 299 rd[c].flags = 0;
300 memset ((char *) rd[c].data, 300 memset((char *)rd[c].data,
301 'a', 301 'a',
302 50); 302 50);
303 } 303 }
304 return rd; 304 return rd;
305} 305}
306 306
307 307
308static void 308static void
309run (void *cls, 309run(void *cls,
310 const struct GNUNET_CONFIGURATION_Handle *mycfg, 310 const struct GNUNET_CONFIGURATION_Handle *mycfg,
311 struct GNUNET_TESTING_Peer *peer) 311 struct GNUNET_TESTING_Peer *peer)
312{ 312{
313 res = 1; 313 res = 1;
314 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 314 privkey = GNUNET_CRYPTO_ecdsa_key_create();
315 GNUNET_assert (NULL != privkey); 315 GNUNET_assert(NULL != privkey);
316 privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); 316 privkey2 = GNUNET_CRYPTO_ecdsa_key_create();
317 GNUNET_assert (NULL != privkey2); 317 GNUNET_assert(NULL != privkey2);
318 318
319 cfg = mycfg; 319 cfg = mycfg;
320 GNUNET_SCHEDULER_add_shutdown (&end, 320 GNUNET_SCHEDULER_add_shutdown(&end,
321 NULL); 321 NULL);
322 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 322 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
323 &endbadly, 323 &endbadly,
324 NULL); 324 NULL);
325 /* Connect to namestore */ 325 /* Connect to namestore */
326 nsh = GNUNET_NAMESTORE_connect (cfg); 326 nsh = GNUNET_NAMESTORE_connect(cfg);
327 if (NULL == nsh) 327 if (NULL == nsh)
328 { 328 {
329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 329 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
330 "Connect to namestore failed\n"); 330 "Connect to namestore failed\n");
331 GNUNET_break (0); 331 GNUNET_break(0);
332 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, 332 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly,
333 NULL); 333 NULL);
334 return; 334 return;
335 } 335 }
336 336
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
338 "Created record 3\n"); 338 "Created record 3\n");
339 /* name in different zone */ 339 /* name in different zone */
340 s_name_3 = "dummy3"; 340 s_name_3 = "dummy3";
341 s_rd_3 = create_record(1); 341 s_rd_3 = create_record(1);
342 GNUNET_assert (NULL != (ns_ops[2] = 342 GNUNET_assert(NULL != (ns_ops[2] =
343 GNUNET_NAMESTORE_records_store (nsh, 343 GNUNET_NAMESTORE_records_store(nsh,
344 privkey2, 344 privkey2,
345 s_name_3, 345 s_name_3,
346 1, 346 1,
347 s_rd_3, 347 s_rd_3,
348 &put_cont, 348 &put_cont,
349 (void *) s_name_3))); 349 (void *)s_name_3)));
350 350
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
352 "Created record 1\n"); 352 "Created record 1\n");
353 s_name_1 = "dummy1"; 353 s_name_1 = "dummy1";
354 s_rd_1 = create_record (1); 354 s_rd_1 = create_record(1);
355 GNUNET_assert (NULL != (ns_ops[0] = 355 GNUNET_assert(NULL != (ns_ops[0] =
356 GNUNET_NAMESTORE_records_store (nsh, 356 GNUNET_NAMESTORE_records_store(nsh,
357 privkey, 357 privkey,
358 s_name_1, 358 s_name_1,
359 1, 359 1,
360 s_rd_1, 360 s_rd_1,
361 &put_cont, 361 &put_cont,
362 (void *) s_name_1))); 362 (void *)s_name_1)));
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
364 "Created record 2 \n"); 364 "Created record 2 \n");
365 s_name_2 = "dummy2"; 365 s_name_2 = "dummy2";
366 s_rd_2 = create_record (1); 366 s_rd_2 = create_record(1);
367 GNUNET_assert (NULL != (ns_ops[1] = 367 GNUNET_assert(NULL != (ns_ops[1] =
368 GNUNET_NAMESTORE_records_store (nsh, 368 GNUNET_NAMESTORE_records_store(nsh,
369 privkey, 369 privkey,
370 s_name_2, 370 s_name_2,
371 1, 371 1,
372 s_rd_2, 372 s_rd_2,
373 &put_cont, 373 &put_cont,
374 (void *) s_name_2))); 374 (void *)s_name_2)));
375} 375}
376 376
377 377
@@ -379,26 +379,26 @@ run (void *cls,
379 379
380 380
381int 381int
382main (int argc, 382main(int argc,
383 char *argv[]) 383 char *argv[])
384{ 384{
385 const char *plugin_name; 385 const char *plugin_name;
386 char *cfg_name; 386 char *cfg_name;
387 387
388 SETUP_CFG (plugin_name, cfg_name); 388 SETUP_CFG(plugin_name, cfg_name);
389 res = 1; 389 res = 1;
390 if (0 != 390 if (0 !=
391 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", 391 GNUNET_TESTING_peer_run("test-namestore-api-monitoring-existing",
392 cfg_name, 392 cfg_name,
393 &run, 393 &run,
394 NULL)) 394 NULL))
395 { 395 {
396 GNUNET_break (0); 396 GNUNET_break(0);
397 res = 1; 397 res = 1;
398 } 398 }
399 GNUNET_DISK_purge_cfg_dir (cfg_name, 399 GNUNET_DISK_purge_cfg_dir(cfg_name,
400 "GNUNET_TEST_HOME"); 400 "GNUNET_TEST_HOME");
401 GNUNET_free (cfg_name); 401 GNUNET_free(cfg_name);
402 return res; 402 return res;
403} 403}
404 404