From 7db4f64461a77f19bb39f1b84d26f96e6acf40ab Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 6 May 2010 19:59:59 +0000 Subject: allow file hashing cancellation -- and make use of it --- src/fs/fs.c | 12 ++++++------ src/fs/fs.h | 5 +++++ src/fs/fs_unindex.c | 25 +++++++++++++++++-------- src/fs/gnunet-service-fs_indexing.c | 27 ++++++++++++++++++++------- 4 files changed, 48 insertions(+), 21 deletions(-) (limited to 'src/fs') 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, switch (uc->state) { case UNINDEX_STATE_HASHING: - GNUNET_CRYPTO_hash_file (uc->h->sched, - GNUNET_SCHEDULER_PRIORITY_IDLE, - uc->filename, - HASHING_BLOCKSIZE, - &GNUNET_FS_unindex_process_hash_, - uc); + uc->fhc = GNUNET_CRYPTO_hash_file (uc->h->sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + uc->filename, + HASHING_BLOCKSIZE, + &GNUNET_FS_unindex_process_hash_, + uc); break; case UNINDEX_STATE_FS_NOTIFY: 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 @@ -1407,6 +1407,11 @@ struct GNUNET_FS_UnindexContext */ char *emsg; + /** + * Context for hashing of the file. + */ + struct GNUNET_CRYPTO_FileHashContext *fhc; + /** * Overall size of the file. */ 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, struct GNUNET_FS_UnindexContext *uc = cls; struct UnindexMessage req; + uc->fhc = NULL; if (uc->state != UNINDEX_STATE_HASHING) { GNUNET_FS_unindex_stop (uc); @@ -410,6 +411,11 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) struct GNUNET_FS_UnindexContext *uc = cls; struct GNUNET_FS_ProgressInfo pi; + if (uc->fhc != NULL) + { + GNUNET_CRYPTO_hash_file_cancel (uc->fhc); + uc->fhc = NULL; + } GNUNET_FS_end_top (uc->h, uc->top); pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; GNUNET_FS_unindex_make_status_ (&pi, uc, @@ -454,13 +460,12 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, pi.status = GNUNET_FS_STATUS_UNINDEX_START; pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; GNUNET_FS_unindex_make_status_ (&pi, ret, 0); - /* FIXME: must be able to abort hashing here! */ - GNUNET_CRYPTO_hash_file (h->sched, - GNUNET_SCHEDULER_PRIORITY_IDLE, - filename, - HASHING_BLOCKSIZE, - &GNUNET_FS_unindex_process_hash_, - ret); + ret->fhc = GNUNET_CRYPTO_hash_file (h->sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + filename, + HASHING_BLOCKSIZE, + &GNUNET_FS_unindex_process_hash_, + ret); ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, ret); @@ -478,7 +483,11 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_FS_ProgressInfo pi; - /* FIXME: stop hashing (if still ongoing) */ + if (uc->fhc != NULL) + { + GNUNET_CRYPTO_hash_file_cancel (uc->fhc); + uc->fhc = NULL; + } /* FIXME: disconnect uc->client (if still connected) */ /* FIXME: disconnect from datastore (if still connected) */ /* 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 @@ * @file fs/gnunet-service-fs_indexing.c * @brief program that provides indexing functions of the file-sharing service * @author Christian Grothoff + * + * TODO: + * - consider doing GNUNET_CRYPTO_hash_file_cancel on active indexing + * jobs during shutdown (currently, shutdown will only happen after + * all of those are done, not sure if this is good or bad) */ #include "platform.h" #include @@ -60,6 +65,11 @@ struct IndexInfo * NULL if we've done this already. */ struct GNUNET_SERVER_TransmitContext *tc; + + /** + * Context for hashing of the file. + */ + struct GNUNET_CRYPTO_FileHashContext *fhc; /** * Hash of the contents of the file. @@ -282,7 +292,8 @@ hash_for_index_val (void *cls, res) { struct IndexInfo *ii = cls; - + + ii->fhc = NULL; if ( (res == NULL) || (0 != memcmp (res, &ii->file_id, @@ -375,12 +386,14 @@ GNUNET_FS_handle_index_start (void *cls, (unsigned int) mydev); #endif /* slow validation, need to hash full file (again) */ - GNUNET_CRYPTO_hash_file (sched, - GNUNET_SCHEDULER_PRIORITY_IDLE, - fn, - HASHING_BLOCKSIZE, - &hash_for_index_val, - ii); + ii->fhc = GNUNET_CRYPTO_hash_file (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + fn, + HASHING_BLOCKSIZE, + &hash_for_index_val, + ii); + if (ii->fhc == NULL) + hash_for_index_val (ii, NULL); GNUNET_free (fn); } -- cgit v1.2.3