gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10778 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r10778 - gnunet/src/fs
Date: Mon, 5 Apr 2010 00:04:00 +0200

Author: grothoff
Date: 2010-04-05 00:04:00 +0200 (Mon, 05 Apr 2010)
New Revision: 10778

Added:
   gnunet/src/fs/test_gnunet_fs.py
Modified:
   gnunet/src/fs/Makefile.am
   gnunet/src/fs/fs_publish.c
   gnunet/src/fs/fs_search.c
   gnunet/src/fs/gnunet-pseudonym.c
   gnunet/src/fs/gnunet-publish.c
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/fs/gnunet-service-fs_drq.c
   gnunet/src/fs/gnunet-service-fs_indexing.c
Log:
bugfixes, more tests

Modified: gnunet/src/fs/Makefile.am
===================================================================
--- gnunet/src/fs/Makefile.am   2010-04-04 22:02:08 UTC (rev 10777)
+++ gnunet/src/fs/Makefile.am   2010-04-04 22:04:00 UTC (rev 10778)
@@ -130,7 +130,12 @@
  test_fs_uri \
  test_gnunet_service_fs_p2p
 
-TESTS = \
+if HAVE_PYTHON_PEXPECT
+check_SCRIPTS = \
+ test_gnunet_fs.py
+endif
+
+TESTS = $(check_SCRIPTS) \
  test_fs_directory \
  test_fs_download \
  test_fs_file_information \

Modified: gnunet/src/fs/fs_publish.c
===================================================================
--- gnunet/src/fs/fs_publish.c  2010-04-04 22:02:08 UTC (rev 10777)
+++ gnunet/src/fs/fs_publish.c  2010-04-04 22:04:00 UTC (rev 10778)
@@ -707,6 +707,7 @@
   struct GNUNET_CLIENT_Connection *client;
   uint32_t dev;
   uint64_t ino;
+  char *fn;
 
   p = sc->fi_pos;
   if (NULL == res) 
@@ -724,13 +725,15 @@
       publish_content (sc);
       return;
     }
-  slen = strlen (p->data.file.filename) + 1;
+  fn = GNUNET_STRINGS_filename_expand (p->data.file.filename);
+  slen = strlen (fn) + 1;
   if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  _("Can not index file `%s': %s.  Will try to insert 
instead.\n"),
-                 p->data.file.filename,
+                 fn,
                  _("filename too long"));
+      GNUNET_free (fn);
       p->data.file.do_index = GNUNET_NO;
       publish_content (sc);
       return;
@@ -752,6 +755,7 @@
                  _("could not connect to `fs' service"));
       p->data.file.do_index = GNUNET_NO;
       publish_content (sc);
+      GNUNET_free (fn);
       return;
     }
   p->data.file.file_id = *res;
@@ -777,8 +781,9 @@
     }
   ism->file_id = *res;
   memcpy (&ism[1],
-         p->data.file.filename,
+         fn,
          slen);
