gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r8978 - in gnunet: . src/fs src/include
Date: Fri, 11 Sep 2009 03:09:39 -0600

Author: grothoff
Date: 2009-09-11 03:09:39 -0600 (Fri, 11 Sep 2009)
New Revision: 8978

Modified:
   gnunet/BUGS
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/fs/test_fs_directory.c
   gnunet/src/include/gnunet_datastore_service.h
Log:
fs

Modified: gnunet/BUGS
===================================================================
--- gnunet/BUGS 2009-09-10 22:44:30 UTC (rev 8977)
+++ gnunet/BUGS 2009-09-11 09:09:39 UTC (rev 8978)
@@ -4,7 +4,6 @@
 
 
 * UTIL:
-  - crypto_hash: use libgcrypt (supports SHA-512 since 2003)
   - container_bloomfilter: improve efficiency (see FIXME)
   - no tests for BIO
   - Windows: use events instead of pipes to signal select()s [Nils]

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2009-09-10 22:44:30 UTC (rev 8977)
+++ gnunet/src/fs/gnunet-service-fs.c   2009-09-11 09:09:39 UTC (rev 8978)
@@ -30,39 +30,239 @@
 #include "gnunet_util_lib.h"
 #include "fs.h"
 
+static struct GNUNET_DATASTORE_Handle *dsh;
 
+/**
+ * Handle INDEX_START-message.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_index_start (void *cls,
+                   struct GNUNET_SERVER_Client *client,
+                   const struct GNUNET_MessageHeader *message)
+{
+  const struct IndexStartMessage *ism;
+  const char *fn;
+  uint16_t msize;
 
+  msize = ntohs(message->size);
+  if ( (msize <= sizeof (struct IndexStartMessage)) ||
+       ( ((const char *)message)[msize-1] != '\0') )
+    {
+      GNUNET_break (0);
+      GNUNET_SERVER_receive_done (client,
+                                 GNUNET_SYSERR);
+      return;
+    }
+  ism = (const struct IndexStartMessage*) message;
+  fn = (const char*) &ism[1];
+  // FIXME: store fn, hash, check, respond to client, etc.
+}
+
+
 /**
- * Handle GET-message.
+ * Handle INDEX_LIST_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)
+handle_index_list_get (void *cls,
+                      struct GNUNET_SERVER_Client *client,
+                      const struct GNUNET_MessageHeader *message)
 {
+  struct GNUNET_SERVER_TransmitContext *tc;
+  struct IndexInfoMessage *iim;
+  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
+  size_t slen;
+  char *fn;
+  struct GNUNET_MessageHeader *msg;
+
+  tc = GNUNET_SERVER_transmit_context_create (client);
+  iim = (struct IndexInfoMessage*) buf;
+  msg = &iim->header;
+  while (0)
+    {
+      iim->reserved = 0;
+      // FIXME: read actual list of indexed files...
+      // iim->file_id = id;
+      fn = "FIXME";
+      slen = strlen (fn) + 1;
+      if (slen + sizeof (struct IndexInfoMessage) > 
+         GNUNET_SERVER_MAX_MESSAGE_SIZE)
+       {
+         GNUNET_break (0);
+         break;
+       }
+      memcpy (&iim[1], fn, slen);
+      GNUNET_SERVER_transmit_context_append
+       (tc,
+        &msg[1],
+        sizeof (struct IndexInfoMessage) 
+        - sizeof (struct GNUNET_MessageHeader) + slen,
+        GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+    }
+  GNUNET_SERVER_transmit_context_append (tc,
+                                        NULL, 0,
+                                        GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+  GNUNET_SERVER_transmit_context_run (tc,
+                                     GNUNET_TIME_UNIT_MINUTES);
 }
 
 
 /**
+ * Handle UNINDEX-message.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_unindex (void *cls,
+               struct GNUNET_SERVER_Client *client,
+               const struct GNUNET_MessageHeader *message)
+{
+  const struct UnindexMessage *um;
+  struct GNUNET_SERVER_TransmitContext *tc;
+  
+  um = (const struct UnindexMessage*) message;
+  // fixme: process!
+  tc = GNUNET_SERVER_transmit_context_create (client);
+  GNUNET_SERVER_transmit_context_append (tc,
+                                        NULL, 0,
+                                        GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
+  GNUNET_SERVER_transmit_context_run (tc,
+                                     GNUNET_TIME_UNIT_MINUTES);
+}
+
+
+/**
+ * FIXME
+ *
+ * @param cls closure
+ * @param ok GNUNET_OK if DS is ready, GNUNET_SYSERR on timeout
+ */
+typedef void (*RequestFunction)(void *cls,
+                               int ok);
+
+
+/**
+ * Run the next DS request in our
+ * queue, we're done with the current one.
+ */
+static void
+next_ds_request ()
+{
+}
+
+
+/**
+ * FIXME.
+ */
+static void
+queue_ds_request (struct GNUNET_TIME_Relative deadline,
+                 RequestFunction fun,
+                 void *fun_cls)
+{
+}
+
+
+
+/**
+ * Closure for processing START_SEARCH
+ * messages from a client.
+ */
+struct LocalGetContext
+{
+  /**
+   * Client that initiated the search.
+   */
+  struct GNUNET_SERVER_Client *client;
+  
+};
+
+
+/**
+ * Handle START_SEARCH-message.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_start_search (void *cls,
+                    struct GNUNET_SERVER_Client *client,
+                    const struct GNUNET_MessageHeader *message)
+{
+  const struct SearchMessage *sm;
+  struct LocalGetContext *lgc;
+
+  sm = (const struct SearchMessage*) message;
+  GNUNET_SERVER_client_keep (client);
+  lgc = GNUNET_malloc (sizeof (struct LocalGetContext));
+  lgc->client = client;
+  lgc->x = y;
+  queue_ds_request (&transmit_local_get,
+                   lgc);
+}
+
+
+static void 
+transmit_local_get (void *cls,
+                   int ok)
+{
+  struct LocalGetContext *lgc = cls;
+  // FIXME: search locally
+
+  GNUNET_assert (GNUNET_OK == ok);
+  GNUNET_SERVER_receive_done (lgc->client,
+                             GNUNET_OK);
+  
+  // FIXME: if not found, initiate P2P search  
+
+  // FIXME: once done with "client" handle:
+  GNUNET_SERVER_client_drop (lgc->client); 
+}
+
+
+/**
  * 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},
+  {&handle_index_start, NULL, 
+   GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
+  {&handle_index_list_get, NULL, 
+   GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) 
},
+  {&handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX, 
+   sizeof (struct UnindexMessage) },
+  {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 
+   sizeof (struct SearchMessage) },
   {NULL, NULL, 0, 0}
 };
 
 
 /**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls,
+              const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_DATASTORE_disconnect (dsh,
+                              GNUNET_NO);
+  dsh = NULL;
+}
+
+
+/**
  * Process fs requests.
  *
  * @param cls closure
@@ -76,8 +276,24 @@
      struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  dsh = GNUNET_DATASTORE_connect (cfg,
+                                 sched);
+  if (NULL == dsh)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to connect to datastore service.\n"));
+      return;
+    }
   GNUNET_SERVER_add_handlers (server, handlers);
   // FIXME: also handle P2P messages!
+
+  GNUNET_SCHEDULER_add_delayed (sched,
+                               GNUNET_YES,
+                               GNUNET_SCHEDULER_PRIORITY_IDLE,
+                               GNUNET_SCHEDULER_NO_TASK,
+                               GNUNET_TIME_UNIT_FOREVER_REL,
+                               &shutdown_task,
+                               NULL);
 }
 
 

Modified: gnunet/src/fs/test_fs_directory.c
===================================================================
--- gnunet/src/fs/test_fs_directory.c   2009-09-10 22:44:30 UTC (rev 8977)
+++ gnunet/src/fs/test_fs_directory.c   2009-09-11 09:09:39 UTC (rev 8978)
@@ -91,7 +91,6 @@
   meta = GNUNET_CONTAINER_meta_data_create ();
   GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title");
   GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author");
-  db = GNUNET_FS_directory_builder_create (meta);
   for (p = 0; p < i; p++)
     {
       mds[p] = GNUNET_CONTAINER_meta_data_create ();
@@ -120,16 +119,19 @@
           GNUNET_free (uris);
           ABORT ();             /* error in testcase */
         }
