diff options
author | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2009-09-06 21:03:16 +0000 |
---|---|---|
committer | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2009-09-06 21:03:16 +0000 |
commit | f9aa59f2c539bc36f90cc28be4aa97a88cc41521 (patch) | |
tree | d20be6f1d2ce6faff9ae6475c507f2aa33691e16 /src | |
parent | 9441a5e84c6058c8b2a4bd3a5db2a9c1960ad620 (diff) |
fs tools
git-svn-id: https://gnunet.org/svn/gnunet@8955 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/fs.c | 9 | ||||
-rw-r--r-- | src/fs/fs.h | 5 | ||||
-rw-r--r-- | src/fs/fs_download.c | 2 | ||||
-rw-r--r-- | src/fs/fs_publish.c | 2 | ||||
-rw-r--r-- | src/fs/gnunet-download.c | 120 | ||||
-rw-r--r-- | src/fs/gnunet-publish.c | 62 | ||||
-rw-r--r-- | src/fs/gnunet-search.c | 104 | ||||
-rw-r--r-- | src/fs/gnunet-unindex.c | 54 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 59 |
9 files changed, 387 insertions, 30 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c index 66699507b1..8396fc18f8 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -37,13 +37,18 @@ * @param client_name unique identifier for this client * @param upcb function to call to notify about FS actions * @param upcb_cls closure for upcb + * @param flags specific attributes for fs-operations + * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END + * @return NULL on error */ struct GNUNET_FS_Handle * GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, - void *upcb_cls) + void *upcb_cls, + enum GNUNET_FS_Flags flags, + ...) { struct GNUNET_FS_Handle *ret; struct GNUNET_CLIENT_Connection *client; @@ -60,6 +65,8 @@ GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, ret->upcb = upcb; ret->upcb_cls = upcb_cls; ret->client = client; + ret->flags = flags; + // FIXME: process varargs! // FIXME: setup receive-loop with client // FIXME: deserialize state; use client-name to find master-directory! diff --git a/src/fs/fs.h b/src/fs/fs.h index 70e02360c5..c2a2e7d032 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -389,6 +389,11 @@ struct GNUNET_FS_Handle */ unsigned int active_probes; + /** + * General flags. + */ + enum GNUNET_FS_Flags flags; + }; diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 145e16818c..77fbb11399 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -142,6 +142,8 @@ make_download_status (struct GNUNET_FS_ProgressInfo *pi, = (dc->parent == NULL) ? NULL : dc->parent->client_info; pi->value.download.uri = dc->uri; + pi->value.download.filename + = dc->filename; pi->value.download.length = dc->length; pi->value.download.duration diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index d58ea3f377..db38b76dac 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -111,6 +111,8 @@ make_publish_status (struct GNUNET_FS_ProgressInfo *pi, = p->client_info; pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; + pi->value.publish.filename + = (p->is_directory) ? p->data.dir.dirname : p->data.file.filename; pi->value.publish.size = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; pi->value.publish.eta diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index c6bb7c115b..681608d6bb 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c @@ -26,21 +26,26 @@ * @author Igor Wronsky * * TODO: - * - all + * - many command-line options */ #include "platform.h" #include "gnunet_fs_service.h" static int ret; +static int verbose; + +static int delete_incomplete; + static const struct GNUNET_CONFIGURATION_Handle *cfg; static struct GNUNET_FS_Handle *ctx; -static struct GNUNET_TIME_Absolute start_time; +static struct GNUNET_FS_DownloadContext *dc; static unsigned int anonymity = 1; +static char *filename; /** * Called by FS client to give information about the progress of an @@ -59,6 +64,44 @@ static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) { + switch (info->status) + { + case GNUNET_FS_STATUS_DOWNLOAD_START: + break; + case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: + if (verbose) + fprintf (stdout, + _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"), + info->value.download.filename, + (unsigned long long) info->value.download.completed, + (unsigned long long) info->value.download.length, + GNUNET_STRINGS_relative_time_to_string(info->value.download.eta), + GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); + break; + case GNUNET_FS_STATUS_DOWNLOAD_ERROR: + fprintf (stderr, + _("Error downloading: %s.\n"), + info->value.download.specifics.error.message); + GNUNET_FS_file_download_stop (dc, delete_incomplete); + break; + case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: + fprintf (stdout, + _("Downloading `%s' done (%s/s).\n"), + info->value.download.filename, + GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); + if (info->value.download.dc == dc) + GNUNET_FS_file_download_stop (dc, delete_incomplete); + break; + case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: + if (info->value.download.dc == dc) + GNUNET_FS_stop (ctx); + break; + default: + fprintf (stderr, + _("Unexpected status: %d\n"), + info->status); + break; + } return NULL; } @@ -79,23 +122,66 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { + struct GNUNET_FS_Uri *uri; + char *emsg; + enum GNUNET_FS_DownloadOptions options; + /* FIXME: check arguments */ + uri = GNUNET_FS_uri_parse (args[0], + &emsg); + if (NULL == uri) + { + fprintf (stderr, + _("Failed to parse URI: %s\n"), + emsg); + GNUNET_free (emsg); + ret = 1; + return; + } + if (! GNUNET_FS_uri_test_chk (uri)) + { + fprintf (stderr, + "Only CHK URIs supported right now.\n"); + ret = 1; + GNUNET_FS_uri_destroy (uri); + return; + } + if (NULL == filename) + { + fprintf (stderr, + "Target filename must be specified.\n"); + ret = 1; + GNUNET_FS_uri_destroy (uri); + return; + } cfg = c; ctx = GNUNET_FS_start (sched, cfg, "gnunet-download", &progress_cb, - NULL); + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + GNUNET_FS_uri_destroy (uri); ret = 1; return; } - start_time = GNUNET_TIME_absolute_get (); - // FIXME: start download + options = GNUNET_FS_DOWNLOAD_OPTION_NONE; + dc = GNUNET_FS_file_download_start (ctx, + uri, + NULL, + filename, + 0, + GNUNET_FS_uri_chk_get_file_size (uri), + anonymity, + options, + NULL); + GNUNET_FS_uri_destroy (uri); } @@ -106,7 +192,31 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { {'a', "anonymity", "LEVEL", gettext_noop ("set the desired LEVEL of receiver-anonymity"), 1, &GNUNET_GETOPT_set_uint, &anonymity}, +#if 0 // FIXME: options! + {'d', "directory", NULL, + gettext_noop + ("download a GNUnet directory that has already been downloaded. Requires that a filename of an existing file is specified instead of the URI. The download will only download the top-level files in the directory unless the `-R' option is also specified."), + 0, &GNUNET_getopt_configure_set_one, &do_directory}, + {'D', "delete-incomplete", NULL, + gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), + 0, &GNUNET_getopt_configure_set_one, &do_delete_incomplete}, +#endif + {'o', "output", "FILENAME", + gettext_noop ("write the file to FILENAME"), + 1, &GNUNET_GETOPT_set_string, &filename}, +#if 0 + {'p', "parallelism", "DOWNLOADS", + gettext_noop + ("set the maximum number of parallel downloads that are allowed"), + 1, &GNUNET_getopt_configure_set_uint, ¶llelism}, + {'R', "recursive", NULL, + gettext_noop ("download a GNUnet directory recursively"), + 0, &GNUNET_getopt_configure_set_one, &do_recursive}, +#endif + {'V', "verbose", NULL, + gettext_noop ("be verbose (print progress information)"), + 0, &GNUNET_GETOPT_set_one, &verbose}, GNUNET_GETOPT_OPTION_END }; diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index b6b9199d0e..a30b36c9ea 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c @@ -27,8 +27,6 @@ * * TODO: * - support for some options is still missing (uri argument) - * - progress callbacks not implemented (and need verbosity option) - * - clean shutdown is not implemented (stop ctx, etc.) */ #include "platform.h" #include "gnunet_fs_service.h" @@ -37,14 +35,14 @@ static int ret; +static int verbose; + static const struct GNUNET_CONFIGURATION_Handle *cfg; static struct GNUNET_FS_Handle *ctx; static struct GNUNET_FS_PublishContext *pc; -static struct GNUNET_TIME_Absolute start_time; - static struct GNUNET_CONTAINER_MetaData *meta; static struct GNUNET_FS_Uri *topKeywords; @@ -89,7 +87,43 @@ static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) { - return NULL; + switch (info->status) + { + case GNUNET_FS_STATUS_PUBLISH_START: + break; + case GNUNET_FS_STATUS_PUBLISH_PROGRESS: + if (verbose) + fprintf (stdout, + _("Publishing `%s' at %llu/%llu (%s remaining)\n"), + info->value.publish.filename, + (unsigned long long) info->value.publish.completed, + (unsigned long long) info->value.publish.size, + GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta)); + break; + case GNUNET_FS_STATUS_PUBLISH_ERROR: + fprintf (stderr, + _("Error publishing: %s.\n"), + info->value.publish.specifics.error.message); + GNUNET_FS_publish_stop (pc); + break; + case GNUNET_FS_STATUS_PUBLISH_COMPLETED: + fprintf (stdout, + _("Publishing `%s' done.\n"), + info->value.publish.filename); + if (info->value.publish.pctx == NULL) + GNUNET_FS_publish_stop (pc); + break; + case GNUNET_FS_STATUS_PUBLISH_STOPPED: + if (info->value.publish.sc == pc) + GNUNET_FS_stop (ctx); + return NULL; + default: + fprintf (stderr, + _("Unexpected status: %d\n"), + info->status); + return NULL; + } + return ""; /* non-null */ } @@ -302,7 +336,9 @@ run (void *cls, cfg, "gnunet-publish", &progress_cb, - NULL); + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { fprintf (stderr, @@ -331,7 +367,6 @@ run (void *cls, // FIXME -- implement! return; } - start_time = GNUNET_TIME_absolute_get (); l = NULL; if (! disable_extractor) @@ -389,6 +424,14 @@ run (void *cls, (do_simulate) ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY : GNUNET_FS_PUBLISH_OPTION_NONE); + if (NULL == pc) + { + fprintf (stderr, + _("Could not start publishing.\n")); + GNUNET_FS_stop (ctx); + ret = 1; + return; + } } @@ -449,7 +492,10 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { {'u', "uri", "URI", gettext_noop ("URI to be published (can be used instead of passing a " "file to add keywords to the file with the respective URI)"), - 1, &GNUNET_GETOPT_set_string, &uri_string}, + 1, &GNUNET_GETOPT_set_string, &uri_string}, + {'V', "verbose", NULL, + gettext_noop ("be verbose (print progress information)"), + 0, &GNUNET_GETOPT_set_one, &verbose}, GNUNET_GETOPT_OPTION_END }; diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 10a3c82fd3..b744d2e1ad 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c @@ -26,7 +26,7 @@ * @author Igor Wronsky * * TODO: - * - all + * - add many options (timeout, namespace search, etc.) */ #include "platform.h" #include "gnunet_fs_service.h" @@ -37,10 +37,24 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; static struct GNUNET_FS_Handle *ctx; -static struct GNUNET_TIME_Absolute start_time; +static struct GNUNET_FS_SearchContext *sc; static unsigned int anonymity = 1; +static int verbose; + +static int +item_printer (void *cls, + EXTRACTOR_KeywordType type, + const char *data) +{ + printf ("\t%20s: %s\n", + dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, + EXTRACTOR_getKeywordTypeAsString (type)), + data); + return GNUNET_OK; +} + /** * Called by FS client to give information about the progress of an @@ -59,6 +73,56 @@ static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) { + char *uri; + char *dotdot; + char *filename; + + switch (info->status) + { + case GNUNET_FS_STATUS_SEARCH_START: + break; + case GNUNET_FS_STATUS_SEARCH_RESULT: + uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); + printf ("%s:\n", uri); + filename = + GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.specifics.result.meta, + EXTRACTOR_FILENAME); + if (filename != NULL) + { + while (NULL != (dotdot = strstr (filename, ".."))) + dotdot[0] = dotdot[1] = '_'; + printf ("gnunet-download -o \"%s\" %s\n", + filename, + uri); + } + else + printf ("gnunet-download %s\n", uri); + if (verbose) + GNUNET_CONTAINER_meta_data_get_contents (info->value.search.specifics.result.meta, + &item_printer, + NULL); + printf ("\n"); + fflush(stdout); + GNUNET_free_non_null (filename); + GNUNET_free (uri); + break; + case GNUNET_FS_STATUS_SEARCH_UPDATE: + break; + case GNUNET_FS_STATUS_SEARCH_ERROR: + fprintf (stderr, + _("Error searching: %s.\n"), + info->value.search.specifics.error.message); + GNUNET_FS_search_stop (sc); + break; + case GNUNET_FS_STATUS_SEARCH_STOPPED: + GNUNET_FS_stop (ctx); + break; + default: + fprintf (stderr, + _("Unexpected status: %d\n"), + info->status); + break; + } return NULL; } @@ -79,23 +143,51 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { - /* FIXME: check arguments */ + struct GNUNET_FS_Uri *uri; + unsigned int argc; + + argc = 0; + while (NULL != args[argc]) + argc++; + uri = GNUNET_FS_uri_ksk_create_from_args (argc, + (const char **) args); + if (NULL == uri) + { + fprintf (stderr, + _("Could not create keyword URI from arguments.\n")); + ret = 1; + GNUNET_FS_uri_destroy (uri); + return; + } cfg = c; ctx = GNUNET_FS_start (sched, cfg, "gnunet-search", &progress_cb, - NULL); + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + GNUNET_FS_uri_destroy (uri); + GNUNET_FS_stop (ctx); + ret = 1; + return; + } + sc = GNUNET_FS_search_start (ctx, + uri, + anonymity); + GNUNET_FS_uri_destroy (uri); + if (NULL == sc) + { + fprintf (stderr, + _("Could not start searching.\n")); ret = 1; return; } - start_time = GNUNET_TIME_absolute_get (); - // FIXME: start search } diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index 2dfef9432e..9b335eec01 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c @@ -24,24 +24,20 @@ * @author Krista Bennett * @author James Blackwell * @author Igor Wronsky - * - * TODO: - * - progress callback - * - error checking */ #include "platform.h" #include "gnunet_fs_service.h" static int ret; +static int verbose; + static const struct GNUNET_CONFIGURATION_Handle *cfg; static struct GNUNET_FS_Handle *ctx; static struct GNUNET_FS_UnindexContext *uc; -static struct GNUNET_TIME_Absolute start_time; - /** * Called by FS client to give information about the progress of an @@ -60,6 +56,38 @@ static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) { + switch (info->status) + { + case GNUNET_FS_STATUS_UNINDEX_START: + break; + case GNUNET_FS_STATUS_UNINDEX_PROGRESS: + if (verbose) + fprintf (stdout, + _("Unindexing at %llu/%llu (%s remaining)\n"), + (unsigned long long) info->value.unindex.completed, + (unsigned long long) info->value.unindex.size, + GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta)); + break; + case GNUNET_FS_STATUS_UNINDEX_ERROR: + fprintf (stderr, + _("Error unindexing: %s.\n"), + info->value.unindex.specifics.error.message); + GNUNET_FS_unindex_stop (uc); + break; + case GNUNET_FS_STATUS_UNINDEX_COMPLETED: + fprintf (stdout, + _("Unindexing done.\n")); + GNUNET_FS_unindex_stop (uc); + break; + case GNUNET_FS_STATUS_UNINDEX_STOPPED: + GNUNET_FS_stop (ctx); + break; + default: + fprintf (stderr, + _("Unexpected status: %d\n"), + info->status); + break; + } return NULL; } @@ -93,7 +121,9 @@ run (void *cls, cfg, "gnunet-unindex", &progress_cb, - NULL); + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { fprintf (stderr, @@ -102,9 +132,14 @@ run (void *cls, ret = 1; return; } - start_time = GNUNET_TIME_absolute_get (); uc = GNUNET_FS_unindex (ctx, args[0]); + if (NULL == uc) + { + fprintf (stderr, + _("Could not start unindex operation.\n")); + GNUNET_FS_stop (ctx); + } } @@ -112,6 +147,9 @@ run (void *cls, * gnunet-unindex command line options */ static struct GNUNET_GETOPT_CommandLineOption options[] = { + {'V', "verbose", NULL, + gettext_noop ("be verbose (print progress information)"), + 0, &GNUNET_GETOPT_set_one, &verbose}, GNUNET_GETOPT_OPTION_END }; diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index ee10a0156f..114128823e 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -360,7 +360,7 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri); * What is the size of the file that this URI * refers to? * - * @param uri the CHK URI to inspect + * @param uri the CHK (or LOC) URI to inspect * @return size of the file as specified in the CHK URI */ uint64_t @@ -718,6 +718,11 @@ struct GNUNET_FS_ProgressInfo * (if this is a file in a directory or a subdirectory). */ void *pctx; + + /** + * Name of the file being published; can be NULL. + */ + const char *filename; /** * How large is the file overall? For directories, @@ -862,6 +867,11 @@ struct GNUNET_FS_ProgressInfo * URI used for this download. */ const struct GNUNET_FS_Uri *uri; + + /** + * Name of the file that we are downloading. + */ + const char *filename; /** * How large is the download overall? This @@ -1394,6 +1404,46 @@ typedef void* (*GNUNET_FS_ProgressCallback) /** + * General (global) option flags for file-sharing. + */ +enum GNUNET_FS_Flags + { + /** + * No special flags set. + */ + GNUNET_FS_FLAGS_NONE = 0, + + /** + * Is persistence of operations desired? + * (will create SUSPEND/RESUME events). + */ + GNUNET_FS_FLAGS_PERSISTENCE = 1 + + }; + +/** + * Options specified in the VARARGs + * portion of GNUNET_FS_start. + */ +enum GNUNET_FS_OPTIONS + { + + /** + * Last option in the VARARG list. + */ + GNUNET_FS_OPTIONS_END = 0, + + /** + * Select the desired amount of parallelism (this option should be + * followed by an "unsigned int" giving the desired maximum number + * of parallel downloads). + */ + GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1 + + }; + + +/** * Handle to the file-sharing service. */ struct GNUNET_FS_Handle; @@ -1407,13 +1457,18 @@ struct GNUNET_FS_Handle; * @param client_name unique identifier for this client * @param upcb function to call to notify about FS actions * @param upcb_cls closure for upcb + * @param flags specific attributes for fs-operations + * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END + * @return NULL on error */ struct GNUNET_FS_Handle * GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, - void *upcb_cls); + void *upcb_cls, + enum GNUNET_FS_Flags flags, + ...); /** |