bug fixes, api fixes, extended testcase
authorChristian Grothoff <christian@grothoff.org>
Tue, 20 Oct 2009 11:33:07 +0000 (11:33 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 20 Oct 2009 11:33:07 +0000 (11:33 +0000)
src/fs/fs.h
src/fs/fs_download.c
src/fs/fs_publish.c
src/fs/gnunet-download.c
src/fs/gnunet-publish.c
src/fs/test_fs_download.c
src/include/gnunet_fs_service.h

index 6c474369e706ebd8aea096f3685e4f56823d00fa..8270d38ba3a134c308f7ce64305babc53c5356b8 100644 (file)
@@ -478,11 +478,6 @@ struct GNUNET_FS_PublishContext
    */ 
   struct GNUNET_FS_Handle *h;
 
-  /**
-   * Argument to pass to the client in callbacks.
-   */
-  void *client_ctx;
-  
   /**
    * File-structure that is being shared.
    */
index 71d10edacca658b0f1e51d4ef96c8051d2f67da5..1938fb08fd9ccc45a13be576757fa8231273d537 100644 (file)
@@ -745,6 +745,7 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
  * @param length how many bytes should be downloaded starting at offset
  * @param anonymity anonymity level to use for the download
  * @param options various options
+ * @param cctx initial value for the client context for this download
  * @param parent parent download to associate this download with (use NULL
  *        for top-level downloads; useful for manually-triggered recursive downloads)
  * @return context that can be used to control this download
@@ -758,6 +759,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
                          uint64_t length,
                          uint32_t anonymity,
                          enum GNUNET_FS_DownloadOptions options,
+                         void *cctx,
                          struct GNUNET_FS_DownloadContext *parent)
 {
   struct GNUNET_FS_ProgressInfo pi;
@@ -789,6 +791,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
   dc->parent = parent;
   dc->uri = GNUNET_FS_uri_dup (uri);
   dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
+  dc->client_info = cctx;
   if (NULL != filename)
     {
       dc->filename = GNUNET_strdup (filename);
index c143b6d178e44c029c785a0f1b80b402d85aef62..6d3bbe7f66e491a4fcc1b89f792f05617ab7d69b 100644 (file)
@@ -930,8 +930,6 @@ fip_signal_start(void *cls,
  * Publish a file or directory.
  *
  * @param h handle to the file sharing subsystem
- * @param ctx initial value to use for the '*ctx'
- *        in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
  * @param fi information about the file or directory structure to publish
  * @param namespace namespace to publish the file in, NULL for no namespace
  * @param nid identifier to use for the publishd content in the namespace
@@ -943,7 +941,6 @@ fip_signal_start(void *cls,
  */
 struct GNUNET_FS_PublishContext *
 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
-                        void *ctx,
                         struct GNUNET_FS_FileInformation *fi,
                         struct GNUNET_FS_Namespace *namespace,
                         const char *nid,
@@ -967,7 +964,6 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext));
   ret->dsh = dsh;
   ret->h = h;
-  ret->client_ctx = ctx;
   ret->fi = fi;
   ret->namespace = namespace;
   if (namespace != NULL)
index b4e787cfae9725564d1f7045dfa29b3ef7289e62..bf3daa68feeb75e5b4659903d31f9cbb87ca88a2 100644 (file)
@@ -180,6 +180,7 @@ run (void *cls,
                                 GNUNET_FS_uri_chk_get_file_size (uri),
                                 anonymity,
                                 options,
+                                NULL,
                                 NULL);
   GNUNET_FS_uri_destroy (uri);
 }
index bf6a46914b083afbe7431df0aa512d08e5a9fa6b..777370c90fe54e9d83badb42c2665c24030f682b 100644 (file)
@@ -416,7 +416,6 @@ run (void *cls,
       return;
     }
   pc = GNUNET_FS_publish_start (ctx,
-                               NULL,
                                fi,
                                namespace,
                                this_id,
index d7fb22bf63415b56ce991a57f2ca3c1c811c7ead..f9a8109c5219b33f1fe514901a9e22a01cf971cf 100644 (file)
@@ -85,8 +85,15 @@ static void
 abort_download_task (void *cls,
                     const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  uint64_t size;
+  
   GNUNET_FS_download_stop (download, GNUNET_YES);
   download = NULL;
+  GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
+  GNUNET_assert (size == FILESIZE); 
+  GNUNET_DISK_directory_remove (fn);
+  GNUNET_free (fn);
+  fn = NULL;
 }
 
 
@@ -104,7 +111,7 @@ progress_cb (void *cls,
               (unsigned long long) event->value.publish.size,
              event->value.publish.specifics.progress.depth,
              (unsigned long long) event->value.publish.specifics.progress.offset);
-#endif
+#endif      
       break;
     case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
       printf ("Publishing complete, %llu kbps.\n",
@@ -119,6 +126,7 @@ progress_cb (void *cls,
                                           FILESIZE,
                                           1,
                                           GNUNET_FS_DOWNLOAD_OPTION_NONE,
+                                          "download",
                                           NULL);
       GNUNET_assert (download != NULL);
       break;
@@ -132,6 +140,7 @@ progress_cb (void *cls,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
+      GNUNET_assert (download == event->value.download.dc);
 #if VERBOSE
       printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n",
               (unsigned long long) event->value.download.completed,
@@ -162,18 +171,32 @@ progress_cb (void *cls,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
     case GNUNET_FS_STATUS_PUBLISH_START:
-      /* FIXME: add checks here... */
+      GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
+      GNUNET_assert (NULL == event->value.publish.pctx);
+      GNUNET_assert (FILESIZE == event->value.publish.size);
+      GNUNET_assert (0 == event->value.publish.completed);
+      GNUNET_assert (1 == event->value.publish.anonymity);
       break;
     case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+      GNUNET_assert (publish == event->value.publish.sc);
+      GNUNET_assert (FILESIZE == event->value.publish.size);
+      GNUNET_assert (1 == event->value.publish.anonymity);
       /* FIXME: add checks here... */
       GNUNET_FS_stop (fs);
       fs = NULL;
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_START:
-      /* FIXME: add checks here... */
+      GNUNET_assert (download == NULL);
+      GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
+      GNUNET_assert (NULL == event->value.download.pctx);
+      GNUNET_assert (NULL != event->value.download.uri);
+      GNUNET_assert (0 == strcmp (fn, event->value.download.filename));
+      GNUNET_assert (FILESIZE == event->value.download.size);
+      GNUNET_assert (0 == event->value.download.completed);
+      GNUNET_assert (1 == event->value.download.anonymity);
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
-      /* FIXME: add checks here... */
+      GNUNET_assert (download == event->value.download.dc);
       GNUNET_SCHEDULER_add_continuation (sched,
                                         GNUNET_NO,
                                         &abort_publish_task,
@@ -254,7 +277,7 @@ run (void *cls,
     buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
   meta = GNUNET_CONTAINER_meta_data_create ();
   kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords);
-  fi = GNUNET_FS_file_information_create_from_data ("file-to-publish",
+  fi = GNUNET_FS_file_information_create_from_data ("publish-context",
                                                    FILESIZE,
                                                    buf,
                                                    kuri,
@@ -268,7 +291,6 @@ run (void *cls,
   GNUNET_assert (NULL != fi);
   start = GNUNET_TIME_absolute_get ();
   publish = GNUNET_FS_publish_start (fs,
-                                   "publish-context",
                                    fi,
                                    NULL, NULL, NULL,
                                    GNUNET_FS_PUBLISH_OPTION_NONE);
index 7c15358e80abbc66e50a0a8ad04daebb829fc8b0..0bed010d9e469eff6ecf77c3a7ea36b145dcb2c5 100644 (file)
@@ -720,9 +720,8 @@ struct GNUNET_FS_ProgressInfo
       const struct GNUNET_FS_FileInformation *fi;
 
       /**
-       * Client context pointer (set the last time
-       * by the client for this operation; initially
-       * NULL on START/RESUME events).
+       * Client context pointer (set the last time by the client for
+       * this operation; initially NULL on START/RESUME events).
        */
       void *cctx;
 
@@ -1877,8 +1876,6 @@ enum GNUNET_FS_PublishOptions
  * Publish a file or directory.
  *
  * @param h handle to the file sharing subsystem
- * @param ctx initial value to use for the '*ctx'
- *        in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
  * @param fi information about the file or directory structure to publish
  * @param namespace namespace to publish the file in, NULL for no namespace
  * @param nid identifier to use for the publishd content in the namespace
@@ -1890,7 +1887,6 @@ enum GNUNET_FS_PublishOptions
  */
 struct GNUNET_FS_PublishContext *
 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
-                        void *ctx,
                         struct GNUNET_FS_FileInformation *fi,
                         struct GNUNET_FS_Namespace *namespace,
                         const char *nid,
@@ -2242,11 +2238,11 @@ enum GNUNET_FS_DownloadOptions
  * @param length how many bytes should be downloaded starting at offset
  * @param anonymity anonymity level to use for the download
  * @param options various download options
+ * @param cctx initial value for the client context for this download
  * @param parent parent download to associate this download with (use NULL
  *        for top-level downloads; useful for manually-triggered recursive downloads)
  * @return context that can be used to control this download
  */
-// FIXME: add a "void *" context for the client to arguments!?
 struct GNUNET_FS_DownloadContext *
 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
                          const struct GNUNET_FS_Uri *uri,
@@ -2256,6 +2252,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
                          uint64_t length,
                          uint32_t anonymity,
                          enum GNUNET_FS_DownloadOptions options,
+                         void *cctx,
                          struct GNUNET_FS_DownloadContext *parent);