commit db729e7c0cf6c138466301357b595d6e9d396001
parent a4189b2fc3d0c37477b4967e58eb888b01bba4ad
Author: Mauricio Günther <mauricio@140774ce-b5e7-0310-ab8b-a85725594a96>
Date: Mon, 26 Mar 2012 13:26:59 +0000
-n.w.c
Diffstat:
3 files changed, 84 insertions(+), 11 deletions(-)
diff --git a/src/ext/gnunet-fuse.c b/src/ext/gnunet-fuse.c
@@ -31,11 +31,16 @@
#include "gnunet-fuse.h"
#include <gnunet/gnunet_container_lib.h>
+#include <gnunet/gnunet_crypto_lib.h>
+
+struct GNUNET_CONTAINER_MultiHashMap *map;
static int ret;
+
+
/* Context for the command. */
struct CommandContext
{
@@ -134,6 +139,46 @@ run (void *cls,
a[4] = "-d";
}
+
+ /* Store a key-value pair in the map. */
+ struct path_uri *t;
+
+ t = GNUNET_malloc (sizeof (struct path_uri));
+
+ GNUNET_CONTAINER_multihashmap_put (map, directory, source, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+
+
+
+/* create MultiHashMap
+struct GNUNET_CONTAINER_MultiHashMap *map;
+unsigned int len = strlen(path);
+
+map = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MultiHashMap));
+map = GNUNET_CONTAINER_multihashmap_create (len);
+*/
+
+/* compute key
+
+int size = sizeof(block);
+struct path_uri * r;
+
+GNUNET_CRYPTO_hash (path, len, r);
+*/
+
+
+/* Store a key-value pair in the map.
+
+struct path_uri *t;
+
+t = GNUNET_malloc (sizeof (struct path_uri));
+
+GNUNET_CONTAINER_multihashmap_put (map, t->path, t->source, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+
+
+*/
+
+
+/* main function of fuse */
fuse_main(argc, a, &fops, NULL);
}
@@ -148,8 +193,6 @@ int
main (int argc, char *const *argv)
{
-
-
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'s', "source", "URI",
gettext_noop ("Source you get the URI from"), 1,
diff --git a/src/ext/gnunet-fuse.h b/src/ext/gnunet-fuse.h
@@ -46,15 +46,19 @@ static char *source;
static char *directory;
+
/* struct containing mapped Path, with URI and other Information like Attributes etc. */
-struct gnunet_fuse_path_uri
+struct path_uri
{
/* uri to corresponding path */
char* source;
-
+/* pathname */
+ char* path;
+/* key */
+ int key;
/*name of temporary file */
- char* tf;
+ char* tmpfile;
};
diff --git a/src/ext/readdir.c b/src/ext/readdir.c
@@ -38,6 +38,8 @@
//#include <GNUnet/gnunet_ecrs_lib.h>
#include <gnunet-fuse.h>
#include <gnunet/gnunet_fs_service.h>
+#include <gnunet/gnunet_container_lib.h>
+#include "gnunet/gnunet_crypto_lib.h"
static int ret;
@@ -63,6 +65,10 @@ struct GNUNET_FS_Handle *fs;
static struct GNUNET_FS_Handle *ctx;
+struct GNUNET_CONTAINER_MultiHashMap *map;
+
+
+
static void
cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -84,7 +90,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
}
-
+/* callback function */
void *progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo * info)
{
@@ -161,18 +167,16 @@ void readdir_task (void *cls,
struct GNUNET_FS_Uri *uri;
char *emsg;
enum GNUNET_FS_DownloadOptions options;
- struct gnunet_fuse_path_uri *w;
- w = GNUNET_malloc (sizeof (struct gnunet_fuse_path_uri));
- w->tf = GNUNET_DISK_mktemp("gnunet-fuse-tempfile");
- w->source = source;
+
uri = GNUNET_FS_uri_parse(w->source, &emsg);
if (NULL == uri)
{
FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg);
GNUNET_free (emsg);
+ GNUNET_FS_stop (ctx); // ?? hmmm....stop before start ??
}
@@ -197,7 +201,7 @@ void readdir_task (void *cls,
options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
struct GNUNET_FS_DownloadContext* dc;
- dc = GNUNET_FS_download_start (fs, uri, NULL, w->tf, NULL, 0,
+ dc = GNUNET_FS_download_start (fs, uri, NULL, w->tmpfile, NULL, 0,
GNUNET_FS_uri_chk_get_file_size(uri),
anonymity, options, NULL, NULL);
@@ -221,6 +225,28 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
(void) fi;
(void) offset;
+
+ /* create MultiHashMap */
+ unsigned int len = strlen();
+
+ map = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MultiHashMap));
+ map = GNUNET_CONTAINER_multihashmap_create (len);
+
+
+ /* compute key */
+ struct path_uri * r;
+
+ GNUNET_CRYPTO_hash (r->path, len, r->key);
+
+
+ /* find value with given key */
+
+ w = GNUNET_malloc (sizeof (struct path_uri));
+ w->tmpfile = GNUNET_DISK_mktemp("gnunet-fuse-tempfile");
+ w->source = GNUNET_CONTAINER_multihashmap_get (map, w->path);
+
+
+
GNUNET_SCHEDULER_run(&readdir_task, NULL);