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.c
22 * @brief testcase for namestore_api.c
25 #include "gnunet_common.h"
26 #include "gnunet_namestore_service.h"
28 #define VERBOSE GNUNET_EXTRA_LOGGING
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;
41 start_arm (const char *cfgname)
43 arm = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
44 "gnunet-service-arm", "-c", cfgname,
58 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
59 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
60 GNUNET_OS_process_wait (arm);
61 GNUNET_OS_process_close (arm);
67 * Re-establish the connection to the service.
69 * @param cls handle to use to re-connect.
70 * @param tc scheduler context
73 endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
76 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
87 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
91 GNUNET_SCHEDULER_cancel (endbadly_task);
92 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
96 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
107 void name_lookup_proc (void *cls,
108 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
109 struct GNUNET_TIME_Absolute expire,
111 unsigned int rd_count,
112 const struct GNUNET_NAMESTORE_RecordData *rd,
113 const struct GNUNET_CRYPTO_RsaSignature *signature)
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "name_lookup_proc %p `%s' %i %p %p\n", zone_key, name, rd_count, rd, signature);
117 GNUNET_SCHEDULER_add_now(&end, NULL);
121 run (void *cls, char *const *args, const char *cfgfile,
122 const struct GNUNET_CONFIGURATION_Handle *cfg)
124 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
126 GNUNET_HashCode zone;
127 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &zone);
128 char * name = "dummy.dummy.gnunet";
131 GNUNET_assert (arm != NULL);
133 nsh = GNUNET_NAMESTORE_connect (cfg);
134 GNUNET_break (NULL != nsh);
136 GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL);
142 static char *const argv[] = { "test-namestore-api",
144 "test_namestore_api.conf",
150 static struct GNUNET_GETOPT_CommandLineOption options[] = {
151 GNUNET_GETOPT_OPTION_END
155 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api",
156 "nohelp", options, &run, &res);
161 main (int argc, char *argv[])
170 /* end of test_namestore_api.c */