2 This file is part of GNUnet.
3 (C) 2005, 2006, 2008, 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 2, 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.
22 * @file fs/test_fs_namespace.c
23 * @brief Test for fs_namespace.c
24 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_arm_service.h"
30 #include "gnunet_fs_service.h"
32 #define START_ARM GNUNET_YES
34 static struct GNUNET_SCHEDULER_Handle *sched;
36 static struct PeerContext p1;
38 static struct GNUNET_FS_Handle *fs;
43 struct GNUNET_CONFIGURATION_Handle *cfg;
44 struct GNUNET_PeerIdentity id;
52 progress_cb (void *cls,
53 const struct GNUNET_FS_ProgressInfo *event)
60 setup_peer (struct PeerContext *p, const char *cfgname)
62 p->cfg = GNUNET_CONFIGURATION_create ();
64 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
70 sleep (1); /* allow ARM to start */
72 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
73 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
78 stop_arm (struct PeerContext *p)
81 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
82 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
83 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
84 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "ARM process %u stopped\n", p->arm_pid);
88 GNUNET_CONFIGURATION_destroy (p->cfg);
96 const GNUNET_HashCode * key)
103 publish_cont (void *cls,
104 const struct GNUNET_FS_Uri *uri,
107 struct GNUNET_FS_SearchContext *search;
109 GNUNET_assert (NULL == emsg);
110 fprintf (stderr, "Starting namespace search...\n");
111 search = GNUNET_FS_search_start (fs, uri, 1, "ns-search");
118 struct GNUNET_FS_Namespace *ns;
119 struct GNUNET_FS_Uri *adv;
120 struct GNUNET_FS_Uri *rootUri;
121 struct GNUNET_CONTAINER_MetaData *meta;
122 struct GNUNET_TIME_Absolute expiration;
124 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
125 meta = GNUNET_CONTAINER_meta_data_create ();
126 adv = GNUNET_FS_uri_ksk_create ("testNamespace", NULL);
127 ns = GNUNET_FS_namespace_create (fs,
129 rootUri = GNUNET_FS_namespace_advertise (fs,
136 GNUNET_assert (NULL != rootUri);
137 GNUNET_FS_publish_sks (fs,
145 GNUNET_FS_PUBLISH_OPTION_NONE,
148 GNUNET_CONTAINER_meta_data_destroy (meta);
152 fprintf (stderr, "Completed namespace search...\n");
153 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
154 GNUNET_assert (GNUNET_SYSERR == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
155 GNUNET_FS_uri_destroy (rootURI);
156 GNUNET_FS_uri_destroy (advURI);
157 GNUNET_assert (match == 1);
165 struct GNUNET_SCHEDULER_Handle *s,
168 const struct GNUNET_CONFIGURATION_Handle *cfg)
171 setup_peer (&p1, "test_fs_download_data.conf");
172 fs = GNUNET_FS_start (sched,
177 GNUNET_FS_FLAGS_NONE,
178 GNUNET_FS_OPTIONS_END);
184 main (int argc, char *argv[])
186 char *const argvx[] = {
189 "test_fs_namespace_data.conf",
195 struct GNUNET_GETOPT_CommandLineOption options[] = {
196 GNUNET_GETOPT_OPTION_END
199 GNUNET_log_setup ("test_fs_namespace",
206 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
207 argvx, "test-fs-namespace",
208 "nohelp", options, &run, NULL);
210 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
216 /* end of test_fs_namespace.c */