fix
authorChristian Grothoff <christian@grothoff.org>
Sun, 5 Sep 2010 21:48:41 +0000 (21:48 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 5 Sep 2010 21:48:41 +0000 (21:48 +0000)
src/fs/fs_namespace.c
src/fs/test_fs_namespace_list_updateable.c

index 2b3fc589f1518e2656246f1d9555e2f375ed106c..8e13df9bc5e345346b0fcb99fa69cd81c2c2d6b7 100644 (file)
@@ -30,6 +30,8 @@
 #include "gnunet_fs_service.h"
 #include "fs.h"
 
+#define DEBUG_NAMESPACE GNUNET_NO
+
 /**
  * Return the name of the directory in which we store
  * our local namespaces (or rather, their public keys).
@@ -1095,6 +1097,8 @@ find_sccs (void *cls,
     {
       if (fc->scc_array[nsn->scc_id] != nsn)
        return GNUNET_YES; /* part of another SCC, end trace */
+      if (nsn->scc_id == fc->id)
+       return GNUNET_YES; /* that's us */
       fc->scc_array[nsn->scc_id] = NULL;
       if (fc->id == UINT_MAX)
        fc->id = nsn->scc_id; /* take over ID */
@@ -1151,7 +1155,14 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
   if (namespace->update_nodes == NULL)
     read_update_information_graph (namespace);
   if (namespace->update_nodes == NULL)
-    return; /* no nodes */
+    {
+#if DEBUG_NAMESPACE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "No updateable nodes found for ID `%s'\n",
+                 next_id);
+#endif
+      return; /* no nodes */
+    }
   if (namespace->update_map == NULL)
     {
       /* need to construct */
@@ -1181,6 +1192,10 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
                                                  &pc);
       return;
     }
+#if DEBUG_NAMESPACE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Calculating SCCs to find roots of update trees\n");
+#endif
   /* Find heads of SCCs in update graph */
   nug = ++namespace->nug_gen;
   fc.scc_array = NULL;
@@ -1190,7 +1205,15 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
     {
       nsn = namespace->update_nodes[i];
       if (nsn->nug == nug)
-       continue; /* already placed in SCC */
+       {
+#if DEBUG_NAMESPACE
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     "SCC of node `%s' is %u\n",
+                     nsn->id,
+                     nsn->nug);
+#endif
+         continue; /* already placed in SCC */
+       }
       GNUNET_CRYPTO_hash (nsn->update,
                          strlen (nsn->update),
                          &hc);
@@ -1221,6 +1244,12 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
                                   nsn);
              nsn->scc_id = fc.id;
            }
+#if DEBUG_NAMESPACE
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     "Starting new SCC %u with node `%s'\n",
+                     nsn->scc_id,
+                     nsn->id);
+#endif
          /* put all nodes with same identifier into this SCC */
          GNUNET_CRYPTO_hash (nsn->id,
                              strlen (nsn->id),
@@ -1239,20 +1268,39 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
          fc.scc_array[fc.id] = nsn;
          nsn->scc_id = fc.id;
        }
+#if DEBUG_NAMESPACE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "SCC of node `%s' is %u\n",
+                 nsn->id,
+                 fc.id);
+#endif
     }
   for (i=0;i<fc.scc_array_size;i++)
     {
       nsn = fc.scc_array[i];
       if (NULL != nsn)
-       ip (ip_cls,
-           nsn->id,
-           nsn->uri,
-           nsn->md,
-           nsn->update);
+       {
+#if DEBUG_NAMESPACE
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     "Root of SCC %u is node `%s'\n",
+                     i,
+                     nsn->id);
+#endif
+
+         ip (ip_cls,
+             nsn->id,
+             nsn->uri,
+             nsn->md,
+             nsn->update);
+       }
     }
   GNUNET_array_grow (fc.scc_array,
                     fc.scc_array_size,
                     0);
+#if DEBUG_NAMESPACE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Done processing SCCs\n");
+#endif
 }
 
 
index c2351471ec60fa082f5705bf04e19f2653cfa31f..fc6b1537a83f1fef7dbab4e5d04107cf32095dd8 100644 (file)
 */
 
 /**
- * @file fs/test_fs_namespace.c
- * @brief Test for fs_namespace.c
+ * @file fs/test_fs_namespace_list_updateable.c
+ * @brief Test for fs_namespace_list_updateable.c
  * @author Christian Grothoff
- *
- * TODO:
- * - add timeout task
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -111,12 +108,62 @@ stop_arm (struct PeerContext *p)
 
 
 
+static void
+check_next (void *cls,
+           const char *last_id, 
+           const struct GNUNET_FS_Uri *last_uri,
+           const struct GNUNET_CONTAINER_MetaData *last_meta,
+           const char *next_id)
+{
+  GNUNET_break (0 == strcmp (last_id, "next"));
+  GNUNET_break (0 == strcmp (next_id, "future"));
+  err -= 4;
+}
+
+
+static void
+check_this_next (void *cls,
+                const char *last_id, 
+                const struct GNUNET_FS_Uri *last_uri,
+                const struct GNUNET_CONTAINER_MetaData *last_meta,
+                const char *next_id)
+{
+  GNUNET_break (0 == strcmp (last_id, "this"));
+  GNUNET_break (0 == strcmp (next_id, "next"));
+  err -= 2;
+  err += 4;
+  GNUNET_FS_namespace_list_updateable (ns,
+                                      next_id,
+                                      &check_next,
+                                      NULL);
+}
+
+
 static void
 sks_cont_next (void *cls,
               const struct GNUNET_FS_Uri *uri,
               const char *emsg)
 {
   GNUNET_assert (NULL == emsg);
+  err += 2;
+  GNUNET_FS_namespace_list_updateable (ns,
+                                      NULL,
+                                      &check_this_next,
+                                      NULL);
+
+}
+
+
+static void
+check_this (void *cls,
+           const char *last_id, 
+           const struct GNUNET_FS_Uri *last_uri,
+           const struct GNUNET_CONTAINER_MetaData *last_meta,
+           const char *next_id)
+{
+  GNUNET_break (0 == strcmp (last_id, "this"));
+  GNUNET_break (0 == strcmp (next_id, "next"));
+  err -= 1;
 }
 
 
@@ -126,7 +173,11 @@ sks_cont_this (void *cls,
               const char *emsg)
 {
   GNUNET_assert (NULL == emsg);
-
+  err = 1;
+  GNUNET_FS_namespace_list_updateable (ns,
+                                      NULL,
+                                      &check_this,
+                                      NULL);
   GNUNET_FS_publish_sks (fs,
                         ns,
                         "next",