authentication of ciphertexts (+ seed)
[oweals/gnunet.git] / src / fs / fs_namespace.c
index a9bcaf8e5589c1c4e75040f65ad60624dd81041e..5c1137eb7d8ea72f14f094f932432d59838acee4 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).
@@ -164,6 +166,12 @@ read_update_information_graph (struct GNUNET_FS_Namespace *ns)
   char *emsg;
   
   fn = get_update_information_directory (ns);
+  if (GNUNET_YES !=
+      GNUNET_DISK_file_test (fn))
+    {
+      GNUNET_free (fn);
+      return;
+    }
   rh = GNUNET_BIO_read_open (fn);
   if (rh == NULL)
     {
@@ -216,7 +224,7 @@ read_update_information_graph (struct GNUNET_FS_Namespace *ns)
          GNUNET_break (0);
          GNUNET_free (emsg);
          GNUNET_free (n->id);
-         GNUNET_free (n->update);
+         GNUNET_free_non_null (n->update);
          GNUNET_CONTAINER_meta_data_destroy (n->md);
          GNUNET_free (n);
          break;
@@ -353,7 +361,8 @@ advertisement_cont (void *cls,
                                         &do_disconnect,
                                         ac->dsh,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-      ac->cont (ac->cont_cls, NULL, msg);
+      if (ac->cont != NULL)
+       ac->cont (ac->cont_cls, NULL, msg);
       GNUNET_FS_uri_destroy (ac->ksk_uri);
       GNUNET_free (ac->pt);
       GNUNET_free (ac->nb);
@@ -368,7 +377,8 @@ advertisement_cont (void *cls,
                                         &do_disconnect,
                                         ac->dsh,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-      ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
+      if (ac->cont != NULL)
+       ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
       GNUNET_FS_uri_destroy (ac->ksk_uri);
       GNUNET_free (ac->pt);
       GNUNET_free (ac->nb);
@@ -406,7 +416,7 @@ advertisement_cont (void *cls,
                        &query,
                        ac->pt_size + sizeof (struct NBlock),
                        ac->nb,
-                       GNUNET_BLOCK_TYPE_NBLOCK,
+                       GNUNET_BLOCK_TYPE_FS_NBLOCK,
                        ac->priority,
                        ac->anonymity,
                        ac->expiration,
@@ -767,9 +777,10 @@ sb_put_cont (void *cls,
     }
   if (GNUNET_OK != success)
     {
-      psc->cont (psc->cont_cls,
-                NULL,
-                msg);
+      if (psc->cont != NULL)
+       psc->cont (psc->cont_cls,
+                  NULL,
+                  msg);
     }
   else
     {
@@ -796,9 +807,10 @@ sb_put_cont (void *cls,
          psc->nsn = NULL;
          write_update_information_graph (psc->namespace);
        }
-      psc->cont (psc->cont_cls,
-                psc->uri,
-                NULL);
+      if (psc->cont != NULL)
+       psc->cont (psc->cont_cls,
+                  psc->uri,
+                  NULL);
     }
   GNUNET_FS_namespace_delete (psc->namespace,
                              GNUNET_NO);
@@ -970,7 +982,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
                        &sb_enc->identifier,
                        size,
                        sb_enc,
-                       GNUNET_BLOCK_TYPE_SBLOCK, 
+                       GNUNET_BLOCK_TYPE_FS_SBLOCK, 
                        priority,
                        anonymity,
                        expirationTime,
@@ -1089,6 +1101,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 */
@@ -1145,7 +1159,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 */
@@ -1175,6 +1196,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;
@@ -1184,7 +1209,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);
@@ -1215,6 +1248,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),
@@ -1233,19 +1272,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];
-      ip (ip_cls,
-         nsn->id,
-         nsn->uri,
-         nsn->md,
-         nsn->update);
+      if (NULL != nsn)
+       {
+#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
 }