aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_list_indexed.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/test_fs_list_indexed.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/test_fs_list_indexed.c')
-rw-r--r--src/fs/test_fs_list_indexed.c280
1 files changed, 134 insertions, 146 deletions
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index b46ebf52d..e3330f3ba 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -49,7 +49,7 @@
49 49
50/** 50/**
51 * How long should our test-content live? 51 * How long should our test-content live?
52 */ 52 */
53#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 53#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
54 54
55struct PeerContext 55struct PeerContext
@@ -75,8 +75,7 @@ static char *fn2;
75static int err; 75static int err;
76 76
77static void 77static void
78abort_publish_task (void *cls, 78abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79 const struct GNUNET_SCHEDULER_TaskContext *tc)
80{ 79{
81 GNUNET_FS_publish_stop (publish); 80 GNUNET_FS_publish_stop (publish);
82 publish = NULL; 81 publish = NULL;
@@ -90,101 +89,96 @@ abort_publish_task (void *cls,
90 89
91 90
92static void 91static void
93list_indexed_task (void *cls, 92list_indexed_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 93{
96 94
97 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 95 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
98 NULL, 96 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
99 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
100} 97}
101 98
102 99
103static void * 100static void *
104progress_cb (void *cls, 101progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
105 const struct GNUNET_FS_ProgressInfo *event)
106{ 102{
107 void *ret; 103 void *ret;
108 104
109 ret = NULL; 105 ret = NULL;
110 switch (event->status) 106 switch (event->status)
111 { 107 {
112 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 108 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
113 ret = event->value.publish.cctx; 109 ret = event->value.publish.cctx;
114 printf ("Publish complete, %llu kbps.\n", 110 printf ("Publish complete, %llu kbps.\n",
115 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 111 (unsigned long long) (FILESIZE * 1000 /
116 if (0 == strcmp ("list_indexed-context-dir", 112 (1 +
117 event->value.publish.cctx)) 113 GNUNET_TIME_absolute_get_duration
118 GNUNET_SCHEDULER_add_continuation (&list_indexed_task, 114 (start).rel_value) / 1024));
119 NULL, 115 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
120 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 116 GNUNET_SCHEDULER_add_continuation (&list_indexed_task,
121 117 NULL,
122 break; 118 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
123 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 119
124 ret = event->value.publish.cctx; 120 break;
125 GNUNET_assert (publish == event->value.publish.pc); 121 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
122 ret = event->value.publish.cctx;
123 GNUNET_assert (publish == event->value.publish.pc);
126#if VERBOSE 124#if VERBOSE
127 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 125 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
128 (unsigned long long) event->value.publish.completed, 126 (unsigned long long) event->value.publish.completed,
129 (unsigned long long) event->value.publish.size, 127 (unsigned long long) event->value.publish.size,
130 event->value.publish.specifics.progress.depth, 128 event->value.publish.specifics.progress.depth,
131 (unsigned long long) event->value.publish.specifics.progress.offset); 129 (unsigned long long) event->value.publish.specifics.
130 progress.offset);
132#endif 131#endif
133 break; 132 break;
134 case GNUNET_FS_STATUS_PUBLISH_ERROR: 133 case GNUNET_FS_STATUS_PUBLISH_ERROR:
135 ret = event->value.publish.cctx; 134 ret = event->value.publish.cctx;
136 fprintf (stderr, 135 fprintf (stderr,
137 "Error publishing file: %s\n", 136 "Error publishing file: %s\n",
138 event->value.publish.specifics.error.message); 137 event->value.publish.specifics.error.message);
139 err = 1; 138 err = 1;
140 if (0 == strcmp ("list_indexed-context-dir", 139 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
141 event->value.publish.cctx)) 140 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
142 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 141 NULL,
143 NULL, 142 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
144 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 143 break;
145 break; 144 case GNUNET_FS_STATUS_PUBLISH_START:
146 case GNUNET_FS_STATUS_PUBLISH_START: 145 ret = event->value.publish.cctx;
147 ret = event->value.publish.cctx; 146 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
148 if (0 == strcmp ("list_indexed-context1", 147 {
149 event->value.publish.cctx)) 148 GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
150 { 149 event->value.publish.pctx));
151 GNUNET_assert (0 == strcmp ("list_indexed-context-dir", 150 GNUNET_assert (FILESIZE == event->value.publish.size);
152 event->value.publish.pctx)); 151 GNUNET_assert (0 == event->value.publish.completed);
153 GNUNET_assert (FILESIZE == event->value.publish.size); 152 GNUNET_assert (1 == event->value.publish.anonymity);
154 GNUNET_assert (0 == event->value.publish.completed);
155 GNUNET_assert (1 == event->value.publish.anonymity);
156 }
157 else if (0 == strcmp ("list_indexed-context2",
158 event->value.publish.cctx))
159 {
160 GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
161 event->value.publish.pctx));
162 GNUNET_assert (FILESIZE == event->value.publish.size);
163 GNUNET_assert (0 == event->value.publish.completed);
164 GNUNET_assert (2 == event->value.publish.anonymity);
165 }
166 else if (0 == strcmp ("list_indexed-context-dir",
167 event->value.publish.cctx))
168 {
169 GNUNET_assert (0 == event->value.publish.completed);
170 GNUNET_assert (3 == event->value.publish.anonymity);
171 }
172 else
173 GNUNET_assert (0);
174 break;
175 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
176 if (0 == strcmp ("list_indexed-context-dir",
177 event->value.publish.cctx))
178 {
179 GNUNET_assert (publish == event->value.publish.pc);
180 publish = NULL;
181 }
182 break;
183 default:
184 printf ("Unexpected event: %d\n",
185 event->status);
186 break;
187 } 153 }
154 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
155 {
156 GNUNET_assert (0 == strcmp ("list_indexed-context-dir",
157 event->value.publish.pctx));
158 GNUNET_assert (FILESIZE == event->value.publish.size);
159 GNUNET_assert (0 == event->value.publish.completed);
160 GNUNET_assert (2 == event->value.publish.anonymity);
161 }
162 else if (0 == strcmp ("list_indexed-context-dir",
163 event->value.publish.cctx))
164 {
165 GNUNET_assert (0 == event->value.publish.completed);
166 GNUNET_assert (3 == event->value.publish.anonymity);
167 }
168 else
169 GNUNET_assert (0);
170 break;
171 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
172 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
173 {
174 GNUNET_assert (publish == event->value.publish.pc);
175 publish = NULL;
176 }
177 break;
178 default:
179 printf ("Unexpected event: %d\n", event->status);
180 break;
181 }
188 return ret; 182 return ret;
189} 183}
190 184
@@ -195,11 +189,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
195 p->cfg = GNUNET_CONFIGURATION_create (); 189 p->cfg = GNUNET_CONFIGURATION_create ();
196#if START_ARM 190#if START_ARM
197 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 191 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
198 "gnunet-service-arm", 192 "gnunet-service-arm",
199#if VERBOSE 193#if VERBOSE
200 "-L", "DEBUG", 194 "-L", "DEBUG",
201#endif 195#endif
202 "-c", cfgname, NULL); 196 "-c", cfgname, NULL);
203#endif 197#endif
204 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 198 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
205} 199}
@@ -210,16 +204,17 @@ stop_arm (struct PeerContext *p)
210{ 204{
211#if START_ARM 205#if START_ARM
212 if (NULL != p->arm_proc) 206 if (NULL != p->arm_proc)
213 { 207 {
214 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 208 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
215 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
216 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 210 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
217 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 211 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
219 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 213 "ARM process %u stopped\n",
220 GNUNET_OS_process_close (p->arm_proc); 214 GNUNET_OS_process_get_pid (p->arm_proc));
221 p->arm_proc = NULL; 215 GNUNET_OS_process_close (p->arm_proc);
222 } 216 p->arm_proc = NULL;
217 }
223#endif 218#endif
224 GNUNET_CONFIGURATION_destroy (p->cfg); 219 GNUNET_CONFIGURATION_destroy (p->cfg);
225} 220}
@@ -228,8 +223,7 @@ stop_arm (struct PeerContext *p)
228static void 223static void
229run (void *cls, 224run (void *cls,
230 char *const *args, 225 char *const *args,
231 const char *cfgfile, 226 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
232 const struct GNUNET_CONFIGURATION_Handle *cfg)
233{ 227{
234 const char *keywords[] = { 228 const char *keywords[] = {
235 "down_foo", 229 "down_foo",
@@ -246,21 +240,20 @@ run (void *cls,
246 240
247 setup_peer (&p1, "test_fs_list_indexed_data.conf"); 241 setup_peer (&p1, "test_fs_list_indexed_data.conf");
248 fs = GNUNET_FS_start (cfg, 242 fs = GNUNET_FS_start (cfg,
249 "test-fs-list_indexed", 243 "test-fs-list_indexed",
250 &progress_cb, 244 &progress_cb,
251 NULL, 245 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
252 GNUNET_FS_FLAGS_NONE, 246 GNUNET_assert (NULL != fs);
253 GNUNET_FS_OPTIONS_END);
254 GNUNET_assert (NULL != fs);
255 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 247 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
256 buf = GNUNET_malloc (FILESIZE); 248 buf = GNUNET_malloc (FILESIZE);
257 for (i = 0; i < FILESIZE; i++) 249 for (i = 0; i < FILESIZE; i++)
258 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 250 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
259 GNUNET_assert (FILESIZE == 251 GNUNET_assert (FILESIZE ==
260 GNUNET_DISK_fn_write (fn1, 252 GNUNET_DISK_fn_write (fn1,
261 buf, 253 buf,
262 FILESIZE, 254 FILESIZE,
263 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 255 GNUNET_DISK_PERM_USER_READ |
256 GNUNET_DISK_PERM_USER_WRITE));
264 GNUNET_free (buf); 257 GNUNET_free (buf);
265 258
266 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 259 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
@@ -268,10 +261,11 @@ run (void *cls,
268 for (i = 0; i < FILESIZE; i++) 261 for (i = 0; i < FILESIZE; i++)
269 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 262 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
270 GNUNET_assert (FILESIZE == 263 GNUNET_assert (FILESIZE ==
271 GNUNET_DISK_fn_write (fn2, 264 GNUNET_DISK_fn_write (fn2,
272 buf, 265 buf,
273 FILESIZE, 266 FILESIZE,
274 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 267 GNUNET_DISK_PERM_USER_READ |
268 GNUNET_DISK_PERM_USER_WRITE));
275 GNUNET_free (buf); 269 GNUNET_free (buf);
276 270
277 meta = GNUNET_CONTAINER_meta_data_create (); 271 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -279,30 +273,24 @@ run (void *cls,
279 bo.content_priority = 42; 273 bo.content_priority = 42;
280 bo.anonymity_level = 1; 274 bo.anonymity_level = 1;
281 bo.replication_level = 0; 275 bo.replication_level = 0;
282 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 276 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
283 fi1 = GNUNET_FS_file_information_create_from_file (fs, 277 fi1 = GNUNET_FS_file_information_create_from_file (fs,
284 "list_indexed-context1", 278 "list_indexed-context1",
285 fn1, 279 fn1,
286 kuri, 280 kuri,
287 meta, 281 meta, GNUNET_YES, &bo);
288 GNUNET_YES,
289 &bo);
290 GNUNET_assert (NULL != fi1); 282 GNUNET_assert (NULL != fi1);
291 bo.anonymity_level = 2; 283 bo.anonymity_level = 2;
292 fi2 = GNUNET_FS_file_information_create_from_file (fs, 284 fi2 = GNUNET_FS_file_information_create_from_file (fs,
293 "list_indexed-context2", 285 "list_indexed-context2",
294 fn2, 286 fn2,
295 kuri, 287 kuri,
296 meta, 288 meta, GNUNET_YES, &bo);
297 GNUNET_YES,
298 &bo);
299 GNUNET_assert (NULL != fi2); 289 GNUNET_assert (NULL != fi2);
300 bo.anonymity_level = 3; 290 bo.anonymity_level = 3;
301 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 291 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
302 "list_indexed-context-dir", 292 "list_indexed-context-dir",
303 kuri, 293 kuri, meta, &bo);
304 meta,
305 &bo);
306 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 294 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
307 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 295 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
308 GNUNET_FS_uri_destroy (kuri); 296 GNUNET_FS_uri_destroy (kuri);
@@ -310,9 +298,9 @@ run (void *cls,
310 GNUNET_assert (NULL != fidir); 298 GNUNET_assert (NULL != fidir);
311 start = GNUNET_TIME_absolute_get (); 299 start = GNUNET_TIME_absolute_get ();
312 publish = GNUNET_FS_publish_start (fs, 300 publish = GNUNET_FS_publish_start (fs,
313 fidir, 301 fidir,
314 NULL, NULL, NULL, 302 NULL, NULL, NULL,
315 GNUNET_FS_PUBLISH_OPTION_NONE); 303 GNUNET_FS_PUBLISH_OPTION_NONE);
316 GNUNET_assert (publish != NULL); 304 GNUNET_assert (publish != NULL);
317} 305}
318 306
@@ -320,7 +308,7 @@ run (void *cls,
320int 308int
321main (int argc, char *argv[]) 309main (int argc, char *argv[])
322{ 310{
323 char *const argvx[] = { 311 char *const argvx[] = {
324 "test-fs-list_indexed", 312 "test-fs-list_indexed",
325 "-c", 313 "-c",
326 "test_fs_list_indexed_data.conf", 314 "test_fs_list_indexed_data.conf",
@@ -333,28 +321,28 @@ main (int argc, char *argv[])
333 GNUNET_GETOPT_OPTION_END 321 GNUNET_GETOPT_OPTION_END
334 }; 322 };
335 323
336 GNUNET_log_setup ("test_fs_list_indexed", 324 GNUNET_log_setup ("test_fs_list_indexed",
337#if VERBOSE 325#if VERBOSE
338 "DEBUG", 326 "DEBUG",
339#else 327#else
340 "WARNING", 328 "WARNING",
341#endif 329#endif
342 NULL); 330 NULL);
343 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 331 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
344 argvx, "test-fs-list_indexed", 332 argvx, "test-fs-list_indexed",
345 "nohelp", options, &run, NULL); 333 "nohelp", options, &run, NULL);
346 stop_arm (&p1); 334 stop_arm (&p1);
347 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/"); 335 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/");
348 if (fn1 != NULL) 336 if (fn1 != NULL)
349 { 337 {
350 GNUNET_DISK_directory_remove (fn1); 338 GNUNET_DISK_directory_remove (fn1);
351 GNUNET_free (fn1); 339 GNUNET_free (fn1);
352 } 340 }
353 if (fn2 != NULL) 341 if (fn2 != NULL)
354 { 342 {
355 GNUNET_DISK_directory_remove (fn2); 343 GNUNET_DISK_directory_remove (fn2);
356 GNUNET_free (fn2); 344 GNUNET_free (fn2);
357 } 345 }
358 return err; 346 return err;
359} 347}
360 348