2 This file is part of GNUnet.
3 Copyright (C) 2004, 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 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file fs/test_fs_list_indexed.c
23 * @brief simple testcase for list_indexed operation (indexing, listing
25 * @author Christian Grothoff
28 * - actually call list_indexed API!
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib.h"
33 #include "gnunet_fs_service.h"
36 * File-size we use for testing.
38 #define FILESIZE (1024 * 1024 * 2)
41 * How long until we give up on transmitting the message?
43 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
46 * How long should our test-content live?
48 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 static struct GNUNET_TIME_Absolute start;
53 static struct GNUNET_FS_Handle *fs;
55 static struct GNUNET_FS_PublishContext *publish;
65 abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67 GNUNET_FS_publish_stop (publish);
69 GNUNET_DISK_directory_remove (fn1);
72 GNUNET_DISK_directory_remove (fn2);
79 list_indexed_task (void *cls,
80 const struct GNUNET_SCHEDULER_TaskContext *tc)
82 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
87 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
92 switch (event->status)
94 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
95 ret = event->value.publish.cctx;
96 printf ("Publish complete, %llu kbps.\n",
97 (unsigned long long) (FILESIZE * 1000000LL /
99 GNUNET_TIME_absolute_get_duration
100 (start).rel_value_us) / 1024));
101 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
102 GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL);
105 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
106 ret = event->value.publish.cctx;
107 GNUNET_assert (publish == event->value.publish.pc);
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
110 (unsigned long long) event->value.publish.completed,
111 (unsigned long long) event->value.publish.size,
112 event->value.publish.specifics.progress.depth,
113 (unsigned long long) event->value.publish.specifics.
116 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
117 ret = event->value.publish.cctx;
119 case GNUNET_FS_STATUS_PUBLISH_ERROR:
120 ret = event->value.publish.cctx;
121 FPRINTF (stderr, "Error publishing file: %s\n",
122 event->value.publish.specifics.error.message);
124 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
125 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
127 case GNUNET_FS_STATUS_PUBLISH_START:
128 ret = event->value.publish.cctx;
129 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
132 strcmp ("list_indexed-context-dir",
133 event->value.publish.pctx));
134 GNUNET_assert (FILESIZE == event->value.publish.size);
135 GNUNET_assert (0 == event->value.publish.completed);
136 GNUNET_assert (1 == event->value.publish.anonymity);
138 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
141 strcmp ("list_indexed-context-dir",
142 event->value.publish.pctx));
143 GNUNET_assert (FILESIZE == event->value.publish.size);
144 GNUNET_assert (0 == event->value.publish.completed);
145 GNUNET_assert (2 == event->value.publish.anonymity);
148 strcmp ("list_indexed-context-dir", event->value.publish.cctx))
150 GNUNET_assert (0 == event->value.publish.completed);
151 GNUNET_assert (3 == event->value.publish.anonymity);
156 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
157 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
159 GNUNET_assert (publish == event->value.publish.pc);
164 printf ("Unexpected event: %d\n", event->status);
173 const struct GNUNET_CONFIGURATION_Handle *cfg,
174 struct GNUNET_TESTING_Peer *peer)
176 const char *keywords[] = {
181 struct GNUNET_CONTAINER_MetaData *meta;
182 struct GNUNET_FS_Uri *kuri;
183 struct GNUNET_FS_FileInformation *fi1;
184 struct GNUNET_FS_FileInformation *fi2;
185 struct GNUNET_FS_FileInformation *fidir;
187 struct GNUNET_FS_BlockOptions bo;
189 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL,
190 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
191 GNUNET_assert (NULL != fs);
192 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
193 buf = GNUNET_malloc (FILESIZE);
194 for (i = 0; i < FILESIZE; i++)
195 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
196 GNUNET_assert (FILESIZE ==
197 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
198 GNUNET_DISK_PERM_USER_READ |
199 GNUNET_DISK_PERM_USER_WRITE));
202 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
203 buf = GNUNET_malloc (FILESIZE);
204 for (i = 0; i < FILESIZE; i++)
205 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
206 GNUNET_assert (FILESIZE ==
207 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
208 GNUNET_DISK_PERM_USER_READ |
209 GNUNET_DISK_PERM_USER_WRITE));
212 meta = GNUNET_CONTAINER_meta_data_create ();
213 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
214 bo.content_priority = 42;
215 bo.anonymity_level = 1;
216 bo.replication_level = 0;
217 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
219 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1",
220 fn1, kuri, meta, GNUNET_YES,
222 GNUNET_assert (NULL != fi1);
223 bo.anonymity_level = 2;
225 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2",
226 fn2, kuri, meta, GNUNET_YES,
228 GNUNET_assert (NULL != fi2);
229 bo.anonymity_level = 3;
231 GNUNET_FS_file_information_create_empty_directory (fs,
232 "list_indexed-context-dir",
233 kuri, meta, &bo, NULL);
234 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
235 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
236 GNUNET_FS_uri_destroy (kuri);
237 GNUNET_CONTAINER_meta_data_destroy (meta);
238 GNUNET_assert (NULL != fidir);
239 start = GNUNET_TIME_absolute_get ();
241 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
242 GNUNET_FS_PUBLISH_OPTION_NONE);
243 GNUNET_assert (publish != NULL);
248 main (int argc, char *argv[])
250 if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed",
251 "test_fs_list_indexed_data.conf",
257 /* end of test_fs_list_indexed.c */