-LRN: fix fip_signal_start recursion
[oweals/gnunet.git] / src / fs / gnunet-service-fs_pr.c
index fee159a20c981b10a453e4836616b947253085eb..c16f94464e5fd9f54d363de1ef005b366cd0a81d 100644 (file)
 #include "gnunet-service-fs_pe.h"
 #include "gnunet-service-fs_pr.h"
 
+/**
+ * Maximum size of the datastore queue for P2P operations.  Needs to
+ * be large enough to queue MAX_QUEUE_PER_PEER operations for roughly
+ * the number of active (connected) peers.
+ */
+#define MAX_DATASTORE_QUEUE (16 * MAX_QUEUE_PER_PEER)
+
+/**
+ * Bandwidth value of a 0-priority content (must be fairly high
+ * compared to query since content is typically significantly larger
+ * -- and more valueable since it can take many queries to get one
+ * piece of content).
+ */
+#define CONTENT_BANDWIDTH_VALUE 800
+
 /**
  * Hard limit on the number of results we may get from the datastore per query.
  */
@@ -103,6 +118,12 @@ struct GSF_PendingRequest
    */
   GNUNET_PEER_Id sender_pid;
 
+  /**
+   * Identity of the peer that we should never forward this query
+   * to since it originated this query (0 for none).
+   */
+  GNUNET_PEER_Id origin_pid;
+
   /**
    * Time we started the last datastore lookup.
    */
@@ -169,6 +190,12 @@ static struct GNUNET_LOAD_Value *datastore_put_load;
 static int active_to_migration;
 
 
+/**
+ * Size of the datastore queue we assume for common requests.
+ * Determined based on the network quota.
+ */
+static unsigned int datastore_queue_size;
+
 /**
  * Heap with the request that will expire next at the top.  Contains
  * pointers of type "struct PendingRequest*"; these will *also* be
@@ -204,10 +231,10 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
   if (pr->bf != NULL)
     GNUNET_CONTAINER_bloomfilter_free (pr->bf);
   pr->mingle =
-    GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
-  pr->bf = GNUNET_BLOCK_construct_bloomfilter (pr->mingle,
-                                              pr->replies_seen,
-                                              pr->replies_seen_count);
+      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+  pr->bf =
+      GNUNET_BLOCK_construct_bloomfilter (pr->mingle, pr->replies_seen,
+                                          pr->replies_seen_count);
 }
 
 
@@ -226,6 +253,7 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
  * @param priority maximum outgoing cummulative request priority to use
  * @param ttl current time-to-live for the request
  * @param sender_pid peer ID to use for the sender when forwarding, 0 for none
+ * @param origin_pid peer ID of origin of query (do not loop back)
  * @param replies_seen hash codes of known local replies
  * @param replies_seen_count size of the 'replies_seen' array
  * @param rh handle to call when we get a reply
@@ -242,6 +270,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
                              uint32_t mingle, uint32_t anonymity_level,
                              uint32_t priority, int32_t ttl,
                              GNUNET_PEER_Id sender_pid,
+                             GNUNET_PEER_Id origin_pid,
                              const GNUNET_HashCode * replies_seen,
                              unsigned int replies_seen_count,
                              GSF_PendingRequestReplyHandler rh, void *rh_cls)
@@ -278,6 +307,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
   pr->public_data.type = type;
   pr->public_data.start_time = GNUNET_TIME_absolute_get ();
   pr->sender_pid = sender_pid;
+  pr->origin_pid = origin_pid;
   pr->rh = rh;
   pr->rh_cls = rh_cls;
   GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY)));
@@ -304,7 +334,8 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
   if (NULL != bf_data)
   {
     pr->bf =
-        GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, GNUNET_CONSTANTS_BLOOMFILTER_K);
+        GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size,
+                                           GNUNET_CONSTANTS_BLOOMFILTER_K);
     pr->mingle = mingle;
   }
   else if ((replies_seen_count > 0) &&
@@ -314,7 +345,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
   }
   GNUNET_CONTAINER_multihashmap_put (pr_map, query, pr,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-  if (0 != (options & GSF_PRO_REQUEST_EXPIRES))
+  if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES))
   {
     pr->hnode =
         GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, pr,
@@ -327,9 +358,10 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
       GNUNET_assert (dpr != NULL);
       if (pr == dpr)
         break;                  /* let the request live briefly... */
