Do not crash if key is NULL.
[oweals/gnunet.git] / src / fs / gnunet-service-fs.c
index 5ea1bb7c1da56e1f17568acb4b62320aa269bb42..b824e6dc64105e0f028d1faa633d7a00e1c64676 100644 (file)
  * @file fs/gnunet-service-fs.c
  * @brief gnunet anonymity protocol implementation
  * @author Christian Grothoff
- *
- * To use:
- * - consider re-issue GSF_dht_lookup_ after non-DHT reply received 
- * - implement 'SUPPORT_DELAYS'
- *
  */
 #include "platform.h"
 #include <float.h>
@@ -48,6 +43,7 @@
 #include "gnunet-service-fs_pr.h"
 #include "gnunet-service-fs_push.h"
 #include "gnunet-service-fs_put.h"
+#include "gnunet-service-fs_cadet.h"
 #include "fs.h"
 
 /**
 
 
 /**
- * How quickly do we age cover traffic?  At the given 
+ * How quickly do we age cover traffic?  At the given
  * time interval, remaining cover traffic counters are
  * decremented by 1/16th.
  */
 #define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
+/**
+ * Collect an instane number of statistics?  May cause excessive IPC.
+ */
+#define INSANE_STATISTICS GNUNET_NO
+
 
 /* ****************************** globals ****************************** */
 
@@ -93,6 +94,18 @@ struct GNUNET_DHT_Handle *GSF_dht;
  */
 struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
 
+/**
+ * Running average of the observed latency to other peers (round trip).
+ * Initialized to 5s as the initial default.
+ */
+struct GNUNET_TIME_Relative GSF_avg_latency = { 500 };
+
+/**
+ * Handle to ATS service.
+ */
+struct GNUNET_ATS_PerformanceHandle *GSF_ats;
+
+
 /**
  * Typical priorities we're seeing from other peers right now.  Since
  * most priorities will be zero, this value is the weighted average of
@@ -106,13 +119,18 @@ struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
 double GSF_current_priorities;
 
 /**
- * How many query messages have we received 'recently' that 
+ * Size of the datastore queue we assume for common requests.
+ */
+unsigned int GSF_datastore_queue_size;
+
+/**
+ * How many query messages have we received 'recently' that
  * have not yet been claimed as cover traffic?
  */
 unsigned int GSF_cover_query_count;
 
 /**
- * How many content messages have we received 'recently' that 
+ * How many content messages have we received 'recently' that
  * have not yet been claimed as cover traffic?
  */
 unsigned int GSF_cover_content_count;
@@ -162,18 +180,16 @@ static struct GNUNET_PeerIdentity my_id;
  * @param tc task context
  */
 static void
-age_cover_counters (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
   GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
-  cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
-                                                &age_cover_counters,
-                                                NULL);
+  cover_age_task =
+      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+                                    NULL);
 }
 
 
