diff options
Diffstat (limited to 'src/fs/test_fs_publish_persistence.c')
-rw-r--r-- | src/fs/test_fs_publish_persistence.c | 324 |
1 files changed, 166 insertions, 158 deletions
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 6242e66f8..7cba55179 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_publish_persistence.c | 21 | * @file fs/test_fs_publish_persistence.c |
22 | * @brief simple testcase for persistence of simple publish operation | 22 | * @brief simple testcase for persistence of simple publish operation |
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -64,39 +64,39 @@ static struct GNUNET_SCHEDULER_Task *rtask; | |||
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | abort_publish_task (void *cls) | 67 | abort_publish_task(void *cls) |
68 | { | 68 | { |
69 | GNUNET_FS_publish_stop (publish); | 69 | GNUNET_FS_publish_stop(publish); |
70 | publish = NULL; | 70 | publish = NULL; |
71 | GNUNET_DISK_directory_remove (fn1); | 71 | GNUNET_DISK_directory_remove(fn1); |
72 | GNUNET_free (fn1); | 72 | GNUNET_free(fn1); |
73 | fn1 = NULL; | 73 | fn1 = NULL; |
74 | GNUNET_DISK_directory_remove (fn2); | 74 | GNUNET_DISK_directory_remove(fn2); |
75 | GNUNET_free (fn2); | 75 | GNUNET_free(fn2); |
76 | fn2 = NULL; | 76 | fn2 = NULL; |
77 | GNUNET_FS_stop (fs); | 77 | GNUNET_FS_stop(fs); |
78 | fs = NULL; | 78 | fs = NULL; |
79 | if (NULL != rtask) | 79 | if (NULL != rtask) |
80 | { | 80 | { |
81 | GNUNET_SCHEDULER_cancel (rtask); | 81 | GNUNET_SCHEDULER_cancel(rtask); |
82 | rtask = NULL; | 82 | rtask = NULL; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static void * | 87 | static void * |
88 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); | 88 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); |
89 | 89 | ||
90 | 90 | ||
91 | static void | 91 | static void |
92 | restart_fs_task (void *cls) | 92 | restart_fs_task(void *cls) |
93 | { | 93 | { |
94 | rtask = NULL; | 94 | rtask = NULL; |
95 | GNUNET_FS_stop (fs); | 95 | GNUNET_FS_stop(fs); |
96 | fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", | 96 | fs = GNUNET_FS_start(cfg, "test-fs-publish-persistence", |
97 | &progress_cb, NULL, | 97 | &progress_cb, NULL, |
98 | GNUNET_FS_FLAGS_PERSISTENCE, | 98 | GNUNET_FS_FLAGS_PERSISTENCE, |
99 | GNUNET_FS_OPTIONS_END); | 99 | GNUNET_FS_OPTIONS_END); |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
@@ -108,7 +108,7 @@ restart_fs_task (void *cls) | |||
108 | * @param ev type of the event to consider | 108 | * @param ev type of the event to consider |
109 | */ | 109 | */ |
110 | static void | 110 | static void |
111 | consider_restart (int ev) | 111 | consider_restart(int ev) |
112 | { | 112 | { |
113 | static int prev[32]; | 113 | static int prev[32]; |
114 | static int off; | 114 | static int off; |
@@ -119,115 +119,123 @@ consider_restart (int ev) | |||
119 | return; | 119 | return; |
120 | prev[off++] = ev; | 120 | prev[off++] = ev; |
121 | rtask = | 121 | rtask = |
122 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, | 122 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, |
123 | &restart_fs_task, NULL); | 123 | &restart_fs_task, NULL); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static void * | 127 | static void * |
128 | progress_cb (void *cls, | 128 | progress_cb(void *cls, |
129 | const struct GNUNET_FS_ProgressInfo *event) | 129 | const struct GNUNET_FS_ProgressInfo *event) |
130 | { | 130 | { |
131 | void *ret; | 131 | void *ret; |
132 | 132 | ||
133 | ret = NULL; | 133 | ret = NULL; |
134 | switch (event->status) | 134 | switch (event->status) |
135 | { | 135 | { |
136 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 136 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
137 | ret = event->value.publish.cctx; | 137 | ret = event->value.publish.cctx; |
138 | printf ("Publish complete, %llu kbps.\n", | 138 | printf("Publish complete, %llu kbps.\n", |
139 | (unsigned long long) (FILESIZE * 1000000LL / | 139 | (unsigned long long)(FILESIZE * 1000000LL / |
140 | (1 + | 140 | (1 + |
141 | GNUNET_TIME_absolute_get_duration | 141 | GNUNET_TIME_absolute_get_duration |
142 | (start).rel_value_us) / 1024)); | 142 | (start).rel_value_us) / 1024)); |
143 | if ( (NULL != event->value.publish.cctx) && | 143 | if ((NULL != event->value.publish.cctx) && |
144 | (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) | 144 | (0 == strcmp("publish-context-dir", event->value.publish.cctx))) |
145 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 145 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
146 | break; | 146 | break; |
147 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 147 | |
148 | ret = event->value.publish.cctx; | 148 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
149 | return ret; | 149 | ret = event->value.publish.cctx; |
150 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 150 | return ret; |
151 | consider_restart (event->status); | 151 | |
152 | ret = event->value.publish.cctx; | 152 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
153 | GNUNET_assert (publish == event->value.publish.pc); | 153 | consider_restart(event->status); |
154 | ret = event->value.publish.cctx; | ||
155 | GNUNET_assert(publish == event->value.publish.pc); | ||
154 | #if VERBOSE | 156 | #if VERBOSE |
155 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 157 | printf("Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
156 | (unsigned long long) event->value.publish.completed, | 158 | (unsigned long long)event->value.publish.completed, |
157 | (unsigned long long) event->value.publish.size, | 159 | (unsigned long long)event->value.publish.size, |
158 | event->value.publish.specifics.progress.depth, | 160 | event->value.publish.specifics.progress.depth, |
159 | (unsigned long long) event->value.publish.specifics. | 161 | (unsigned long long)event->value.publish.specifics. |
160 | progress.offset); | 162 | progress.offset); |
161 | #endif | 163 | #endif |
162 | break; | 164 | break; |
163 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 165 | |
164 | if (event->value.publish.pc == publish) | 166 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
165 | publish = NULL; | 167 | if (event->value.publish.pc == publish) |
166 | break; | 168 | publish = NULL; |
167 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 169 | break; |
168 | if (NULL == publish) | 170 | |
169 | { | 171 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
170 | GNUNET_assert (GNUNET_YES == | 172 | if (NULL == publish) |
171 | GNUNET_FS_file_information_is_directory (event-> | 173 | { |
172 | value.publish. | 174 | GNUNET_assert(GNUNET_YES == |
173 | fi)); | 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); | ||
174 | publish = event->value.publish.pc; | 193 | publish = event->value.publish.pc; |
175 | return "publish-context-dir"; | 194 | ret = event->value.publish.cctx; |
176 | } | 195 | if (0 == strcmp("publish-context1", event->value.publish.cctx)) |
177 | break; | 196 | { |
178 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 197 | GNUNET_assert(0 == |
179 | ret = event->value.publish.cctx; | 198 | strcmp("publish-context-dir", event->value.publish.pctx)); |
180 | fprintf (stderr, "Error publishing file: %s\n", | 199 | GNUNET_assert(FILESIZE == event->value.publish.size); |
181 | event->value.publish.specifics.error.message); | 200 | GNUNET_assert(0 == event->value.publish.completed); |
182 | err = 1; | 201 | GNUNET_assert(1 == event->value.publish.anonymity); |
183 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 202 | } |
184 | break; | 203 | else if (0 == strcmp("publish-context2", event->value.publish.cctx)) |
185 | case GNUNET_FS_STATUS_PUBLISH_START: | 204 | { |
186 | consider_restart (event->status); | 205 | GNUNET_assert(0 == |
187 | publish = event->value.publish.pc; | 206 | strcmp("publish-context-dir", event->value.publish.pctx)); |
188 | ret = event->value.publish.cctx; | 207 | GNUNET_assert(FILESIZE == event->value.publish.size); |
189 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) | 208 | GNUNET_assert(0 == event->value.publish.completed); |
190 | { | 209 | GNUNET_assert(2 == event->value.publish.anonymity); |
191 | GNUNET_assert (0 == | 210 | } |
192 | strcmp ("publish-context-dir", event->value.publish.pctx)); | 211 | else if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) |
193 | GNUNET_assert (FILESIZE == event->value.publish.size); | 212 | { |
194 | GNUNET_assert (0 == event->value.publish.completed); | 213 | GNUNET_assert(0 == event->value.publish.completed); |
195 | GNUNET_assert (1 == event->value.publish.anonymity); | 214 | GNUNET_assert(3 == event->value.publish.anonymity); |
196 | } | 215 | } |
197 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) | 216 | else |
198 | { | 217 | GNUNET_assert(0); |
199 | GNUNET_assert (0 == | 218 | break; |
200 | strcmp ("publish-context-dir", event->value.publish.pctx)); | 219 | |
201 | GNUNET_assert (FILESIZE == event->value.publish.size); | 220 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
202 | GNUNET_assert (0 == event->value.publish.completed); | 221 | consider_restart(event->status); |
203 | GNUNET_assert (2 == event->value.publish.anonymity); | 222 | if ((NULL != event->value.publish.cctx) && |
204 | } | 223 | (0 == strcmp("publish-context-dir", event->value.publish.cctx))) |
205 | else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 224 | GNUNET_assert(publish == event->value.publish.pc); |
206 | { | 225 | break; |
207 | GNUNET_assert (0 == event->value.publish.completed); | 226 | |
208 | GNUNET_assert (3 == event->value.publish.anonymity); | 227 | default: |
228 | printf("Unexpected event: %d\n", event->status); | ||
229 | break; | ||
209 | } | 230 | } |
210 | else | ||
211 | GNUNET_assert (0); | ||
212 | break; | ||
213 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
214 | consider_restart (event->status); | ||
215 | if ( (NULL != event->value.publish.cctx) && | ||
216 | (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) | ||
217 | GNUNET_assert (publish == event->value.publish.pc); | ||
218 | break; | ||
219 | default: | ||
220 | printf ("Unexpected event: %d\n", event->status); | ||
221 | break; | ||
222 | } | ||
223 | return ret; | 231 | return ret; |
224 | } | 232 | } |
225 | 233 | ||
226 | 234 | ||
227 | static void | 235 | static void |
228 | run (void *cls, | 236 | run(void *cls, |
229 | const struct GNUNET_CONFIGURATION_Handle *c, | 237 | const struct GNUNET_CONFIGURATION_Handle *c, |
230 | struct GNUNET_TESTING_Peer *peer) | 238 | struct GNUNET_TESTING_Peer *peer) |
231 | { | 239 | { |
232 | const char *keywords[] = { | 240 | const char *keywords[] = { |
233 | "down_foo", | 241 | "down_foo", |
@@ -243,67 +251,67 @@ run (void *cls, | |||
243 | struct GNUNET_FS_BlockOptions bo; | 251 | struct GNUNET_FS_BlockOptions bo; |
244 | 252 | ||
245 | cfg = c; | 253 | cfg = c; |
246 | fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, | 254 | fs = GNUNET_FS_start(cfg, "test-fs-publish-persistence", &progress_cb, NULL, |
247 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 255 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
248 | GNUNET_assert (NULL != fs); | 256 | GNUNET_assert(NULL != fs); |
249 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 257 | fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); |
250 | buf = GNUNET_malloc (FILESIZE); | 258 | buf = GNUNET_malloc(FILESIZE); |
251 | for (i = 0; i < FILESIZE; i++) | 259 | for (i = 0; i < FILESIZE; i++) |
252 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 260 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
253 | GNUNET_assert (FILESIZE == | 261 | GNUNET_assert(FILESIZE == |
254 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 262 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, |
255 | GNUNET_DISK_PERM_USER_READ | | 263 | GNUNET_DISK_PERM_USER_READ | |
256 | GNUNET_DISK_PERM_USER_WRITE)); | 264 | GNUNET_DISK_PERM_USER_WRITE)); |
257 | GNUNET_free (buf); | 265 | GNUNET_free(buf); |
258 | 266 | ||
259 | fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 267 | fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); |
260 | buf = GNUNET_malloc (FILESIZE); | 268 | buf = GNUNET_malloc(FILESIZE); |
261 | for (i = 0; i < FILESIZE; i++) | 269 | for (i = 0; i < FILESIZE; i++) |
262 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 270 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
263 | GNUNET_assert (FILESIZE == | 271 | GNUNET_assert(FILESIZE == |
264 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 272 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, |
265 | GNUNET_DISK_PERM_USER_READ | | 273 | GNUNET_DISK_PERM_USER_READ | |
266 | GNUNET_DISK_PERM_USER_WRITE)); | 274 | GNUNET_DISK_PERM_USER_WRITE)); |
267 | GNUNET_free (buf); | 275 | GNUNET_free(buf); |
268 | 276 | ||
269 | meta = GNUNET_CONTAINER_meta_data_create (); | 277 | meta = GNUNET_CONTAINER_meta_data_create(); |
270 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 278 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
271 | bo.content_priority = 42; | 279 | bo.content_priority = 42; |
272 | bo.anonymity_level = 1; | 280 | bo.anonymity_level = 1; |
273 | bo.replication_level = 0; | 281 | bo.replication_level = 0; |
274 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 282 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
275 | fi1 = | 283 | fi1 = |
276 | GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, | 284 | GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, |
277 | kuri, meta, GNUNET_YES, &bo); | 285 | kuri, meta, GNUNET_YES, &bo); |
278 | GNUNET_assert (NULL != fi1); | 286 | GNUNET_assert(NULL != fi1); |
279 | bo.anonymity_level = 2; | 287 | bo.anonymity_level = 2; |
280 | fi2 = | 288 | fi2 = |
281 | GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, | 289 | GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, |
282 | kuri, meta, GNUNET_YES, &bo); | 290 | kuri, meta, GNUNET_YES, &bo); |
283 | GNUNET_assert (NULL != fi2); | 291 | GNUNET_assert(NULL != fi2); |
284 | bo.anonymity_level = 3; | 292 | bo.anonymity_level = 3; |
285 | fidir = | 293 | fidir = |
286 | GNUNET_FS_file_information_create_empty_directory (fs, | 294 | GNUNET_FS_file_information_create_empty_directory(fs, |
287 | "publish-context-dir", | 295 | "publish-context-dir", |
288 | kuri, meta, &bo, NULL); | 296 | kuri, meta, &bo, NULL); |
289 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); | 297 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); |
290 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); | 298 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); |
291 | GNUNET_FS_uri_destroy (kuri); | 299 | GNUNET_FS_uri_destroy(kuri); |
292 | GNUNET_CONTAINER_meta_data_destroy (meta); | 300 | GNUNET_CONTAINER_meta_data_destroy(meta); |
293 | GNUNET_assert (NULL != fidir); | 301 | GNUNET_assert(NULL != fidir); |
294 | start = GNUNET_TIME_absolute_get (); | 302 | start = GNUNET_TIME_absolute_get(); |
295 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, | 303 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, |
296 | GNUNET_FS_PUBLISH_OPTION_NONE); | 304 | GNUNET_FS_PUBLISH_OPTION_NONE); |
297 | GNUNET_assert (publish != NULL); | 305 | GNUNET_assert(publish != NULL); |
298 | } | 306 | } |
299 | 307 | ||
300 | 308 | ||
301 | int | 309 | int |
302 | main (int argc, char *argv[]) | 310 | main(int argc, char *argv[]) |
303 | { | 311 | { |
304 | if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence", | 312 | if (0 != GNUNET_TESTING_peer_run("test-fs-publish-persistence", |
305 | "test_fs_publish_data.conf", | 313 | "test_fs_publish_data.conf", |
306 | &run, NULL)) | 314 | &run, NULL)) |
307 | return 1; | 315 | return 1; |
308 | return err; | 316 | return err; |
309 | } | 317 | } |