-      dpr->rh (dpr->rh_cls, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, dpr,
-               UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY,
-               NULL, 0);
+      if (NULL != dpr->rh)
+       dpr->rh (dpr->rh_cls, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, dpr,
+                UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_ABS,
+                 GNUNET_BLOCK_TYPE_ANY, NULL, 0);
       GSF_pending_request_cancel_ (dpr, GNUNET_YES);
     }
   }
@@ -339,7 +371,6 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
   return pr;
 }
 
-
 /**
  * Obtain the public data associated with a pending request
  *
@@ -418,17 +449,16 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
       pr->mingle =
           GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
       pr->bf =
-       GNUNET_BLOCK_construct_bloomfilter (pr->mingle,
-                                           replies_seen,
-                                           replies_seen_count);
-    } 
+          GNUNET_BLOCK_construct_bloomfilter (pr->mingle, replies_seen,
+                                              replies_seen_count);
+    }
     else
     {
       for (i = 0; i < pr->replies_seen_count; i++)
-       {
-         GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
-         GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
-       }
+      {
+        GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
+        GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
+      }
     }
   }
 }
@@ -562,6 +592,8 @@ clean_request (void *cls, const GNUNET_HashCode * key, void *value)
   }
   GNUNET_PEER_change_rc (pr->sender_pid, -1);
   pr->sender_pid = 0;
+  GNUNET_PEER_change_rc (pr->origin_pid, -1);
+  pr->origin_pid = 0;
   if (NULL != pr->hnode)
   {
     GNUNET_CONTAINER_heap_remove_node (pr->hnode);
@@ -742,6 +774,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
   struct ProcessReplyClosure *prq = cls;
   struct GSF_PendingRequest *pr = value;
   GNUNET_HashCode chash;
+  struct GNUNET_TIME_Absolute last_transmission;
 
   if (NULL == pr->rh)
     return GNUNET_YES;
@@ -771,9 +804,11 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
     GNUNET_LOAD_update (GSF_rt_entry_lifetime,
                         GNUNET_TIME_absolute_get_duration (pr->
                                                            public_data.start_time).rel_value);
+    if (!GSF_request_plan_reference_get_last_transmission_ (pr->public_data.rpr_head, prq->sender, &last_transmission))
+      last_transmission.abs_value = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value;
     /* pass on to other peers / local clients */
     pr->rh (pr->rh_cls, prq->eval, pr, prq->anonymity_level, prq->expiration,
-            prq->type, prq->data, prq->size);
+            last_transmission, prq->type, prq->data, prq->size);
     return GNUNET_YES;
   case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
     GNUNET_STATISTICS_update (GSF_stats,
@@ -822,8 +857,10 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
   pr->public_data.results_found++;
   prq->request_found = GNUNET_YES;
   /* finally, pass on to other peer / local client */
+  if (!GSF_request_plan_reference_get_last_transmission_ (pr->public_data.rpr_head, prq->sender, &last_transmission))
+    last_transmission.abs_value = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value;
   pr->rh (pr->rh_cls, prq->eval, pr, prq->anonymity_level, prq->expiration,
-          prq->type, prq->data, prq->size);
+          last_transmission, prq->type, prq->data, prq->size);
   return GNUNET_YES;
 }
 
@@ -858,48 +895,76 @@ struct PutMigrationContext
  *
  * @param cls closure
  * @param success GNUNET_SYSERR on failure
+ * @param min_expiration minimum expiration time required for content to be stored
  * @param msg NULL on success, otherwise an error message
  */
 static void
