aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_publish_persistence.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_publish_persistence.c')
-rw-r--r--src/fs/test_fs_publish_persistence.c322
1 files changed, 0 insertions, 322 deletions
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
deleted file mode 100644
index da0209793..000000000
--- a/src/fs/test_fs_publish_persistence.c
+++ /dev/null
@@ -1,322 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file fs/test_fs_publish_persistence.c
22 * @brief simple testcase for persistence of simple publish operation
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_testing_lib.h"
28#include "gnunet_fs_service.h"
29
30
31/**
32 * File-size we use for testing.
33 */
34#define FILESIZE (1024 * 1024 * 2)
35
36/**
37 * How long until we give up on transmitting the message?
38 */
39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
40
41/**
42 * How long should our test-content live?
43 */
44#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
45
46
47static struct GNUNET_TIME_Absolute start;
48
49static struct GNUNET_FS_Handle *fs;
50
51static const struct GNUNET_CONFIGURATION_Handle *cfg;
52
53static struct GNUNET_FS_PublishContext *publish;
54
55static struct GNUNET_FS_PublishContext *publish;
56
57static char *fn1;
58
59static char *fn2;
60
61static int err;
62
63static struct GNUNET_SCHEDULER_Task *rtask;
64
65
66static void
67abort_publish_task (void *cls)
68{
69 GNUNET_FS_publish_stop (publish);
70 publish = NULL;
71 GNUNET_DISK_directory_remove (fn1);
72 GNUNET_free (fn1);
73 fn1 = NULL;
74 GNUNET_DISK_directory_remove (fn2);
75 GNUNET_free (fn2);
76 fn2 = NULL;
77 GNUNET_FS_stop (fs);
78 fs = NULL;
79 if (NULL != rtask)
80 {
81 GNUNET_SCHEDULER_cancel (rtask);
82 rtask = NULL;
83 }
84}
85
86
87static void *
88progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event);
89
90
91static void
92restart_fs_task (void *cls)
93{
94 rtask = NULL;
95 GNUNET_FS_stop (fs);
96 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence",
97 &progress_cb, NULL,
98 GNUNET_FS_FLAGS_PERSISTENCE,
99 GNUNET_FS_OPTIONS_END);
100}
101
102
103/**
104 * Consider scheduling the restart-task.
105 * Only runs the restart task once per event
106 * category.
107 *
108 * @param ev type of the event to consider
109 */
110static void
111consider_restart (int ev)
112{
113 static int prev[32];
114 static int off;
115 int i;
116
117 for (i = 0; i < off; i++)
118 if (prev[i] == ev)
119 return;
120 prev[off++] = ev;
121 rtask =
122 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
123 &restart_fs_task, NULL);
124}
125
126
127static void *
128progress_cb (void *cls,
129 const struct GNUNET_FS_ProgressInfo *event)
130{
131 void *ret;
132
133 ret = NULL;
134 switch (event->status)
135 {
136 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
137 ret = event->value.publish.cctx;
138 printf ("Publish complete, %llu kbps.\n",
139 (unsigned long long) (FILESIZE * 1000000LL
140 / (1
141 + GNUNET_TIME_absolute_get_duration
142 (start).rel_value_us) / 1024));
143 if ((NULL != event->value.publish.cctx) &&
144 (0 == strcmp ("publish-context-dir", event->value.publish.cctx)))
145 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
146 break;
147
148 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
149 ret = event->value.publish.cctx;
150 return ret;
151
152 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
153 consider_restart (event->status);
154 ret = event->value.publish.cctx;
155 GNUNET_assert (publish == event->value.publish.pc);
156#if VERBOSE
157 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
158 (unsigned long long) event->value.publish.completed,
159 (unsigned long long) event->value.publish.size,
160 event->value.publish.specifics.progress.depth,
161 (unsigned long long) event->value.publish.specifics.
162 progress.offset);
163#endif
164 break;
165
166 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
167 if (event->value.publish.pc == publish)
168 publish = NULL;
169 break;
170
171 case GNUNET_FS_STATUS_PUBLISH_RESUME:
172 if (NULL == publish)
173 {
174 GNUNET_assert (GNUNET_YES ==
175 GNUNET_FS_file_information_is_directory (event->
176 value.publish.
177 fi));
178 publish = event->value.publish.pc;
179 return "publish-context-dir";
180 }
181 break;
182
183 case GNUNET_FS_STATUS_PUBLISH_ERROR:
184 ret = event->value.publish.cctx;
185 fprintf (stderr, "Error publishing file: %s\n",
186 event->value.publish.specifics.error.message);
187 err = 1;
188 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
189 break;
190
191 case GNUNET_FS_STATUS_PUBLISH_START:
192 consider_restart (event->status);
193 publish = event->value.publish.pc;
194 ret = event->value.publish.cctx;
195 if (0 == strcmp ("publish-context1", event->value.publish.cctx))
196 {
197 GNUNET_assert (0 ==
198 strcmp ("publish-context-dir", event->value.publish.pctx));
199 GNUNET_assert (FILESIZE == event->value.publish.size);
200 GNUNET_assert (0 == event->value.publish.completed);
201 GNUNET_assert (1 == event->value.publish.anonymity);
202 }
203 else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
204 {
205 GNUNET_assert (0 ==
206 strcmp ("publish-context-dir", event->value.publish.pctx));
207 GNUNET_assert (FILESIZE == event->value.publish.size);
208 GNUNET_assert (0 == event->value.publish.completed);
209 GNUNET_assert (2 == event->value.publish.anonymity);
210 }
211 else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
212 {
213 GNUNET_assert (0 == event->value.publish.completed);
214 GNUNET_assert (3 == event->value.publish.anonymity);
215 }
216 else
217 GNUNET_assert (0);
218 break;
219
220 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
221 consider_restart (event->status);
222 if ((NULL != event->value.publish.cctx) &&
223 (0 == strcmp ("publish-context-dir", event->value.publish.cctx)))
224 GNUNET_assert (publish == event->value.publish.pc);
225 break;
226
227 default:
228 printf ("Unexpected event: %d\n", event->status);
229 break;
230 }
231 return ret;
232}
233
234
235static void
236run (void *cls,
237 const struct GNUNET_CONFIGURATION_Handle *c,
238 struct GNUNET_TESTING_Peer *peer)
239{
240 const char *keywords[] = {
241 "down_foo",
242 "down_bar",
243 };
244 char *buf;
245 struct GNUNET_CONTAINER_MetaData *meta;
246 struct GNUNET_FS_Uri *kuri;
247 struct GNUNET_FS_FileInformation *fi1;
248 struct GNUNET_FS_FileInformation *fi2;
249 struct GNUNET_FS_FileInformation *fidir;
250 size_t i;
251 struct GNUNET_FS_BlockOptions bo;
252
253 cfg = c;
254 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL,
255 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
256 GNUNET_assert (NULL != fs);
257 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
258 buf = GNUNET_malloc (FILESIZE);
259 for (i = 0; i < FILESIZE; i++)
260 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
261 (void) GNUNET_DISK_directory_remove (fn1);
262 GNUNET_assert (GNUNET_OK ==
263 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
264 GNUNET_DISK_PERM_USER_READ
265 | GNUNET_DISK_PERM_USER_WRITE));
266 GNUNET_free (buf);
267
268 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
269 buf = GNUNET_malloc (FILESIZE);
270 for (i = 0; i < FILESIZE; i++)
271 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
272 (void) GNUNET_DISK_directory_remove (fn2);
273 GNUNET_assert (GNUNET_OK ==
274 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
275 GNUNET_DISK_PERM_USER_READ
276 | GNUNET_DISK_PERM_USER_WRITE));
277 GNUNET_free (buf);
278
279 meta = GNUNET_CONTAINER_meta_data_create ();
280 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
281 bo.content_priority = 42;
282 bo.anonymity_level = 1;
283 bo.replication_level = 0;
284 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
285 fi1 =
286 GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1,
287 kuri, meta, GNUNET_YES, &bo);
288 GNUNET_assert (NULL != fi1);
289 bo.anonymity_level = 2;
290 fi2 =
291 GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2,
292 kuri, meta, GNUNET_YES, &bo);
293 GNUNET_assert (NULL != fi2);
294 bo.anonymity_level = 3;
295 fidir =
296 GNUNET_FS_file_information_create_empty_directory (fs,
297 "publish-context-dir",
298 kuri, meta, &bo, NULL);
299 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
300 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
301 GNUNET_FS_uri_destroy (kuri);
302 GNUNET_CONTAINER_meta_data_destroy (meta);
303 GNUNET_assert (NULL != fidir);
304 start = GNUNET_TIME_absolute_get ();
305 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
306 GNUNET_FS_PUBLISH_OPTION_NONE);
307 GNUNET_assert (publish != NULL);
308}
309
310
311int
312main (int argc, char *argv[])
313{
314 if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence",
315 "test_fs_publish_data.conf",
316 &run, NULL))
317 return 1;
318 return err;
319}
320
321
322/* end of test_fs_publish_persistence.c */