From 97ae3ebc7d3fe74c7a64b38be16e18a613b6d2c0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 7 Sep 2009 20:00:18 +0000 Subject: [PATCH] prep work --- TODO | 4 +- src/fs/Makefile.am | 33 +++++-- src/fs/gnunet-directory.c | 167 ++++++++++++++++++++++++++++++++ src/fs/gnunet-pseudonym.c | 78 +++++++++++++++ src/fs/gnunet-service-fs.c | 100 +++++++++++++++++++ src/include/gnunet_fs_service.h | 1 + 6 files changed, 374 insertions(+), 9 deletions(-) create mode 100644 src/fs/gnunet-directory.c create mode 100644 src/fs/gnunet-pseudonym.c create mode 100644 src/fs/gnunet-service-fs.c diff --git a/TODO b/TODO index fe9f791c4..c380be538 100644 --- a/TODO +++ b/TODO @@ -78,7 +78,9 @@ Urgent items (before announcing ng.gnunet.org): + gnunet-publish (URI args) + gnunet-download (directory) + gnunet-search (options, incl. namespace search) - - gnunet-download (many options) + + gnunet-download (many options) + + gnunet-directory (man page, options) + + gnunet-pseudonym (all of it) - implement adv. FS testcases + insert: sblocks, loc uris + download: loc uris diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 0948b349f..f2bcab615 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -39,19 +39,20 @@ libgnunetfs_la_LDFLAGS = \ bin_PROGRAMS = \ + gnunet-directory \ gnunet-download \ gnunet-publish \ + gnunet-pseudonym \ gnunet-search \ + gnunet-service-fs \ gnunet-unindex -# gnunet-directory -# gnunet-pseudonym -#gnunet_directory_SOURCES = -# gnunet-directory.c -#gnunet_directory_LDADD = -# $(top_builddir)/src/fs/libgnunetfs.la -# $(top_builddir)/src/util/libgnunetutil.la -# $(GN_LIBINTL) +gnunet_directory_SOURCES = \ + gnunet-directory.c +gnunet_directory_LDADD = \ + $(top_builddir)/src/fs/libgnunetfs.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) gnunet_download_SOURCES = \ gnunet-download.c @@ -67,6 +68,13 @@ gnunet_publish_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) +gnunet_pseudonym_SOURCES = \ + gnunet-pseudonym.c +gnunet_pseudonym_LDADD = \ + $(top_builddir)/src/fs/libgnunetfs.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) + gnunet_search_SOURCES = \ gnunet-search.c gnunet_search_LDADD = \ @@ -74,6 +82,15 @@ gnunet_search_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) +gnunet_service_fs_SOURCES = \ + gnunet-service-fs.c +gnunet_service_fs_LDADD = \ + $(top_builddir)/src/fs/libgnunetfs.la \ + $(top_builddir)/src/datastore/libgnunetdatastore.la \ + $(top_builddir)/src/core/libgnunetcore.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) + gnunet_unindex_SOURCES = \ gnunet-unindex.c gnunet_unindex_LDADD = \ diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c new file mode 100644 index 000000000..0cbf700d1 --- /dev/null +++ b/src/fs/gnunet-directory.c @@ -0,0 +1,167 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file fs/gnunet-directory.c + * @brief display content of GNUnet directories + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_fs_service.h" + +static int ret; + +/** + * Print a meta data entry. + */ +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; +} + + + +/** + * Print an entry in a directory. + * + * @param cls closure (not used) + * @param filename name of the file in the directory + * @param uri URI of the file + * @param metadata metadata for the file; metadata for + * the directory if everything else is NULL/zero + * @param length length of the available data for the file + * (of type size_t since data must certainly fit + * into memory; if files are larger than size_t + * permits, then they will certainly not be + * embedded with the directory itself). + * @param data data available for the file (length bytes) + */ +static void +print_entry (void *cls, + const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + size_t length, + const void *data) +{ + char *string; + + string = GNUNET_FS_uri_to_string (uri); + printf ("%s:\n", string); + GNUNET_free (string); + GNUNET_CONTAINER_meta_data_get_contents (meta, + &item_printer, + NULL); +} + + +/** + * Main function that will be run by the scheduler. + * + * @param cls closure + * @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 + */ +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle *sched, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_DISK_MapHandle *map; + struct GNUNET_DISK_FileHandle *h; + void *data; + size_t len; + uint64_t size; + const char *filename = args[0]; + + if (NULL == filename) + { + fprintf (stderr, + _("You must specify a filename to inspect.")); + ret = 1; + return; + } + if ( (GNUNET_OK != + GNUNET_DISK_file_size (filename, + &size, + GNUNET_YES)) || + (NULL == (h = GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_READ))) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to read directory `%s'\n"), + filename); + ret = 1; + return; + } + len = (size_t) size; + data = GNUNET_DISK_file_map (h, + &map, + GNUNET_DISK_MAP_READ, + len); + GNUNET_assert (NULL != data); + GNUNET_FS_directory_list_contents (len, + data, + 0, + &print_entry, + NULL); + GNUNET_DISK_file_unmap (map); + GNUNET_DISK_file_close (h); +} + + +/** + * gnunet-directory command line options + */ +static struct GNUNET_GETOPT_CommandLineOption options[] = { + // FIXME: options! + GNUNET_GETOPT_OPTION_END +}; + + +/** + * The main function to inspect GNUnet directories. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + return (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-directory", + gettext_noop + ("Display GNUnet directories."), + options, &run, NULL)) ? ret : 1; +} + +/* end of gnunet-directory.c */ diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c new file mode 100644 index 000000000..e443d1e32 --- /dev/null +++ b/src/fs/gnunet-pseudonym.c @@ -0,0 +1,78 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file fs/gnunet-pseudonym.c + * @brief manage GNUnet namespaces / pseudonyms + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_fs_service.h" + +static int ret; + +/** + * Main function that will be run by the scheduler. + * + * @param cls closure + * @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 + */ +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle *sched, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + // FIXME +} + + +/** + * gnunet-pseudonym command line options + */ +static struct GNUNET_GETOPT_CommandLineOption options[] = { + // FIXME: options! + GNUNET_GETOPT_OPTION_END +}; + + +/** + * The main function to inspect GNUnet directories. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + return (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-pseudonym", + gettext_noop + ("Manage GNUnet pseudonyms."), + options, &run, NULL)) ? ret : 1; +} + +/* end of gnunet-pseudonym.c */ diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c new file mode 100644 index 000000000..253fd24b2 --- /dev/null +++ b/src/fs/gnunet-service-fs.c @@ -0,0 +1,100 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file statistics/gnunet-service-fs.c + * @brief program that provides the file-sharing service + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_protocols.h" +#include "gnunet_core_service.h" +#include "gnunet_datastore_service.h" +#include "gnunet_util_lib.h" +#include "fs.h" + + + +/** + * Handle GET-message. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + * @return GNUNET_OK to keep the connection open, + * GNUNET_SYSERR to close it (signal serious error) + */ +static void +handle_xxx (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ +} + + +/** + * List of handlers for the messages understood by this + * service. + */ +static struct GNUNET_SERVER_MessageHandler handlers[] = { + {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0}, + {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, 0}, + {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX, 0}, + {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 0}, + {NULL, NULL, 0, 0} +}; + + +/** + * Process fs requests. + * + * @param cls closure + * @param sched scheduler to use + * @param server the initialized server + * @param cfg configuration to use + */ +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_SERVER_Handle *server, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + GNUNET_SERVER_add_handlers (server, handlers); + // FIXME: also handle P2P messages! +} + + +/** + * The main function for the fs service. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + return (GNUNET_OK == + GNUNET_SERVICE_run (argc, + argv, + "fs", &run, NULL, NULL, NULL)) ? 0 : 1; +} + +/* end of gnunet-service-fs.c */ diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 114128823..210455311 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -117,6 +117,7 @@ GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri); char * GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri); + /** * Convert a UTF-8 String to a URI. * -- 2.25.1