-put_migration_continuation (void *cls, int success, const char *msg)
+put_migration_continuation (void *cls, int success, 
+                           struct GNUNET_TIME_Absolute min_expiration,
+                           const char *msg)
 {
   struct PutMigrationContext *pmc = cls;
-  struct GNUNET_TIME_Relative delay;
-  struct GNUNET_TIME_Relative block_time;
   struct GSF_ConnectedPeer *cp;
+  struct GNUNET_TIME_Relative mig_pause;
   struct GSF_PeerPerformanceData *ppd;
 
-  delay = GNUNET_TIME_absolute_get_duration (pmc->start);
+  if (NULL != datastore_put_load)
+  {
+    if (GNUNET_SYSERR != success)
+    {
+      GNUNET_LOAD_update (datastore_put_load, 
+                         GNUNET_TIME_absolute_get_duration (pmc->start).rel_value);
+    }
+    else
+    {
+      /* on queue failure / timeout, increase the put load dramatically */
+      GNUNET_LOAD_update (datastore_put_load, 
+                         GNUNET_TIME_UNIT_MINUTES.rel_value);
+    }
+  }
   cp = GSF_peer_get_ (&pmc->origin);
-  if ((GNUNET_OK != success) && (GNUNET_NO == pmc->requested))
+  if (GNUNET_OK == success)
   {
-    /* block migration for a bit... */
     if (NULL != cp)
     {
       ppd = GSF_get_peer_performance_data_ (cp);
-      ppd->migration_duplication++;
-      block_time =
-          GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
-                                         5 * ppd->migration_duplication +
-                                         GNUNET_CRYPTO_random_u32
-                                         (GNUNET_CRYPTO_QUALITY_WEAK, 5));
-      GSF_block_peer_migration_ (cp, block_time);
+      ppd->migration_delay.rel_value /= 2;
     }
+    GNUNET_free (pmc);
+    return;
   }
-  else
+  if ( (GNUNET_NO == success) && 
+       (GNUNET_NO == pmc->requested) && 
+       (NULL != cp) )
   {
-    if (NULL != cp)
+    ppd = GSF_get_peer_performance_data_ (cp);
+    if (min_expiration.abs_value > 0)
     {
-      ppd = GSF_get_peer_performance_data_ (cp);
-      ppd->migration_duplication = 0;   /* reset counter */
+#if DEBUG_FS
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+                 "Asking to stop migration for %llu ms because datastore is full\n",
+                 (unsigned long long) GNUNET_TIME_absolute_get_remaining (min_expiration).rel_value);
+#endif
+      GSF_block_peer_migration_ (cp, min_expiration);      
+    }
+    else
+    {
+      ppd->migration_delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_SECONDS,
+                                                      ppd->migration_delay);
+      ppd->migration_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
+                                                      ppd->migration_delay);
+      mig_pause.rel_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                                     ppd->migration_delay.rel_value);
+      ppd->migration_delay = GNUNET_TIME_relative_multiply (ppd->migration_delay, 2);
+#if DEBUG_FS
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+                 "Replicated content already exists locally, asking to stop migration for %llu ms\n",
+                 (unsigned long long) mig_pause.rel_value);
+#endif
+      GSF_block_peer_migration_ (cp, GNUNET_TIME_relative_to_absolute (mig_pause));
     }
   }
   GNUNET_free (pmc);
-  /* FIXME: should we really update the load value on failure? */
-  if (NULL != datastore_put_load)
-    GNUNET_LOAD_update (datastore_put_load, delay.rel_value);
-  if (GNUNET_OK == success)
-    return;
   GNUNET_STATISTICS_update (GSF_stats,
                             gettext_noop ("# Datastore `PUT' failures"), 1,
                             GNUNET_NO);
@@ -953,10 +1018,10 @@ static void
 handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
                   const GNUNET_HashCode * key,
                   const struct GNUNET_PeerIdentity *get_path,
