gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8859 - in gnunet/src: fs include


From: gnunet
Subject: [GNUnet-SVN] r8859 - in gnunet/src: fs include
Date: Wed, 26 Aug 2009 03:13:06 -0600

Author: grothoff
Date: 2009-08-26 03:13:06 -0600 (Wed, 26 Aug 2009)
New Revision: 8859

Added:
   gnunet/src/fs/test_fs.c
Removed:
   gnunet/src/fs/fs_test.c
Modified:
   gnunet/src/fs/Makefile.am
   gnunet/src/fs/fs.h
   gnunet/src/fs/fs_download.c
   gnunet/src/fs/fs_publish.c
   gnunet/src/fs/fs_search.c
   gnunet/src/fs/fs_unindex.c
   gnunet/src/include/gnunet_fs_service.h
Log:
hxing

Modified: gnunet/src/fs/Makefile.am
===================================================================
--- gnunet/src/fs/Makefile.am   2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/Makefile.am   2009-08-26 09:13:06 UTC (rev 8859)
@@ -16,10 +16,13 @@
   fs.c \
   fs_collection.c \
   fs_directory.c \
+  fs_download.c \
   fs_file_information.c \
   fs_getopt.c \
   fs_publish.c \
   fs_namespace.c \
+  fs_search.c \
+  fs_unindex.c \
   fs_uri.c 
 
 libgnunetfs_la_LIBADD = \

Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h  2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/fs.h  2009-08-26 09:13:06 UTC (rev 8859)
@@ -318,4 +318,79 @@
 };
 
 
+/**
+ * Handle for controlling an upload.
+ */
+struct GNUNET_FS_PublishContext
+{
+  /**
+   * Handle to the global fs context.
+   */ 
+  struct GNUNET_FS_Handle *h;
+
+  /**
+   * Argument to pass to the client in callbacks.
+   */
+  void *client_ctx;
+  
+  /**
+   * File-structure that is being shared.
+   */
+  struct GNUNET_FS_FileInformation *fi;
+
+  /**
+   * Namespace that we are publishing in, NULL if we have no namespace.
+   */
+  struct GNUNET_FS_Namespace *namespace;
+
+  /**
+   * ID of the content in the namespace, NULL if we have no namespace.
+   */
+  char *nid;
+
+  /**
+   * ID for future updates, NULL if we have no namespace or no updates.
+   */
+  char *nuid;
+
+  /**
+   * ID of the task performing the upload. NO_TASK
+   * if the upload has completed.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier upload_task;
+};
+
+
+/**
+ * Handle for controlling an unindexing operation.
+ */
+struct GNUNET_FS_UnindexContext
+{
+};
+
+
+/**
+ * Handle for controlling a search.
+ */
+struct GNUNET_FS_SearchContext
+{
+};
+
+
+/**
+ * Context for controlling a download.
+ */
+struct GNUNET_FS_DownloadContext
+{
+};
+
+struct GNUNET_FS_Namespace
+{
+  /**
+   * Reference counter.
+   */
+  unsigned int rc;
+};
+
+
 #endif

Modified: gnunet/src/fs/fs_download.c
===================================================================
--- gnunet/src/fs/fs_download.c 2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/fs_download.c 2009-08-26 09:13:06 UTC (rev 8859)
@@ -18,24 +18,77 @@
      Boston, MA 02111-1307, USA.
 */
 /**
- * @file applications/fs/ecrs/download.c
+ * @file fs/fs_download.c
  * @brief DOWNLOAD helper methods (which do the real work).
  * @author Christian Grothoff
  */
 
 #include "platform.h"
-#include "gnunet_protocols.h"
-#include "gnunet_ecrs_lib.h"
-#include "gnunet_fs_lib.h"
-#include "gnunet_identity_lib.h"
-#include "ecrs_core.h"
-#include "ecrs.h"
+#include "gnunet_fs_service.h"
 #include "fs.h"
-#include "tree.h"
 
-#define DEBUG_DOWNLOAD GNUNET_NO
+#define DEBUG_DOWNLOAD GNUNET_YES
 
+
+
 /**
+ * Download parts of a file.  Note that this will store
+ * the blocks at the respective offset in the given file.  Also, the
+ * download is still using the blocking of the underlying FS
+ * encoding.  As a result, the download may *write* outside of the
+ * given boundaries (if offset and length do not match the 32k FS
+ * block boundaries). <p>
+ *
+ * This function should be used to focus a download towards a
+ * particular portion of the file (optimization), not to strictly
+ * limit the download to exactly those bytes.
+ *
+ * @param h handle to the file sharing subsystem
+ * @param uri the URI of the file (determines what to download); CHK or LOC URI
+ * @param filename where to store the file, maybe NULL (then no file is
+ *        created on disk and data must be grabbed from the callbacks)
+ * @param offset at what offset should we start the download (typically 0)
+ * @param length how many bytes should be downloaded starting at offset
+ * @param anonymity anonymity level to use for the download
+ * @param no_temporaries set to GNUNET_YES to disallow generation of temporary 
files
+ * @param recursive should this be a recursive download (useful for directories
+ *        to automatically trigger download of files in the directories)
+ * @param parent parent download to associate this download with (use NULL
+ *        for top-level downloads; useful for manually-triggered recursive 
downloads)
+ * @return context that can be used to control this download
+ */
+struct GNUNET_FS_DownloadContext *
+GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
+                              const struct GNUNET_FS_Uri *uri,
+                              const char *filename,
+                              unsigned long long offset,
+                              unsigned long long length,
+                              unsigned int anonymity,
+                              int no_temporaries,      
+                              int recursive,
+                              struct GNUNET_FS_DownloadContext *parent)
+{
+  return NULL;
+}
+
+/**
+ * Stop a download (aborts if download is incomplete).
+ *
+ * @param rm handle for the download
+ * @param do_delete delete files of incomplete downloads
+ */
+void
+GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm,
+                             int do_delete)
+{
+}
+
+
+
+
+#if 0
+
+/**
  * Node-specific data (not shared, keep small!). 152 bytes.
  * Nodes are kept in a doubly-linked list.
  */
