diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-23 10:54:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-23 10:54:26 +0000 |
commit | df6cfdf376e83edfd04e083c6feafa8577bc237c (patch) | |
tree | ca1e65baf6ee3041c2fe59d0fe8cd55515dde1ea /src/fs/test_fs_namespace.c | |
parent | 129376c98b928d01c998dcfcb811bcf08cfae288 (diff) | |
download | gnunet-df6cfdf376e83edfd04e083c6feafa8577bc237c.tar.gz gnunet-df6cfdf376e83edfd04e083c6feafa8577bc237c.zip |
hacking on fs
Diffstat (limited to 'src/fs/test_fs_namespace.c')
-rw-r--r-- | src/fs/test_fs_namespace.c | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c new file mode 100644 index 000000000..8ee9ab37a --- /dev/null +++ b/src/fs/test_fs_namespace.c | |||
@@ -0,0 +1,214 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file fs/test_fs_namespace.c | ||
23 | * @brief Test for fs_namespace.c | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_arm_service.h" | ||
30 | #include "gnunet_fs_service.h" | ||
31 | |||
32 | #define START_ARM GNUNET_YES | ||
33 | |||
34 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
35 | |||
36 | static struct PeerContext p1; | ||
37 | |||
38 | static struct GNUNET_FS_Handle *fs; | ||
39 | |||
40 | |||
41 | struct PeerContext | ||
42 | { | ||
43 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | struct GNUNET_PeerIdentity id; | ||
45 | #if START_ARM | ||
46 | pid_t arm_pid; | ||
47 | #endif | ||
48 | }; | ||
49 | |||
50 | |||
51 | static void * | ||
52 | progress_cb (void *cls, | ||
53 | const struct GNUNET_FS_ProgressInfo *event) | ||
54 | { | ||
55 | return NULL; | ||
56 | } | ||
57 | |||
58 | |||
59 | static void | ||
60 | setup_peer (struct PeerContext *p, const char *cfgname) | ||
61 | { | ||
62 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
63 | #if START_ARM | ||
64 | p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm", | ||
65 | "gnunet-service-arm", | ||
66 | #if VERBOSE | ||
67 | "-L", "DEBUG", | ||
68 | #endif | ||
69 | "-c", cfgname, NULL); | ||
70 | sleep (1); /* allow ARM to start */ | ||
71 | #endif | ||
72 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
73 | GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); | ||
74 | } | ||
75 | |||
76 | |||
77 | static void | ||
78 | stop_arm (struct PeerContext *p) | ||
79 | { | ||
80 | #if START_ARM | ||
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); | ||
87 | #endif | ||
88 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
89 | } | ||
90 | |||
91 | |||
92 | static void | ||
93 | spcb (void *cls, | ||
94 | const char *name, | ||
95 | const GNUNET_HashCode * key) | ||
96 | { | ||
97 | } | ||
98 | |||
99 | |||
100 | static void | ||
101 | publish_cont (void *cls, | ||
102 | const struct GNUNET_FS_Uri *uri, | ||
103 | const char *emsg) | ||
104 | { | ||
105 | struct GNUNET_FS_SearchContext *search; | ||
106 | |||
107 | GNUNET_assert (NULL == emsg); | ||
108 | fprintf (stderr, "Starting namespace search...\n"); | ||
109 | search = GNUNET_FS_search_start (fs, uri, 1); | ||
110 | } | ||
111 | |||
112 | |||
113 | static void | ||
114 | testNamespace () | ||
115 | { | ||
116 | struct GNUNET_FS_Namespace *ns; | ||
117 | struct GNUNET_FS_Uri *adv; | ||
118 | struct GNUNET_FS_Uri *rootUri; | ||
119 | struct GNUNET_CONTAINER_MetaData *meta; | ||
120 | struct GNUNET_TIME_Absolute expiration; | ||
121 | |||
122 | expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | ||
123 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
124 | adv = GNUNET_FS_uri_ksk_create ("testNamespace", NULL); | ||
125 | ns = GNUNET_FS_namespace_create (fs, | ||
126 | "testNamespace"); | ||
127 | rootUri = GNUNET_FS_namespace_advertise (fs, | ||
128 | ns, | ||
129 | meta, | ||
130 | 1, 1, | ||
131 | expiration, | ||
132 | adv, | ||
133 | "root"); | ||
134 | GNUNET_assert (NULL != rootUri); | ||
135 | GNUNET_FS_publish_sks (fs, | ||
136 | ns, | ||
137 | "this", | ||
138 | "next", | ||
139 | meta, | ||
140 | rootUri, | ||
141 | expiration, | ||
142 | 1, 1, | ||
143 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
144 | &publish_cont, | ||
145 | NULL); | ||
146 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
147 | } | ||
148 | |||
149 | #if 0 | ||
150 | fprintf (stderr, "Completed namespace search...\n"); | ||
151 | GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (NULL, cfg, &pid)); | ||
152 | GNUNET_assert (GNUNET_SYSERR == GNUNET_FS_namespace_delete (NULL, cfg, &pid)); | ||
153 | GNUNET_FS_uri_destroy (rootURI); | ||
154 | GNUNET_FS_uri_destroy (advURI); | ||
155 | GNUNET_assert (match == 1); | ||
156 | return 0; | ||
157 | } | ||
158 | #endif | ||
159 | |||
160 | |||
161 | static void | ||
162 | run (void *cls, | ||
163 | struct GNUNET_SCHEDULER_Handle *s, | ||
164 | char *const *args, | ||
165 | const char *cfgfile, | ||
166 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
167 | { | ||
168 | sched = s; | ||
169 | setup_peer (&p1, "test_fs_download_data.conf"); | ||
170 | fs = GNUNET_FS_start (sched, | ||
171 | cfg, | ||
172 | "test-fs-namespace", | ||
173 | &progress_cb, | ||
174 | NULL, | ||
175 | GNUNET_FS_FLAGS_NONE, | ||
176 | GNUNET_FS_OPTIONS_END); | ||
177 | testNamespace (); | ||
178 | } | ||
179 | |||
180 | |||
181 | int | ||
182 | main (int argc, char *argv[]) | ||
183 | { | ||
184 | char *const argvx[] = { | ||
185 | "test-fs-namespace", | ||
186 | "-c", | ||
187 | "test_fs_namespace_data.conf", | ||
188 | #if VERBOSE | ||
189 | "-L", "DEBUG", | ||
190 | #endif | ||
191 | NULL | ||
192 | }; | ||
193 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
194 | GNUNET_GETOPT_OPTION_END | ||
195 | }; | ||
196 | |||
197 | GNUNET_log_setup ("test_fs_namespace", | ||
198 | #if VERBOSE | ||
199 | "DEBUG", | ||
200 | #else | ||
201 | "WARNING", | ||
202 | #endif | ||
203 | NULL); | ||
204 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | ||
205 | argvx, "test-fs-namespace", | ||
206 | "nohelp", options, &run, NULL); | ||
207 | stop_arm (&p1); | ||
208 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/"); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | |||
213 | |||
214 | /* end of test_fs_namespace.c */ | ||