fix
[oweals/gnunet.git] / src / fs / fs_publish.c
index 6d3f4679db9058d3b2c1eb93df68b9565b6f87c2..4d93579bd227bd16b8ecf008ec958971626ea5e3 100644 (file)
@@ -109,11 +109,15 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
 /**
  * Cleanup the publish context, we're done with it.
  *
- * @param pc struct to clean up after
+ * @param cls struct to clean up after
+ * @param tc scheduler context
  */
 static void
-publish_cleanup (struct GNUNET_FS_PublishContext *pc)
+publish_cleanup (void *cls,
+                const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  struct GNUNET_FS_PublishContext *pc = cls;
+
   GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
   if (pc->namespace != NULL)
     GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
@@ -121,7 +125,10 @@ publish_cleanup (struct GNUNET_FS_PublishContext *pc)
   GNUNET_free_non_null (pc->nuid);
   GNUNET_free_non_null (pc->serialization);
   if (pc->dsh != NULL)
-    GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+    {
+      GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+      pc->dsh = NULL;
+    }
   if (pc->client != NULL)
     GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO);
   GNUNET_free (pc);
@@ -146,9 +153,12 @@ ds_put_cont (void *cls,
 
   if (GNUNET_SYSERR == pcc->sc->in_network_wait)
     {
-      /* we were aborted in the meantime,
-        finish shutdown! */
-      publish_cleanup (pcc->sc);
+      /* we were aborted in the meantime, finish shutdown! */
+      GNUNET_SCHEDULER_add_continuation (pcc->sc->h->sched,                                     
+                                        &publish_cleanup,
+                                        pcc->sc,
+                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      GNUNET_free (pcc);
       return;
     }
   GNUNET_assert (GNUNET_YES == pcc->sc->in_network_wait);
@@ -482,6 +492,7 @@ block_proc (void *cls,
                            p->priority,
                            p->anonymity,
                            p->expirationTime,
+                           -2, 1,
                            GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                            &ds_put_cont,
                            dpc_cls);     
@@ -503,6 +514,7 @@ block_proc (void *cls,
                        p->priority,
                        p->anonymity,
                        p->expirationTime,
+                       -2, 1,
                        GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                        &ds_put_cont,
                        dpc_cls);
@@ -989,6 +1001,11 @@ fip_signal_suspend(void *cls,
   pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
   GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
   *client_info = NULL;
+  if (NULL != sc->dsh)
+    {
+      GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO);
+      sc->dsh = NULL;
+    }
   return GNUNET_OK;
 }
 
@@ -1013,9 +1030,10 @@ GNUNET_FS_publish_signal_suspend_ (void *cls)
                                      &fip_signal_suspend,
                                      pc);
   GNUNET_FS_end_top (pc->h, pc->top);
-  publish_cleanup (pc);
+  publish_cleanup (pc, NULL);
 }
 
+
 /**
  * Publish a file or directory.
  *
@@ -1141,6 +1159,11 @@ void
 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
 {
   GNUNET_FS_end_top (pc->h, pc->top);
+  if (NULL != pc->dsh)
+    {
+      GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
+      pc->dsh = NULL;
+    }
   if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
     {
       GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
@@ -1160,7 +1183,7 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
       pc->in_network_wait = GNUNET_SYSERR;
       return;
     }
-  publish_cleanup (pc);
+  publish_cleanup (pc, NULL);
 }
 
 
@@ -1271,7 +1294,11 @@ kb_put_cont (void *cls,
 
   if (GNUNET_OK != success)
     {
-      GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+      if (NULL != pkc->dsh)
+       {
+         GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+         pkc->dsh = NULL;
+       }
       GNUNET_free (pkc->cpy);
       GNUNET_free (pkc->kb);
       pkc->cont (pkc->cont_cls,
@@ -1312,7 +1339,10 @@ publish_ksk_cont (void *cls,
        (NULL == pkc->dsh) )
     {
       if (NULL != pkc->dsh)
-       GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+       {
+         GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+         pkc->dsh = NULL;
+       }
       GNUNET_free (pkc->cpy);
       GNUNET_free (pkc->kb);
       pkc->cont (pkc->cont_cls,
@@ -1353,6 +1383,7 @@ publish_ksk_cont (void *cls,
                        pkc->priority,
                        pkc->anonymity,
                        pkc->expirationTime,
+                       -2, 1,
                        GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                        &kb_put_cont,
                        pkc);
@@ -1437,7 +1468,10 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
       GNUNET_break (0);
       GNUNET_free (pkc->kb);
       if (pkc->dsh != NULL)
-       GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+       {
+         GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
+         pkc->dsh = NULL;
+       }
       cont (cont_cls, NULL, _("Internal error."));
       GNUNET_free (pkc);
       return;
@@ -1503,7 +1537,10 @@ sb_put_cont (void *cls,
   struct PublishSksContext *psc = cls;
 
   if (NULL != psc->dsh)
-    GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
+    {
+      GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
+      psc->dsh = NULL;
+    }
   if (GNUNET_OK != success)
     psc->cont (psc->cont_cls,
               NULL,
@@ -1587,6 +1624,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
   memcpy (dest, update, nidlen);
   dest += nidlen;
   memcpy (dest, uris, slen);
+  GNUNET_free (uris);
   dest += slen;
   mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
                                                 &dest,
@@ -1596,7 +1634,6 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
   if (mdsize == -1)
     {
       GNUNET_break (0);
-      GNUNET_free (uris);
       GNUNET_free (sb);
       cont (cont_cls,
            NULL,
@@ -1666,10 +1703,10 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
                        priority,
                        anonymity,
                        expirationTime,
+                       -2, 1,
                        GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                        &sb_put_cont,
                        psc);
-
   GNUNET_free (sb);
   GNUNET_free (sb_enc);
 }