bugfixes
authorChristian Grothoff <christian@grothoff.org>
Thu, 6 May 2010 13:02:14 +0000 (13:02 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 6 May 2010 13:02:14 +0000 (13:02 +0000)
src/fs/fs.c
src/fs/fs_download.c
src/fs/fs_publish.c
src/fs/test_fs_download_persistence.c

index 58045591ed1c62eaa7cfa5d7d2a25edf362e6e7d..78d29dff1cee9a5158ff396500f57da9d57936e9 100644 (file)
@@ -529,9 +529,7 @@ get_write_handle (struct GNUNET_FS_Handle *h,
     }
   ret = GNUNET_BIO_write_open (fn);
   if (ret == NULL)
-    fprintf (stderr,
-            "Failed to create write handle for `%s' from `%s/%s'\n",
-            fn, ext, ent);
+    GNUNET_break (0);
   GNUNET_free (fn);
   return ret;
 }
@@ -1671,11 +1669,13 @@ count_download_requests (void *cls,
  *
  * @param dc download context to compute for
  * @param uni unique filename to use, use "" for the directory name
+ * @param ext extension to use, use ".dir" for our own subdirectory
  * @return the expanded file name, NULL for none
  */
 static char *
 get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
-                           const char *uni)
+                           const char *uni,
+                           const char *ext)
 {
   char *par;
   char *epar;
@@ -1688,14 +1688,15 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
                                        uni);
   if (dc->parent->serialization == NULL)
     return NULL;
-  par = get_download_sync_filename (dc->parent, dc->parent->serialization);
+  par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
   if (par == NULL)
     return NULL;
   GNUNET_asprintf (&epar,
-                  "%s.dir%s%s",
+                  "%s.dir%s%s%s",
                   par,
                   DIR_SEPARATOR_STR,
-                  uni);
+                  uni,
+                  ext);
   GNUNET_free (par);
   return epar;
 }