+  GNUNET_free (fn);
   sc->client = client;
   GNUNET_break (GNUNET_YES ==
                GNUNET_CLIENT_transmit_and_get_response (client,
@@ -1465,7 +1470,7 @@
                       struct GNUNET_FS_Namespace *namespace,
                       const char *identifier,
                       const char *update,
-                      struct GNUNET_CONTAINER_MetaData *meta,
+                      const struct GNUNET_CONTAINER_MetaData *meta,
                       const struct GNUNET_FS_Uri *uri,
                       struct GNUNET_TIME_Absolute expirationTime,
                       uint32_t anonymity,
@@ -1487,17 +1492,22 @@
   struct SBlock *sb;
   struct SBlock *sb_enc;
   char *dest;
+  struct GNUNET_CONTAINER_MetaData *mmeta;
   GNUNET_HashCode key;         /* hash of thisId = key */
   GNUNET_HashCode id;          /* hash of hc = identifier */
   GNUNET_HashCode query;       /* id ^ nsid = DB query */
 
+  if (NULL == meta)
+    mmeta = GNUNET_CONTAINER_meta_data_create ();
+  else
+    mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
   uris = GNUNET_FS_uri_to_string (uri);
   slen = strlen (uris) + 1;
   idlen = strlen (identifier);
   if (update == NULL)
     update = "";
   nidlen = strlen (update) + 1;
-  mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
+  mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
   size = sizeof (struct SBlock) + slen + nidlen + mdsize;
   if (size > MAX_SBLOCK_SIZE)
     {
@@ -1510,10 +1520,11 @@
   dest += nidlen;
   memcpy (dest, uris, slen);
   dest += slen;
-  mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
+  mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
                                                 &dest,
                                                 mdsize, 
                                                 
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+  GNUNET_CONTAINER_meta_data_destroy (mmeta);
   if (mdsize == -1)
     {
       GNUNET_break (0);

Modified: gnunet/src/fs/fs_search.c
===================================================================
--- gnunet/src/fs/fs_search.c   2010-04-04 22:02:08 UTC (rev 10777)
+++ gnunet/src/fs/fs_search.c   2010-04-04 22:04:00 UTC (rev 10778)
@@ -24,7 +24,9 @@
  * @author Christian Grothoff
  *
  * TODO:
- * - handle namespace advertisements (can wait; might already work!?)
+ * - handle namespace advertisements (NBlocks, see FIXME;
+ *   note that we currently use KBLOCK instead of ANY when
+ *   searching => NBLOCKS would not fit! FIX this as well!)
  * - add support for pushing "already seen" information
  *   to FS service for bloomfilter (can wait)
  * - handle availability probes (can wait)
@@ -382,8 +384,11 @@
       return;
     }
   j = eos - pt + 1;
-  meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j],
-                                                sizeof (pt) - j);
+  if (sizeof (pt) == j)
+    meta = GNUNET_CONTAINER_meta_data_create ();
+  else
+    meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j],
+                                                  sizeof (pt) - j);
   if (meta == NULL)
     {
       GNUNET_break_op (0);       /* kblock malformed */
@@ -529,6 +534,9 @@
        }
       process_sblock (sc, data, size);
       break;
+    case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK:
+      GNUNET_break (0); // FIXME: not implemented!
+      break;
     case GNUNET_DATASTORE_BLOCKTYPE_ANY:
     case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
     case GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND:

Modified: gnunet/src/fs/gnunet-pseudonym.c
===================================================================
--- gnunet/src/fs/gnunet-pseudonym.c    2010-04-04 22:02:08 UTC (rev 10777)
+++ gnunet/src/fs/gnunet-pseudonym.c    2010-04-04 22:04:00 UTC (rev 10778)
@@ -343,12 +343,12 @@
    ("add an additional keyword for the advertisment"
     " (this option can be specified multiple times)"),
    1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
