adding single location for no_forcestart configuration list
[oweals/gnunet.git] / src / fs / gnunet-service-fs_push.c
index 6d8c05999fbd4d3e817b7839f1ddf8d93d2344f1..c80dc8b08533e649b1ab0e5731450742eb698d9b 100644 (file)
 #include "gnunet-service-fs_push.h"
 
 
-#define DEBUG_FS_MIGRATION GNUNET_NO
+/**
+ * Maximum number of blocks we keep in memory for migration.
+ */
+#define MAX_MIGRATION_QUEUE 8
+
+/**
+ * Blocks are at most migrated to this number of peers
+ * plus one, each time they are fetched from the database.
+ */
+#define MIGRATION_LIST_SIZE 2
 
 /**
- * How long must content remain valid for us to consider it for migration?  
+ * How long must content remain valid for us to consider it for migration?
  * If content will expire too soon, there is clearly no point in pushing
  * it to other peers.  This value gives the threshold for migration.  Note
  * that if this value is increased, the migration testcase may need to be
@@ -62,10 +71,10 @@ struct MigrationReadyBlock
   /**
    * Query for the block.
    */
-  GNUNET_HashCode query;
+  struct GNUNET_HashCode query;
 
   /**
-   * When does this block expire? 
+   * When does this block expire?
    */
   struct GNUNET_TIME_Absolute expiration;
 
@@ -191,7 +200,8 @@ delete_migration_block (struct MigrationReadyBlock *mb)
 /**
  * Find content for migration to this peer.
  */
-static void find_content (struct MigrationReadyPeer *mrp);
+static void
+find_content (struct MigrationReadyPeer *mrp);
 
 
 /**
@@ -215,10 +225,8 @@ transmit_message (void *cls, size_t buf_size, void *buf)
   peer->msg = NULL;
   if (buf == NULL)
   {
-#if DEBUG_FS_MIGRATION
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Failed to migrate content to another peer (disconnect)\n");
-#endif
     GNUNET_free (msg);
     return 0;
   }
@@ -226,10 +234,8 @@ transmit_message (void *cls, size_t buf_size, void *buf)
   GNUNET_assert (msize <= buf_size);
   memcpy (buf, msg, msize);
   GNUNET_free (msg);
-#if DEBUG_FS_MIGRATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pushing %u bytes to another peer\n",
               msize);
-#endif
   find_content (peer);
   return msize;
 }
@@ -280,10 +286,8 @@ transmit_content (struct MigrationReadyPeer *peer,
   {
     ret = GNUNET_NO;
   }
-#if DEBUG_FS_MIGRATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Asking for transmission of %u bytes for migration\n", msize);
-#endif
   peer->th = GSF_peer_transmit_ (peer->peer, GNUNET_NO, 0 /* priority */ ,
                                  GNUNET_TIME_UNIT_FOREVER_REL, msize,
                                  &transmit_message, peer);
@@ -312,7 +316,7 @@ count_targets (struct MigrationReadyBlock *block)
 
 /**
  * Check if sending this block to this peer would
- * be a good idea. 
+ * be a good idea.
  *
  * @param peer target peer
  * @param block the block
@@ -325,6 +329,7 @@ score_content (struct MigrationReadyPeer *peer,
   unsigned int i;
   struct GSF_PeerPerformanceData *ppd;
   struct GNUNET_PeerIdentity id;
+  struct GNUNET_HashCode hc;
   uint32_t dist;
 
   ppd = GSF_get_peer_performance_data_ (peer->peer);
@@ -333,7 +338,8 @@ score_content (struct MigrationReadyPeer *peer,
       return -1;
   GNUNET_assert (0 != ppd->pid);
   GNUNET_PEER_resolve (ppd->pid, &id);
-  dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, &id.hashPubKey);
+  GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &hc);
+  dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, &hc);
   /* closer distance, higher score: */
   return UINT32_MAX - dist;
 }
@@ -343,7 +349,8 @@ score_content (struct MigrationReadyPeer *peer,
  * If the migration task is not currently running, consider
  * (re)scheduling it with the appropriate delay.
  */
-static void consider_gathering (void);
+static void
+consider_gathering (void);
 
 
 /**
@@ -377,16 +384,12 @@ find_content (struct MigrationReadyPeer *mrp)
   {
     if (mig_size < MAX_MIGRATION_QUEUE)
     {
-#if DEBUG_FS_MIGRATION
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "No content found for pushing, waiting for queue to fill\n");
-#endif
       return;                   /* will fill up eventually... */
     }
-#if DEBUG_FS_MIGRATION
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "No suitable content found, purging content from full queue\n");
-#endif
     /* failed to find migration target AND
      * queue is full, purge most-forwarded
      * block from queue to make room for more */
