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_to_name.c
22 * @brief testcase for zone to name translation
25 #include "gnunet_common.h"
26 #include "gnunet_namestore_service.h"
27 #include "namestore.h"
28 #include "gnunet_signatures.h"
30 #define VERBOSE GNUNET_NO
32 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
34 static struct GNUNET_NAMESTORE_Handle * nsh;
36 static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
37 static struct GNUNET_OS_Process *arm;
39 static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
40 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
42 static GNUNET_HashCode s_zone;
43 static GNUNET_HashCode s_zone_value;
48 start_arm (const char *cfgname)
50 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
51 "gnunet-service-arm", "-c", cfgname,
65 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
66 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
67 GNUNET_OS_process_wait (arm);
68 GNUNET_OS_process_close (arm);
74 * Re-establish the connection to the service.
76 * @param cls handle to use to re-connect.
77 * @param tc scheduler context
80 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
87 GNUNET_CRYPTO_rsa_key_free (privkey);
98 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
100 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
102 GNUNET_SCHEDULER_cancel (endbadly_task);
103 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
107 GNUNET_CRYPTO_rsa_key_free (privkey);
111 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
118 void zone_to_name_proc (void *cls,
119 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
120 struct GNUNET_TIME_Absolute expire,
122 unsigned int rd_count,
123 const struct GNUNET_NAMESTORE_RecordData *rd,
124 const struct GNUNET_CRYPTO_RsaSignature *signature)
126 if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL))
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n");
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found\n");
136 GNUNET_SCHEDULER_add_now(&end, NULL);
141 delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
146 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
147 "FILENAME", &afsdir))
149 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
150 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
151 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
153 GNUNET_free (afsdir);
159 run (void *cls, char *const *args, const char *cfgfile,
160 const struct GNUNET_CONFIGURATION_Handle *cfg)
162 delete_existing_db(cfg);
164 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
166 /* load privat key */
167 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
168 GNUNET_assert (privkey != NULL);
170 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
173 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
174 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &s_zone_value);
177 GNUNET_assert (arm != NULL);
179 nsh = GNUNET_NAMESTORE_connect (cfg);
180 GNUNET_break (NULL != nsh);
182 /* create initial record */
183 GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL);
189 static char *const argv[] = { "test-namestore-api",
191 "test_namestore_api.conf",
197 static struct GNUNET_GETOPT_CommandLineOption options[] = {
198 GNUNET_GETOPT_OPTION_END
202 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api",
203 "nohelp", options, &run, &res);
208 main (int argc, char *argv[])
216 /* end of test_namestore_api.c */