2 This file is part of GNUnet.
3 (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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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, const struct GNUNET_SCHEDULER_TaskContext *tc)
82 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
83 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
88 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
93 switch (event->status)
95 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
96 ret = event->value.publish.cctx;
97 printf ("Publish complete, %llu kbps.\n",
98 (unsigned long long) (FILESIZE * 1000000LL /
100 GNUNET_TIME_absolute_get_duration
101 (start).rel_value_us) / 1024));
102 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
103 GNUNET_SCHEDULER_add_continuation (&list_indexed_task, NULL,
104 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
107 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
108 ret = event->value.publish.cctx;
109 GNUNET_assert (publish == event->value.publish.pc);
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
112 (unsigned long long) event->value.publish.completed,
113 (unsigned long long) event->value.publish.size,
114 event->value.publish.specifics.progress.depth,
115 (unsigned long long) event->value.publish.specifics.
118 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
119 ret = event->value.publish.cctx;
121 case GNUNET_FS_STATUS_PUBLISH_ERROR:
122 ret = event->value.publish.cctx;
123 FPRINTF (stderr, "Error publishing file: %s\n",
124 event->value.publish.specifics.error.message);
126 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
127 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
128 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
130 case GNUNET_FS_STATUS_PUBLISH_START:
131 ret = event->value.publish.cctx;
132 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
135 strcmp ("list_indexed-context-dir",
136 event->value.publish.pctx));
137 GNUNET_assert (FILESIZE == event->value.publish.size);
138 GNUNET_assert (0 == event->value.publish.completed);
139 GNUNET_assert (1 == event->value.publish.anonymity);
141 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
144 strcmp ("list_indexed-context-dir",
145 event->value.publish.pctx));
146 GNUNET_assert (FILESIZE == event->value.publish.size);
147 GNUNET_assert (0 == event->value.publish.completed);
148 GNUNET_assert (2 == event->value.publish.anonymity);
151 strcmp ("list_indexed-context-dir", event->value.publish.cctx))
153 GNUNET_assert (0 == event->value.publish.completed);
154 GNUNET_assert (3 == event->value.publish.anonymity);
159 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
160 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
162 GNUNET_assert (publish == event->value.publish.pc);
167 printf ("Unexpected event: %d\n", event->status);
176 const struct GNUNET_CONFIGURATION_Handle *cfg,
177 struct GNUNET_TESTING_Peer *peer)
179 const char *keywords[] = {
184 struct GNUNET_CONTAINER_MetaData *meta;
185 struct GNUNET_FS_Uri *kuri;
186 struct GNUNET_FS_FileInformation *fi1;
187 struct GNUNET_FS_FileInformation *fi2;
188 struct GNUNET_FS_FileInformation *fidir;
190 struct GNUNET_FS_BlockOptions bo;
192 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL,
193 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
194 GNUNET_assert (NULL != fs);
195 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
196 buf = GNUNET_malloc (FILESIZE);
197 for (i = 0; i < FILESIZE; i++)
198 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
199 GNUNET_assert (FILESIZE ==
200 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
201 GNUNET_DISK_PERM_USER_READ |
202 GNUNET_DISK_PERM_USER_WRITE));
205 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
206 buf = GNUNET_malloc (FILESIZE);
207 for (i = 0; i < FILESIZE; i++)
208 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
209 GNUNET_assert (FILESIZE ==
210 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
211 GNUNET_DISK_PERM_USER_READ |
212 GNUNET_DISK_PERM_USER_WRITE));
215 meta = GNUNET_CONTAINER_meta_data_create ();
216 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
217 bo.content_priority = 42;
218 bo.anonymity_level = 1;
219 bo.replication_level = 0;
220 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
222 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1",
223 fn1, kuri, meta, GNUNET_YES,
225 GNUNET_assert (NULL != fi1);
226 bo.anonymity_level = 2;
228 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2",
229 fn2, kuri, meta, GNUNET_YES,
231 GNUNET_assert (NULL != fi2);
232 bo.anonymity_level = 3;
234 GNUNET_FS_file_information_create_empty_directory (fs,
235 "list_indexed-context-dir",
236 kuri, meta, &bo, NULL);
237 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
238 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
239 GNUNET_FS_uri_destroy (kuri);
240 GNUNET_CONTAINER_meta_data_destroy (meta);
241 GNUNET_assert (NULL != fidir);
242 start = GNUNET_TIME_absolute_get ();
244 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
245 GNUNET_FS_PUBLISH_OPTION_NONE);
246 GNUNET_assert (publish != NULL);
251 main (int argc, char *argv[])
253 if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed",
254 "test_fs_list_indexed_data.conf",
260 /* end of test_fs_list_indexed.c */