-  {'l', "local-only", NULL,
-   gettext_noop ("print names of local namespaces"),
-   0, &GNUNET_GETOPT_set_one, &print_local_only},
   {'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},
+  {'o', "only-local", NULL,
+   gettext_noop ("print names of local namespaces"),
+   0, &GNUNET_GETOPT_set_one, &print_local_only},
   {'p', "priority", "PRIORITY",
    gettext_noop ("use the given PRIORITY for the advertisments"),
    1, &GNUNET_GETOPT_set_uint, &priority},

Modified: gnunet/src/fs/gnunet-publish.c
===================================================================
--- gnunet/src/fs/gnunet-publish.c      2010-04-04 22:02:08 UTC (rev 10777)
+++ gnunet/src/fs/gnunet-publish.c      2010-04-04 22:04:00 UTC (rev 10778)
@@ -46,6 +46,8 @@
 
 static struct GNUNET_FS_Uri *topKeywords;
 
+static struct GNUNET_FS_Uri *uri;
+
 static unsigned int anonymity = 1;
 
 static unsigned int priority = 365;
@@ -328,10 +330,31 @@
 
 
 static void 
+uri_sks_continuation (void *cls,
+                     const struct GNUNET_FS_Uri *ksk_uri,
+                     const char *emsg)
+{
+  if (emsg != NULL)
+    {
+      fprintf (stderr,
+              "%s\n",
+              emsg);
+      ret = 1;
+    }
+  GNUNET_FS_uri_destroy (uri);
+  uri = NULL;
+  GNUNET_FS_stop (ctx);
+  ctx = NULL;
+}
+
+
+static void 
 uri_ksk_continuation (void *cls,
-                     const struct GNUNET_FS_Uri *uri,
+                     const struct GNUNET_FS_Uri *ksk_uri,
                      const char *emsg)
 {
+  struct GNUNET_FS_Namespace *ns;
+
   if (emsg != NULL)
     {
       fprintf (stderr,
@@ -339,7 +362,40 @@
               emsg);
       ret = 1;
     }
+  if (pseudonym != NULL)
+    {
+      ns = GNUNET_FS_namespace_create (ctx,
+                                      pseudonym);
+      if (ns == NULL)
+       {
+         fprintf (stderr,
+                  _("Failed to create namespace `%s'\n"),
+                  pseudonym);
+         ret = 1;
+       }
+      else
+       {
+         GNUNET_FS_publish_sks (ctx,
+                                ns,
+                                this_id,
+                                next_id,
+                                meta,
+                                uri,
+                                GNUNET_TIME_relative_to_absolute 
(DEFAULT_EXPIRATION),
+                                anonymity,
+                                priority,
+                                GNUNET_FS_PUBLISH_OPTION_NONE,
+                                uri_sks_continuation,
+                                NULL);
+         GNUNET_assert (GNUNET_OK ==
+                        GNUNET_FS_namespace_delete (ns, GNUNET_NO));
+         return;
+       }
+    }
+  GNUNET_FS_uri_destroy (uri);
+  uri = NULL;
   GNUNET_FS_stop (ctx);
+  ctx = NULL;
 }
 
 
@@ -365,7 +421,6 @@
   struct stat sbuf;
   char *ex;
   char *emsg;
-  struct GNUNET_FS_Uri *uri;
   
   sched = s;
   /* check arguments */
@@ -419,7 +474,8 @@
          return;
         }
     }
-  if (args[0] == NULL)
+  if ( (args[0] == NULL) &&
+       (uri_string == NULL) )
     {
       fprintf (stderr,
               _("Need the name of a file to publish!\n"));

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2010-04-04 22:02:08 UTC (rev 10777)
+++ gnunet/src/fs/gnunet-service-fs.c   2010-04-04 22:04:00 UTC (rev 10778)
@@ -2852,7 +2852,7 @@
                               type,                           
                               &process_local_reply,
                               pr,
-                              GNUNET_TIME_UNIT_FOREVER_REL,
+                              GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                               GNUNET_YES);
 }
 

Modified: gnunet/src/fs/gnunet-service-fs_drq.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_drq.c       2010-04-04 22:02:08 UTC (rev 
10777)
+++ gnunet/src/fs/gnunet-service-fs_drq.c       2010-04-04 22:04:00 UTC (rev 
10778)
@@ -26,6 +26,7 @@
 #include "platform.h"
 #include "gnunet-service-fs_drq.h"
 
+#define DEBUG_DRQ GNUNET_NO
 
 /**
  * Signature of a function that is called whenever a datastore
@@ -165,17 +166,32 @@
   if (gc->iter == NULL) 
     {
       /* stop the iteration */
