2 This file is part of GNUnet.
3 (C) 2009 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_zone_iteration.c
22 * @brief testcase for namestore_api.c zone iteration functionality
25 #include "gnunet_common.h"
26 #include "gnunet_namestore_service.h"
28 #define VERBOSE GNUNET_NO
30 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
32 static struct GNUNET_NAMESTORE_Handle * nsh;
34 static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
35 static struct GNUNET_OS_Process *arm;
37 static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
38 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
39 static GNUNET_HashCode zone;
41 static struct GNUNET_NAMESTORE_ZoneIterator *zi;
45 start_arm (const char *cfgname)
47 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
48 "gnunet-service-arm", "-c", cfgname,
62 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
63 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
64 GNUNET_OS_process_wait (arm);
65 GNUNET_OS_process_close (arm);
71 * Re-establish the connection to the service.
73 * @param cls handle to use to re-connect.
74 * @param tc scheduler context
77 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
84 GNUNET_CRYPTO_rsa_key_free (privkey);
95 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
97 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
99 GNUNET_SCHEDULER_cancel (endbadly_task);
100 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
104 GNUNET_CRYPTO_rsa_key_free (privkey);
108 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
119 void zone_proc (void *cls,
120 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
121 struct GNUNET_TIME_Absolute expire,
123 unsigned int rd_count,
124 const struct GNUNET_NAMESTORE_RecordData *rd,
125 const struct GNUNET_CRYPTO_RsaSignature *signature)
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
128 endbadly_task = GNUNET_SCHEDULER_add_now (&end, NULL);
132 run (void *cls, char *const *args, const char *cfgfile,
133 const struct GNUNET_CONFIGURATION_Handle *cfg)
135 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
137 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
138 GNUNET_assert (privkey != NULL);
139 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
141 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone);
144 GNUNET_assert (arm != NULL);
146 nsh = GNUNET_NAMESTORE_connect (cfg);
147 GNUNET_break (NULL != nsh);
149 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
151 GNUNET_NAMESTORE_RF_NONE,
152 GNUNET_NAMESTORE_RF_NONE,
158 GNUNET_SCHEDULER_cancel (endbadly_task);
159 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
166 static char *const argv[] = { "test_namestore_api_zone_iteration",
168 "test_namestore_api.conf",
174 static struct GNUNET_GETOPT_CommandLineOption options[] = {
175 GNUNET_GETOPT_OPTION_END
179 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration",
180 "nohelp", options, &run, &res);
185 main (int argc, char *argv[])
194 /* end of test_namestore_api_zone_iteration.c */