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_unindex.c
21 * @brief simple testcase for simple publish + unindex operation
22 * @author Christian Grothoff
25 #include "gnunet_util_lib.h"
26 #include "gnunet_fs_service.h"
27 #include "gnunet_testing_lib.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_UnindexContext *unindex;
52 static struct GNUNET_FS_PublishContext *publish;
58 abort_publish_task (void *cls)
60 GNUNET_FS_publish_stop (publish);
66 abort_unindex_task (void *cls)
68 GNUNET_FS_unindex_stop (unindex);
70 GNUNET_DISK_directory_remove (fn);
77 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
80 switch (event->status)
82 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
85 (unsigned long long) event->value.publish.completed,
86 (unsigned long long) event->value.publish.size,
87 event->value.publish.specifics.progress.depth,
88 (unsigned long long) event->value.publish.specifics.
91 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
93 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
94 printf ("Publishing complete, %llu kbps.\n",
95 (unsigned long long) (FILESIZE * 1000000LL /
97 GNUNET_TIME_absolute_get_duration
98 (start).rel_value_us) / 1024));
99 start = GNUNET_TIME_absolute_get ();
100 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
101 GNUNET_assert (unindex != NULL);
103 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
104 printf ("Unindex complete, %llu kbps.\n",
105 (unsigned long long) (FILESIZE * 1000000LL /
107 GNUNET_TIME_absolute_get_duration
108 (start).rel_value_us) / 1024));
109 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
111 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
112 GNUNET_assert (unindex == event->value.unindex.uc);
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
114 "Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
115 (unsigned long long) event->value.unindex.completed,
116 (unsigned long long) event->value.unindex.size,
117 event->value.unindex.specifics.progress.depth,
118 (unsigned long long) event->value.unindex.specifics.
121 case GNUNET_FS_STATUS_PUBLISH_ERROR:
122 FPRINTF (stderr, "Error publishing file: %s\n",
123 event->value.publish.specifics.error.message);
125 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
127 case GNUNET_FS_STATUS_UNINDEX_ERROR:
128 FPRINTF (stderr, "Error unindexing file: %s\n",
129 event->value.unindex.specifics.error.message);
130 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
132 case GNUNET_FS_STATUS_PUBLISH_START:
133 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
134 GNUNET_assert (NULL == event->value.publish.pctx);
135 GNUNET_assert (FILESIZE == event->value.publish.size);
136 GNUNET_assert (0 == event->value.publish.completed);
137 GNUNET_assert (1 == event->value.publish.anonymity);
139 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
140 GNUNET_assert (publish == event->value.publish.pc);
141 GNUNET_assert (FILESIZE == event->value.publish.size);
142 GNUNET_assert (1 == event->value.publish.anonymity);
146 case GNUNET_FS_STATUS_UNINDEX_START:
147 GNUNET_assert (unindex == NULL);
148 GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
149 GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
150 GNUNET_assert (FILESIZE == event->value.unindex.size);
151 GNUNET_assert (0 == event->value.unindex.completed);
153 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
154 GNUNET_assert (unindex == event->value.unindex.uc);
155 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
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 *fi;
179 struct GNUNET_FS_BlockOptions bo;
181 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
182 fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL,
183 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
184 GNUNET_assert (NULL != fs);
185 buf = GNUNET_malloc (FILESIZE);
186 for (i = 0; i < FILESIZE; i++)
187 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
188 GNUNET_assert (FILESIZE ==
189 GNUNET_DISK_fn_write (fn, buf, FILESIZE,
190 GNUNET_DISK_PERM_USER_READ |
191 GNUNET_DISK_PERM_USER_WRITE));
193 meta = GNUNET_CONTAINER_meta_data_create ();
194 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
195 bo.content_priority = 42;
196 bo.anonymity_level = 1;
197 bo.replication_level = 0;
198 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
199 fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn,
200 kuri, meta, GNUNET_YES,
202 GNUNET_FS_uri_destroy (kuri);
203 GNUNET_CONTAINER_meta_data_destroy (meta);
204 GNUNET_assert (NULL != fi);
205 start = GNUNET_TIME_absolute_get ();
207 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
208 GNUNET_FS_PUBLISH_OPTION_NONE);
209 GNUNET_assert (publish != NULL);
214 main (int argc, char *argv[])
216 if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex",
217 "test_fs_unindex_data.conf",
223 /* end of test_fs_unindex.c */