@@ -920,4 +973,6 @@
                                             dpcb, dpcbClosure, tt, ttClosure);
 }
 
-/* end of download.c */
+#endif
+
+/* end of fs_download.c */

Modified: gnunet/src/fs/fs_publish.c
===================================================================
--- gnunet/src/fs/fs_publish.c  2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/fs_publish.c  2009-08-26 09:13:06 UTC (rev 8859)
@@ -34,7 +34,96 @@
 #define DEBUG_PUBLISH GNUNET_YES
 
 
+/**
+ * Main function that performs the upload.
+ * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
+ * @param tc task context
+ */
+static void
+do_upload (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_FS_PublishContext *sc = cls;
 
+  sc->upload_task = GNUNET_SCHEDULER_NO_TASK;  
+
+  // FIXME: find next block, process, schedule
+  // transmission to FS service
+}
+
+
+/**
+ * Publish a file or directory.
+ *
+ * @param h handle to the file sharing subsystem
+ * @param ctx initial value to use for the '*ctx'
+ *        in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
+ * @param fi information about the file or directory structure to publish
+ * @param namespace namespace to publish the file in, NULL for no namespace
+ * @param nid identifier to use for the publishd content in the namespace
+ *        (can be NULL, must be NULL if namespace is NULL)
+ * @param nuid update-identifier that will be used for future updates 
+ *        (can be NULL, must be NULL if namespace or nid is NULL)
+ * @return context that can be used to control the publish operation
+ */
+struct GNUNET_FS_PublishContext *
+GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
+                        void *ctx,
+                        struct GNUNET_FS_FileInformation *fi,
+                        struct GNUNET_FS_Namespace *namespace,
+                        const char *nid,
+                        const char *nuid)
+{
+  struct GNUNET_FS_PublishContext *ret;
+
+  ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
+  ret->h = h;
+  ret->client_ctx = ctx;
+  ret->fi = fi;
+  ret->namespace = namespace;
+  if (namespace != NULL)
+    {
+      namespace->rc++;
+      GNUNET_assert (NULL != nid);
+      ret->nid = GNUNET_strdup (nid);
+      if (NULL != nuid)
+       ret->nuid = GNUNET_strdup (nuid);
+    }
+  // FIXME: make upload persistent!
+  ret->upload_task 
+    = GNUNET_SCHEDULER_add_delayed (h->sched,
+                                   GNUNET_NO,
+                                   GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+                                   GNUNET_SCHEDULER_NO_TASK,
+                                   GNUNET_TIME_UNIT_ZERO,
+                                   &do_upload,
+                                   ret);
+  return ret;
+}
+
+
+/**
+ * Stop an upload.  Will abort incomplete uploads (but 
+ * not remove blocks that have already been publishd) or
+ * simply clean up the state for completed uploads.
+ *
+ * @param sc context for the upload to stop
+ */
+void 
+GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc)
+{
+  if (GNUNET_SCHEDULER_NO_TASK != sc->upload_task)
+    GNUNET_SCHEDULER_cancel (sc->h->sched, sc->upload_task);
+  // FIXME: remove from persistence DB (?) --- think more about
+  //        shutdown / persistent-resume APIs!!!
+  GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL);
+  GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO);
+  GNUNET_free_non_null (sc->nid);  
+  GNUNET_free_non_null (sc->nuid);
+  GNUNET_free (sc);
+}
+
+
 #if 0
 
 /**

Modified: gnunet/src/fs/fs_search.c
===================================================================
--- gnunet/src/fs/fs_search.c   2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/fs_search.c   2009-08-26 09:13:06 UTC (rev 8859)
@@ -19,21 +19,73 @@
 */
 
 /**
- * @file applications/fs/ecrs/search.c
+ * @file fs/fs_search.c
  * @brief Helper functions for searching.
  * @author Christian Grothoff
  */
 
 #include "platform.h"
