diff options
Diffstat (limited to 'src/fs/fs_test_lib.c')
-rw-r--r-- | src/fs/fs_test_lib.c | 424 |
1 files changed, 213 insertions, 211 deletions
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c index abbda1ece..e3ab0ec88 100644 --- a/src/fs/fs_test_lib.c +++ b/src/fs/fs_test_lib.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 | /** | 21 | /** |
22 | * @file fs/fs_test_lib.c | 22 | * @file fs/fs_test_lib.c |
@@ -37,9 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * Handle for a publishing operation started for testing FS. | 38 | * Handle for a publishing operation started for testing FS. |
39 | */ | 39 | */ |
40 | struct TestPublishOperation | 40 | struct TestPublishOperation { |
41 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * Handle for the operation to connect to the peer's 'fs' service. | 42 | * Handle for the operation to connect to the peer's 'fs' service. |
45 | */ | 43 | */ |
@@ -110,9 +108,7 @@ struct TestPublishOperation | |||
110 | /** | 108 | /** |
111 | * Handle for a download operation started for testing FS. | 109 | * Handle for a download operation started for testing FS. |
112 | */ | 110 | */ |
113 | struct TestDownloadOperation | 111 | struct TestDownloadOperation { |
114 | { | ||
115 | |||
116 | /** | 112 | /** |
117 | * Handle for the operation to connect to the peer's 'fs' service. | 113 | * Handle for the operation to connect to the peer's 'fs' service. |
118 | */ | 114 | */ |
@@ -172,7 +168,6 @@ struct TestDownloadOperation | |||
172 | * Verbosity level of the current operation. | 168 | * Verbosity level of the current operation. |
173 | */ | 169 | */ |
174 | unsigned int verbose; | 170 | unsigned int verbose; |
175 | |||
176 | }; | 171 | }; |
177 | 172 | ||
178 | 173 | ||
@@ -183,23 +178,23 @@ struct TestDownloadOperation | |||
183 | * @param tc scheduler context (unused) | 178 | * @param tc scheduler context (unused) |
184 | */ | 179 | */ |
185 | static void | 180 | static void |
186 | report_uri (void *cls) | 181 | report_uri(void *cls) |
187 | { | 182 | { |
188 | struct TestPublishOperation *po = cls; | 183 | struct TestPublishOperation *po = cls; |
189 | 184 | ||
190 | GNUNET_FS_publish_stop (po->publish_context); | 185 | GNUNET_FS_publish_stop(po->publish_context); |
191 | GNUNET_TESTBED_operation_done (po->fs_op); | 186 | GNUNET_TESTBED_operation_done(po->fs_op); |
192 | po->publish_cont (po->publish_cont_cls, | 187 | po->publish_cont(po->publish_cont_cls, |
193 | po->publish_uri, | 188 | po->publish_uri, |
194 | (GNUNET_YES == po->do_index) | 189 | (GNUNET_YES == po->do_index) |
195 | ? po->publish_tmp_file | 190 | ? po->publish_tmp_file |
196 | : NULL); | 191 | : NULL); |
197 | GNUNET_FS_uri_destroy (po->publish_uri); | 192 | GNUNET_FS_uri_destroy(po->publish_uri); |
198 | if ( (GNUNET_YES != po->do_index) && | 193 | if ((GNUNET_YES != po->do_index) && |
199 | (NULL != po->publish_tmp_file) ) | 194 | (NULL != po->publish_tmp_file)) |
200 | (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); | 195 | (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); |
201 | GNUNET_free_non_null (po->publish_tmp_file); | 196 | GNUNET_free_non_null(po->publish_tmp_file); |
202 | GNUNET_free (po); | 197 | GNUNET_free(po); |
203 | } | 198 | } |
204 | 199 | ||
205 | 200 | ||
@@ -209,19 +204,19 @@ report_uri (void *cls) | |||
209 | * @param cls the publish operation context | 204 | * @param cls the publish operation context |
210 | */ | 205 | */ |
211 | static void | 206 | static void |
212 | publish_timeout (void *cls) | 207 | publish_timeout(void *cls) |
213 | { | 208 | { |
214 | struct TestPublishOperation *po = cls; | 209 | struct TestPublishOperation *po = cls; |
215 | 210 | ||
216 | po->publish_timeout_task = NULL; | 211 | po->publish_timeout_task = NULL; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 212 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
218 | "Timeout while trying to publish data\n"); | 213 | "Timeout while trying to publish data\n"); |
219 | GNUNET_TESTBED_operation_done (po->fs_op); | 214 | GNUNET_TESTBED_operation_done(po->fs_op); |
220 | GNUNET_FS_publish_stop (po->publish_context); | 215 | GNUNET_FS_publish_stop(po->publish_context); |
221 | po->publish_cont (po->publish_cont_cls, NULL, NULL); | 216 | po->publish_cont(po->publish_cont_cls, NULL, NULL); |
222 | (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); | 217 | (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); |
223 | GNUNET_free_non_null (po->publish_tmp_file); | 218 | GNUNET_free_non_null(po->publish_tmp_file); |
224 | GNUNET_free (po); | 219 | GNUNET_free(po); |
225 | } | 220 | } |
226 | 221 | ||
227 | 222 | ||
@@ -232,37 +227,41 @@ publish_timeout (void *cls) | |||
232 | * @param info information about the event | 227 | * @param info information about the event |
233 | */ | 228 | */ |
234 | static void * | 229 | static void * |
235 | publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | 230 | publish_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) |
236 | { | 231 | { |
237 | struct TestPublishOperation *po = cls; | 232 | struct TestPublishOperation *po = cls; |
238 | 233 | ||
239 | switch (info->status) | 234 | switch (info->status) |
240 | { | 235 | { |
241 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 236 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
242 | GNUNET_SCHEDULER_cancel (po->publish_timeout_task); | 237 | GNUNET_SCHEDULER_cancel(po->publish_timeout_task); |
243 | po->publish_timeout_task = NULL; | 238 | po->publish_timeout_task = NULL; |
244 | po->publish_uri = | 239 | po->publish_uri = |
245 | GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); | 240 | GNUNET_FS_uri_dup(info->value.publish.specifics.completed.chk_uri); |
246 | GNUNET_SCHEDULER_add_now (&report_uri, | 241 | GNUNET_SCHEDULER_add_now(&report_uri, |
247 | po); | 242 | po); |
248 | break; | 243 | break; |
249 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 244 | |
250 | if (po->verbose) | 245 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", | 246 | if (po->verbose) |
252 | (unsigned long long) info->value.publish.completed, | 247 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", |
253 | (unsigned long long) info->value.publish.size); | 248 | (unsigned long long)info->value.publish.completed, |
254 | break; | 249 | (unsigned long long)info->value.publish.size); |
255 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 250 | break; |
256 | break; | 251 | |
257 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 252 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
258 | if (po->verbose) | 253 | break; |
259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", | 254 | |
260 | (unsigned long long) info->value.download.completed, | 255 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
261 | (unsigned long long) info->value.download.size); | 256 | if (po->verbose) |
262 | break; | 257 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", |
263 | default: | 258 | (unsigned long long)info->value.download.completed, |
264 | break; | 259 | (unsigned long long)info->value.download.size); |
265 | } | 260 | break; |
261 | |||
262 | default: | ||
263 | break; | ||
264 | } | ||
266 | return NULL; | 265 | return NULL; |
267 | } | 266 | } |
268 | 267 | ||
@@ -278,11 +277,11 @@ publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
278 | * @return number of bytes written to buf | 277 | * @return number of bytes written to buf |
279 | */ | 278 | */ |
280 | static size_t | 279 | static size_t |
281 | file_generator (void *cls, | 280 | file_generator(void *cls, |
282 | uint64_t offset, | 281 | uint64_t offset, |
283 | size_t max, | 282 | size_t max, |
284 | void *buf, | 283 | void *buf, |
285 | char **emsg) | 284 | char **emsg) |
286 | { | 285 | { |
287 | uint32_t *publish_seed = cls; | 286 | uint32_t *publish_seed = cls; |
288 | uint64_t pos; | 287 | uint64_t pos; |
@@ -294,14 +293,14 @@ file_generator (void *cls, | |||
294 | if (buf == NULL) | 293 | if (buf == NULL) |
295 | return 0; | 294 | return 0; |
296 | for (pos = 0; pos < 8; pos++) | 295 | for (pos = 0; pos < 8; pos++) |
297 | cbuf[pos] = (uint8_t) (offset >> pos * 8); | 296 | cbuf[pos] = (uint8_t)(offset >> pos * 8); |
298 | for (pos = 8; pos < max; pos++) | 297 | for (pos = 8; pos < max; pos++) |
299 | { | 298 | { |
300 | mod = (255 - (offset / 1024 / 32)); | 299 | mod = (255 - (offset / 1024 / 32)); |
301 | if (mod == 0) | 300 | if (mod == 0) |
302 | mod = 1; | 301 | mod = 1; |
303 | cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod); | 302 | cbuf[pos] = (uint8_t)((offset * (*publish_seed)) % mod); |
304 | } | 303 | } |
305 | return max; | 304 | return max; |
306 | } | 305 | } |
307 | 306 | ||
@@ -316,16 +315,16 @@ file_generator (void *cls, | |||
316 | * @return service handle to return in 'op_result', NULL on error | 315 | * @return service handle to return in 'op_result', NULL on error |
317 | */ | 316 | */ |
318 | static void * | 317 | static void * |
319 | publish_connect_adapter (void *cls, | 318 | publish_connect_adapter(void *cls, |
320 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 319 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
321 | { | 320 | { |
322 | struct TestPublishOperation *po = cls; | 321 | struct TestPublishOperation *po = cls; |
323 | 322 | ||
324 | return GNUNET_FS_start (cfg, | 323 | return GNUNET_FS_start(cfg, |
325 | "fs-test-publish", | 324 | "fs-test-publish", |
326 | &publish_progress_cb, po, | 325 | &publish_progress_cb, po, |
327 | GNUNET_FS_FLAGS_NONE, | 326 | GNUNET_FS_FLAGS_NONE, |
328 | GNUNET_FS_OPTIONS_END); | 327 | GNUNET_FS_OPTIONS_END); |
329 | } | 328 | } |
330 | 329 | ||
331 | 330 | ||
@@ -336,12 +335,12 @@ publish_connect_adapter (void *cls, | |||
336 | * @param op_result unused (different for publish/download!) | 335 | * @param op_result unused (different for publish/download!) |
337 | */ | 336 | */ |
338 | static void | 337 | static void |
339 | fs_disconnect_adapter (void *cls, | 338 | fs_disconnect_adapter(void *cls, |
340 | void *op_result) | 339 | void *op_result) |
341 | { | 340 | { |
342 | struct GNUNET_FS_Handle *fs = op_result; | 341 | struct GNUNET_FS_Handle *fs = op_result; |
343 | 342 | ||
344 | GNUNET_FS_stop (fs); | 343 | GNUNET_FS_stop(fs); |
345 | } | 344 | } |
346 | 345 | ||
347 | 346 | ||
@@ -355,10 +354,10 @@ fs_disconnect_adapter (void *cls, | |||
355 | * operation has executed successfully. | 354 | * operation has executed successfully. |
356 | */ | 355 | */ |
357 | static void | 356 | static void |
358 | publish_fs_connect_complete_cb (void *cls, | 357 | publish_fs_connect_complete_cb(void *cls, |
359 | struct GNUNET_TESTBED_Operation *op, | 358 | struct GNUNET_TESTBED_Operation *op, |
360 | void *ca_result, | 359 | void *ca_result, |
361 | const char *emsg) | 360 | const char *emsg) |
362 | { | 361 | { |
363 | struct TestPublishOperation *po = cls; | 362 | struct TestPublishOperation *po = cls; |
364 | struct GNUNET_FS_FileInformation *fi; | 363 | struct GNUNET_FS_FileInformation *fi; |
@@ -371,58 +370,58 @@ publish_fs_connect_complete_cb (void *cls, | |||
371 | 370 | ||
372 | if (NULL == ca_result) | 371 | if (NULL == ca_result) |
373 | { | 372 | { |
374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); | 373 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); |
375 | po->publish_cont (po->publish_cont_cls, | 374 | po->publish_cont(po->publish_cont_cls, |
376 | NULL, NULL); | 375 | NULL, NULL); |
377 | GNUNET_TESTBED_operation_done (po->fs_op); | 376 | GNUNET_TESTBED_operation_done(po->fs_op); |
378 | GNUNET_free (po); | 377 | GNUNET_free(po); |
379 | return; | 378 | return; |
380 | } | 379 | } |
381 | po->fs = ca_result; | 380 | po->fs = ca_result; |
382 | 381 | ||
383 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME); | 382 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(CONTENT_LIFETIME); |
384 | bo.anonymity_level = po->anonymity; | 383 | bo.anonymity_level = po->anonymity; |
385 | bo.content_priority = 42; | 384 | bo.content_priority = 42; |
386 | bo.replication_level = 1; | 385 | bo.replication_level = 1; |
387 | if (GNUNET_YES == po->do_index) | 386 | if (GNUNET_YES == po->do_index) |
388 | { | ||
389 | po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); | ||
390 | GNUNET_assert (po->publish_tmp_file != NULL); | ||
391 | fh = GNUNET_DISK_file_open (po->publish_tmp_file, | ||
392 | GNUNET_DISK_OPEN_WRITE | | ||
393 | GNUNET_DISK_OPEN_CREATE, | ||
394 | GNUNET_DISK_PERM_USER_READ | | ||
395 | GNUNET_DISK_PERM_USER_WRITE); | ||
396 | GNUNET_assert (NULL != fh); | ||
397 | off = 0; | ||
398 | while (off < po->size) | ||
399 | { | 387 | { |
400 | bsize = GNUNET_MIN (sizeof (buf), po->size - off); | 388 | po->publish_tmp_file = GNUNET_DISK_mktemp("fs-test-publish-index"); |
401 | emsg = NULL; | 389 | GNUNET_assert(po->publish_tmp_file != NULL); |
402 | GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, buf, &em)); | 390 | fh = GNUNET_DISK_file_open(po->publish_tmp_file, |
403 | GNUNET_assert (em == NULL); | 391 | GNUNET_DISK_OPEN_WRITE | |
404 | GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); | 392 | GNUNET_DISK_OPEN_CREATE, |
405 | off += bsize; | 393 | GNUNET_DISK_PERM_USER_READ | |
394 | GNUNET_DISK_PERM_USER_WRITE); | ||
395 | GNUNET_assert(NULL != fh); | ||
396 | off = 0; | ||
397 | while (off < po->size) | ||
398 | { | ||
399 | bsize = GNUNET_MIN(sizeof(buf), po->size - off); | ||
400 | emsg = NULL; | ||
401 | GNUNET_assert(bsize == file_generator(&po->publish_seed, off, bsize, buf, &em)); | ||
402 | GNUNET_assert(em == NULL); | ||
403 | GNUNET_assert(bsize == GNUNET_DISK_file_write(fh, buf, bsize)); | ||
404 | off += bsize; | ||
405 | } | ||
406 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); | ||
407 | fi = GNUNET_FS_file_information_create_from_file(po->fs, po, | ||
408 | po->publish_tmp_file, | ||
409 | NULL, NULL, po->do_index, | ||
410 | &bo); | ||
411 | GNUNET_assert(NULL != fi); | ||
406 | } | 412 | } |
407 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | ||
408 | fi = GNUNET_FS_file_information_create_from_file (po->fs, po, | ||
409 | po->publish_tmp_file, | ||
410 | NULL, NULL, po->do_index, | ||
411 | &bo); | ||
412 | GNUNET_assert (NULL != fi); | ||
413 | } | ||
414 | else | 413 | else |
415 | { | 414 | { |
416 | fi = GNUNET_FS_file_information_create_from_reader (po->fs, po, | 415 | fi = GNUNET_FS_file_information_create_from_reader(po->fs, po, |
417 | po->size, | 416 | po->size, |
418 | &file_generator, &po->publish_seed, | 417 | &file_generator, &po->publish_seed, |
419 | NULL, NULL, | 418 | NULL, NULL, |
420 | po->do_index, &bo); | 419 | po->do_index, &bo); |
421 | GNUNET_assert (NULL != fi); | 420 | GNUNET_assert(NULL != fi); |
422 | } | 421 | } |
423 | po->publish_context = | 422 | po->publish_context = |
424 | GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL, | 423 | GNUNET_FS_publish_start(po->fs, fi, NULL, NULL, NULL, |
425 | GNUNET_FS_PUBLISH_OPTION_NONE); | 424 | GNUNET_FS_PUBLISH_OPTION_NONE); |
426 | } | 425 | } |
427 | 426 | ||
428 | 427 | ||
@@ -442,15 +441,15 @@ publish_fs_connect_complete_cb (void *cls, | |||
442 | * @param cont_cls closure for cont | 441 | * @param cont_cls closure for cont |
443 | */ | 442 | */ |
444 | void | 443 | void |
445 | GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, | 444 | GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, |
446 | struct GNUNET_TIME_Relative timeout, uint32_t anonymity, | 445 | struct GNUNET_TIME_Relative timeout, uint32_t anonymity, |
447 | int do_index, uint64_t size, uint32_t seed, | 446 | int do_index, uint64_t size, uint32_t seed, |
448 | unsigned int verbose, | 447 | unsigned int verbose, |
449 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) | 448 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) |
450 | { | 449 | { |
451 | struct TestPublishOperation *po; | 450 | struct TestPublishOperation *po; |
452 | 451 | ||
453 | po = GNUNET_new (struct TestPublishOperation); | 452 | po = GNUNET_new(struct TestPublishOperation); |
454 | po->publish_cont = cont; | 453 | po->publish_cont = cont; |
455 | po->publish_cont_cls = cont_cls; | 454 | po->publish_cont_cls = cont_cls; |
456 | po->publish_seed = seed; | 455 | po->publish_seed = seed; |
@@ -458,16 +457,16 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, | |||
458 | po->size = size; | 457 | po->size = size; |
459 | po->verbose = verbose; | 458 | po->verbose = verbose; |
460 | po->do_index = do_index; | 459 | po->do_index = do_index; |
461 | po->fs_op = GNUNET_TESTBED_service_connect (po, | 460 | po->fs_op = GNUNET_TESTBED_service_connect(po, |
462 | peer, | 461 | peer, |
463 | "fs", | 462 | "fs", |
464 | &publish_fs_connect_complete_cb, | 463 | &publish_fs_connect_complete_cb, |
465 | po, | 464 | po, |
466 | &publish_connect_adapter, | 465 | &publish_connect_adapter, |
467 | &fs_disconnect_adapter, | 466 | &fs_disconnect_adapter, |
468 | po); | 467 | po); |
469 | po->publish_timeout_task = | 468 | po->publish_timeout_task = |
470 | GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, po); | 469 | GNUNET_SCHEDULER_add_delayed(timeout, &publish_timeout, po); |
471 | } | 470 | } |
472 | 471 | ||
473 | 472 | ||
@@ -480,20 +479,20 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, | |||
480 | * @param cls the download operation context | 479 | * @param cls the download operation context |
481 | */ | 480 | */ |
482 | static void | 481 | static void |
483 | download_timeout (void *cls) | 482 | download_timeout(void *cls) |
484 | { | 483 | { |
485 | struct TestDownloadOperation *dop = cls; | 484 | struct TestDownloadOperation *dop = cls; |
486 | 485 | ||
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 486 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
488 | "Timeout while trying to download file\n"); | 487 | "Timeout while trying to download file\n"); |
489 | dop->download_timeout_task = NULL; | 488 | dop->download_timeout_task = NULL; |
490 | GNUNET_FS_download_stop (dop->download_context, | 489 | GNUNET_FS_download_stop(dop->download_context, |
491 | GNUNET_YES); | 490 | GNUNET_YES); |
492 | GNUNET_SCHEDULER_add_now (dop->download_cont, | 491 | GNUNET_SCHEDULER_add_now(dop->download_cont, |
493 | dop->download_cont_cls); | 492 | dop->download_cont_cls); |
494 | GNUNET_TESTBED_operation_done (dop->fs_op); | 493 | GNUNET_TESTBED_operation_done(dop->fs_op); |
495 | GNUNET_FS_uri_destroy (dop->uri); | 494 | GNUNET_FS_uri_destroy(dop->uri); |
496 | GNUNET_free (dop); | 495 | GNUNET_free(dop); |
497 | } | 496 | } |
498 | 497 | ||
499 | 498 | ||
@@ -503,17 +502,17 @@ download_timeout (void *cls) | |||
503 | * @param cls the download operation context | 502 | * @param cls the download operation context |
504 | */ | 503 | */ |
505 | static void | 504 | static void |
506 | report_success (void *cls) | 505 | report_success(void *cls) |
507 | { | 506 | { |
508 | struct TestDownloadOperation *dop = cls; | 507 | struct TestDownloadOperation *dop = cls; |
509 | 508 | ||
510 | GNUNET_FS_download_stop (dop->download_context, | 509 | GNUNET_FS_download_stop(dop->download_context, |
511 | GNUNET_YES); | 510 | GNUNET_YES); |
512 | GNUNET_SCHEDULER_add_now (dop->download_cont, | 511 | GNUNET_SCHEDULER_add_now(dop->download_cont, |
513 | dop->download_cont_cls); | 512 | dop->download_cont_cls); |
514 | GNUNET_TESTBED_operation_done (dop->fs_op); | 513 | GNUNET_TESTBED_operation_done(dop->fs_op); |
515 | GNUNET_FS_uri_destroy (dop->uri); | 514 | GNUNET_FS_uri_destroy(dop->uri); |
516 | GNUNET_free (dop); | 515 | GNUNET_free(dop); |
517 | } | 516 | } |
518 | 517 | ||
519 | 518 | ||
@@ -524,34 +523,37 @@ report_success (void *cls) | |||
524 | * @param info information about the event | 523 | * @param info information about the event |
525 | */ | 524 | */ |
526 | static void * | 525 | static void * |
527 | download_progress_cb (void *cls, | 526 | download_progress_cb(void *cls, |
528 | const struct GNUNET_FS_ProgressInfo *info) | 527 | const struct GNUNET_FS_ProgressInfo *info) |
529 | { | 528 | { |
530 | struct TestDownloadOperation *dop = cls; | 529 | struct TestDownloadOperation *dop = cls; |
531 | 530 | ||
532 | switch (info->status) | 531 | switch (info->status) |
533 | { | 532 | { |
534 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 533 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
535 | if (dop->verbose) | 534 | if (dop->verbose) |
536 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 535 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
537 | "Download at %llu/%llu bytes\n", | 536 | "Download at %llu/%llu bytes\n", |
538 | (unsigned long long) info->value.download.completed, | 537 | (unsigned long long)info->value.download.completed, |
539 | (unsigned long long) info->value.download.size); | 538 | (unsigned long long)info->value.download.size); |
540 | break; | 539 | break; |
541 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 540 | |
542 | GNUNET_SCHEDULER_cancel (dop->download_timeout_task); | 541 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
543 | dop->download_timeout_task = NULL; | 542 | GNUNET_SCHEDULER_cancel(dop->download_timeout_task); |
544 | GNUNET_SCHEDULER_add_now (&report_success, dop); | 543 | dop->download_timeout_task = NULL; |
545 | break; | 544 | GNUNET_SCHEDULER_add_now(&report_success, dop); |
546 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 545 | break; |
547 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 546 | |
548 | break; | 547 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
548 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
549 | break; | ||
550 | |||
549 | /* FIXME: monitor data correctness during download progress */ | 551 | /* FIXME: monitor data correctness during download progress */ |
550 | /* FIXME: do performance reports given sufficient verbosity */ | 552 | /* FIXME: do performance reports given sufficient verbosity */ |
551 | /* FIXME: advance timeout task to "immediate" on error */ | 553 | /* FIXME: advance timeout task to "immediate" on error */ |
552 | default: | 554 | default: |
553 | break; | 555 | break; |
554 | } | 556 | } |
555 | return NULL; | 557 | return NULL; |
556 | } | 558 | } |
557 | 559 | ||
@@ -566,16 +568,16 @@ download_progress_cb (void *cls, | |||
566 | * @return service handle to return in 'op_result', NULL on error | 568 | * @return service handle to return in 'op_result', NULL on error |
567 | */ | 569 | */ |
568 | static void * | 570 | static void * |
569 | download_connect_adapter (void *cls, | 571 | download_connect_adapter(void *cls, |
570 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 572 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
571 | { | 573 | { |
572 | struct TestPublishOperation *po = cls; | 574 | struct TestPublishOperation *po = cls; |
573 | 575 | ||
574 | return GNUNET_FS_start (cfg, | 576 | return GNUNET_FS_start(cfg, |
575 | "fs-test-download", | 577 | "fs-test-download", |
576 | &download_progress_cb, po, | 578 | &download_progress_cb, po, |
577 | GNUNET_FS_FLAGS_NONE, | 579 | GNUNET_FS_FLAGS_NONE, |
578 | GNUNET_FS_OPTIONS_END); | 580 | GNUNET_FS_OPTIONS_END); |
579 | } | 581 | } |
580 | 582 | ||
581 | 583 | ||
@@ -589,19 +591,19 @@ download_connect_adapter (void *cls, | |||
589 | * operation has executed successfully. | 591 | * operation has executed successfully. |
590 | */ | 592 | */ |
591 | static void | 593 | static void |
592 | download_fs_connect_complete_cb (void *cls, | 594 | download_fs_connect_complete_cb(void *cls, |
593 | struct GNUNET_TESTBED_Operation *op, | 595 | struct GNUNET_TESTBED_Operation *op, |
594 | void *ca_result, | 596 | void *ca_result, |
595 | const char *emsg) | 597 | const char *emsg) |
596 | { | 598 | { |
597 | struct TestDownloadOperation *dop = cls; | 599 | struct TestDownloadOperation *dop = cls; |
598 | 600 | ||
599 | dop->fs = ca_result; | 601 | dop->fs = ca_result; |
600 | GNUNET_assert (NULL != dop->fs); | 602 | GNUNET_assert(NULL != dop->fs); |
601 | dop->download_context = | 603 | dop->download_context = |
602 | GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, | 604 | GNUNET_FS_download_start(dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, |
603 | dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, | 605 | dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, |
604 | NULL, NULL); | 606 | NULL, NULL); |
605 | } | 607 | } |
606 | 608 | ||
607 | 609 | ||
@@ -619,33 +621,33 @@ download_fs_connect_complete_cb (void *cls, | |||
619 | * @param cont_cls closure for cont | 621 | * @param cont_cls closure for cont |
620 | */ | 622 | */ |
621 | void | 623 | void |
622 | GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, | 624 | GNUNET_FS_TEST_download(struct GNUNET_TESTBED_Peer *peer, |
623 | struct GNUNET_TIME_Relative timeout, | 625 | struct GNUNET_TIME_Relative timeout, |
624 | uint32_t anonymity, uint32_t seed, | 626 | uint32_t anonymity, uint32_t seed, |
625 | const struct GNUNET_FS_Uri *uri, unsigned int verbose, | 627 | const struct GNUNET_FS_Uri *uri, unsigned int verbose, |
626 | GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) | 628 | GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) |
627 | { | 629 | { |
628 | struct TestDownloadOperation *dop; | 630 | struct TestDownloadOperation *dop; |
629 | 631 | ||
630 | dop = GNUNET_new (struct TestDownloadOperation); | 632 | dop = GNUNET_new(struct TestDownloadOperation); |
631 | dop->uri = GNUNET_FS_uri_dup (uri); | 633 | dop->uri = GNUNET_FS_uri_dup(uri); |
632 | dop->size = GNUNET_FS_uri_chk_get_file_size (uri); | 634 | dop->size = GNUNET_FS_uri_chk_get_file_size(uri); |
633 | dop->verbose = verbose; | 635 | dop->verbose = verbose; |
634 | dop->anonymity = anonymity; | 636 | dop->anonymity = anonymity; |
635 | dop->download_cont = cont; | 637 | dop->download_cont = cont; |
636 | dop->download_cont_cls = cont_cls; | 638 | dop->download_cont_cls = cont_cls; |
637 | dop->download_seed = seed; | 639 | dop->download_seed = seed; |
638 | 640 | ||
639 | dop->fs_op = GNUNET_TESTBED_service_connect (dop, | 641 | dop->fs_op = GNUNET_TESTBED_service_connect(dop, |
640 | peer, | 642 | peer, |
641 | "fs", | 643 | "fs", |
642 | &download_fs_connect_complete_cb, | 644 | &download_fs_connect_complete_cb, |
643 | dop, | 645 | dop, |
644 | &download_connect_adapter, | 646 | &download_connect_adapter, |
645 | &fs_disconnect_adapter, | 647 | &fs_disconnect_adapter, |
646 | dop); | 648 | dop); |
647 | dop->download_timeout_task = | 649 | dop->download_timeout_task = |
648 | GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, dop); | 650 | GNUNET_SCHEDULER_add_delayed(timeout, &download_timeout, dop); |
649 | } | 651 | } |
650 | 652 | ||
651 | 653 | ||