@@ -1720,7 +1721,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
 
   if (NULL == dc->serialization)    
     {
-      dir = get_download_sync_filename (dc, "");
+      dir = get_download_sync_filename (dc, "", "");
       if (dir == NULL)
        return;
       if (GNUNET_OK !=
@@ -1735,7 +1736,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
     }
   else
     {
-      fn = get_download_sync_filename (dc, dc->serialization);
+      fn = get_download_sync_filename (dc, dc->serialization, "");
     }
   wh = GNUNET_BIO_write_open (fn);
   if (wh == NULL)
@@ -2440,6 +2441,15 @@ deserialize_subdownload (void *cls,
 
   ser = get_serialization_short_name (filename);
   rh = GNUNET_BIO_read_open (filename);
+  if (rh == NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                 _("Failed to resume sub-download `%s': could not open file `%s'\n"),
+                 ser,
+                 filename);
+      GNUNET_free (ser);
+      return GNUNET_OK;
+    }
   deserialize_download (parent->h,
                        rh,
                        parent,
@@ -2591,9 +2601,14 @@ deserialize_download (struct GNUNET_FS_Handle *h,
       dr->is_pending = GNUNET_YES;
       dr->next = dc->pending;
       dc->pending = dr;
+      GNUNET_CONTAINER_multihashmap_put (dc->active,
+                                        &dr->chk.query,
+                                        dr,
+                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+
       dr = NULL;
     }
-  dn = get_download_sync_filename (dc, "");
+  dn = get_download_sync_filename (dc, dc->serialization, ".dir");
   if (dn != NULL)
     {
       if (GNUNET_YES ==
@@ -2602,20 +2617,25 @@ deserialize_download (struct GNUNET_FS_Handle *h,
       GNUNET_free (dn);
     }
   if (parent != NULL)
-    GNUNET_CONTAINER_DLL_insert (parent->child_head,
-                                parent->child_tail,
-                                dc);
+    {
+      abort (); // for debugging for now
+      GNUNET_CONTAINER_DLL_insert (parent->child_head,
+                                  parent->child_tail,
+                                  dc);
+    }
   if (search != NULL)
     {
       dc->search = search;
       search->download = dc;
     }
-  if ( (parent == NULL) || 
+  if ( (parent == NULL) &&
        (search == NULL) )
-    dc->top = GNUNET_FS_make_top (dc->h,
-                                 &GNUNET_FS_download_signal_suspend_,
-                                 dc);
-  signal_download_resume (dc);  
+    {
+      dc->top = GNUNET_FS_make_top (dc->h,
+                                   &GNUNET_FS_download_signal_suspend_,
+                                   dc);      
+      signal_download_resume (dc);  
+    }
   GNUNET_free (uris);
   return;
  cleanup:
index 4732606016904665da6528b52e5d7f85fc5dcf2c..dca419fd35a59be53cbcf629d5def41810c0a4dd 100644 (file)
@@ -1359,6 +1359,8 @@ activate_fs_download (void *cls,
   struct GNUNET_FS_ProgressInfo pi;
 
   GNUNET_assert (NULL != client);
+  GNUNET_assert (dc->client == NULL);
+  GNUNET_assert (dc->th == NULL);
   dc->client = client;
   GNUNET_CLIENT_receive (client,
                         &receive_results,
@@ -1369,14 +1371,12 @@ activate_fs_download (void *cls,
   GNUNET_CONTAINER_multihashmap_iterate (dc->active,
                                         &retry_entry,
                                         dc);
-  if ( (dc->th == NULL) &&
-       (dc->client != NULL) )
-    dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
-                                                 sizeof (struct SearchMessage),
-                                                 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
-                                                 GNUNET_NO,
-                                                 &transmit_download_request,
-                                                 dc);
+  dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
+                                               sizeof (struct SearchMessage),
+                                               GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+                                               GNUNET_NO,
+                                               &transmit_download_request,
+                                               dc);    
 }
 
 
@@ -1559,9 +1559,11 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
              dc->treedepth);
 #endif
   if (parent == NULL)
-    dc->top = GNUNET_FS_make_top (dc->h,
-                                 &GNUNET_FS_download_signal_suspend_,
-                                 dc);
+    {
+      dc->top = GNUNET_FS_make_top (dc->h,
+                                   &GNUNET_FS_download_signal_suspend_,
+                                   dc);
+    }
   pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
   pi.value.download.specifics.start.meta = meta;
   GNUNET_FS_download_make_status_ (&pi, dc);
@@ -1707,6 +1709,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
 void
 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
 {
+  GNUNET_assert (dc->job_queue == NULL);
   dc->job_queue = GNUNET_FS_queue_ (dc->h, 
                                    &activate_fs_download,
                                    &deactivate_fs_download,
index 37d33ace1d391e3e12c49e4fa7c9026fb7b4de2f..6d3f4679db9058d3b2c1eb93df68b9565b6f87c2 100644 (file)
@@ -1115,12 +1115,9 @@ fip_signal_stop(void *cls,
 
   if (fi->serialization != NULL) 
     {
-      if (0 != UNLINK (fi->serialization))
-       {
-         GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
-                                   "unlink",
-                                   fi->serialization); 
-       }
+      GNUNET_FS_remove_sync_file_ (sc->h,
+                                  GNUNET_FS_SYNC_PATH_FILE_INFO,
+                                  fi->serialization);
       GNUNET_free (fi->serialization);
       fi->serialization = NULL;
     }
index dda7369efe770e199baa44f97e8f277d8ab8629c..82e19a7979957a98f78afc591519fc3e83bcff7b 100644 (file)
@@ -175,7 +175,6 @@ static void *
 progress_cb (void *cls, 
             const struct GNUNET_FS_ProgressInfo *event)
 {
-
   switch (event->status)
     {
     case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
@@ -192,17 +191,17 @@ progress_cb (void *cls,
              (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL));
       fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
       start = GNUNET_TIME_absolute_get ();
-      download = GNUNET_FS_download_start (fs,
-                                          event->value.publish.specifics.completed.chk_uri,
-                                          NULL,
-                                          fn, NULL,
-                                          0,
-                                          FILESIZE,
-                                          1,
-                                          GNUNET_FS_DOWNLOAD_OPTION_NONE,
-                                          "download",
-                                          NULL);
-      GNUNET_assert (download != NULL);
+      GNUNET_assert (download == NULL);
+      GNUNET_FS_download_start (fs,
+                               event->value.publish.specifics.completed.chk_uri,
+                               NULL,
+                               fn, NULL,
+                               0,
+                               FILESIZE,
+                               1,
+                               GNUNET_FS_DOWNLOAD_OPTION_NONE,
+                               "download",
+                               NULL);
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
       consider_restart (event->status);
@@ -241,6 +240,22 @@ progress_cb (void *cls,
                                &abort_download_task,
                                NULL);
       break;
+    case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
+      GNUNET_assert (event->value.publish.sc == publish);
+      publish = NULL;
+      break;
+    case GNUNET_FS_STATUS_PUBLISH_RESUME:
+      GNUNET_assert (NULL == publish);
+      publish = event->value.publish.sc;
+      break;
+    case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
+      GNUNET_assert (event->value.download.dc == download);
+      download = NULL;
+      break;
+    case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
+      GNUNET_assert (NULL == download);
+      download = event->value.download.dc;
+      break;
     case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
       consider_restart (event->status);
       break;
@@ -264,6 +279,7 @@ progress_cb (void *cls,
     case GNUNET_FS_STATUS_DOWNLOAD_START:
       consider_restart (event->status);
       GNUNET_assert (download == NULL);
+      download = event->value.download.dc;
       GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
       GNUNET_assert (NULL == event->value.download.pctx);
       GNUNET_assert (NULL != event->value.download.uri);
@@ -273,12 +289,12 @@ progress_cb (void *cls,
       GNUNET_assert (1 == event->value.download.anonymity);
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
-      consider_restart (event->status);
       GNUNET_assert (download == event->value.download.dc);
       GNUNET_SCHEDULER_add_continuation (sched,
                                         &abort_publish_task,
                                         NULL,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      download = NULL;
       break;
     default:
       printf ("Unexpected event: %d\n", 
@@ -394,7 +410,6 @@ main (int argc, char *argv[])
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-
   GNUNET_log_setup ("test_fs_download_persistence", 
 #if VERBOSE
                    "DEBUG",
@@ -402,6 +417,7 @@ main (int argc, char *argv[])
                    "WARNING",
 #endif
                    NULL);
+  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
                       argvx, "test-fs-download-persistence",
                      "nohelp", options, &run, NULL);