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