[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11238 - in gnunet/src: fs include transport util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11238 - in gnunet/src: fs include transport util |
Date: |
Thu, 6 May 2010 21:59:59 +0200 |
Author: grothoff
Date: 2010-05-06 21:59:59 +0200 (Thu, 06 May 2010)
New Revision: 11238
Modified:
gnunet/src/fs/fs.c
gnunet/src/fs/fs.h
gnunet/src/fs/fs_unindex.c
gnunet/src/fs/gnunet-service-fs_indexing.c
gnunet/src/include/gnunet_crypto_lib.h
gnunet/src/transport/plugin_transport_http.c
gnunet/src/util/crypto_hash.c
gnunet/src/util/test_crypto_hash.c
Log:
allow file hashing cancellation -- and make use of it
Modified: gnunet/src/fs/fs.c
===================================================================
--- gnunet/src/fs/fs.c 2010-05-06 19:44:57 UTC (rev 11237)
+++ gnunet/src/fs/fs.c 2010-05-06 19:59:59 UTC (rev 11238)
@@ -2058,12 +2058,12 @@
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;
Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h 2010-05-06 19:44:57 UTC (rev 11237)
+++ gnunet/src/fs/fs.h 2010-05-06 19:59:59 UTC (rev 11238)
@@ -1408,6 +1408,11 @@
char *emsg;
/**
+ * Context for hashing of the file.
+ */
+ struct GNUNET_CRYPTO_FileHashContext *fhc;
+
+ /**
* Overall size of the file.
*/
uint64_t file_size;
Modified: gnunet/src/fs/fs_unindex.c
===================================================================
--- gnunet/src/fs/fs_unindex.c 2010-05-06 19:44:57 UTC (rev 11237)
+++ gnunet/src/fs/fs_unindex.c 2010-05-06 19:59:59 UTC (rev 11238)
@@ -365,6 +365,7 @@
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 @@
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 @@
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 @@
{
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? */
Modified: gnunet/src/fs/gnunet-service-fs_indexing.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_indexing.c 2010-05-06 19:44:57 UTC (rev
11237)
+++ gnunet/src/fs/gnunet-service-fs_indexing.c 2010-05-06 19:59:59 UTC (rev
11238)
@@ -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 <float.h>
@@ -60,6 +65,11 @@
* 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 @@
res)
{
struct IndexInfo *ii = cls;
-
+
+ ii->fhc = NULL;
if ( (res == NULL) ||
(0 != memcmp (res,
&ii->file_id,
@@ -375,12 +386,14 @@
(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);
}
Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h 2010-05-06 19:44:57 UTC (rev
11237)
+++ gnunet/src/include/gnunet_crypto_lib.h 2010-05-06 19:59:59 UTC (rev
11238)
@@ -366,6 +366,11 @@
/**
+ * Handle to file hashing operation.
+ */
+struct GNUNET_CRYPTO_FileHashContext;
+
+/**
* Compute the hash of an entire file.
*
* @param sched scheduler to use
@@ -374,16 +379,27 @@
* @param blocksize number of bytes to process in one task
* @param callback function to call upon completion
* @param callback_cls closure for callback
+ * @return NULL on (immediate) errror
*/
-void GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
- enum GNUNET_SCHEDULER_Priority priority,
- const char *filename,
- size_t blocksize,
- GNUNET_CRYPTO_HashCompletedCallback callback,
- void *callback_cls);
+struct GNUNET_CRYPTO_FileHashContext *
+GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
+ enum GNUNET_SCHEDULER_Priority priority,
+ const char *filename,
+ size_t blocksize,
+ GNUNET_CRYPTO_HashCompletedCallback callback,
+ void *callback_cls);
/**
+ * Cancel a file hashing operation.
+ *
+ * @param fhc operation to cancel (callback must not yet have been invoked)
+ */
+void
+GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
+
+
+/**
* Create a random hash code.
*
* @param mode desired quality level
Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c 2010-05-06 19:44:57 UTC
(rev 11237)
+++ gnunet/src/transport/plugin_transport_http.c 2010-05-06 19:59:59 UTC
(rev 11238)
@@ -181,12 +181,14 @@
return strdup("http://localhost:12389");
}
+#if 0
static size_t curl_read_function( void *ptr, size_t size, size_t nmemb, void
*stream)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl read function\n");
// strcpy ("Testmessa")
return 0;
}
+#endif
/**
* Task that is run when we are ready to receive more data from the hostlist
Modified: gnunet/src/util/crypto_hash.c
===================================================================
--- gnunet/src/util/crypto_hash.c 2010-05-06 19:44:57 UTC (rev 11237)
+++ gnunet/src/util/crypto_hash.c 2010-05-06 19:59:59 UTC (rev 11238)
@@ -372,7 +372,7 @@
/**
* Context used when hashing a file.
*/
-struct FileHashContext
+struct GNUNET_CRYPTO_FileHashContext
{
/**
@@ -396,16 +396,21 @@
char *filename;
/**
- * Cummulated hash.
+ * File descriptor.
*/
- struct sha512_ctx hctx;
+ struct GNUNET_DISK_FileHandle *fh;
/**
- * Blocksize.
+ * Our scheduler.
*/
- size_t bsize;
+ struct GNUNET_SCHEDULER_Handle *sched;
/**
+ * Cummulated hash.
+ */
+ struct sha512_ctx hctx;
+
+ /**
* Size of the file.
*/
uint64_t fsize;
@@ -416,10 +421,15 @@
uint64_t offset;
/**
- * File descriptor.
+ * Current task for hashing.
*/
- struct GNUNET_DISK_FileHandle *fh;
+ GNUNET_SCHEDULER_TaskIdentifier task;
+ /**
+ * Blocksize.
+ */
+ size_t bsize;
+
};
@@ -428,7 +438,8 @@
* and free associated resources.
*/
static void
-file_hash_finish (struct FileHashContext *fhc, const GNUNET_HashCode * res)
+file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
+ const GNUNET_HashCode * res)
{
fhc->callback (fhc->callback_cls, res);
GNUNET_free (fhc->filename);
@@ -447,10 +458,11 @@
static void
file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct FileHashContext *fhc = cls;
+ struct GNUNET_CRYPTO_FileHashContext *fhc = cls;
GNUNET_HashCode res;
size_t delta;
+ fhc->task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (fhc->offset < fhc->fsize);
delta = fhc->bsize;
if (fhc->fsize - fhc->offset < delta)
@@ -470,8 +482,10 @@
file_hash_finish (fhc, &res);
return;
}
- GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
+ fhc->task
+ = GNUNET_SCHEDULER_add_after (tc->sched,
+ GNUNET_SCHEDULER_NO_TASK,
+ &file_hash_task, fhc);
}
@@ -484,8 +498,9 @@
* @param blocksize number of bytes to process in one task
* @param callback function to call upon completion
* @param callback_cls closure for callback
+ * @return NULL on (immediate) errror
*/
-void
+struct GNUNET_CRYPTO_FileHashContext *
GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
enum GNUNET_SCHEDULER_Priority priority,
const char *filename,
@@ -493,12 +508,13 @@
GNUNET_CRYPTO_HashCompletedCallback callback,
void *callback_cls)
{
- struct FileHashContext *fhc;
+ struct GNUNET_CRYPTO_FileHashContext *fhc;
GNUNET_assert (blocksize > 0);
- fhc = GNUNET_malloc (sizeof (struct FileHashContext) + blocksize);
+ fhc = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) +
blocksize);
fhc->callback = callback;
fhc->callback_cls = callback_cls;
+ fhc->sched = sched;
fhc->buffer = (unsigned char *) &fhc[1];
fhc->filename = GNUNET_strdup (filename);
fhc->fh = NULL;
@@ -506,21 +522,43 @@
fhc->bsize = blocksize;
if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO))
{
- file_hash_finish (fhc, NULL);
- return;
+ GNUNET_free (fhc->filename);
+ GNUNET_free (fhc);
+ return NULL;
}
fhc->fh = GNUNET_DISK_file_open (filename,
GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (!fhc->fh)
{
- file_hash_finish (fhc, NULL);
- return;
+ GNUNET_free (fhc->filename);
+ GNUNET_free (fhc);
+ return NULL;
}
- GNUNET_SCHEDULER_add_with_priority (sched, priority, &file_hash_task, fhc);
+ fhc->task
+ = GNUNET_SCHEDULER_add_with_priority (sched, priority,
+ &file_hash_task, fhc);
+ return fhc;
}
+/**
+ * Cancel a file hashing operation.
+ *
+ * @param fhc operation to cancel (callback must not yet have been invoked)
+ */
+void
+GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc)
+{
+ GNUNET_SCHEDULER_cancel (fhc->sched,
+ fhc->task);
+ GNUNET_free (fhc->filename);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
+ GNUNET_free (fhc);
+}
+
+
+
/* ***************** binary-ASCII encoding *************** */
/**
Modified: gnunet/src/util/test_crypto_hash.c
===================================================================
--- gnunet/src/util/test_crypto_hash.c 2010-05-06 19:44:57 UTC (rev 11237)
+++ gnunet/src/util/test_crypto_hash.c 2010-05-06 19:59:59 UTC (rev 11238)
@@ -122,9 +122,11 @@
static void
file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_CRYPTO_hash_file (tc->sched,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- FILENAME, 1024, &finished_task, cls);
+ GNUNET_assert (NULL !=
+ GNUNET_CRYPTO_hash_file (tc->sched,
+ GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ FILENAME, 1024,
+ &finished_task, cls));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11238 - in gnunet/src: fs include transport util,
gnunet <=