-                 unsigned int get_path_length,
+                  unsigned int get_path_length,
                   const struct GNUNET_PeerIdentity *put_path,
-                 unsigned int put_path_length,
-                  enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+                  unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+                  size_t size, const void *data)
 {
   struct GSF_PendingRequest *pr = cls;
   struct ProcessReplyClosure prq;
@@ -968,6 +1033,9 @@ handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
   memset (&prq, 0, sizeof (prq));
   prq.data = data;
   prq.expiration = exp;
+  /* do not allow migrated content to live longer than 1 year */
+  prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS),
+                                            prq.expiration);
   prq.size = size;
   prq.type = type;
   process_reply (&prq, key, pr);
@@ -990,7 +1058,7 @@ handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
                               GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                               &put_migration_continuation, pmc))
     {
-      put_migration_continuation (pmc, GNUNET_NO, NULL);
+      put_migration_continuation (pmc, GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
     }
   }
 }
@@ -1034,11 +1102,10 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
   pr->gh =
       GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL,
                             pr->public_data.type, &pr->public_data.query,
-                            5 /* DEFAULT_GET_REPLICATION */,
-                            GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 
-                           /* FIXME: can no longer pass pr->bf/pr->mingle... */
-                            xquery, xquery_size, &handle_dht_reply,
-                            pr);
+                            5 /* DEFAULT_GET_REPLICATION */ ,
+                            GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+                            /* FIXME: can no longer pass pr->bf/pr->mingle... */
+                            xquery, xquery_size, &handle_dht_reply, pr);
 }
 
 
@@ -1154,7 +1221,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
   if (NULL == key)
   {
 #if DEBUG_FS
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
                 "No further local responses available.\n");
 #endif
     if ((pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK) ||
@@ -1214,18 +1281,17 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
                                   /* queue priority */ ,
                                   (0 !=
                                    (GSF_PRO_PRIORITY_UNLIMITED &
-                                    pr->public_data.options)) ? UINT_MAX : 1
+                                    pr->public_data.options)) ? UINT_MAX :
+                                  datastore_queue_size
                                   /* max queue size */ ,
                                   GNUNET_TIME_UNIT_FOREVER_REL,
                                   &process_local_reply, pr);
     if (NULL != pr->qe)
-    {
-      GNUNET_STATISTICS_update (GSF_stats,
-                                gettext_noop
-                                ("# Datastore lookups concluded (error queueing)"),
-                                1, GNUNET_NO);
       return;                   /* we're done */
-    }
+    GNUNET_STATISTICS_update (GSF_stats,
+                              gettext_noop
+                              ("# Datastore lookups concluded (error queueing)"),
+                              1, GNUNET_NO);
     goto check_error_and_continue;
   }
   old_rf = pr->public_data.results_found;
@@ -1255,7 +1321,8 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
                                   /* queue priority */ ,
                                   (0 !=
                                    (GSF_PRO_PRIORITY_UNLIMITED &
-                                    pr->public_data.options)) ? UINT_MAX : 1
+                                    pr->public_data.options)) ? UINT_MAX :
+                                  datastore_queue_size
                                   /* max queue size */ ,
                                   GNUNET_TIME_UNIT_FOREVER_REL,
                                   &process_local_reply, pr);
@@ -1281,7 +1348,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
   {
     GNUNET_STATISTICS_update (GSF_stats,
                               gettext_noop
-                              ("# Datastore lookups concluded (found ultimate result)"),
+                              ("# Datastore lookups concluded (found last result)"),
                               1, GNUNET_NO);
     goto check_error_and_continue;
   }
@@ -1314,7 +1381,8 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
                                 /* queue priority */ ,
                                 (0 !=
                                  (GSF_PRO_PRIORITY_UNLIMITED & pr->
-                                  public_data.options)) ? UINT_MAX : 1
+                                  public_data.options)) ? UINT_MAX :
+                                datastore_queue_size
                                 /* max queue size */ ,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &process_local_reply, pr);
