From 5d27676deba6a3f404acf088d3bedc8a0e1d2b1b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 31 Mar 2010 06:40:20 +0000 Subject: fs hxing --- src/fs/Makefile.am | 1 + src/fs/fs_directory.c | 5 ++- src/fs/fs_download.c | 4 +- src/fs/fs_search.c | 7 ++- src/fs/fs_uri.c | 28 ++++++++++++ src/fs/gnunet-download.c | 111 ++++++++++++++++++++++++++++------------------ src/fs/gnunet-pseudonym.c | 105 ++++++++++++++++++++++++++++++++++++------- src/fs/gnunet-publish.c | 47 +++++++++++++++++--- src/fs/gnunet-search.c | 47 +++++++++++++++++--- 9 files changed, 277 insertions(+), 78 deletions(-) (limited to 'src/fs') diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index a83eef460..df781e1e6 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -82,6 +82,7 @@ gnunet_pseudonym_SOURCES = \ gnunet_pseudonym_LDADD = \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la \ + -lextractor \ $(GN_LIBINTL) gnunet_search_SOURCES = \ diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index 48578c650..82d0e8690 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c @@ -291,7 +291,10 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir struct GNUNET_FS_DirectoryBuilder *ret; ret = GNUNET_malloc(sizeof(struct GNUNET_FS_DirectoryBuilder)); - ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir); + if (mdir != NULL) + ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir); + else + ret->meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_FS_meta_data_make_directory (ret->meta); return ret; } diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 12d6ff0b6..3de192e12 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -23,10 +23,10 @@ * @author Christian Grothoff * * TODO: + * - handle recursive downloads (need directory & + * fs-level download-parallelism management) * - location URI suppport (can wait, easy) * - check if blocks exist already (can wait, easy) - * - handle recursive downloads (need directory & - * fs-level download-parallelism management, can wait) * - check if iblocks can be computed from existing blocks (can wait, hard) * - persistence (can wait) */ diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 596ea0c63..c4994b6a6 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -24,12 +24,11 @@ * @author Christian Grothoff * * TODO: - * - handle SKS updates searches nicely (can wait) - * - handle availability probes (can wait) - * - make operations persistent (can wait) - * - handle namespace advertisements (can wait) + * - handle namespace advertisements (can wait; might already work!?) * - add support for pushing "already seen" information * to FS service for bloomfilter (can wait) + * - handle availability probes (can wait) + * - make operations persistent (can wait) */ #include "platform.h" diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index b402fa830..5ddb48f2a 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c @@ -881,6 +881,34 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, } +/** + * Create an SKS URI from a namespace and an identifier. + * + * @param ns namespace + * @param id identifier + * @param emsg where to store an error message + * @return an FS URI for the given namespace and identifier + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, + const char *id, + char **emsg) +{ + struct GNUNET_FS_Uri *ns_uri; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; + + ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); + ns_uri->type = sks; + GNUNET_CRYPTO_rsa_key_get_public (ns->key, + &pk); + GNUNET_CRYPTO_hash (&pk, + sizeof (pk), + &ns_uri->data.sks.namespace); + ns_uri->data.sks.identifier = GNUNET_strdup (id); + return ns_uri; +} + + /** * Canonicalize a keyword. * diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 5279ce459..63895d4b2 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c @@ -26,7 +26,7 @@ * @author Igor Wronsky * * TODO: - * - many command-line options + * - download-directory option support (do_directory) */ #include "platform.h" #include "gnunet_fs_service.h" @@ -47,6 +47,12 @@ static struct GNUNET_FS_DownloadContext *dc; static unsigned int anonymity = 1; +static unsigned int parallelism = 16; + +static int do_recursive; + +static int do_directory; + static char *filename; @@ -127,8 +133,15 @@ progress_cb (void *cls, info->value.download.filename, s); GNUNET_free (s); - if (info->value.download.dc == dc) - GNUNET_SCHEDULER_shutdown (sched); + if (do_directory) + { + GNUNET_break (0); //FIXME: not implemented + } + else + { + if (info->value.download.dc == dc) + GNUNET_SCHEDULER_shutdown (sched); + } break; case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: if (info->value.download.dc == dc) @@ -168,25 +181,31 @@ run (void *cls, enum GNUNET_FS_DownloadOptions options; sched = s; - /* FIXME: check arguments */ - uri = GNUNET_FS_uri_parse (args[0], - &emsg); - if (NULL == uri) + if (do_directory) { - fprintf (stderr, - _("Failed to parse URI: %s\n"), - emsg); - GNUNET_free (emsg); - ret = 1; - return; + GNUNET_break (0); //FIXME: not implemented } - if (! GNUNET_FS_uri_test_chk (uri)) + else { - fprintf (stderr, - "Only CHK URIs supported right now.\n"); - ret = 1; - GNUNET_FS_uri_destroy (uri); - return; + 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) { @@ -203,6 +222,8 @@ run (void *cls, &progress_cb, NULL, GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, + parallelism, GNUNET_FS_OPTIONS_END); if (NULL == ctx) { @@ -214,22 +235,31 @@ run (void *cls, return; } options = GNUNET_FS_DOWNLOAD_OPTION_NONE; - dc = GNUNET_FS_download_start (ctx, - uri, - NULL, - filename, - 0, - GNUNET_FS_uri_chk_get_file_size (uri), - anonymity, - options, - NULL, - NULL); - GNUNET_FS_uri_destroy (uri); - if (dc == NULL) + if (do_recursive) + options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; + if (do_directory) { - GNUNET_FS_stop (ctx); - ctx = NULL; - return; + GNUNET_break (0); //FIXME: not implemented + } + else + { + dc = GNUNET_FS_download_start (ctx, + uri, + NULL, + filename, + 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 (sched, GNUNET_TIME_UNIT_FOREVER_REL, @@ -245,28 +275,23 @@ 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}, + 0, &GNUNET_GETOPT_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 + 0, &GNUNET_GETOPT_set_one, &delete_incomplete}, {'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}, + 1, &GNUNET_GETOPT_set_uint, ¶llelism}, {'R', "recursive", NULL, gettext_noop ("download a GNUnet directory recursively"), - 0, &GNUNET_getopt_configure_set_one, &do_recursive}, -#endif + 0, &GNUNET_GETOPT_set_one, &do_recursive}, {'V', "verbose", NULL, gettext_noop ("be verbose (print progress information)"), 0, &GNUNET_GETOPT_set_one, &verbose}, diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c index 2d35e8e8c..b8bd12b35 100644 --- a/src/fs/gnunet-pseudonym.c +++ b/src/fs/gnunet-pseudonym.c @@ -65,11 +65,6 @@ static int print_local_only; */ static struct GNUNET_CONTAINER_MetaData *adv_metadata; -/** - * -n option. - */ -static int no_advertising; - /** * -p option. */ @@ -100,6 +95,10 @@ static struct GNUNET_FS_Handle *h; */ static struct GNUNET_FS_Namespace *ns; +/** + * Our configuration. + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; static int ret; @@ -126,11 +125,45 @@ ns_printer (void *cls, } +static int +pseudo_printer (void *cls, + const GNUNET_HashCode * + pseudonym, + const struct + GNUNET_CONTAINER_MetaData * md, + int rating) +{ + char *id; + + id = GNUNET_PSEUDONYM_id_to_name (cfg, + pseudonym); + if (id == NULL) + { + GNUNET_break (0); + return GNUNET_OK; + } + fprintf (stdout, + "%s (%d):\n", + id, + rating); + GNUNET_CONTAINER_meta_data_iterate (md, + &EXTRACTOR_meta_data_print, + stdout); + fprintf (stdout, "\n"); + GNUNET_free (id); + return GNUNET_OK; +} + + static void post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) { + GNUNET_HashCode nsid; + char *set; + int delta; + if (emsg != NULL) { fprintf (stderr, "%s", emsg); @@ -153,7 +186,39 @@ post_advertising (void *cls, } if (NULL != rating_change) { - GNUNET_break (0); // FIXME: not implemented + set = rating_change; + while ((*set != '\0') && (*set != ':')) + set++; + if (*set != ':') + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Invalid argument `%s'\n"), + rating_change); + } + else + { + *set = '\0'; + delta = strtol (&set[1], NULL, /* no error handling yet */ + 10); + if (GNUNET_OK == + GNUNET_PSEUDONYM_name_to_id (cfg, + rating_change, + &nsid)) + { + GNUNET_PSEUDONYM_rank (cfg, + &nsid, + delta); + + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Namespace `%s' unknown.\n"), + rating_change); + } + } + GNUNET_free (rating_change); + rating_change = NULL; } if (0 != print_local_only) { @@ -163,10 +228,10 @@ post_advertising (void *cls, } else if (0 == no_remote_printing) { - GNUNET_break (0); // FIXME: not implemented + GNUNET_PSEUDONYM_list_all (cfg, + &pseudo_printer, + NULL); } - /* FIXME: is this OK here, or do we need - for completion of previous requests? */ GNUNET_FS_stop (h); } @@ -178,18 +243,20 @@ post_advertising (void *cls, * @param sched the scheduler to use * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) - * @param cfg configuration + * @param c configuration */ static void run (void *cls, struct GNUNET_SCHEDULER_Handle *sched, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_FS_Uri *ns_uri; struct GNUNET_TIME_Absolute expiration; + char *emsg; + cfg = c; h = GNUNET_FS_start (sched, cfg, "gnunet-pseudonym", @@ -221,11 +288,18 @@ run (void *cls, } else { - if (0 == no_advertising) + if (NULL != root_identifier) { - GNUNET_break (0); // FIXME: not implemented - ns_uri = NULL; // FIXME!! + emsg = NULL; + ns_uri = GNUNET_FS_uri_sks_create (ns, root_identifier, &emsg); + GNUNET_assert (emsg == NULL); expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS); + if (ksk_uri == NULL) + { + emsg = NULL; + ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); + GNUNET_assert (NULL == emsg); + } GNUNET_FS_publish_ksk (h, ksk_uri, adv_metadata, @@ -275,9 +349,6 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { {'m', "meta", "TYPE:VALUE", gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata}, - {'n', "no-advertisement", NULL, - gettext_noop ("do not create an advertisement"), - 0, &GNUNET_GETOPT_set_one, &no_advertising}, {'p', "priority", "PRIORITY", gettext_noop ("use the given PRIORITY for the advertisments"), 1, &GNUNET_GETOPT_set_uint, &priority}, diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 860a81522..1e0884361 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c @@ -24,9 +24,6 @@ * @author Krista Bennett * @author James Blackwell * @author Igor Wronsky - * - * TODO: - * - support for some options is still missing (uri argument) */ #include "platform.h" #include "gnunet_fs_service.h" @@ -307,6 +304,22 @@ publish_inspector (void *cls, } +static void +uri_ksk_continuation (void *cls, + const struct GNUNET_FS_Uri *uri, + const char *emsg) +{ + if (emsg != NULL) + { + fprintf (stderr, + "%s\n", + emsg); + ret = 1; + } + GNUNET_FS_stop (ctx); +} + + /** * Main function that will be run by the scheduler. * @@ -329,6 +342,7 @@ run (void *cls, struct stat sbuf; char *ex; char *emsg; + struct GNUNET_FS_Uri *uri; sched = s; /* check arguments */ @@ -421,11 +435,32 @@ run (void *cls, } } if (NULL != uri_string) - { - // FIXME -- implement! + { + emsg = NULL; + uri = GNUNET_FS_uri_parse (uri_string, + &emsg); + if (uri == NULL) + { + fprintf (stderr, + _("Failed to parse URI: %s\n"), + emsg); + GNUNET_free (emsg); + GNUNET_FS_stop (ctx); + ret = 1; + return; + } + GNUNET_FS_publish_ksk (ctx, + topKeywords, + meta, + uri, + GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION), + anonymity, + priority, + GNUNET_FS_PUBLISH_OPTION_NONE, + &uri_ksk_continuation, + NULL); return; } - l = NULL; if (! disable_extractor) { diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 462f432c8..33c81c9d7 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c @@ -24,9 +24,6 @@ * @author Krista Bennett * @author James Blackwell * @author Igor Wronsky - * - * TODO: - * - add many options (timeout, namespace search, etc.) */ #include "platform.h" #include "gnunet_fs_service.h" @@ -41,6 +38,10 @@ static struct GNUNET_FS_Handle *ctx; static struct GNUNET_FS_SearchContext *sc; +static char *output_filename; + +static struct GNUNET_FS_DirectoryBuilder *db; + static unsigned int anonymity = 1; static int verbose; @@ -64,12 +65,39 @@ item_printer (void *cls, return GNUNET_OK; } + static void clean_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + size_t dsize; + void *ddata; + GNUNET_FS_stop (ctx); ctx = NULL; + if (output_filename == NULL) + return; + if (GNUNET_OK != + GNUNET_FS_directory_builder_finish (db, + &dsize, + &ddata)) + { + GNUNET_break (0); + GNUNET_free (output_filename); + return; + } + if (dsize != + GNUNET_DISK_fn_write (output_filename, + ddata, + dsize, + GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) + { + fprintf (stderr, + _("Failed to write directory with search results to `%s'\n"), + output_filename); + } + GNUNET_free_non_null (ddata); + GNUNET_free (output_filename); } @@ -99,6 +127,11 @@ progress_cb (void *cls, case GNUNET_FS_STATUS_SEARCH_START: break; case GNUNET_FS_STATUS_SEARCH_RESULT: + if (db != NULL) + GNUNET_FS_directory_builder_add (db, + info->value.search.specifics.result.uri, + info->value.search.specifics.result.meta, + NULL); uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); printf ("%s:\n", uri); filename = @@ -135,7 +168,6 @@ progress_cb (void *cls, GNUNET_SCHEDULER_shutdown (sched); break; case GNUNET_FS_STATUS_SEARCH_STOPPED: - sc = NULL; GNUNET_SCHEDULER_add_continuation (sched, &clean_task, NULL, @@ -214,6 +246,8 @@ run (void *cls, ret = 1; return; } + if (output_filename != NULL) + db = GNUNET_FS_directory_builder_create (NULL); sc = GNUNET_FS_search_start (ctx, uri, anonymity, @@ -241,7 +275,10 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { {'a', "anonymity", "LEVEL", gettext_noop ("set the desired LEVEL of receiver-anonymity"), 1, &GNUNET_GETOPT_set_uint, &anonymity}, - // FIXME: options! + {'o', "output", "PREFIX", + gettext_noop + ("write search results to file starting with PREFIX"), + 1, &GNUNET_GETOPT_set_string, &output_filename}, GNUNET_GETOPT_OPTION_END }; -- cgit v1.2.3