2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file namestore/test_namestore_api_monitoring.c
22 * @brief testcase for zone iteration functionality: iterate of a specific zone
25 #include "gnunet_common.h"
26 #include "gnunet_namestore_service.h"
27 #include "gnunet_testing_lib.h"
28 #include "namestore.h"
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
34 static struct GNUNET_NAMESTORE_Handle * nsh;
36 static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
38 static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task;
40 static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
42 static struct GNUNET_CRYPTO_EccPublicKey pubkey;
44 static struct GNUNET_HashCode zone;
46 static struct GNUNET_CRYPTO_EccPrivateKey * privkey2;
48 static struct GNUNET_CRYPTO_EccPublicKey pubkey2;
50 static struct GNUNET_HashCode zone2;
52 static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
56 static int returned_records;
58 static struct GNUNET_CRYPTO_EccSignature *sig_1;
60 static char * s_name_1;
62 static struct GNUNET_NAMESTORE_RecordData *s_rd_1;
64 static struct GNUNET_CRYPTO_EccSignature *sig_2;
66 static char * s_name_2;
68 static struct GNUNET_NAMESTORE_RecordData *s_rd_2;
70 static struct GNUNET_CRYPTO_EccSignature *sig_3;
72 static char * s_name_3;
74 static struct GNUNET_NAMESTORE_RecordData *s_rd_3;
80 if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
82 GNUNET_SCHEDULER_cancel (stopiteration_task);
83 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
87 GNUNET_NAMESTORE_zone_monitor_stop (zm);
92 GNUNET_NAMESTORE_disconnect (nsh);
95 GNUNET_free_non_null(sig_1);
96 GNUNET_free_non_null(sig_2);
97 GNUNET_free_non_null(sig_3);
98 GNUNET_free_non_null(s_name_1);
99 GNUNET_free_non_null(s_name_2);
100 GNUNET_free_non_null(s_name_3);
104 GNUNET_free ((void *)s_rd_1->data);
105 GNUNET_free (s_rd_1);
109 GNUNET_free ((void *)s_rd_2->data);
110 GNUNET_free (s_rd_2);
114 GNUNET_free ((void *)s_rd_3->data);
115 GNUNET_free (s_rd_3);
120 GNUNET_CRYPTO_ecc_key_free (privkey);
123 if (NULL != privkey2)
125 GNUNET_CRYPTO_ecc_key_free (privkey2);
132 * Re-establish the connection to the service.
134 * @param cls handle to use to re-connect.
135 * @param tc scheduler context
138 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
154 zone_proc (void *cls,
155 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
156 struct GNUNET_TIME_Absolute expire,
158 unsigned int rd_count,
159 const struct GNUNET_NAMESTORE_RecordData *rd,
160 const struct GNUNET_CRYPTO_EccSignature *signature)
162 GNUNET_break (NULL == signature);
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Comparing results name %s\n",
166 if (0 == strcmp (name, s_name_1))
168 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
171 if (0 == strcmp (name, s_name_2))
173 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
176 if (0 == strcmp (name, s_name_3))
178 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_3))
181 if (3 == ++returned_records)
183 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
185 GNUNET_SCHEDULER_cancel (endbadly_task);
186 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
188 GNUNET_SCHEDULER_add_now (&end, NULL);
194 put_cont (void *cls, int32_t success, const char *emsg)
198 if (success == GNUNET_OK)
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u\n", c);
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n");
207 GNUNET_SCHEDULER_cancel (endbadly_task);
208 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
213 static struct GNUNET_NAMESTORE_RecordData *
214 create_record (unsigned int count)
217 struct GNUNET_NAMESTORE_RecordData * rd;
219 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
220 for (c = 0; c < count; c++)
222 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
223 rd[c].record_type = 1111;
224 rd[c].data_size = 50;
225 rd[c].data = GNUNET_malloc(50);
226 memset ((char *) rd[c].data, 'a', 50);
234 const struct GNUNET_CONFIGURATION_Handle *cfg,
235 struct GNUNET_TESTING_Peer *peer)
238 struct GNUNET_TIME_Absolute et;
241 returned_records = 0;
242 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
249 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone monitor\n");
251 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
254 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
255 nsh = GNUNET_NAMESTORE_connect (cfg);
256 GNUNET_break (NULL != nsh);
258 GNUNET_asprintf(&hostkey_file,
261 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 "Using zonekey file `%s' \n", hostkey_file);
264 privkey = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file);
265 GNUNET_free (hostkey_file);
266 GNUNET_assert (privkey != NULL);
267 GNUNET_CRYPTO_ecc_key_get_public(privkey, &pubkey);
268 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
270 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
272 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
274 privkey2 = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file);
275 GNUNET_free (hostkey_file);
277 GNUNET_assert (privkey2 != NULL);
278 GNUNET_CRYPTO_ecc_key_get_public(privkey2, &pubkey2);
279 GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2);
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
283 GNUNET_asprintf(&s_name_1, "dummy1");
284 s_rd_1 = create_record(1);
285 et.abs_value_us = s_rd_1->expiration_time;
286 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1);
287 GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_1,
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
293 GNUNET_asprintf(&s_name_2, "dummy2");
294 s_rd_2 = create_record(1);
296 et.abs_value_us = s_rd_2->expiration_time;
297 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1);
298 GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_2,
302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
303 /* name in different zone */
304 GNUNET_asprintf(&s_name_3, "dummy3");
305 s_rd_3 = create_record(1);
306 et.abs_value_us = s_rd_3->expiration_time;
307 sig_3 = GNUNET_NAMESTORE_create_signature(privkey2, et, s_name_3, s_rd_3, 1);
308 GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3,
309 GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3,
315 main (int argc, char *argv[])
319 GNUNET_TESTING_service_run ("test-namestore-api-monitoring",
321 "test_namestore_api.conf",
329 /* end of test_namestore_api_monitoring.c */