-
 /**
  * We've just now completed a datastore request.  Update our
  * datastore load calculations.
@@ -186,16 +202,16 @@ GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start)
   struct GNUNET_TIME_Relative delay;
 
   delay = GNUNET_TIME_absolute_get_duration (start);
-  GNUNET_LOAD_update (datastore_get_load,
-                     delay.rel_value);
+  GNUNET_LOAD_update (datastore_get_load, delay.rel_value_us);
 }
 
 
 /**
  * Test if the DATABASE (GET) load on this peer is too high
  * to even consider processing the query at
- * all.  
- * 
+ * all.
+ *
+ * @param priority priority of the request (used as a reference point to compare with the load)
  * @return GNUNET_YES if the load is too high to do anything (load high)
  *         GNUNET_NO to process normally (load normal)
  *         GNUNET_SYSERR to process for free (load low)
@@ -207,13 +223,64 @@ GSF_test_get_load_too_high_ (uint32_t priority)
 
   ld = GNUNET_LOAD_get_load (datastore_get_load);
   if (ld < 1)
-    return GNUNET_SYSERR;    
-  if (ld <= priority)    
-    return GNUNET_NO;    
+    return GNUNET_SYSERR;
+  if (ld <= priority)
+    return GNUNET_NO;
   return GNUNET_YES;
 }
 
 
+/**
+ * We've received peer performance information. Update
+ * our running average for the P2P latency.
+*
+ * @param cls closure
+ * @param address the address
+ * @param active is this address in active use
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
+ * @param ats performance data for the address (as far as known)
+ * @param ats_count number of performance records in 'ats'
+ */
+static void
+update_latencies (void *cls,
+                 const struct GNUNET_HELLO_Address *address,
+                 int active,
+                 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+                 const struct GNUNET_ATS_Information *ats,
+                 uint32_t ats_count)
+{
+  unsigned int i;
+  struct GNUNET_TIME_Relative latency;
+
+  if (NULL == address)
+  {
+    /* ATS service temporarily disconnected */
+    return;
+  }
+
+  if (GNUNET_YES != active)
+    return;
+  for (i = 0; i < ats_count; i++)
+  {
+    if (GNUNET_ATS_QUALITY_NET_DELAY != ntohl (ats[i].type))
+      continue;
+    latency.rel_value_us = ntohl (ats[i].value);
+    GSF_update_peer_latency_ (&address->peer,
+                             latency);
+    GSF_avg_latency.rel_value_us =
+      (GSF_avg_latency.rel_value_us * 31 +
+       GNUNET_MIN (5000, ntohl (ats[i].value))) / 32;
+    GNUNET_STATISTICS_set (GSF_stats,
+                          gettext_noop
+                          ("# running average P2P latency (ms)"),
+                          GSF_avg_latency.rel_value_us / 1000LL, GNUNET_NO);
+    break;
+  }
+}
+
+
 /**
  * Handle P2P "PUT" message.
  *
@@ -221,24 +288,21 @@ GSF_test_get_load_too_high_ (uint32_t priority)
  * @param other the other peer involved (sender or receiver, NULL
  *        for loopback messages where we are both sender and receiver)
  * @param message the actual message
- * @param atsi performance information
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_p2p_put (void *cls,
-               const struct GNUNET_PeerIdentity *other,
-               const struct GNUNET_MessageHeader *message,
-               const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
+                const struct GNUNET_MessageHeader *message)
 {
   struct GSF_ConnectedPeer *cp;
 
   cp = GSF_peer_get_ (other);
   if (NULL == cp)
-    {
-      GNUNET_break (0);
-      return GNUNET_OK;
-    }
+  {
+    GNUNET_break (0);
+    return GNUNET_OK;
+  }
   GSF_cover_content_count++;
   return GSF_handle_p2p_content_ (cp, message);
 }
@@ -255,12 +319,21 @@ handle_p2p_put (void *cls,
  */
 static void
 consider_request_for_forwarding (void *cls,
-                                const struct GNUNET_PeerIdentity *peer,
-                                struct GSF_ConnectedPeer *cp,
-                                const struct GSF_PeerPerformanceData *ppd)
+                                 const struct GNUNET_PeerIdentity *peer,
+                                 struct GSF_ConnectedPeer *cp,
+                                 const struct GSF_PeerPerformanceData *ppd)
 {
   struct GSF_PendingRequest *pr = cls;
 
+  if (GNUNET_YES != GSF_pending_request_test_target_ (pr, peer))
+  {
+#if INSANE_STATISTICS
+    GNUNET_STATISTICS_update (GSF_stats,
+                              gettext_noop ("# Loopback routes suppressed"), 1,
+                              GNUNET_NO);
+#endif
+    return;
+  }
   GSF_plan_add_ (cp, pr);
 }
 
@@ -276,14 +349,12 @@ consider_request_for_forwarding (void *cls,
  * @param result final datastore lookup result
  */
 static void
-consider_forwarding (void *cls,
-                    struct GSF_PendingRequest *pr,
-                    enum GNUNET_BLOCK_EvaluationResult result)
+consider_forwarding (void *cls, struct GSF_PendingRequest *pr,
+                     enum GNUNET_BLOCK_EvaluationResult result)
 {
   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
-    return; /* we're done... */
-  GSF_iterate_connected_peers_ (&consider_request_for_forwarding,
-                               pr);
+    return;                     /* we're done... */
+  GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr);
 }
 
 
