gnunet-fuse

GNUnet file-sharing directory mounting via FUSE
Log | Files | Refs | Submodules | README | LICENSE

commit 11dba0f1a415dd65376c974e44d4e49aaee34e4c
parent 9f51323d3d19a9663515a6c94b0eb6f06b20601f
Author: Mauricio Günther <mauricio@140774ce-b5e7-0310-ab8b-a85725594a96>
Date:   Wed, 28 Mar 2012 08:09:39 +0000

-changes


Diffstat:
Msrc/ext/gnunet-fuse.c | 57++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/ext/gnunet-fuse.h | 12++++++++----
Msrc/ext/readdir.c | 65++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
3 files changed, 112 insertions(+), 22 deletions(-)

diff --git a/src/ext/gnunet-fuse.c b/src/ext/gnunet-fuse.c @@ -33,7 +33,6 @@ #include <gnunet/gnunet_container_lib.h> #include <gnunet/gnunet_crypto_lib.h> -//struct GNUNET_CONTAINER_MultiHashMap *map; static int ret; @@ -83,6 +82,40 @@ static struct fuse_operations fops = { }; +struct GNUNET_FUSE_path_info * +create_path_info (const char *path, const struct GNUNET_FS_Uri *uri) +{ + struct GNUNET_FUSE_path_info * pi; + + GNUNET_assert (NULL != path); + GNUNET_assert (NULL != uri); + + pi = GNUNET_malloc (sizeof (struct GNUNET_FUSE_path_info)); + pi->path = strdup (path); + //FIX + //pi->source = strdup (uri); + + return pi; +} + +void +delete_path_info (struct GNUNET_FUSE_path_info *pi) +{ + GNUNET_free (pi->path); + // FIX free uri + GNUNET_free (pi); +} + +int cleanup_path_info (void *cls, + const GNUNET_HashCode * key, + void *value) +{ + struct GNUNET_FUSE_path_info *pi = value; + + delete_path_info (pi); +} + + /** * Main function that will be run by the scheduler. * @@ -98,7 +131,10 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { int argc; + struct GNUNET_FUSE_path_info *pi; + struct GNUNET_FS_Uri *uri; ret = 0; + //char * test= GNUNET_malloc(500); //GNUNET_free (test); //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR\n-d option for mountpoint required %s\n", test); @@ -138,17 +174,24 @@ run (void *cls, a[3] = "-f"; a[4] = "-d"; } + /* create MultiHashMap */ + map = GNUNET_CONTAINER_multihashmap_create (10); + GNUNET_HashCode path_hash; + char * path = "/"; + GNUNET_CRYPTO_hash (path, strlen (path), &path_hash); -/* create MultiHashMap */ -unsigned int len = strlen(directory); + /* new path */ + // FIX parse source string to uri + pi = create_path_info (path, uri); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(map, &path_hash, pi, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); -struct GNUNET_CONTAINER_MultiHashMap *map; -map = GNUNET_CONTAINER_multihashmap_create (len); + /* main function of fuse */ + fuse_main(argc, a, &fops, NULL); + GNUNET_CONTAINER_multihashmap_iterate(map, &cleanup_path_info, NULL); -/* main function of fuse */ - fuse_main(argc, a, &fops, NULL); + GNUNET_CONTAINER_multihashmap_destroy(map); } /** diff --git a/src/ext/gnunet-fuse.h b/src/ext/gnunet-fuse.h @@ -44,7 +44,7 @@ static char *source; static char *directory; - +struct GNUNET_CONTAINER_MultiHashMap *map; /* struct containing mapped Path, with URI and other Information like Attributes etc. */ @@ -52,17 +52,21 @@ static char *directory; struct GNUNET_FUSE_path_info { /* uri to corresponding path */ - char* source; + struct GNUNET_FS_Uri *uri; /* pathname */ char* path; -/* key */ - GNUNET_HashCode hash; + /*name of temporary file */ char* tmpfile; /*file attributes*/ struct stat; }; +struct GNUNET_FUSE_path_info * +create_path_info (path, uri); + +void +delet_path_info (struct GNUNET_FUSE_path_info *pi); /* FUSE function files */ int gn_getattr(const char *path, struct stat *stbuf); diff --git a/src/ext/readdir.c b/src/ext/readdir.c @@ -72,6 +72,11 @@ struct GNUNET_CONTAINER_MultiHashMap *map; struct GNUNET_FS_Uri *uri; +char *emsg; + +struct GNUNET_FUSE_path_info *r; + + static void @@ -170,7 +175,7 @@ void readdir_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { - char *emsg; + enum GNUNET_FS_DownloadOptions options; @@ -206,7 +211,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->tmpfile, NULL, 0, + dc = GNUNET_FS_download_start (fs, uri, NULL, r->tmpfile, NULL, 0, GNUNET_FS_uri_chk_get_file_size(uri), anonymity, options, NULL, NULL); @@ -226,29 +231,52 @@ void readdir_task (void *cls, int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { - + struct GNUNET_FUSE_path_info * path_info = NULL; + printf("FUSE PATH gives me: `%s'\n", path); (void) fi; (void) offset; - struct GNUNET_FUSE_path_info *r; + + GNUNET_HashCode path_hash; + GNUNET_CRYPTO_hash (path, strlen (path), &path_hash); + if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(map, &path_hash)) + { + /* new path */ + path_info = create_path_info (path, NULL); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(map, &path_hash, path_info, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } + else + { + /* existing path */ + path_info = GNUNET_CONTAINER_multihashmap_get (map, &path_hash); + } + + GNUNET_assert (path_info != NULL); + +#if 0 + r = GNUNET_malloc (sizeof (struct GNUNET_FUSE_path_info)); + int len = strlen(path); int exist = 0; + r->path = path; - r = GNUNET_malloc (sizeof (struct GNUNET_FUSE_path_info)); + /* compute key */ - exist = GNUNET_CONTAINER_multihashmap_contains (map, r->hash,); - if ( exist == GNUNET_NO) + GNUNET_CRYPTO_hash (r->path, len, r->hash); + + + exist = GNUNET_CONTAINER_multihashmap_contains (map, r->hash); + if ( exist == GNUNET_NO) + { -/* compute key */ - GNUNET_CRYPTO_hash (r->path, len, r->hash); /* Store a key-value pair in the map */ - GNUNET_CONTAINER_multihashmap_put (map, directory, source, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + GNUNET_CONTAINER_multihashmap_put (map, r->hash, r->path, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); /* store to temporary file */ r->tmpfile = GNUNET_DISK_mktemp("gnunet-fuse-tempfile"); /* find value with given key */ - r->source = GNUNET_CONTAINER_multihashmap_get (map, r->path); + r->source = GNUNET_CONTAINER_multihashmap_get (map, r->hash); /* parse uri from given source */ uri = GNUNET_FS_uri_parse(r->source, &emsg); @@ -258,7 +286,22 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, filler(buf, "..", NULL, 0); return 0; + } + + else + { + uri = GNUNET_FS_uri_parse(r->source, &emsg); + GNUNET_SCHEDULER_run(&readdir_task, NULL); + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + return 0; + } +#endif + + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + return 0; }