- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.c
index 76296c19888fbd1796c41f53bb2ddf1bc18c67df..aa9f52fe618ae72ecf157101d7b8934da4da82f8 100644 (file)
@@ -413,6 +413,9 @@ send_core_connection_create (struct MeshConnection *c, size_t size, void *buf)
   size_t size_needed;
   int i;
 
+  if (NULL == p)
+    return 0;
+
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION CREATE...\n");
   size_needed =
       sizeof (struct GNUNET_MESH_ConnectionCreate) +
@@ -642,7 +645,8 @@ peer_delete_oldest (void)
 
 
 /**
- * Choose the best path towards a peer considering the tunnel properties.
+ * Choose the best (yet unused) path towards a peer,
+ * considering the tunnel properties.
  *
  * @param peer The destination peer.
  *
@@ -808,6 +812,7 @@ queue_send (void *cls, size_t size, void *buf)
   {
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
+    case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
     case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
     case GNUNET_MESSAGE_TYPE_MESH_KX:
     case GNUNET_MESSAGE_TYPE_MESH_ACK:
@@ -1293,9 +1298,7 @@ GMP_connect (struct MeshPeer *peer)
   struct MeshConnection *c;
   int rerun_search;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "peer_connect towards %s\n",
-              GMP_2s (peer));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "peer_connect towards %s\n", GMP_2s (peer));
   t = peer->tunnel;
   c = NULL;
   rerun_search = GNUNET_NO;
@@ -1321,9 +1324,11 @@ GMP_connect (struct MeshPeer *peer)
          * path.
          *
          * Re-running the DHT GET should give core time to callback.
+         *
+         * GMT_use_path -> GMC_new -> register_neighbors takes care of
+         * updating statistics about this issue.
          */
-        GNUNET_break(0);
-                rerun_search = GNUNET_YES;
+        rerun_search = GNUNET_YES;
       }
       else
       {
@@ -1591,6 +1596,37 @@ GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed)
 }
 
 
+/**
+ * Remove any path to the peer that has the extact same peers as the one given.
+ *
+ * @param peer Peer to remove the path from.
+ * @param path Path to remove. Is always destroyed .
+ */
+void
+GMP_remove_path (struct MeshPeer *peer, struct MeshPeerPath *path)
+{
+  struct MeshPeerPath *iter;
+  struct MeshPeerPath *next;
+
+  GNUNET_assert (myid == path->peers[0]);
+  GNUNET_assert (peer->id == path->peers[path->length - 1]);
+
+  for (iter = peer->path_head; NULL != iter; iter = next)
+  {
+    next = iter->next;
+    if (0 == memcmp (path->peers, iter->peers,
+                     sizeof (GNUNET_PEER_Id) * path->length))
+    {
+      GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+      path_destroy (iter);
+      if (path == iter)
+        return;
+    }
+  }
+  path_destroy (path);
+}
+
+
 /**
  * Remove a connection from a neighboring peer.
  *
@@ -1605,8 +1641,7 @@ GMP_remove_connection (struct MeshPeer *peer,
 {
   if (NULL == peer || NULL == peer->connections)
   {
-    GNUNET_break (0);
-    LOG (GNUNET_ERROR_TYPE_WARNING,
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Peer %s is not a neighbor!\n",
          GMP_2s (peer));
     return GNUNET_SYSERR;
@@ -1693,6 +1728,7 @@ GMP_get_short_id (const struct MeshPeer *peer)
 struct MeshTunnel3 *
 GMP_get_tunnel (const struct MeshPeer *peer)
 {
+  GNUNET_assert (NULL != peer->tunnel);
   return peer->tunnel;
 }