@@ -294,24 +365,20 @@ consider_forwarding (void *cls,
  * @param other the other peer involved (sender or receiver, NULL
  *        for loopback messages where we are both sender and receiver)
  * @param message the actual message
- * @param atsi performance information
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_p2p_get (void *cls,
-               const struct GNUNET_PeerIdentity *other,
-               const struct GNUNET_MessageHeader *message,
-               const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
+                const struct GNUNET_MessageHeader *message)
 {
   struct GSF_PendingRequest *pr;
 
   pr = GSF_handle_p2p_query_ (other, message);
   if (NULL == pr)
     return GNUNET_SYSERR;
-  GSF_local_lookup_ (pr, 
-                    &consider_forwarding,
-                    NULL);
+  GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
+  GSF_local_lookup_ (pr, &consider_forwarding, NULL);
   return GNUNET_OK;
 }
 
@@ -319,7 +386,7 @@ handle_p2p_get (void *cls,
 /**
  * We're done with the local lookup, now consider
  * P2P processing (depending on request options and
- * result status).  Also signal that we can now 
+ * result status).  Also signal that we can now
  * receive more request information from the client.
  *
  * @param cls the client doing the request ('struct GNUNET_SERVER_Client')
@@ -327,30 +394,46 @@ handle_p2p_get (void *cls,
  * @param result final datastore lookup result
  */
 static void
-start_p2p_processing (void *cls,
-                     struct GSF_PendingRequest *pr,
-                     enum GNUNET_BLOCK_EvaluationResult result)
+start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
+                      enum GNUNET_BLOCK_EvaluationResult result)
 {
   struct GNUNET_SERVER_Client *client = cls;
   struct GSF_PendingRequestData *prd;
 
   prd = GSF_pending_request_get_data_ (pr);
-#if DEBUG_FS_CLIENT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Finished database lookup for local request `%s' with result %d\n",
-             GNUNET_h2s (&prd->query),
-             result);
-#endif
-  GNUNET_SERVER_receive_done (client,
-                             GNUNET_OK);
+              "Finished database lookup for local request `%s' with result %d\n",
+              GNUNET_h2s (&prd->query), result);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
-    return; /* we're done, 'pr' was already destroyed... */
-  if (0 != (GSF_PRO_LOCAL_ONLY & prd->options) )
+    return;                     /* we're done, 'pr' was already destroyed... */
+  if (0 != (GSF_PRO_LOCAL_ONLY & prd->options))
+  {
+    GSF_pending_request_cancel_ (pr, GNUNET_YES);
+    return;
+  }
+  if (0 == prd->anonymity_level)
+  {
+    switch (prd->type)
     {
-      GSF_pending_request_cancel_ (pr, GNUNET_YES);
-      return;
+    case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+    case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+      /* the above block types MAY be available via 'cadet' */
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Considering cadet-based download for block\n");
+      GSF_cadet_lookup_ (pr);
+      break;
+    case GNUNET_BLOCK_TYPE_FS_UBLOCK:
+      /* the above block types are in the DHT */
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Considering DHT-based search for block\n");
+      GSF_dht_lookup_ (pr);
+      break;
+    default:
+      GNUNET_break (0);
+      break;
     }
-  GSF_dht_lookup_ (pr);
+  }
   consider_forwarding (NULL, pr, result);
 }
 
@@ -363,21 +446,29 @@ start_p2p_processing (void *cls,
  * @param message the actual message
  */
 static void
-handle_start_search (void *cls,
-                    struct GNUNET_SERVER_Client *client,
-                    const struct GNUNET_MessageHeader *message)
+handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
+                     const struct GNUNET_MessageHeader *message)
 {
   struct GSF_PendingRequest *pr;
-
-  pr = GSF_local_client_start_search_handler_ (client, message);
-  if (NULL == pr)
-    {
-      /* GNUNET_SERVER_receive_done was already called! */
-      return;
-    }
-  GSF_local_lookup_ (pr, 
-                    &start_p2p_processing,
-                    client);
+  int ret;
+
+  pr = NULL;
+  ret = GSF_local_client_start_search_handler_ (client, message, &pr);
+  switch (ret)
+  {
+  case GNUNET_SYSERR:
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    break;
+  case GNUNET_NO:
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    break;
+  case GNUNET_YES:
+    GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
+    GSF_local_lookup_ (pr, &start_p2p_processing, client);
+    break;
+  default:
+    GNUNET_assert (0);
+  }
 }
 
 
