gnunet-fuse

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

commit 0ea485361bd0f316648152dc2977913584ea03cb
parent add3740dc9f3d6cafe030afbb45b8f13cd26f9cd
Author: Mauricio Günther <mauricio@140774ce-b5e7-0310-ab8b-a85725594a96>
Date:   Fri, 23 Mar 2012 10:13:27 +0000

-changes


Diffstat:
Msrc/ext/getattr.c | 43+++----------------------------------------
Msrc/ext/gnunet-fuse.h | 1-
Msrc/ext/open.c | 16++++++++++------
Msrc/ext/read.c | 26++++++++++++++++++++++----
Msrc/ext/readdir.c | 188++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
5 files changed, 213 insertions(+), 61 deletions(-)

diff --git a/src/ext/getattr.c b/src/ext/getattr.c @@ -23,48 +23,11 @@ int gn_getattr(const char *path, struct stat *stbuf) memset(stbuf, 0, sizeof(*stbuf)); - stbuf->st_mode = S_IFDIR | 0555; - stbuf->st_nlink = 1; - // stbuf->st_size = GNUNET_ECRS_uri_get_file_size(de->de_fi.uri); + stbuf->st_mode = S_IFDIR | 0555; + stbuf->st_nlink = 1; - - - - - /* int ret = 0; - //GNUNET_break (0); - memset(stbuf, 0, sizeof(struct stat)); - - if(strcmp(path, "") == 0) - { - stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 1; // changed from 2 - } -*/ - - /* - else if(strcmp(path, directory) == 0) - { - stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 1; - } - - - - else if(strcmp(path, "/probe/mal") == 0) - { - stbuf->st_mode = S_IFREG | 0444; - stbuf->st_nlink = 1; - stbuf->st_size = strlen("/probe/mal/inhalt"); - } - - */ - -/* else return -ENOENT; - - return ret; */ - + return 0; diff --git a/src/ext/gnunet-fuse.h b/src/ext/gnunet-fuse.h @@ -7,7 +7,6 @@ * * * This file is part of gnunet-fuse. - * Copyright (C) 2007 David Barksdale * * gnunet-fuse is free software; you can redistribute it and/or * modify if under the terms of version 2 of the GNU General Public License diff --git a/src/ext/open.c b/src/ext/open.c @@ -35,16 +35,20 @@ int gn_open(const char *path, struct fuse_file_info *fi) { - if (strcmp(path, "/home/mg/gnunet-fuse2/gnunet-fuse/src/ext/monti") == 0) - return 0; + //if (strcmp(path, "/home/mg/gnunet-fuse2/gnunet-fuse/src/ext/monti") == 0) + // return 0; +// +// else if ((fi->flags & 3) != O_RDONLY) +// return -EACCES; - else if ((fi->flags & 3) != O_RDONLY) - return -EACCES; +// else return 0; - else return 0; +/* + * when user is allowed to open, return 0 + */ + return 0; } - diff --git a/src/ext/read.c b/src/ext/read.c @@ -29,20 +29,37 @@ int gn_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { +/* (void) fi; size_t len; //until now read-function isn't used.... +if(strcmp(path, "/") == 0) +{ + len = strlen("/"); + if (offset < len) + { + if (offset + size > len) + size = len - offset; + memcpy(buf, "/" + offset, size); + } + else + size = 0; + + return size; + } -/* if (strcmp(path, "") == 0) + +if (strcmp(path, "/home/mg/gnunet-fuse2/gnunet-fuse/fuse/src/ext/monti/prueba") == 0) { - len = strlen(""); + + len = strlen("test"); if (offset < len) { if (offset + size > len) size = len - offset; - memcpy(buf, "" + offset, size); + memcpy(buf, "test" + offset, size); } else size = 0; @@ -50,9 +67,10 @@ int gn_read(const char *path, char *buf, size_t size, off_t offset, return size; } -*/ +else return -ENOENT; +*/ } diff --git a/src/ext/readdir.c b/src/ext/readdir.c @@ -2,7 +2,8 @@ * reddir.c - FUSE read directory function * * Created on: Mar 14, 2012 - * Author: mg + * Author: mg, Christian Grothoff, Matthias Wachs, + * Krista Bennett, James Blackwell, Igor Wronsky * * Read directory * @@ -36,29 +37,193 @@ #include <fuse.h> //#include <GNUnet/gnunet_ecrs_lib.h> #include <gnunet-fuse.h> +#include <gnunet/gnunet_fs_service.h> +static int ret; +static int verbose; +static int delete_incomplete; +static struct GNUNET_FS_DownloadContext *dc; + +static unsigned int parallelism = 16; + +static unsigned int request_parallelism = 4092; + +static int do_recursive; + +static int local_only; + +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static unsigned int anonymity = 1; + +struct GNUNET_FS_Handle *fs; + +static struct GNUNET_FS_Handle *ctx; + +static void +cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_FS_stop (ctx); + ctx = NULL; +} + +static void +shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_FS_DownloadContext *d; + + if (dc != NULL) + { + d = dc; + dc = NULL; + GNUNET_FS_download_stop (d, delete_incomplete); + } +} + + + +void *progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo * info) +{ + + char *s; + char*s2; + char *t; + + switch (info->status) + { + case GNUNET_FS_STATUS_DOWNLOAD_START: + if (verbose > 1) + FPRINTF (stderr, _("Starting download `%s'.\n"), + info->value.download.filename); + break; + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + if (verbose) + { + s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta); + if (info->value.download.specifics.progress.block_download_duration.rel_value + == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) + s2 = GNUNET_strdup (_("<unknown time>")); + else + s2 = GNUNET_STRINGS_relative_time_to_string ( + info->value.download.specifics.progress.block_download_duration); + t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * + 1000LL / + (info->value.download. + duration.rel_value + 1)); + FPRINTF (stdout, + _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), + info->value.download.filename, + (unsigned long long) info->value.download.completed, + (unsigned long long) info->value.download.size, s, t, s2); + GNUNET_free (s); + GNUNET_free (s2); + GNUNET_free (t); + } + break; + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: + FPRINTF (stderr, _("Error downloading: %s.\n"), + info->value.download.specifics.error.message); + GNUNET_SCHEDULER_shutdown (); + break; + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 / + (info->value.download. + duration.rel_value + 1)); + FPRINTF (stdout, _("Downloading `%s' done (%s/s).\n"), + info->value.download.filename, s); + GNUNET_free (s); + if (info->value.download.dc == dc) + GNUNET_SCHEDULER_shutdown (); + break; + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + if (info->value.download.dc == dc) + GNUNET_SCHEDULER_add_continuation (&cleanup_task, NULL, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); + break; + case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: + case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: + break; + default: + FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); + break; + } + +return NULL; +} + + +void readdir_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext* tc) +{ + struct GNUNET_FS_Uri *uri; + char *emsg; + enum GNUNET_FS_DownloadOptions options; + char* filename = GNUNET_DISK_mktemp(source); + + uri = GNUNET_FS_uri_parse(source, &emsg); + + if (NULL == uri) + { + FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg); + GNUNET_free (emsg); + } + + + fs = GNUNET_FS_start (cfg, "gnunet-fuse", &progress_cb, NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, parallelism, + GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, request_parallelism, + GNUNET_FS_OPTIONS_END); + + if (NULL == fs) + { + FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + GNUNET_FS_uri_destroy (uri); + ret = 1; + return; + } + + options = GNUNET_FS_DOWNLOAD_OPTION_NONE; + if (do_recursive) + options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; + if (local_only) + options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; + + struct GNUNET_FS_DownloadContext* dc; + dc = GNUNET_FS_download_start (fs, uri, NULL, filename, NULL, 0, + GNUNET_FS_uri_chk_get_file_size(uri), + anonymity, options, NULL, NULL); + + GNUNET_FS_uri_destroy (uri); + if (dc == NULL) + { + GNUNET_FS_stop (ctx); + ctx = NULL; + return; + } + + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); + +} int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { - //char* track = "mal"; - //char var[strlen(directory)+strlen(track)+1]; - //memcpy(var,directory,strlen(directory)); - //int len = strlen(directory); -// GNUNET_asprintf(); + (void) fi; + (void) offset; +// GNUNET_SCHEDULER_run(readdir_task, NULL); - filler(buf, ".", NULL, 0); - filler(buf, "..", NULL, 0); - //filler(buf, "/home/mg/gnunet-fuse2/gnunet-fuse/src/ext/monti"+1, NULL, 0); - //return 0; + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + return 0; } @@ -71,3 +236,6 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, + + +