-add priorities to download queue
authorChristian Grothoff <christian@grothoff.org>
Sun, 4 Mar 2012 21:07:31 +0000 (21:07 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 4 Mar 2012 21:07:31 +0000 (21:07 +0000)
src/fs/fs_api.c
src/fs/fs_api.h
src/fs/fs_download.c

index 1df9b2e0ac3a730bb7f151c3b014b326c26fa3c5..64f55e3443c4e48213a4e84f0558436377b04334 100644 (file)
@@ -145,11 +145,13 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param stop function to call to pause the job, or on dequeue (if the job was running)
  * @param cls closure for start and stop
  * @param blocks number of blocks this jobs uses
+ * @param priority how important is this download
  * @return queue handle
  */
 struct GNUNET_FS_QueueEntry *
 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
-                  GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks)
+                  GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks,
+                 enum GNUNET_FS_QueuePriority priority)
 {
   struct GNUNET_FS_QueueEntry *qe;
 
@@ -160,6 +162,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
   qe->cls = cls;
   qe->queue_time = GNUNET_TIME_absolute_get ();
   qe->blocks = blocks;
+  qe->priority = priority;
   GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail,
                                      h->pending_tail, qe);
   if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
index de66ac661efd997a158181cf3f8126216b318f71..154e63893dbe5c03915819a5dcb0298d86e4f5ac 100644 (file)
@@ -417,6 +417,24 @@ typedef void (*GNUNET_FS_QueueStart) (void *cls,
 typedef void (*GNUNET_FS_QueueStop) (void *cls);
 
 
+
+/**
+ * Priorities for the queue.
+ */ 
+enum GNUNET_FS_QueuePriority
+  {
+    /**
+     * This is a probe (low priority).
+     */
+    GNUNET_FS_QUEUE_PRIORITY_PROBE,
+
+    /**
+     * Default priority.
+     */
+    GNUNET_FS_QUEUE_PRIORITY_NORMAL
+  };
+
+
 /**
  * Entry in the job queue.
  */
@@ -478,6 +496,11 @@ struct GNUNET_FS_QueueEntry
    */
   unsigned int blocks;
 
+  /**
+   * How important is this download?
+   */
+  enum GNUNET_FS_QueuePriority priority;
+
   /**
    * How often have we (re)started this download?
    */
@@ -599,11 +622,13 @@ struct GNUNET_FS_SearchResult
  * @param stop function to call to pause the job, or on dequeue (if the job was running)
  * @param cls closure for start and stop
  * @param blocks number of blocks this download has
+ * @param priority how important is this download
  * @return queue handle
  */
 struct GNUNET_FS_QueueEntry *
 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
-                  GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks);
+                  GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks,
+                 enum GNUNET_FS_QueuePriority priority);
 
 
 /**
index b23d14b87ea1729b348157cd9044bd04842f8d59..2efdcb019f3e1f784cfff89f71e61b3683dcb047 100644 (file)
@@ -2165,7 +2165,10 @@ 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,
-                        dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE);
+                        dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
+                       (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
+                       ? GNUNET_FS_QUEUE_PRIORITY_NORMAL 
+                       : GNUNET_FS_QUEUE_PRIORITY_PROBE);
 }