@@ -1336,6 +1404,29 @@ check_error_and_continue:
 }
 
 
+/**
+ * Is the given target a legitimate peer for forwarding the given request?
+ *
+ * @param pr request
+ * @param target
+ * @return GNUNET_YES if this request could be forwarded to the given peer
+ */
+int
+GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
+                                  const struct GNUNET_PeerIdentity *target)
+{
+  struct GNUNET_PeerIdentity pi;
+
+  if (0 == pr->origin_pid)
+    return GNUNET_YES;
+  GNUNET_PEER_resolve (pr->origin_pid, &pi);
+  return (0 ==
+          memcmp (&pi, target,
+                  sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :
+      GNUNET_YES;
+}
+
+
 /**
  * Look up the request in the local datastore.
  *
@@ -1370,19 +1461,17 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
                                 /* queue priority */ ,
                                 (0 !=
                                  (GSF_PRO_PRIORITY_UNLIMITED & pr->
-                                  public_data.options)) ? UINT_MAX : 1
+                                  public_data.options)) ? UINT_MAX :
+                                datastore_queue_size
                                 /* max queue size */ ,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &process_local_reply, pr);
-  if (NULL == pr->qe)
-  {
-    GNUNET_STATISTICS_update (GSF_stats,
-                              gettext_noop
-                              ("# Datastore lookups concluded (error queueing)"),
-                              1, GNUNET_NO);
-
+  if (NULL != pr->qe)
     return;
-  }
+  GNUNET_STATISTICS_update (GSF_stats,
+                            gettext_noop
+                            ("# Datastore lookups concluded (error queueing)"),
+                            1, GNUNET_NO);
   GNUNET_SCHEDULER_cancel (pr->warn_task);
   pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
   pr->llc_cont = NULL;
@@ -1430,6 +1519,9 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
   dsize = msize - sizeof (struct PutMessage);
   type = ntohl (put->type);
   expiration = GNUNET_TIME_absolute_ntoh (put->expiration);
+  /* do not allow migrated content to live longer than 1 year */
+  expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS),
+                                        expiration);
   if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
     return GNUNET_SYSERR;
   if (GNUNET_OK !=
@@ -1484,7 +1576,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
                               GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                               &put_migration_continuation, pmc))
     {
-      put_migration_continuation (pmc, GNUNET_NO, NULL);
+      put_migration_continuation (pmc, GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
     }
   }
   else
@@ -1509,7 +1601,15 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
                                        GNUNET_CRYPTO_random_u32
                                        (GNUNET_CRYPTO_QUALITY_WEAK,
                                         (unsigned int) (60000 * putl * putl)));
-    GSF_block_peer_migration_ (cp, block_time);
+#if DEBUG_FS
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+               "Asking to stop migration for %llu ms because of load %f and events %d/%d\n",
+               (unsigned long long) block_time.rel_value,
+               putl,
+               active_to_migration,
+               (GNUNET_NO == prq.request_found));
+#endif
+    GSF_block_peer_migration_ (cp, GNUNET_TIME_relative_to_absolute (block_time));
   }
   return GNUNET_OK;
 }
@@ -1521,6 +1621,8 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
 void
 GSF_pending_request_init_ ()
 {
+  unsigned long long bps;
+
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (GSF_cfg, "fs",
                                              "MAX_PENDING_REQUESTS",
@@ -1531,6 +1633,21 @@ GSF_pending_request_init_ ()
                 ("Configuration fails to specify `%s', assuming default value."),
                 "MAX_PENDING_REQUESTS");
   }
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "ats", "WAN_QUOTA_OUT",
+                                           &bps))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                _
+                ("Configuration fails to specify `%s', assuming default value."),
+                "WAN_QUOTA_OUT");
+    bps = 65536;
+  }
+  /* queue size should be #queries we can have pending and satisfy within
+   * a carry interval: */
+  datastore_queue_size =
+      bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE;
+
   active_to_migration =
       GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
   datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);