fix
authorChristian Grothoff <christian@grothoff.org>
Tue, 20 Oct 2009 08:38:04 +0000 (08:38 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 20 Oct 2009 08:38:04 +0000 (08:38 +0000)
src/fs/fs_download.c
src/fs/test_fs_download.c

index e0c4471ac7435e52b172eb27645dfc80401e4dd5..71d10edacca658b0f1e51d4ef96c8051d2f67da5 100644 (file)
@@ -822,8 +822,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
   dc->length = length;
   dc->anonymity = anonymity;
   dc->options = options;
-  // dc->active = GNUNET_CONTAINER_multihashmap_create (1); // + (length / DBLOCK_SIZE));
-  dc->active = GNUNET_CONTAINER_multihashmap_create (1 + (length / DBLOCK_SIZE));
+  dc->active = GNUNET_CONTAINER_multihashmap_create (2 * (length / DBLOCK_SIZE));
   dc->treedepth = GNUNET_FS_compute_depth (GNUNET_ntohll(dc->uri->data.chk.file_length));
 #if DEBUG_DOWNLOAD
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
index 879f054b8c5e60a6400f926db4dda1b9b679088d..d7fb22bf63415b56ce991a57f2ca3c1c811c7ead 100644 (file)
@@ -20,7 +20,7 @@
 
 /**
  * @file fs/test_fs_download.c
- * @brief simple testcase for download
+ * @brief simple testcase for simple publish + download operation
  * @author Christian Grothoff
  */
 
@@ -33,6 +33,9 @@
 
 #define START_ARM GNUNET_YES
 
+/**
+ * File-size we use for testing.
+ */
 #define FILESIZE (1024 * 1024 * 2)
 
 /**
@@ -56,6 +59,7 @@ struct PeerContext
 
 static struct PeerContext p1;
 
+static struct GNUNET_TIME_Absolute start;
 
 static struct GNUNET_SCHEDULER_Handle *sched;
 
@@ -69,20 +73,20 @@ static char *fn;
 
 
 static void
-abort_download_task (void *cls,
+abort_publish_task (void *cls,
                     const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_FS_download_stop (download, GNUNET_YES);
-  download = NULL;
+  GNUNET_FS_publish_stop (publish);
+  publish = NULL;
 }
 
 
 static void
-abort_publish_task (void *cls,
+abort_download_task (void *cls,
                     const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_FS_publish_stop (publish);
-  publish = NULL;
+  GNUNET_FS_download_stop (download, GNUNET_YES);
+  download = NULL;
 }
 
 
@@ -103,15 +107,10 @@ progress_cb (void *cls,
 #endif
       break;
     case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
-#if VERBOSE
-      printf ("Publish complete.\n");
-#endif
-      GNUNET_SCHEDULER_add_continuation (sched,
-                                        GNUNET_NO,
-                                        &abort_publish_task,
-                                        NULL,
-                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      printf ("Publishing complete, %llu kbps.\n",
+             (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
       fn = GNUNET_DISK_mktemp ("gnunet-download-test-dstXXXXXX");
+      start = GNUNET_TIME_absolute_get ();
       download = GNUNET_FS_download_start (fs,
                                           event->value.publish.specifics.completed.chk_uri,
                                           NULL,
@@ -124,9 +123,8 @@ progress_cb (void *cls,
       GNUNET_assert (download != NULL);
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
-#if VERBOSE
-      printf ("Download complete.\n");
-#endif
+      printf ("Download complete,  %llu kbps.\n",
+             (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
       GNUNET_SCHEDULER_add_continuation (sched,
                                         GNUNET_NO,
                                         &abort_download_task,
@@ -168,14 +166,19 @@ progress_cb (void *cls,
       break;
     case GNUNET_FS_STATUS_PUBLISH_STOPPED:
       /* FIXME: add checks here... */
+      GNUNET_FS_stop (fs);
+      fs = NULL;
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_START:
       /* FIXME: add checks here... */
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
       /* FIXME: add checks here... */
-      GNUNET_FS_stop (fs);
-      fs = NULL;
+      GNUNET_SCHEDULER_add_continuation (sched,
+                                        GNUNET_NO,
+                                        &abort_publish_task,
+                                        NULL,
+                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
     default:
       printf ("Unexpected event: %d\n", 
@@ -263,6 +266,7 @@ run (void *cls,
   GNUNET_FS_uri_destroy (kuri);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   GNUNET_assert (NULL != fi);
+  start = GNUNET_TIME_absolute_get ();
   publish = GNUNET_FS_publish_start (fs,
                                    "publish-context",
                                    fi,