-#include "gnunet_protocols.h"
-#include "gnunet_fs_lib.h"
-#include "gnunet_ecrs_lib.h"
-#include "ecrs_core.h"
-#include "ecrs.h"
+#include "gnunet_fs_service.h"
+#include "fs.h"
 
-#define DEBUG_SEARCH GNUNET_NO
+#define DEBUG_SEARCH GNUNET_YES
 
+
 /**
+ * Start search for content.
+ *
+ * @param h handle to the file sharing subsystem
+ * @param uri specifies the search parameters; can be
+ *        a KSK URI or an SKS URI.
+ * @param anonymity desired level of anonymity
+ * @return context that can be used to control the search
+ */
+struct GNUNET_FS_SearchContext *
+GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
+                       const struct GNUNET_FS_Uri *uri,
+                       unsigned int anonymity)
+{
+  return NULL;
+}
+
+
+/**
+ * Pause search.  
+ *
+ * @param sc context for the search that should be paused
+ */
+void 
+GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
+{
+}
+
+/**
+ * Continue paused search.
+ *
+ * @param sc context for the search that should be resumed
+ */
+void 
+GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
+{
+}
+
+
+/**
+ * Stop search for content.
+ *
+ * @param sc context for the search that should be stopped
+ */
+void 
+GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
+{
+}
+
+
+
+
+#if 0
+
+/**
  * Context for an individual search.  Followed
  *  by keyCount keys of type GNUNET_HashCode.
  */
@@ -568,5 +620,6 @@
   return GNUNET_OK;
 }
 
+#endif
 
-/* end of search.c */
+/* end of fs_search.c */

