Do not crash if key is NULL.
[oweals/gnunet.git] / src / fs / gnunet-service-fs.c
index 0e38d0dc9778b40476a50ab918a7dfc3d26445d7..b824e6dc64105e0f028d1faa633d7a00e1c64676 100644 (file)
@@ -43,7 +43,7 @@
 #include "gnunet-service-fs_pr.h"
 #include "gnunet-service-fs_push.h"
 #include "gnunet-service-fs_put.h"
-#include "gnunet-service-fs_mesh.h"
+#include "gnunet-service-fs_cadet.h"
 #include "fs.h"
 
 /**
@@ -254,8 +254,14 @@ update_latencies (void *cls,
   unsigned int i;
   struct GNUNET_TIME_Relative latency;
 
+  if (NULL == address)
+  {
+    /* ATS service temporarily disconnected */
+    return;
+  }
+
   if (GNUNET_YES != active)
-       return;
+    return;
   for (i = 0; i < ats_count; i++)
   {
     if (GNUNET_ATS_QUALITY_NET_DELAY != ntohl (ats[i].type))
@@ -412,10 +418,10 @@ start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
     {
     case GNUNET_BLOCK_TYPE_FS_DBLOCK:
     case GNUNET_BLOCK_TYPE_FS_IBLOCK:
-      /* the above block types MAY be available via 'mesh' */
+      /* the above block types MAY be available via 'cadet' */
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                 "Considering mesh-based download for block\n");
-      GSF_mesh_lookup_ (pr);
+                 "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 */
@@ -475,8 +481,8 @@ handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GSF_mesh_stop_client ();
-  GSF_mesh_stop_server ();
+  GSF_cadet_stop_client ();
+  GSF_cadet_stop_server ();
   if (NULL != GSF_core)
   {
     GNUNET_CORE_disconnect (GSF_core);
@@ -545,6 +551,21 @@ consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode * key,
 }
 
 
+/**
+ * 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.
  *
@@ -554,14 +575,9 @@ consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode * key,
 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);
-  if (NULL == cp)
-    return;
-  GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
+  GSF_peer_connect_handler_ (peer, &connected_peer_cb, NULL);
 }
 
 
@@ -646,8 +662,8 @@ main_init (struct GNUNET_SERVER_Handle *server,
       GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
                                     NULL);
   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
-  GSF_mesh_start_server ();
-  GSF_mesh_start_client ();
+  GSF_cadet_start_server ();
+  GSF_cadet_start_client ();
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
                                 NULL);
   return GNUNET_OK;