aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_monitoring.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_monitoring.c')
-rw-r--r--src/namestore/test_namestore_api_monitoring.c102
1 files changed, 46 insertions, 56 deletions
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index f6d4fe226..1051e3248 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -1,21 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 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 General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_monitoring.c 19 * @file namestore/test_namestore_api_monitoring.c
@@ -25,6 +23,10 @@
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29
28 30
29 31
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
@@ -56,7 +58,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
56 58
57struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 59struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
58 60
59static char *directory;
60 61
61static void 62static void
62do_shutdown () 63do_shutdown ()
@@ -66,7 +67,6 @@ do_shutdown ()
66 GNUNET_NAMESTORE_zone_monitor_stop (zm); 67 GNUNET_NAMESTORE_zone_monitor_stop (zm);
67 zm = NULL; 68 zm = NULL;
68 } 69 }
69
70 if (NULL != ns_ops[0]) 70 if (NULL != ns_ops[0])
71 { 71 {
72 GNUNET_NAMESTORE_cancel(ns_ops[0]); 72 GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -82,13 +82,11 @@ do_shutdown ()
82 GNUNET_NAMESTORE_cancel(ns_ops[2]); 82 GNUNET_NAMESTORE_cancel(ns_ops[2]);
83 ns_ops[2] = NULL; 83 ns_ops[2] = NULL;
84 } 84 }
85
86 if (NULL != nsh) 85 if (NULL != nsh)
87 { 86 {
88 GNUNET_NAMESTORE_disconnect (nsh); 87 GNUNET_NAMESTORE_disconnect (nsh);
89 nsh = NULL; 88 nsh = NULL;
90 } 89 }
91
92 GNUNET_free_non_null(s_name_1); 90 GNUNET_free_non_null(s_name_1);
93 GNUNET_free_non_null(s_name_2); 91 GNUNET_free_non_null(s_name_2);
94 GNUNET_free_non_null(s_name_3); 92 GNUNET_free_non_null(s_name_3);
@@ -192,7 +190,8 @@ zone_proc (void *cls,
192 GNUNET_break (0); 190 GNUNET_break (0);
193 fail = GNUNET_YES; 191 fail = GNUNET_YES;
194 } 192 }
195 193 GNUNET_NAMESTORE_zone_monitor_next (zm,
194 1);
196 if (2 == ++returned_records) 195 if (2 == ++returned_records)
197 { 196 {
198 if (endbadly_task != NULL) 197 if (endbadly_task != NULL)
@@ -247,14 +246,14 @@ put_cont (void *cls,
247static struct GNUNET_GNSRECORD_Data * 246static struct GNUNET_GNSRECORD_Data *
248create_record (unsigned int count) 247create_record (unsigned int count)
249{ 248{
250 unsigned int c; 249 struct GNUNET_GNSRECORD_Data *rd;
251 struct GNUNET_GNSRECORD_Data * rd;
252 250
253 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 251 rd = GNUNET_new_array (count,
254 for (c = 0; c < count; c++) 252 struct GNUNET_GNSRECORD_Data);
253 for (unsigned int c = 0; c < count; c++)
255 { 254 {
256 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 255 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
257 rd[c].record_type = 1111; 256 rd[c].record_type = TEST_RECORD_TYPE;
258 rd[c].data_size = 50; 257 rd[c].data_size = 50;
259 rd[c].data = GNUNET_malloc(50); 258 rd[c].data = GNUNET_malloc(50);
260 rd[c].flags = 0; 259 rd[c].flags = 0;
@@ -283,23 +282,8 @@ run (void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg, 282 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer) 283 struct GNUNET_TESTING_Peer *peer)
285{ 284{
286 char *hostkey_file;
287
288 res = 1; 285 res = 1;
289 286 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
290 directory = NULL;
291 GNUNET_assert (GNUNET_OK ==
292 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
293 GNUNET_DISK_directory_remove (directory);
294
295 GNUNET_asprintf(&hostkey_file,
296 "zonefiles%s%s",
297 DIR_SEPARATOR_STR,
298 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Using zonekey file `%s' \n", hostkey_file);
301 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
302 GNUNET_free (hostkey_file);
303 GNUNET_assert (privkey != NULL); 287 GNUNET_assert (privkey != NULL);
304 288
305 /* Start monitoring */ 289 /* Start monitoring */
@@ -332,16 +316,12 @@ run (void *cls,
332 return; 316 return;
333 } 317 }
334 318
335 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 319 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
336 DIR_SEPARATOR_STR,
337 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
339 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
340 GNUNET_free (hostkey_file);
341 GNUNET_assert (privkey2 != NULL); 320 GNUNET_assert (privkey2 != NULL);
342 321
343 322
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); 323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
324 "Created record 3\n");
345 /* name in different zone */ 325 /* name in different zone */
346 GNUNET_asprintf(&s_name_3, "dummy3"); 326 GNUNET_asprintf(&s_name_3, "dummy3");
347 s_rd_3 = create_record(1); 327 s_rd_3 = create_record(1);
@@ -357,22 +337,33 @@ run (void *cls,
357 "Created record 1\n"); 337 "Created record 1\n");
358 GNUNET_asprintf(&s_name_1, "dummy1"); 338 GNUNET_asprintf(&s_name_1, "dummy1");
359 s_rd_1 = create_record(1); 339 s_rd_1 = create_record(1);
360 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 340 GNUNET_assert (NULL != (ns_ops[0] =
361 1, s_rd_1, &put_cont, s_name_1))); 341 GNUNET_NAMESTORE_records_store (nsh,
342 privkey,
343 s_name_1,
344 1,
345 s_rd_1,
346 &put_cont,
347 s_name_1)));
362 348
363 349
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
365 GNUNET_asprintf(&s_name_2, "dummy2"); 351 GNUNET_asprintf(&s_name_2, "dummy2");
366 s_rd_2 = create_record(1); 352 s_rd_2 = create_record(1);
367 GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 353 GNUNET_assert (NULL != (ns_ops[1] =
368 1, s_rd_2, &put_cont, s_name_2))); 354 GNUNET_NAMESTORE_records_store (nsh,
369 355 privkey,
370 356 s_name_2,
357 1,
358 s_rd_2,
359 &put_cont,
360 s_name_2)));
371} 361}
372 362
373 363
374int 364int
375main (int argc, char *argv[]) 365main (int argc,
366 char *argv[])
376{ 367{
377 const char *plugin_name; 368 const char *plugin_name;
378 char *cfg_name; 369 char *cfg_name;
@@ -381,6 +372,8 @@ main (int argc, char *argv[])
381 GNUNET_asprintf (&cfg_name, 372 GNUNET_asprintf (&cfg_name,
382 "test_namestore_api_%s.conf", 373 "test_namestore_api_%s.conf",
383 plugin_name); 374 plugin_name);
375 GNUNET_DISK_purge_cfg_dir (cfg_name,
376 "GNUNET_TEST_HOME");
384 res = 1; 377 res = 1;
385 if (0 != 378 if (0 !=
386 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", 379 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
@@ -390,12 +383,9 @@ main (int argc, char *argv[])
390 { 383 {
391 res = 1; 384 res = 1;
392 } 385 }
386 GNUNET_DISK_purge_cfg_dir (cfg_name,
387 "GNUNET_TEST_HOME");
393 GNUNET_free (cfg_name); 388 GNUNET_free (cfg_name);
394 if (NULL != directory)
395 {
396 GNUNET_DISK_directory_remove (directory);
397 GNUNET_free (directory);
398 }
399 return res; 389 return res;
400} 390}
401 391