diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-06 19:59:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-06 19:59:59 +0000 |
commit | 7db4f64461a77f19bb39f1b84d26f96e6acf40ab (patch) | |
tree | 7d2adef1cebe18d80806bba3d534e9a1e4a44ac6 /src/fs | |
parent | 0ece77aca2114b6e5ec153477fccb43ceb807c77 (diff) | |
download | gnunet-7db4f64461a77f19bb39f1b84d26f96e6acf40ab.tar.gz gnunet-7db4f64461a77f19bb39f1b84d26f96e6acf40ab.zip |
allow file hashing cancellation -- and make use of it
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs.c | 12 | ||||
-rw-r--r-- | src/fs/fs.h | 5 | ||||
-rw-r--r-- | src/fs/fs_unindex.c | 25 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_indexing.c | 27 |
4 files changed, 48 insertions, 21 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c index 31c8eee49..1968a8453 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c | |||
@@ -2058,12 +2058,12 @@ deserialize_unindex_file (void *cls, | |||
2058 | switch (uc->state) | 2058 | switch (uc->state) |
2059 | { | 2059 | { |
2060 | case UNINDEX_STATE_HASHING: | 2060 | case UNINDEX_STATE_HASHING: |
2061 | GNUNET_CRYPTO_hash_file (uc->h->sched, | 2061 | uc->fhc = GNUNET_CRYPTO_hash_file (uc->h->sched, |
2062 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 2062 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
2063 | uc->filename, | 2063 | uc->filename, |
2064 | HASHING_BLOCKSIZE, | 2064 | HASHING_BLOCKSIZE, |
2065 | &GNUNET_FS_unindex_process_hash_, | 2065 | &GNUNET_FS_unindex_process_hash_, |
2066 | uc); | 2066 | uc); |
2067 | break; | 2067 | break; |
2068 | case UNINDEX_STATE_FS_NOTIFY: | 2068 | case UNINDEX_STATE_FS_NOTIFY: |
2069 | uc->state = UNINDEX_STATE_HASHING; | 2069 | uc->state = UNINDEX_STATE_HASHING; |
diff --git a/src/fs/fs.h b/src/fs/fs.h index d8e997324..bca8fc691 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -1408,6 +1408,11 @@ struct GNUNET_FS_UnindexContext | |||
1408 | char *emsg; | 1408 | char *emsg; |
1409 | 1409 | ||
1410 | /** | 1410 | /** |
1411 | * Context for hashing of the file. | ||
1412 | */ | ||
1413 | struct GNUNET_CRYPTO_FileHashContext *fhc; | ||
1414 | |||
1415 | /** | ||
1411 | * Overall size of the file. | 1416 | * Overall size of the file. |
1412 | */ | 1417 | */ |
1413 | uint64_t file_size; | 1418 | uint64_t file_size; |
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index 5989fd2c0..db0540607 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c | |||
@@ -365,6 +365,7 @@ GNUNET_FS_unindex_process_hash_ (void *cls, | |||
365 | struct GNUNET_FS_UnindexContext *uc = cls; | 365 | struct GNUNET_FS_UnindexContext *uc = cls; |
366 | struct UnindexMessage req; | 366 | struct UnindexMessage req; |
367 | 367 | ||
368 | uc->fhc = NULL; | ||
368 | if (uc->state != UNINDEX_STATE_HASHING) | 369 | if (uc->state != UNINDEX_STATE_HASHING) |
369 | { | 370 | { |
370 | GNUNET_FS_unindex_stop (uc); | 371 | GNUNET_FS_unindex_stop (uc); |
@@ -410,6 +411,11 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) | |||
410 | struct GNUNET_FS_UnindexContext *uc = cls; | 411 | struct GNUNET_FS_UnindexContext *uc = cls; |
411 | struct GNUNET_FS_ProgressInfo pi; | 412 | struct GNUNET_FS_ProgressInfo pi; |
412 | 413 | ||
414 | if (uc->fhc != NULL) | ||
415 | { | ||
416 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); | ||
417 | uc->fhc = NULL; | ||
418 | } | ||
413 | GNUNET_FS_end_top (uc->h, uc->top); | 419 | GNUNET_FS_end_top (uc->h, uc->top); |
414 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; | 420 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; |
415 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 421 | GNUNET_FS_unindex_make_status_ (&pi, uc, |
@@ -454,13 +460,12 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, | |||
454 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; | 460 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; |
455 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 461 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
456 | GNUNET_FS_unindex_make_status_ (&pi, ret, 0); | 462 | GNUNET_FS_unindex_make_status_ (&pi, ret, 0); |
457 | /* FIXME: must be able to abort hashing here! */ | 463 | ret->fhc = GNUNET_CRYPTO_hash_file (h->sched, |
458 | GNUNET_CRYPTO_hash_file (h->sched, | 464 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
459 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 465 | filename, |
460 | filename, | 466 | HASHING_BLOCKSIZE, |
461 | HASHING_BLOCKSIZE, | 467 | &GNUNET_FS_unindex_process_hash_, |
462 | &GNUNET_FS_unindex_process_hash_, | 468 | ret); |
463 | ret); | ||
464 | ret->top = GNUNET_FS_make_top (h, | 469 | ret->top = GNUNET_FS_make_top (h, |
465 | &GNUNET_FS_unindex_signal_suspend_, | 470 | &GNUNET_FS_unindex_signal_suspend_, |
466 | ret); | 471 | ret); |
@@ -478,7 +483,11 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) | |||
478 | { | 483 | { |
479 | struct GNUNET_FS_ProgressInfo pi; | 484 | struct GNUNET_FS_ProgressInfo pi; |
480 | 485 | ||
481 | /* FIXME: stop hashing (if still ongoing) */ | 486 | if (uc->fhc != NULL) |
487 | { | ||
488 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); | ||
489 | uc->fhc = NULL; | ||
490 | } | ||
482 | /* FIXME: disconnect uc->client (if still connected) */ | 491 | /* FIXME: disconnect uc->client (if still connected) */ |
483 | /* FIXME: disconnect from datastore (if still connected) */ | 492 | /* FIXME: disconnect from datastore (if still connected) */ |
484 | /* FIXME: other termination operations? */ | 493 | /* FIXME: other termination operations? */ |
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index a5ac0dda3..f8593ffd4 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c | |||
@@ -22,6 +22,11 @@ | |||
22 | * @file fs/gnunet-service-fs_indexing.c | 22 | * @file fs/gnunet-service-fs_indexing.c |
23 | * @brief program that provides indexing functions of the file-sharing service | 23 | * @brief program that provides indexing functions of the file-sharing service |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | ||
26 | * TODO: | ||
27 | * - consider doing GNUNET_CRYPTO_hash_file_cancel on active indexing | ||
28 | * jobs during shutdown (currently, shutdown will only happen after | ||
29 | * all of those are done, not sure if this is good or bad) | ||
25 | */ | 30 | */ |
26 | #include "platform.h" | 31 | #include "platform.h" |
27 | #include <float.h> | 32 | #include <float.h> |
@@ -60,6 +65,11 @@ struct IndexInfo | |||
60 | * NULL if we've done this already. | 65 | * NULL if we've done this already. |
61 | */ | 66 | */ |
62 | struct GNUNET_SERVER_TransmitContext *tc; | 67 | struct GNUNET_SERVER_TransmitContext *tc; |
68 | |||
69 | /** | ||
70 | * Context for hashing of the file. | ||
71 | */ | ||
72 | struct GNUNET_CRYPTO_FileHashContext *fhc; | ||
63 | 73 | ||
64 | /** | 74 | /** |
65 | * Hash of the contents of the file. | 75 | * Hash of the contents of the file. |
@@ -282,7 +292,8 @@ hash_for_index_val (void *cls, | |||
282 | res) | 292 | res) |
283 | { | 293 | { |
284 | struct IndexInfo *ii = cls; | 294 | struct IndexInfo *ii = cls; |
285 | 295 | ||
296 | ii->fhc = NULL; | ||
286 | if ( (res == NULL) || | 297 | if ( (res == NULL) || |
287 | (0 != memcmp (res, | 298 | (0 != memcmp (res, |
288 | &ii->file_id, | 299 | &ii->file_id, |
@@ -375,12 +386,14 @@ GNUNET_FS_handle_index_start (void *cls, | |||
375 | (unsigned int) mydev); | 386 | (unsigned int) mydev); |
376 | #endif | 387 | #endif |
377 | /* slow validation, need to hash full file (again) */ | 388 | /* slow validation, need to hash full file (again) */ |
378 | GNUNET_CRYPTO_hash_file (sched, | 389 | ii->fhc = GNUNET_CRYPTO_hash_file (sched, |
379 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 390 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
380 | fn, | 391 | fn, |
381 | HASHING_BLOCKSIZE, | 392 | HASHING_BLOCKSIZE, |
382 | &hash_for_index_val, | 393 | &hash_for_index_val, |
383 | ii); | 394 | ii); |
395 | if (ii->fhc == NULL) | ||
396 | hash_for_index_val (ii, NULL); | ||
384 | GNUNET_free (fn); | 397 | GNUNET_free (fn); |
385 | } | 398 | } |
386 | 399 | ||