Deleted: gnunet/src/fs/fs_test.c
===================================================================
--- gnunet/src/fs/fs_test.c     2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/fs_test.c     2009-08-26 09:13:06 UTC (rev 8859)
@@ -1,259 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2004, 2005, 2006, 2008 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 applications/fs/fsui/basic_fsui_test.c
- * @brief testcase for fsui (upload-search-download-unindex)
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto 
FAILURE; }
-
-static char *
-makeName (unsigned int i)
-{
-  char *fn;
-
-  fn =
-    GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
-                   14);
-  GNUNET_snprintf (fn,
-                   strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
-                   14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i);
-  GNUNET_disk_directory_create_for_file (NULL, fn);
-  return fn;
-}
-
-static volatile enum GNUNET_FSUI_EventType lastEvent;
-
-static struct GNUNET_MetaData *search_meta;
-
-static struct GNUNET_ECRS_URI *search_uri;
-
-static struct GNUNET_FSUI_Context *ctx;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
-  static char unused;
-
-  switch (event->type)
-    {
-    case GNUNET_FSUI_search_resumed:
-    case GNUNET_FSUI_download_resumed:
-    case GNUNET_FSUI_upload_resumed:
-    case GNUNET_FSUI_unindex_resumed:
-      return &unused;
-    case GNUNET_FSUI_search_result:
-#if DEBUG_VERBOSE
-      printf ("Received search result\n");
-#endif
-      search_uri =
-        GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
-      search_meta =
-        GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta);
-      break;
-    case GNUNET_FSUI_upload_completed:
-#if DEBUG_VERBOSE
-      printf ("Upload complete.\n");
-#endif
-      break;
-    case GNUNET_FSUI_download_completed:
-#if DEBUG_VERBOSE
-      printf ("Download complete.\n");
-#endif
-      break;
-    case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
-      printf ("Unindex complete.\n");
-#endif
-      break;
-    default:
-      break;
-    }
-  lastEvent = event->type;
-  return NULL;
-}
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
-  pid_t daemon;
-#endif
-  int ok;
-  struct GNUNET_ECRS_URI *uri;
-  char *filename = NULL;
-  char *keywords[] = {
-    "fsui_foo",
-    "fsui_bar",
-  };
-  char keyword[40];
-  char *fn;
-  int prog;
-  struct GNUNET_MetaData *meta;
-  struct GNUNET_ECRS_URI *kuri;
-  struct GNUNET_GC_Configuration *cfg;
-  struct GNUNET_FSUI_UploadList *upload = NULL;
-  struct GNUNET_FSUI_SearchList *search = NULL;
-  struct GNUNET_FSUI_UnindexList *unindex = NULL;
-  struct GNUNET_FSUI_DownloadList *download = NULL;
-
-  cfg = GNUNET_GC_create ();
-  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
-    {
-      GNUNET_GC_free (cfg);
-      return -1;
-    }
-#if START_DAEMON
-  daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
-  GNUNET_GE_ASSERT (NULL, daemon > 0);
-  CHECK (GNUNET_OK ==
-         GNUNET_wait_for_daemon_running (NULL, cfg,
-                                         60 * GNUNET_CRON_SECONDS));
-#endif
-  GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);        /* give apps time to 
start */
-  ok = GNUNET_YES;
-
-  /* ACTUAL TEST CODE */
-  ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32,    /* thread pool 
size */
-                           GNUNET_NO,   /* no resume */
-                           &eventCallback, NULL);
-  CHECK (ctx != NULL);
-  filename = makeName (42);
-  GNUNET_disk_file_write (NULL,
-                          filename,
-                          "foo bar test!", strlen ("foo bar test!"), "600");
-  meta = GNUNET_meta_data_create ();
-  kuri =
-    GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
-                                             (const char **) keywords);
-  /* upload */
-  upload = GNUNET_FSUI_upload_start (ctx, filename, 
(GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0,  /* 
anonymity */
-                                     0, /* priority */
-                                     GNUNET_YES,
-                                     GNUNET_NO,
-                                     GNUNET_NO,
-                                     GNUNET_get_time () +
-                                     5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
-  CHECK (upload != NULL);
-  GNUNET_ECRS_uri_destroy (kuri);
-  GNUNET_meta_data_destroy (meta);
-  prog = 0;
-  while (lastEvent != GNUNET_FSUI_upload_completed)
-    {
-      prog++;
-      CHECK (prog <
-             10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
-      if (GNUNET_shutdown_test () == GNUNET_YES)
-        break;
-    }
-
-  /* search */
-  GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
-  uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
-  search = GNUNET_FSUI_search_start (ctx, 0, uri);
-  GNUNET_ECRS_uri_destroy (uri);
-  CHECK (search != NULL);
-  prog = 0;
-  while (lastEvent != GNUNET_FSUI_search_result)
-    {
-      prog++;
-      CHECK (prog < 10000);
-      GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
-      if (GNUNET_shutdown_test () == GNUNET_YES)
-        break;
-    }
-  GNUNET_FSUI_search_abort (search);
-  GNUNET_FSUI_search_stop (search);
-
-  /* download */
-  fn = makeName (43);
-  download = GNUNET_FSUI_download_start (ctx,
-                                         0,
-                                         GNUNET_NO,
-                                         search_uri,
-                                         search_meta, fn, NULL, NULL);
-  GNUNET_free (fn);
-  prog = 0;
-  while (lastEvent != GNUNET_FSUI_download_completed)
-    {
-      prog++;
-      CHECK (prog < 10000);
-      GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
-      if (GNUNET_shutdown_test () == GNUNET_YES)
-        break;
-    }
-  GNUNET_FSUI_download_stop (download);
-  download = NULL;
-  GNUNET_ECRS_uri_destroy (search_uri);
-  GNUNET_meta_data_destroy (search_meta);
-  /* unindex */
-  unindex = GNUNET_FSUI_unindex_start (ctx, filename);
-  prog = 0;
-  while (lastEvent != GNUNET_FSUI_unindex_completed)
-    {
-      prog++;
-      CHECK (prog < 10000);
-      GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
-      if (GNUNET_shutdown_test () == GNUNET_YES)
-        break;
-    }
-  if (lastEvent != GNUNET_FSUI_unindex_completed)
-    GNUNET_FSUI_unindex_abort (unindex);
-  GNUNET_FSUI_unindex_stop (unindex);
-
-
-  /* END OF TEST CODE */
-FAILURE:
-  if (ctx != NULL)
-    GNUNET_FSUI_stop (ctx);
-  if (filename != NULL)
-    {
-      UNLINK (filename);
-      GNUNET_free (filename);
-    }
-  if (download != NULL)
-    {
-      GNUNET_FSUI_download_abort (download);
-      GNUNET_FSUI_download_stop (download);
-    }
-  filename = makeName (43);
-  /* TODO: verify file 'filename(42)' == file 'filename(43)' */
-  UNLINK (filename);
-  GNUNET_free (filename);
-
-#if START_DAEMON
-  GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
-  GNUNET_GC_free (cfg);
-
-  return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of basic_fsui_test.c */

Modified: gnunet/src/fs/fs_unindex.c
===================================================================
--- gnunet/src/fs/fs_unindex.c  2009-08-26 09:12:48 UTC (rev 8858)
+++ gnunet/src/fs/fs_unindex.c  2009-08-26 09:13:06 UTC (rev 8859)
@@ -19,26 +19,63 @@
 */
 
 /**
- * @file applications/fs/ecrs/unindex.c
+ * @file fs/fs_unindex.c
  * @author Krista Bennett
  * @author Christian Grothoff
+ * @brief Unindex file.
  *
- * Unindex file.
- *
  * TODO:
  * - code cleanup (share more with upload.c)
  */
 
 #include "platform.h"
-#include "gnunet_protocols.h"
-#include "gnunet_ecrs_lib.h"
-#include "gnunet_fs_lib.h"
-#include "gnunet_getoption_lib.h"
-#include "ecrs_core.h"
-#include "ecrs.h"
+#include "gnunet_fs_service.h"
 #include "fs.h"
-#include "tree.h"
 
+/**
+ * Iterate over all indexed files.
+ *
+ * @param h handle to the file sharing subsystem
+ * @param iterator function to call on each indexed file
+ * @param iterator_cls closure for iterator
+ */
+void 
+GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
+                            GNUNET_FS_IndexedFileProcessor iterator,
+                            void *iterator_cls)
+{
+}
+
+
+/**
+ * Unindex a file.
+ *
+ * @param h handle to the file sharing subsystem
+ * @param filename file to unindex
+ * @return NULL on error, otherwise handle 
+ */
+struct GNUNET_FS_UnindexContext *
+GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
+                  const char *filename)
+{
+  return NULL;
+}
+
+
+/**
+ * Clean up after completion of an unindex operation.
+ *
+ * @param uc handle
+ */
+void
+GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
+{
+}
+
+
+
+#if 0
+
 #define STRICT_CHECKS GNUNET_NO
 
 /**
@@ -391,4 +428,6 @@
   return GNUNET_SYSERR;
 }
 
-/* end of unindex.c */
+#endif 
+
+/* end of fs_unindex.c */

Copied: gnunet/src/fs/test_fs.c (from rev 8843, gnunet/src/fs/fs_test.c)
===================================================================
--- gnunet/src/fs/test_fs.c                             (rev 0)
+++ gnunet/src/fs/test_fs.c     2009-08-26 09:13:06 UTC (rev 8859)
@@ -0,0 +1,259 @@
+/*
+     This file is part of GNUnet.
+     (C) 2004, 2005, 2006, 2008 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 applications/fs/fsui/basic_fsui_test.c
+ * @brief testcase for fsui (upload-search-download-unindex)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto 
FAILURE; }
+
+static char *
+makeName (unsigned int i)
+{
+  char *fn;
+
+  fn =
+    GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
+                   14);
+  GNUNET_snprintf (fn,
+                   strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
+                   14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i);
+  GNUNET_disk_directory_create_for_file (NULL, fn);
+  return fn;
+}
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+
+static struct GNUNET_MetaData *search_meta;
+
+static struct GNUNET_ECRS_URI *search_uri;
+
+static struct GNUNET_FSUI_Context *ctx;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+  static char unused;
+
+  switch (event->type)
+    {
+    case GNUNET_FSUI_search_resumed:
+    case GNUNET_FSUI_download_resumed:
+    case GNUNET_FSUI_upload_resumed:
+    case GNUNET_FSUI_unindex_resumed:
+      return &unused;
+    case GNUNET_FSUI_search_result:
+#if DEBUG_VERBOSE
+      printf ("Received search result\n");
+#endif
+      search_uri =
+        GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
+      search_meta =
+        GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta);
+      break;
+    case GNUNET_FSUI_upload_completed:
+#if DEBUG_VERBOSE
+      printf ("Upload complete.\n");
+#endif
+      break;
+    case GNUNET_FSUI_download_completed:
+#if DEBUG_VERBOSE
+      printf ("Download complete.\n");
+#endif
+      break;
+    case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+      printf ("Unindex complete.\n");
+#endif
+      break;
+    default:
+      break;
+    }
+  lastEvent = event->type;
+  return NULL;
+}
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+  pid_t daemon;
+#endif
+  int ok;
+  struct GNUNET_ECRS_URI *uri;
+  char *filename = NULL;
+  char *keywords[] = {
+    "fsui_foo",
+    "fsui_bar",
+  };
+  char keyword[40];
+  char *fn;
+  int prog;
+  struct GNUNET_MetaData *meta;
+  struct GNUNET_ECRS_URI *kuri;
+  struct GNUNET_GC_Configuration *cfg;
+  struct GNUNET_FSUI_UploadList *upload = NULL;
+  struct GNUNET_FSUI_SearchList *search = NULL;
+  struct GNUNET_FSUI_UnindexList *unindex = NULL;
+  struct GNUNET_FSUI_DownloadList *download = NULL;
+
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#if START_DAEMON
+  daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
+  GNUNET_GE_ASSERT (NULL, daemon > 0);
+  CHECK (GNUNET_OK ==
+         GNUNET_wait_for_daemon_running (NULL, cfg,
+                                         60 * GNUNET_CRON_SECONDS));
+#endif
+  GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);        /* give apps time to 
start */
+  ok = GNUNET_YES;
+
+  /* ACTUAL TEST CODE */
+  ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32,    /* thread pool 
size */
+                           GNUNET_NO,   /* no resume */
+                           &eventCallback, NULL);
+  CHECK (ctx != NULL);
+  filename = makeName (42);
+  GNUNET_disk_file_write (NULL,
+                          filename,
+                          "foo bar test!", strlen ("foo bar test!"), "600");
+  meta = GNUNET_meta_data_create ();
+  kuri =
+    GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
+                                             (const char **) keywords);
+  /* upload */
+  upload = GNUNET_FSUI_upload_start (ctx, filename, 
(GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0,  /* 
anonymity */
+                                     0, /* priority */
+                                     GNUNET_YES,
+                                     GNUNET_NO,
+                                     GNUNET_NO,
+                                     GNUNET_get_time () +
+                                     5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
+  CHECK (upload != NULL);
+  GNUNET_ECRS_uri_destroy (kuri);
+  GNUNET_meta_data_destroy (meta);
+  prog = 0;
+  while (lastEvent != GNUNET_FSUI_upload_completed)
+    {
+      prog++;
+      CHECK (prog <
+             10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+      if (GNUNET_shutdown_test () == GNUNET_YES)
+        break;
+    }
+
+  /* search */
+  GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+  uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
+  search = GNUNET_FSUI_search_start (ctx, 0, uri);
+  GNUNET_ECRS_uri_destroy (uri);
+  CHECK (search != NULL);
+  prog = 0;
+  while (lastEvent != GNUNET_FSUI_search_result)
+    {
+      prog++;
+      CHECK (prog < 10000);
+      GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+      if (GNUNET_shutdown_test () == GNUNET_YES)
+        break;
+    }
+  GNUNET_FSUI_search_abort (search);
+  GNUNET_FSUI_search_stop (search);
+
+  /* download */
+  fn = makeName (43);
+  download = GNUNET_FSUI_download_start (ctx,
+                                         0,
+                                         GNUNET_NO,
+                                         search_uri,
+                                         search_meta, fn, NULL, NULL);
+  GNUNET_free (fn);
+  prog = 0;
+  while (lastEvent != GNUNET_FSUI_download_completed)
+    {
+      prog++;
+      CHECK (prog < 10000);
+      GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+      if (GNUNET_shutdown_test () == GNUNET_YES)
+        break;
+    }
+  GNUNET_FSUI_download_stop (download);
+  download = NULL;
+  GNUNET_ECRS_uri_destroy (search_uri);
+  GNUNET_meta_data_destroy (search_meta);
+  /* unindex */
+  unindex = GNUNET_FSUI_unindex_start (ctx, filename);
+  prog = 0;
+  while (lastEvent != GNUNET_FSUI_unindex_completed)
+    {
+      prog++;
+      CHECK (prog < 10000);
+      GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+      if (GNUNET_shutdown_test () == GNUNET_YES)
+        break;
+    }
+  if (lastEvent != GNUNET_FSUI_unindex_completed)
+    GNUNET_FSUI_unindex_abort (unindex);
+  GNUNET_FSUI_unindex_stop (unindex);
+
+
+  /* END OF TEST CODE */
+FAILURE:
+  if (ctx != NULL)
+    GNUNET_FSUI_stop (ctx);
+  if (filename != NULL)
+    {
+      UNLINK (filename);
+      GNUNET_free (filename);
+    }
+  if (download != NULL)
+    {
+      GNUNET_FSUI_download_abort (download);
+      GNUNET_FSUI_download_stop (download);
+    }
+  filename = makeName (43);
+  /* TODO: verify file 'filename(42)' == file 'filename(43)' */
+  UNLINK (filename);
+  GNUNET_free (filename);
+
+#if START_DAEMON
+  GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+  GNUNET_GC_free (cfg);
+
+  return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of basic_fsui_test.c */

Modified: gnunet/src/include/gnunet_fs_service.h
===================================================================
--- gnunet/src/include/gnunet_fs_service.h      2009-08-26 09:12:48 UTC (rev 
8858)
+++ gnunet/src/include/gnunet_fs_service.h      2009-08-26 09:13:06 UTC (rev 
8859)
@@ -1763,11 +1763,11 @@
  */
 struct GNUNET_FS_PublishContext *
 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
-                      void *ctx,
-                      const struct GNUNET_FS_FileInformation *fi,
-                      struct GNUNET_FS_Namespace *namespace,
-                      const char *nid,
-                      const char *nuid);
+                        void *ctx,
+                        struct GNUNET_FS_FileInformation *fi,
+                        struct GNUNET_FS_Namespace *namespace,
+                        const char *nid,
+                        const char *nuid);
 
 
 /**





reply via email to

[Prev in Thread] Current Thread [Next in Thread]