2 This file is part of GNUnet.
3 Copyright (C) 2004, 2005, 2006, 2008, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file fs/test_fs_list_indexed.c
21 * @brief simple testcase for list_indexed operation (indexing, listing
23 * @author Christian Grothoff
26 * - actually call list_indexed API!
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testing_lib.h"
31 #include "gnunet_fs_service.h"
34 * File-size we use for testing.
36 #define FILESIZE (1024 * 1024 * 2)
39 * How long until we give up on transmitting the message?
41 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
44 * How long should our test-content live?
46 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
49 static struct GNUNET_TIME_Absolute start;
51 static struct GNUNET_FS_Handle *fs;
53 static struct GNUNET_FS_PublishContext *publish;
63 abort_publish_task (void *cls)
65 GNUNET_FS_publish_stop (publish);
67 GNUNET_DISK_directory_remove (fn1);
70 GNUNET_DISK_directory_remove (fn2);
77 list_indexed_task (void *cls)
79 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
84 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
89 switch (event->status)
91 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
92 ret = event->value.publish.cctx;
93 printf ("Publish complete, %llu kbps.\n",
94 (unsigned long long) (FILESIZE * 1000000LL /
96 GNUNET_TIME_absolute_get_duration
97 (start).rel_value_us) / 1024));
98 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
99 GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL);
102 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
103 ret = event->value.publish.cctx;
104 GNUNET_assert (publish == event->value.publish.pc);
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
106 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
107 (unsigned long long) event->value.publish.completed,
108 (unsigned long long) event->value.publish.size,
109 event->value.publish.specifics.progress.depth,
110 (unsigned long long) event->value.publish.specifics.
113 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
114 ret = event->value.publish.cctx;
116 case GNUNET_FS_STATUS_PUBLISH_ERROR:
117 ret = event->value.publish.cctx;
118 FPRINTF (stderr, "Error publishing file: %s\n",
119 event->value.publish.specifics.error.message);
121 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
122 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
124 case GNUNET_FS_STATUS_PUBLISH_START:
125 ret = event->value.publish.cctx;
126 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
129 strcmp ("list_indexed-context-dir",
130 event->value.publish.pctx));
131 GNUNET_assert (FILESIZE == event->value.publish.size);
132 GNUNET_assert (0 == event->value.publish.completed);
133 GNUNET_assert (1 == event->value.publish.anonymity);
135 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
138 strcmp ("list_indexed-context-dir",
139 event->value.publish.pctx));
140 GNUNET_assert (FILESIZE == event->value.publish.size);
141 GNUNET_assert (0 == event->value.publish.completed);
142 GNUNET_assert (2 == event->value.publish.anonymity);
145 strcmp ("list_indexed-context-dir", event->value.publish.cctx))
147 GNUNET_assert (0 == event->value.publish.completed);
148 GNUNET_assert (3 == event->value.publish.anonymity);
153 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
154 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
156 GNUNET_assert (publish == event->value.publish.pc);
161 printf ("Unexpected event: %d\n", event->status);
170 const struct GNUNET_CONFIGURATION_Handle *cfg,
171 struct GNUNET_TESTING_Peer *peer)
173 const char *keywords[] = {
178 struct GNUNET_CONTAINER_MetaData *meta;
179 struct GNUNET_FS_Uri *kuri;
180 struct GNUNET_FS_FileInformation *fi1;
181 struct GNUNET_FS_FileInformation *fi2;
182 struct GNUNET_FS_FileInformation *fidir;
184 struct GNUNET_FS_BlockOptions bo;
186 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL,
187 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
188 GNUNET_assert (NULL != fs);
189 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
190 buf = GNUNET_malloc (FILESIZE);
191 for (i = 0; i < FILESIZE; i++)
192 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
193 GNUNET_assert (FILESIZE ==
194 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
195 GNUNET_DISK_PERM_USER_READ |
196 GNUNET_DISK_PERM_USER_WRITE));
199 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
200 buf = GNUNET_malloc (FILESIZE);
201 for (i = 0; i < FILESIZE; i++)
202 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
203 GNUNET_assert (FILESIZE ==
204 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
205 GNUNET_DISK_PERM_USER_READ |
206 GNUNET_DISK_PERM_USER_WRITE));
209 meta = GNUNET_CONTAINER_meta_data_create ();
210 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
211 bo.content_priority = 42;
212 bo.anonymity_level = 1;
213 bo.replication_level = 0;
214 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
216 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1",
217 fn1, kuri, meta, GNUNET_YES,
219 GNUNET_assert (NULL != fi1);
220 bo.anonymity_level = 2;
222 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2",
223 fn2, kuri, meta, GNUNET_YES,
225 GNUNET_assert (NULL != fi2);
226 bo.anonymity_level = 3;
228 GNUNET_FS_file_information_create_empty_directory (fs,
229 "list_indexed-context-dir",
230 kuri, meta, &bo, NULL);
231 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
232 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
233 GNUNET_FS_uri_destroy (kuri);
234 GNUNET_CONTAINER_meta_data_destroy (meta);
235 GNUNET_assert (NULL != fidir);
236 start = GNUNET_TIME_absolute_get ();
238 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
239 GNUNET_FS_PUBLISH_OPTION_NONE);
240 GNUNET_assert (publish != NULL);
245 main (int argc, char *argv[])
247 if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed",
248 "test_fs_list_indexed_data.conf",
254 /* end of test_fs_list_indexed.c */