prep work
authorChristian Grothoff <christian@grothoff.org>
Mon, 7 Sep 2009 20:00:18 +0000 (20:00 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 7 Sep 2009 20:00:18 +0000 (20:00 +0000)
TODO
src/fs/Makefile.am
src/fs/gnunet-directory.c [new file with mode: 0644]
src/fs/gnunet-pseudonym.c [new file with mode: 0644]
src/fs/gnunet-service-fs.c [new file with mode: 0644]
src/include/gnunet_fs_service.h

diff --git a/TODO b/TODO
index fe9f791c4c404285cdbbc813d3862c7e6bbe4b99..c380be5384e917a30fc3b96668745044f661d7b1 100644 (file)
--- 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
index 0948b349f2722d4004b29cbfd19c2d966b3a2e89..f2bcab615a643ed642ef406840c3c7bb3cf1cbbf 100644 (file)
@@ -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 (file)
index 0000000..0cbf700
--- /dev/null
@@ -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 (file)
index 0000000..e443d1e
--- /dev/null
@@ -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 (file)
index 0000000..253fd24
--- /dev/null
@@ -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 */
index 114128823e3d3dbd0d5450fe88f9e08da7483d7e..210455311216d2c458bea253a0034cbb60081e74 100644 (file)
@@ -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.
  *