-      GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
     }
   start = GNUNET_TIME_absolute_get ();
+  db = GNUNET_FS_directory_builder_create (meta);
+  for (p = 0; p < i; p++)
+    GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
   GNUNET_FS_directory_builder_finish (db,
                                      &dlen,
                                      (void**) &data);
   s = GNUNET_STRINGS_relative_time_to_string 
(GNUNET_TIME_absolute_get_duration (start));
   fprintf (stdout,
-          "Creating directory with %u entires took %s\n",
+          "Creating directory with %u entires and total size %llu took %s\n",
           i,
+          (unsigned long long) dlen,
           s);
   GNUNET_free (s);
   if (i < 1000)
@@ -167,7 +169,7 @@
                    "WARNING",
 #endif
                    NULL);
-  for (i = 17; i < 10000; i *= 2)
+  for (i = 17; i < 4000; i *= 2)
     failureCount += testDirectory (i);    
   fprintf (stderr, "\n");
 

Modified: gnunet/src/include/gnunet_datastore_service.h
===================================================================
--- gnunet/src/include/gnunet_datastore_service.h       2009-09-10 22:44:30 UTC 
(rev 8977)
+++ gnunet/src/include/gnunet_datastore_service.h       2009-09-11 09:09:39 UTC 
(rev 8978)
@@ -231,7 +231,7 @@
 void
 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
                       const GNUNET_HashCode * key,
-                      uint32_t type,
+                     uint32_t type,
                       GNUNET_DATASTORE_Iterator iter, void *iter_cls,
                      struct GNUNET_TIME_Relative timeout);
 





reply via email to

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