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_unindex.c
18 * @brief simple testcase for simple publish + unindex operation
19 * @author Christian Grothoff
22 #include "gnunet_util_lib.h"
23 #include "gnunet_fs_service.h"
24 #include "gnunet_testing_lib.h"
28 * File-size we use for testing.
30 #define FILESIZE (1024 * 1024 * 2)
33 * How long until we give up on transmitting the message?
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
38 * How long should our test-content live?
40 #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
43 static struct GNUNET_TIME_Absolute start;
45 static struct GNUNET_FS_Handle *fs;
47 static struct GNUNET_FS_UnindexContext *unindex;
49 static struct GNUNET_FS_PublishContext *publish;
55 abort_publish_task (void *cls)
57 GNUNET_FS_publish_stop (publish);
63 abort_unindex_task (void *cls)
65 GNUNET_FS_unindex_stop (unindex);
67 GNUNET_DISK_directory_remove (fn);
74 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
77 switch (event->status)
79 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
82 (unsigned long long) event->value.publish.completed,
83 (unsigned long long) event->value.publish.size,
84 event->value.publish.specifics.progress.depth,
85 (unsigned long long) event->value.publish.specifics.
88 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
90 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
91 printf ("Publishing complete, %llu kbps.\n",
92 (unsigned long long) (FILESIZE * 1000000LL /
94 GNUNET_TIME_absolute_get_duration
95 (start).rel_value_us) / 1024));
96 start = GNUNET_TIME_absolute_get ();
97 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
98 GNUNET_assert (unindex != NULL);
100 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
101 printf ("Unindex complete, %llu kbps.\n",
102 (unsigned long long) (FILESIZE * 1000000LL /
104 GNUNET_TIME_absolute_get_duration
105 (start).rel_value_us) / 1024));
106 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
108 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
109 GNUNET_assert (unindex == event->value.unindex.uc);
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
112 (unsigned long long) event->value.unindex.completed,
113 (unsigned long long) event->value.unindex.size,
114 event->value.unindex.specifics.progress.depth,
115 (unsigned long long) event->value.unindex.specifics.
118 case GNUNET_FS_STATUS_PUBLISH_ERROR:
119 FPRINTF (stderr, "Error publishing file: %s\n",
120 event->value.publish.specifics.error.message);
122 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
124 case GNUNET_FS_STATUS_UNINDEX_ERROR:
125 FPRINTF (stderr, "Error unindexing file: %s\n",
126 event->value.unindex.specifics.error.message);
127 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
129 case GNUNET_FS_STATUS_PUBLISH_START:
130 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
131 GNUNET_assert (NULL == event->value.publish.pctx);
132 GNUNET_assert (FILESIZE == event->value.publish.size);
133 GNUNET_assert (0 == event->value.publish.completed);
134 GNUNET_assert (1 == event->value.publish.anonymity);
136 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
137 GNUNET_assert (publish == event->value.publish.pc);
138 GNUNET_assert (FILESIZE == event->value.publish.size);
139 GNUNET_assert (1 == event->value.publish.anonymity);
143 case GNUNET_FS_STATUS_UNINDEX_START:
144 GNUNET_assert (unindex == NULL);
145 GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
146 GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
147 GNUNET_assert (FILESIZE == event->value.unindex.size);
148 GNUNET_assert (0 == event->value.unindex.completed);
150 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
151 GNUNET_assert (unindex == event->value.unindex.uc);
152 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
155 printf ("Unexpected event: %d\n", event->status);
164 const struct GNUNET_CONFIGURATION_Handle *cfg,
165 struct GNUNET_TESTING_Peer *peer)
167 const char *keywords[] = {
172 struct GNUNET_CONTAINER_MetaData *meta;
173 struct GNUNET_FS_Uri *kuri;
174 struct GNUNET_FS_FileInformation *fi;
176 struct GNUNET_FS_BlockOptions bo;
178 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
179 fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL,
180 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
181 GNUNET_assert (NULL != fs);
182 buf = GNUNET_malloc (FILESIZE);
183 for (i = 0; i < FILESIZE; i++)
184 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
185 GNUNET_assert (FILESIZE ==
186 GNUNET_DISK_fn_write (fn, buf, FILESIZE,
187 GNUNET_DISK_PERM_USER_READ |
188 GNUNET_DISK_PERM_USER_WRITE));
190 meta = GNUNET_CONTAINER_meta_data_create ();
191 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
192 bo.content_priority = 42;
193 bo.anonymity_level = 1;
194 bo.replication_level = 0;
195 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
196 fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn,
197 kuri, meta, GNUNET_YES,
199 GNUNET_FS_uri_destroy (kuri);
200 GNUNET_CONTAINER_meta_data_destroy (meta);
201 GNUNET_assert (NULL != fi);
202 start = GNUNET_TIME_absolute_get ();
204 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
205 GNUNET_FS_PUBLISH_OPTION_NONE);
206 GNUNET_assert (publish != NULL);
211 main (int argc, char *argv[])
213 if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex",
214 "test_fs_unindex_data.conf",
220 /* end of test_fs_unindex.c */