+#if DEBUG_DRQ
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Iteration terminated\n");
+#endif
       if (key != NULL)
        GNUNET_DATASTORE_get_next (dsh, GNUNET_NO);
     }
   else
     {
+#if DEBUG_DRQ
+      if (key != NULL)
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                   "Iteration produced %u-byte result for `%s'\n",
+                   size,
+                   GNUNET_h2s (key));
+#endif
       gc->iter (gc->iter_cls,
                key, size, data, type,
                priority, anonymity, expiration, uid);
     }
   if (key == NULL)
     {
+#if DEBUG_DRQ
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Iteration completed\n");
+#endif
       GNUNET_assert (gc == drq_running);
       GNUNET_free (gc);
       drq_running = NULL;
@@ -197,6 +213,12 @@
   struct DatastoreRequestQueue *gc = cls;
 
   gc->task = GNUNET_SCHEDULER_NO_TASK;
+#if DEBUG_DRQ
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Running datastore request for `%s' of type %u\n",
+             GNUNET_h2s (&gc->key),
+             gc->type);
+#endif
   GNUNET_DATASTORE_get (dsh, &gc->key, gc->type, 
                        &get_iterator,
                        gc,
@@ -239,6 +261,10 @@
 {
   struct DatastoreRequestQueue *e = cls;
 
+#if DEBUG_DRQ
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Datastore request timed out in queue before transmission\n");
+#endif
   e->task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
   if (e->iter != NULL)
@@ -261,6 +287,10 @@
 {
   struct DatastoreRequestQueue *drq;
 
+#if DEBUG_DRQ
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "DRQ shutdown initiated\n");
+#endif
   GNUNET_assert (NULL != dsh);
   GNUNET_DATASTORE_disconnect (dsh,
                               GNUNET_NO);
@@ -306,6 +336,12 @@
   struct DatastoreRequestQueue *e;
   struct DatastoreRequestQueue *bef;
 
+#if DEBUG_DRQ
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "DRQ receives request for `%s' of type %u\n",
+             GNUNET_h2s (key),
+             type);
+#endif
   e = GNUNET_malloc (sizeof (struct DatastoreRequestQueue));
   e->timeout = GNUNET_TIME_relative_to_absolute (timeout);
   e->forced_head = immediate;
@@ -348,6 +384,10 @@
 void
 GNUNET_FS_drq_get_cancel (struct DatastoreRequestQueue *drq)
 {
+#if DEBUG_DRQ
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "DRQ receives request cancellation request\n");
+#endif
   if (drq == drq_running)
     {
       /* 'DATASTORE_get' has already been started (and this call might
@@ -376,11 +416,42 @@
 void
 GNUNET_FS_drq_get_next (int more)
 {
+#if DEBUG_DRQ
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "DRQ receives request for next result (more is %d)\n",
+             more);
+#endif
   GNUNET_DATASTORE_get_next (dsh, more);
 }
 
 
 /**
+ * Closure for 'drq_remove_cont'.
+ */
+struct RemoveContext
+{
+  struct GNUNET_DATASTORE_Handle *rmdsh; 
+  GNUNET_DATASTORE_ContinuationWithStatus cont;
+  void *cont_cls;
+};
+
+
+static void 
+drq_remove_cont (void *cls,
+                int success,
+                const char *msg)
+{
+  struct RemoveContext *rc = cls;
+
+  rc->cont (rc->cont_cls,
+           success,
+           msg);
+  GNUNET_DATASTORE_disconnect (rc->rmdsh, GNUNET_NO);
+  GNUNET_free (rc);
+}
+
+
+/**
  * Explicitly remove some content from the database.
  * The "cont"inuation will be called with status
  * "GNUNET_OK" if content was removed, "GNUNET_NO"
@@ -401,13 +472,26 @@
                      void *cont_cls,
                      struct GNUNET_TIME_Relative timeout)
 {
-  if (dsh == NULL)
+  struct GNUNET_DATASTORE_Handle *rmdsh; 
+  struct RemoveContext *rc;
+
+  rmdsh = GNUNET_DATASTORE_connect (cfg,
+                                   sched);
+  if (rmdsh == NULL)
     {
       GNUNET_break (0);
+      cont (cont_cls,
+           GNUNET_SYSERR,
+           _("Failed to connect to datastore"));
       return;
     }
-  GNUNET_DATASTORE_remove (dsh, key, size, data,
-                          cont, cont_cls, timeout);
+  rc = GNUNET_malloc (sizeof (struct RemoveContext));
+  rc->cont = cont;
+  rc->cont_cls = cont_cls;
+  rc->rmdsh = rmdsh;
+  GNUNET_DATASTORE_remove (rmdsh, key, size, data,
+                          &drq_remove_cont, 
+                          rc, timeout);
 }
 
 

Modified: gnunet/src/fs/gnunet-service-fs_indexing.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_indexing.c  2010-04-04 22:02:08 UTC (rev 
10777)
+++ gnunet/src/fs/gnunet-service-fs_indexing.c  2010-04-04 22:04:00 UTC (rev 
10778)
@@ -322,7 +322,7 @@
                              const struct GNUNET_MessageHeader *message)
 {
   const struct IndexStartMessage *ism;
-  const char *fn;
+  char *fn;
   uint16_t msize;
   struct IndexInfo *ii;
   size_t slen;
@@ -341,7 +341,7 @@
       return;
     }
   ism = (const struct IndexStartMessage*) message;
-  fn = (const char*) &ism[1];
+  fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]);
   dev = ntohl (ism->device);
   ino = GNUNET_ntohll (ism->inode);
   ism = (const struct IndexStartMessage*) message;
@@ -363,6 +363,7 @@
     {      
       /* fast validation OK! */
       signal_index_ok (ii);
+      GNUNET_free (fn);
       return;
     }
 #if DEBUG_FS
