2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file namestore/test_namestore_api_zone_to_name.c
22 * @brief testcase for zone to name translation
25 #include "gnunet_namestore_service.h"
26 #include "gnunet_testing_lib.h"
27 #include "namestore.h"
31 #define TEST_RECORD_TYPE 1234
33 #define TEST_RECORD_DATALEN 123
35 #define TEST_RECORD_DATA 'a'
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
40 static struct GNUNET_NAMESTORE_Handle *nsh;
42 static struct GNUNET_SCHEDULER_Task *endbadly_task;
44 static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
46 static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
48 static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value;
54 static char *directory;
56 static struct GNUNET_NAMESTORE_QueueEntry *qe;
60 * Re-establish the connection to the service.
62 * @param cls handle to use to re-connect.
68 GNUNET_SCHEDULER_shutdown ();
78 GNUNET_NAMESTORE_cancel (qe);
81 if (NULL != endbadly_task)
83 GNUNET_SCHEDULER_cancel (endbadly_task);
88 GNUNET_free (privkey);
93 GNUNET_NAMESTORE_disconnect (nsh);
100 zone_to_name_proc (void *cls,
101 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
103 unsigned int rd_count,
104 const struct GNUNET_GNSRECORD_Data *rd)
106 int fail = GNUNET_NO;
109 if ( (NULL == zone_key) &&
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "No result found\n");
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Result found: `%s'\n",
135 if ( (NULL == zone_key) ||
136 (0 != memcmp (zone_key,
138 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))
143 if (fail == GNUNET_NO)
148 GNUNET_SCHEDULER_add_now (&end,
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 GNUNET_SCHEDULER_shutdown ();
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Name store added record for `%s': %s\n",
175 (success == GNUNET_OK) ? "SUCCESS" : emsg);
176 if (success == GNUNET_OK)
180 qe = GNUNET_NAMESTORE_zone_to_name (nsh,
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
192 "Failed to put records for name `%s'\n",
194 GNUNET_SCHEDULER_add_now (&end,
202 const struct GNUNET_CONFIGURATION_Handle *cfg,
203 struct GNUNET_TESTING_Peer *peer)
208 GNUNET_assert (GNUNET_OK ==
209 GNUNET_CONFIGURATION_get_value_string (cfg,
213 GNUNET_DISK_directory_remove (directory);
215 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
218 GNUNET_SCHEDULER_add_shutdown (&end,
220 GNUNET_asprintf (&s_name, "dummy");
221 /* load privat key */
225 GNUNET_asprintf (&zonekey_file,
228 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Using zonekey file `%s'\n",
232 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
233 GNUNET_free (zonekey_file);
235 GNUNET_assert (NULL != privkey);
237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
240 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
242 sizeof (s_zone_value));
244 struct GNUNET_GNSRECORD_Data rd;
246 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
247 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
248 rd.data_size = sizeof (s_zone_value);
249 rd.data = &s_zone_value;
252 nsh = GNUNET_NAMESTORE_connect (cfg);
253 GNUNET_break (NULL != nsh);
254 GNUNET_NAMESTORE_records_store (nsh,
269 const char *plugin_name;
273 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
274 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf",
279 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
286 GNUNET_free (cfg_name);
287 if (NULL != directory)
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
295 /* end of test_namestore_api_zone_to_name.c */