@@ -406,10 +409,8 @@ find_content (struct MigrationReadyPeer *mrp)
     consider_gathering ();
     return;
   }
-#if DEBUG_FS_MIGRATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Preparing to push best content to peer\n");
-#endif
   transmit_content (mrp, best);
 }
 
@@ -417,13 +418,13 @@ find_content (struct MigrationReadyPeer *mrp)
 /**
  * Task that is run periodically to obtain blocks for content
  * migration
- * 
+ *
  * @param cls unused
  * @param tc scheduler context (also unused)
  */
-static void gather_migration_blocks (void *cls,
-                                     const struct GNUNET_SCHEDULER_TaskContext
-                                     *tc);
+static void
+gather_migration_blocks (void *cls,
+                         const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 
 /**
@@ -446,10 +447,8 @@ consider_gathering ()
   delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, mig_size);
   delay = GNUNET_TIME_relative_divide (delay, MAX_MIGRATION_QUEUE);
   delay = GNUNET_TIME_relative_max (delay, min_migration_delay);
-#if DEBUG_FS_MIGRATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Scheduling gathering task (queue size: %u)\n", mig_size);
-#endif
   mig_task =
       GNUNET_SCHEDULER_add_delayed (delay, &gather_migration_blocks, NULL);
 }
@@ -470,7 +469,7 @@ consider_gathering ()
  *        maybe 0 if no unique identifier is available
  */
 static void
-process_migration_content (void *cls, const GNUNET_HashCode * key, size_t size,
+process_migration_content (void *cls, const struct GNUNET_HashCode * key, size_t size,
                            const void *data, enum GNUNET_BLOCK_Type type,
                            uint32_t priority, uint32_t anonymity,
                            struct GNUNET_TIME_Absolute expiration, uint64_t uid)
@@ -481,14 +480,12 @@ process_migration_content (void *cls, const GNUNET_HashCode * key, size_t size,
   mig_qe = NULL;
   if (key == NULL)
   {
-#if DEBUG_FS_MIGRATION
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No content found for migration...\n");
-#endif
     consider_gathering ();
     return;
   }
-  if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value <
-      MIN_MIGRATION_CONTENT_LIFETIME.rel_value)
+  if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us <
+      MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us)
   {
     /* content will expire soon, don't bother */
     consider_gathering ();
@@ -503,11 +500,9 @@ process_migration_content (void *cls, const GNUNET_HashCode * key, size_t size,
       consider_gathering ();
     return;
   }
-#if DEBUG_FS_MIGRATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n",
               GNUNET_h2s (key), type, mig_size + 1, MAX_MIGRATION_QUEUE);
-#endif
   mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size);
   mb->query = *key;
   mb->expiration = expiration;
@@ -521,10 +516,8 @@ process_migration_content (void *cls, const GNUNET_HashCode * key, size_t size,
   {
     if (NULL == pos->th)
     {
-#if DEBUG_FS_MIGRATION
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Preparing to push best content to peer\n");
-#endif
       if (GNUNET_YES == transmit_content (pos, mb))
         break;                  /* 'mb' was freed! */
     }
@@ -537,7 +530,7 @@ process_migration_content (void *cls, const GNUNET_HashCode * key, size_t size,
 /**
  * Task that is run periodically to obtain blocks for content
  * migration
- * 
+ *
  * @param cls unused
  * @param tc scheduler context (also unused)
  */
@@ -550,11 +543,9 @@ gather_migration_blocks (void *cls,
     return;
   if (GSF_dsh != NULL)
   {
-#if DEBUG_FS_MIGRATION
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Asking datastore for content for replication (queue size: %u)\n",
                 mig_size);
-#endif
     mig_qe =
         GNUNET_DATASTORE_get_for_replication (GSF_dsh, 0, UINT_MAX,
                                               GNUNET_TIME_UNIT_FOREVER_REL,
@@ -578,7 +569,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer)
 
   if (GNUNET_YES != enabled)
     return;
-  mrp = GNUNET_malloc (sizeof (struct MigrationReadyPeer));
+  mrp = GNUNET_new (struct MigrationReadyPeer);
   mrp->peer = peer;
   find_content (mrp);
   GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, mrp);
@@ -635,10 +626,9 @@ GSF_push_init_ ()
       GNUNET_CONFIGURATION_get_value_time (GSF_cfg, "fs", "MIN_MIGRATION_DELAY",
                                            &min_migration_delay))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                _
-                ("Invalid value specified for option `%s' in section `%s', content pushing disabled\n"),
-                "MIN_MIGRATION_DELAY", "fs");
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
+                              "fs", "MIN_MIGRATION_DELAY",
+                              _("time required, content pushing disabled"));
     return;
   }
   consider_gathering ();