@@ -380,6 +381,7 @@
                           HASHING_BLOCKSIZE,
                           &hash_for_index_val,
                           ii);
+  GNUNET_free (fn);
 }
 
 

Added: gnunet/src/fs/test_gnunet_fs.py
===================================================================
--- gnunet/src/fs/test_gnunet_fs.py                             (rev 0)
+++ gnunet/src/fs/test_gnunet_fs.py     2010-04-04 22:04:00 UTC (rev 10778)
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+import pexpect
+import os
+import signal
+import re
+
+os.system ('gnunet-arm -s')
+try:
+# first, basic publish-search-download run
+  pub = pexpect.spawn ('gnunet-publish -k gpl ../../COPYING')
+  pub.expect ('Publishing `../../COPYING\' done.\r')
+  pub.expect ("URI is 
`gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147'.\r")
+  pub.expect (pexpect.EOF)
+
+  search = pexpect.spawn ('gnunet-search gpl')
+  search.expect ("gnunet-download -o \"COPYING\" 
gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147\r")
+  search.kill (signal.SIGTERM)
+  search.expect (pexpect.EOF)
+# FIXME: check for meta-data (also need to add meta data in publish call!)
+  
+  down = pexpect.spawn ('gnunet-download -o \"COPYING\" 
gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147')
+  down.expect (re.compile ("Downloading `COPYING\' done \(.*\).\r"));
+  down.expect (pexpect.EOF);
+  os.system ('rm COPYING');
+
+# second, same with namespace creation  
+  pseu = pexpect.spawn ('gnunet-pseudonym -C licenses -k gpl -k test -m 
"description:Free Software Licenses"')
+  pseu.expect (pexpect.EOF)
+  pseu = pexpect.spawn ('gnunet-pseudonym -o')
+  pseu.expect (re.compile("licenses \(.*\)\r"))
+  pseu.expect (pexpect.EOF)
+
+  pub = pexpect.spawn ('gnunet-publish -k licenses -P licenses -u 
gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147
 -t gpl -N gpl3')
+  pub.expect (pexpect.EOF)
+
+#  search = pexpect.spawn ('gnunet-search licenses')
+# FIXME: check that namespace was found
+# FIXME: check for meta-data!
+
+finally:
+  os.system ('gnunet-arm -e')


Property changes on: gnunet/src/fs/test_gnunet_fs.py
___________________________________________________________________
Added: svn:executable
   + *





reply via email to

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