diff options
Diffstat (limited to 'src/fs/test_fs_list_indexed.c')
-rw-r--r-- | src/fs/test_fs_list_indexed.c | 265 |
1 files changed, 0 insertions, 265 deletions
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c deleted file mode 100644 index 2f04a017a..000000000 --- a/src/fs/test_fs_list_indexed.c +++ /dev/null | |||
@@ -1,265 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2004, 2005, 2006, 2008, 2009 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 | /** | ||
22 | * @file fs/test_fs_list_indexed.c | ||
23 | * @brief simple testcase for list_indexed operation (indexing, listing | ||
24 | * indexed) | ||
25 | * @author Christian Grothoff | ||
26 | * | ||
27 | * TODO: | ||
28 | * - actually call list_indexed API! | ||
29 | */ | ||
30 | #include "platform.h" | ||
31 | #include "gnunet_util_lib.h" | ||
32 | #include "gnunet_testing_lib.h" | ||
33 | #include "gnunet_fs_service.h" | ||
34 | |||
35 | /** | ||
36 | * File-size we use for testing. | ||
37 | */ | ||
38 | #define FILESIZE (1024 * 1024 * 2) | ||
39 | |||
40 | /** | ||
41 | * How long until we give up on transmitting the message? | ||
42 | */ | ||
43 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
44 | |||
45 | /** | ||
46 | * How long should our test-content live? | ||
47 | */ | ||
48 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | ||
49 | |||
50 | |||
51 | static struct GNUNET_TIME_Absolute start; | ||
52 | |||
53 | static struct GNUNET_FS_Handle *fs; | ||
54 | |||
55 | static struct GNUNET_FS_PublishContext *publish; | ||
56 | |||
57 | static char *fn1; | ||
58 | |||
59 | static char *fn2; | ||
60 | |||
61 | static int err; | ||
62 | |||
63 | |||
64 | static void | ||
65 | abort_publish_task (void *cls) | ||
66 | { | ||
67 | GNUNET_FS_publish_stop (publish); | ||
68 | publish = NULL; | ||
69 | GNUNET_DISK_directory_remove (fn1); | ||
70 | GNUNET_free (fn1); | ||
71 | fn1 = NULL; | ||
72 | GNUNET_DISK_directory_remove (fn2); | ||
73 | GNUNET_free (fn2); | ||
74 | fn2 = NULL; | ||
75 | } | ||
76 | |||
77 | |||
78 | static void | ||
79 | list_indexed_task (void *cls) | ||
80 | { | ||
81 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
82 | } | ||
83 | |||
84 | |||
85 | static void * | ||
86 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | ||
87 | { | ||
88 | void *ret; | ||
89 | |||
90 | ret = NULL; | ||
91 | switch (event->status) | ||
92 | { | ||
93 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
94 | ret = event->value.publish.cctx; | ||
95 | printf ("Publish complete, %llu kbps.\n", | ||
96 | (unsigned long long) (FILESIZE * 1000000LL | ||
97 | / (1 | ||
98 | + GNUNET_TIME_absolute_get_duration | ||
99 | (start).rel_value_us) / 1024)); | ||
100 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
101 | GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL); | ||
102 | |||
103 | break; | ||
104 | |||
105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
106 | ret = event->value.publish.cctx; | ||
107 | GNUNET_assert (publish == event->value.publish.pc); | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
110 | (unsigned long long) event->value.publish.completed, | ||
111 | (unsigned long long) event->value.publish.size, | ||
112 | event->value.publish.specifics.progress.depth, | ||
113 | (unsigned long long) event->value.publish.specifics. | ||
114 | progress.offset); | ||
115 | break; | ||
116 | |||
117 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
118 | ret = event->value.publish.cctx; | ||
119 | break; | ||
120 | |||
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); | ||
125 | err = 1; | ||
126 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
127 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
128 | break; | ||
129 | |||
130 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
131 | ret = event->value.publish.cctx; | ||
132 | if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx)) | ||
133 | { | ||
134 | GNUNET_assert (0 == | ||
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); | ||
140 | } | ||
141 | else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx)) | ||
142 | { | ||
143 | GNUNET_assert (0 == | ||
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); | ||
149 | } | ||
150 | else if (0 == | ||
151 | strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
152 | { | ||
153 | GNUNET_assert (0 == event->value.publish.completed); | ||
154 | GNUNET_assert (3 == event->value.publish.anonymity); | ||
155 | } | ||
156 | else | ||
157 | GNUNET_assert (0); | ||
158 | break; | ||
159 | |||
160 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
161 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
162 | { | ||
163 | GNUNET_assert (publish == event->value.publish.pc); | ||
164 | publish = NULL; | ||
165 | } | ||
166 | break; | ||
167 | |||
168 | default: | ||
169 | printf ("Unexpected event: %d\n", event->status); | ||
170 | break; | ||
171 | } | ||
172 | return ret; | ||
173 | } | ||
174 | |||
175 | |||
176 | static void | ||
177 | run (void *cls, | ||
178 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
179 | struct GNUNET_TESTING_Peer *peer) | ||
180 | { | ||
181 | const char *keywords[] = { | ||
182 | "down_foo", | ||
183 | "down_bar", | ||
184 | }; | ||
185 | char *buf; | ||
186 | struct GNUNET_CONTAINER_MetaData *meta; | ||
187 | struct GNUNET_FS_Uri *kuri; | ||
188 | struct GNUNET_FS_FileInformation *fi1; | ||
189 | struct GNUNET_FS_FileInformation *fi2; | ||
190 | struct GNUNET_FS_FileInformation *fidir; | ||
191 | size_t i; | ||
192 | struct GNUNET_FS_BlockOptions bo; | ||
193 | |||
194 | fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL, | ||
195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | ||
196 | GNUNET_assert (NULL != fs); | ||
197 | fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); | ||
198 | buf = GNUNET_malloc (FILESIZE); | ||
199 | for (i = 0; i < FILESIZE; i++) | ||
200 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | ||
201 | (void) GNUNET_DISK_directory_remove (fn1); | ||
202 | GNUNET_assert (GNUNET_OK == | ||
203 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | ||
204 | GNUNET_DISK_PERM_USER_READ | ||
205 | | GNUNET_DISK_PERM_USER_WRITE)); | ||
206 | GNUNET_free (buf); | ||
207 | |||
208 | fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); | ||
209 | buf = GNUNET_malloc (FILESIZE); | ||
210 | for (i = 0; i < FILESIZE; i++) | ||
211 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | ||
212 | (void) GNUNET_DISK_directory_remove (fn2); | ||
213 | GNUNET_assert (GNUNET_OK == | ||
214 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | ||
215 | GNUNET_DISK_PERM_USER_READ | ||
216 | | GNUNET_DISK_PERM_USER_WRITE)); | ||
217 | GNUNET_free (buf); | ||
218 | |||
219 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
220 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | ||
221 | bo.content_priority = 42; | ||
222 | bo.anonymity_level = 1; | ||
223 | bo.replication_level = 0; | ||
224 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | ||
225 | fi1 = | ||
226 | GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1", | ||
227 | fn1, kuri, meta, GNUNET_YES, | ||
228 | &bo); | ||
229 | GNUNET_assert (NULL != fi1); | ||
230 | bo.anonymity_level = 2; | ||
231 | fi2 = | ||
232 | GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2", | ||
233 | fn2, kuri, meta, GNUNET_YES, | ||
234 | &bo); | ||
235 | GNUNET_assert (NULL != fi2); | ||
236 | bo.anonymity_level = 3; | ||
237 | fidir = | ||
238 | GNUNET_FS_file_information_create_empty_directory (fs, | ||
239 | "list_indexed-context-dir", | ||
240 | kuri, meta, &bo, NULL); | ||
241 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); | ||
242 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); | ||
243 | GNUNET_FS_uri_destroy (kuri); | ||
244 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
245 | GNUNET_assert (NULL != fidir); | ||
246 | start = GNUNET_TIME_absolute_get (); | ||
247 | publish = | ||
248 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, | ||
249 | GNUNET_FS_PUBLISH_OPTION_NONE); | ||
250 | GNUNET_assert (publish != NULL); | ||
251 | } | ||
252 | |||
253 | |||
254 | int | ||
255 | main (int argc, char *argv[]) | ||
256 | { | ||
257 | if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed", | ||
258 | "test_fs_list_indexed_data.conf", | ||
259 | &run, NULL)) | ||
260 | return 1; | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | |||
265 | /* end of test_fs_list_indexed.c */ | ||