@@ -388,14 +479,20 @@ handle_start_search (void *cls,
  * @param tc unused
  */
 static void
-shutdown_task (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  GSF_cadet_stop_client ();
+  GSF_cadet_stop_server ();
   if (NULL != GSF_core)
-    {
-      GNUNET_CORE_disconnect (GSF_core);
-      GSF_core = NULL;
-    }
+  {
+    GNUNET_CORE_disconnect (GSF_core);
+    GSF_core = NULL;
+  }
+  if (NULL != GSF_ats)
+  {
+    GNUNET_ATS_performance_done (GSF_ats);
+    GSF_ats = NULL;
+  }
   GSF_put_done_ ();
   GSF_push_done_ ();
   GSF_pending_request_done_ ();
@@ -412,10 +509,10 @@ shutdown_task (void *cls,
   GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO);
   GSF_stats = NULL;
   if (GNUNET_SCHEDULER_NO_TASK != cover_age_task)
-    {
-      GNUNET_SCHEDULER_cancel (cover_age_task);
-      cover_age_task = GNUNET_SCHEDULER_NO_TASK;
-    }
+  {
+    GNUNET_SCHEDULER_cancel (cover_age_task);
+    cover_age_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   GNUNET_FS_indexing_done ();
   GNUNET_LOAD_value_free (datastore_get_load);
   datastore_get_load = NULL;
@@ -435,38 +532,52 @@ shutdown_task (void *cls,
  * @return GNUNET_YES to continue to iterate
  */
 static int
-consider_peer_for_forwarding (void *cls,
-                             const GNUNET_HashCode *key,
-                             struct GSF_PendingRequest *pr)
+consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode * key,
+                              struct GSF_PendingRequest *pr)
 {
   struct GSF_ConnectedPeer *cp = cls;
-  
+  struct GNUNET_PeerIdentity pid;
+
+  GSF_connected_peer_get_identity_ (cp, &pid);
+  if (GNUNET_YES != GSF_pending_request_test_target_ (pr, &pid))
+  {
+    GNUNET_STATISTICS_update (GSF_stats,
+                              gettext_noop ("# Loopback routes suppressed"), 1,
+                              GNUNET_NO);
+    return GNUNET_YES;
+  }
   GSF_plan_add_ (cp, pr);
   return GNUNET_YES;
 }
 
 
+/**
+ * Function called after the creation of a connected peer record is complete.
+ *
+ * @param cls closure (unused)
+ * @param cp handle to the newly created connected peer record
+ */
+static void
+connected_peer_cb (void *cls, struct GSF_ConnectedPeer *cp)
+{
+  if (NULL == cp)
+    return;
+  GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
+}
+
+
 /**
  * Method called whenever a given peer connects.
  *
  * @param cls closure, not used
  * @param peer peer identity this notification is about
- * @param atsi performance information
  */
-static void 
-peer_connect_handler (void *cls,
-                     const struct GNUNET_PeerIdentity *peer,
-                     const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+static void
+peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
-  struct GSF_ConnectedPeer *cp;
-
   if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
     return;
-   cp = GSF_peer_connect_handler_ (peer, atsi);
-  if (NULL == cp)
-    return;
-  GSF_iterate_pending_requests_ (&consider_peer_for_forwarding,
-                                cp);
+  GSF_peer_connect_handler_ (peer, &connected_peer_cb, NULL);
 }
 
 
@@ -478,18 +589,11 @@ peer_connect_handler (void *cls,
  * directly (which should work if you are authorized...).
  *
  * @param cls closure
- * @param server handle to the server, NULL if we failed
  * @param my_identity ID of this peer, NULL if we failed
- * @param publicKey public key of this peer, NULL if we failed
  */
 static void
 peer_init_handler (void *cls,
-                  struct GNUNET_CORE_Handle * server,
-                  const struct GNUNET_PeerIdentity *
-                  my_identity,
-                  const struct
-                  GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
-                  publicKey)
+                   const struct GNUNET_PeerIdentity *my_identity)
 {
   my_id = *my_identity;
 }
@@ -503,59 +607,65 @@ peer_init_handler (void *cls,
  */
 static int
 main_init (struct GNUNET_SERVER_Handle *server,
-          const struct GNUNET_CONFIGURATION_Handle *c)
+           const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  static const struct GNUNET_CORE_MessageHandler p2p_handlers[] =
-    {
-      { &handle_p2p_get, 
-       GNUNET_MESSAGE_TYPE_FS_GET, 0 },
-      { &handle_p2p_put, 
-       GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
-      { &GSF_handle_p2p_migration_stop_, 
-       GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
-       sizeof (struct MigrationStopMessage) },
-      { NULL, 0, 0 }
-    };
+  static const struct GNUNET_CORE_MessageHandler no_p2p_handlers[] = {
+    {NULL, 0, 0}
+  };
+  static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
+    {&handle_p2p_get,
+     GNUNET_MESSAGE_TYPE_FS_GET, 0},
+    {&handle_p2p_put,
+     GNUNET_MESSAGE_TYPE_FS_PUT, 0},
+    {&GSF_handle_p2p_migration_stop_,
+     GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
+     sizeof (struct MigrationStopMessage)},
+    {NULL, 0, 0}
+  };
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
-    {&GNUNET_FS_handle_index_start, NULL, 
+    {&GNUNET_FS_handle_index_start, NULL,
      GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
-    {&GNUNET_FS_handle_index_list_get, NULL, 
-     GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) },
-    {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX, 
-     sizeof (struct UnindexMessage) },
-    {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 
-     0 },
+    {&GNUNET_FS_handle_index_list_get, NULL,
+     GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
+     sizeof (struct GNUNET_MessageHeader)},
+    {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
+     sizeof (struct UnindexMessage)},
+    {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
+     0},
     {NULL, NULL, 0, 0}
   };
-
-  GSF_core = GNUNET_CORE_connect (GSF_cfg,
-                                 2, /* larger? */
-                                 NULL,
-                                 &peer_init_handler,
-                                 &peer_connect_handler,
-                                 &GSF_peer_disconnect_handler_,
-                                 &GSF_peer_status_handler_,
-                                 NULL, GNUNET_NO,
-                                 NULL, GNUNET_NO,
-                                 p2p_handlers);
+  int anon_p2p_off;
+
+  /* this option is really only for testcases that need to disable
+     _anonymous_ file-sharing for some reason */
+  anon_p2p_off = (GNUNET_YES ==
+                 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
+                                                       "fs",
+                                                       "DISABLE_ANON_TRANSFER"));
+  GSF_core =
+      GNUNET_CORE_connect (GSF_cfg, NULL, &peer_init_handler,
+                           &peer_connect_handler, &GSF_peer_disconnect_handler_,
+                           NULL, GNUNET_NO, NULL, GNUNET_NO,
+                          (GNUNET_YES == anon_p2p_off)
+                          ? no_p2p_handlers
+                          : p2p_handlers);
   if (NULL == GSF_core)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                 _("Failed to connect to `%s' service.\n"),
-                 "core");
-      return GNUNET_SYSERR;
-    }
-  GNUNET_SERVER_disconnect_notify (server, 
-                                  &GSF_client_disconnect_handler_,
-                                  NULL);
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to connect to `%s' service.\n"), "core");
+    return GNUNET_SYSERR;
+  }
+  GNUNET_SERVER_disconnect_notify (server, &GSF_client_disconnect_handler_,
+                                   NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
-  cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
-                                                &age_cover_counters,
-                                                NULL);
+  cover_age_task =
+      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+                                    NULL);
   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &shutdown_task,
-                               NULL);
+  GSF_cadet_start_server ();
+  GSF_cadet_start_client ();
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+                                NULL);
   return GNUNET_OK;
 }
 
@@ -568,42 +678,48 @@ main_init (struct GNUNET_SERVER_Handle *server,
  * @param cfg configuration to use
  */
 static void
-run (void *cls,
-     struct GNUNET_SERVER_Handle *server,
+run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  unsigned long long dqs;
+
   GSF_cfg = cfg;
-  GSF_enable_randomized_delays = GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "fs", "DATASTORE_QUEUE_SIZE",
+                                           &dqs))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
+                              "fs", "DATASTORE_QUEUE_SIZE");
+    dqs = 1024;
+  }
+  GSF_datastore_queue_size = (unsigned int) dqs;
+  GSF_enable_randomized_delays =
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
   GSF_dsh = GNUNET_DATASTORE_connect (cfg);
   if (NULL == GSF_dsh)
-    {
-      GNUNET_SCHEDULER_shutdown ();
-      return;
-    }
+  {
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
   GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL);
   GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
   block_cfg = GNUNET_CONFIGURATION_create ();
-  GNUNET_CONFIGURATION_set_value_string (block_cfg,
-                                        "block",
-                                        "PLUGINS",
-                                        "fs");
   GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
   GNUNET_assert (NULL != GSF_block_ctx);
-  GSF_dht = GNUNET_DHT_connect (cfg,
-                               FS_DHT_HT_SIZE);
+  GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE);
   GSF_plan_init ();
   GSF_pending_request_init_ ();
   GSF_connected_peer_init_ ();
+  GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, &update_latencies, NULL);
   GSF_push_init_ ();
   GSF_put_init_ ();
-  if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
-       
-       (GNUNET_OK != main_init (server, cfg)) )
-    {    
-      GNUNET_SCHEDULER_shutdown ();
-      shutdown_task (NULL, NULL);
-      return;   
-    }
+  if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
+      (GNUNET_OK != main_init (server, cfg)))
+  {
+    GNUNET_SCHEDULER_shutdown ();
+    shutdown_task (NULL, NULL);
+    return;
+  }
 }
 
 
@@ -618,11 +734,8 @@ int
 main (int argc, char *const *argv)
 {
   return (GNUNET_OK ==
-          GNUNET_SERVICE_run (argc,
-                              argv,
-                              "fs",
-                             GNUNET_SERVICE_OPTION_NONE,
-                             &run, NULL)) ? 0 : 1;
+          GNUNET_SERVICE_run (argc, argv, "fs", GNUNET_SERVICE_OPTION_NONE,
+                              &run, NULL)) ? 0 : 1;
 }
 
 /* end of gnunet-service-fs.c */