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 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.
17 * @file fs/test_fs_list_indexed.c
18 * @brief simple testcase for list_indexed operation (indexing, listing
20 * @author Christian Grothoff
23 * - actually call list_indexed API!
26 #include "gnunet_util_lib.h"
27 #include "gnunet_testing_lib.h"
28 #include "gnunet_fs_service.h"
31 * File-size we use for testing.
33 #define FILESIZE (1024 * 1024 * 2)
36 * How long until we give up on transmitting the message?
38 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
41 * How long should our test-content live?
43 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
46 static struct GNUNET_TIME_Absolute start;
48 static struct GNUNET_FS_Handle *fs;
50 static struct GNUNET_FS_PublishContext *publish;
60 abort_publish_task (void *cls)
62 GNUNET_FS_publish_stop (publish);
64 GNUNET_DISK_directory_remove (fn1);
67 GNUNET_DISK_directory_remove (fn2);
74 list_indexed_task (void *cls)
76 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
81 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
86 switch (event->status)
88 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
89 ret = event->value.publish.cctx;
90 printf ("Publish complete, %llu kbps.\n",
91 (unsigned long long) (FILESIZE * 1000000LL /
93 GNUNET_TIME_absolute_get_duration
94 (start).rel_value_us) / 1024));
95 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
96 GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL);
99 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
100 ret = event->value.publish.cctx;
101 GNUNET_assert (publish == event->value.publish.pc);
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
104 (unsigned long long) event->value.publish.completed,
105 (unsigned long long) event->value.publish.size,
106 event->value.publish.specifics.progress.depth,
107 (unsigned long long) event->value.publish.specifics.
110 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
111 ret = event->value.publish.cctx;
113 case GNUNET_FS_STATUS_PUBLISH_ERROR:
114 ret = event->value.publish.cctx;
115 FPRINTF (stderr, "Error publishing file: %s\n",
116 event->value.publish.specifics.error.message);
118 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
119 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
121 case GNUNET_FS_STATUS_PUBLISH_START:
122 ret = event->value.publish.cctx;
123 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
126 strcmp ("list_indexed-context-dir",
127 event->value.publish.pctx));
128 GNUNET_assert (FILESIZE == event->value.publish.size);
129 GNUNET_assert (0 == event->value.publish.completed);
130 GNUNET_assert (1 == event->value.publish.anonymity);
132 else if (0 == strcmp ("list_indexed-context2", 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 (2 == event->value.publish.anonymity);
142 strcmp ("list_indexed-context-dir", event->value.publish.cctx))
144 GNUNET_assert (0 == event->value.publish.completed);
145 GNUNET_assert (3 == event->value.publish.anonymity);
150 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
151 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
153 GNUNET_assert (publish == event->value.publish.pc);
158 printf ("Unexpected event: %d\n", event->status);
167 const struct GNUNET_CONFIGURATION_Handle *cfg,
168 struct GNUNET_TESTING_Peer *peer)
170 const char *keywords[] = {
175 struct GNUNET_CONTAINER_MetaData *meta;
176 struct GNUNET_FS_Uri *kuri;
177 struct GNUNET_FS_FileInformation *fi1;
178 struct GNUNET_FS_FileInformation *fi2;
179 struct GNUNET_FS_FileInformation *fidir;
181 struct GNUNET_FS_BlockOptions bo;
183 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL,
184 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
185 GNUNET_assert (NULL != fs);
186 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
187 buf = GNUNET_malloc (FILESIZE);
188 for (i = 0; i < FILESIZE; i++)
189 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
190 GNUNET_assert (FILESIZE ==
191 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
192 GNUNET_DISK_PERM_USER_READ |
193 GNUNET_DISK_PERM_USER_WRITE));
196 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
197 buf = GNUNET_malloc (FILESIZE);
198 for (i = 0; i < FILESIZE; i++)
199 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
200 GNUNET_assert (FILESIZE ==
201 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
202 GNUNET_DISK_PERM_USER_READ |
203 GNUNET_DISK_PERM_USER_WRITE));
206 meta = GNUNET_CONTAINER_meta_data_create ();
207 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
208 bo.content_priority = 42;
209 bo.anonymity_level = 1;
210 bo.replication_level = 0;
211 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
213 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1",
214 fn1, kuri, meta, GNUNET_YES,
216 GNUNET_assert (NULL != fi1);
217 bo.anonymity_level = 2;
219 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2",
220 fn2, kuri, meta, GNUNET_YES,
222 GNUNET_assert (NULL != fi2);
223 bo.anonymity_level = 3;
225 GNUNET_FS_file_information_create_empty_directory (fs,
226 "list_indexed-context-dir",
227 kuri, meta, &bo, NULL);
228 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
229 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
230 GNUNET_FS_uri_destroy (kuri);
231 GNUNET_CONTAINER_meta_data_destroy (meta);
232 GNUNET_assert (NULL != fidir);
233 start = GNUNET_TIME_absolute_get ();
235 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
236 GNUNET_FS_PUBLISH_OPTION_NONE);
237 GNUNET_assert (publish != NULL);
242 main (int argc, char *argv[])
244 if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed",
245 "test_fs_list_indexed_data.conf",
251 /* end of test_fs_list_indexed.c */