- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.c
index 967bd1712b0fb88c6cf97a2bcaf6002412900970..aa9f52fe618ae72ecf157101d7b8934da4da82f8 100644 (file)
@@ -318,9 +318,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
     sizeof (struct GNUNET_MESH_ConnectionBroken)},
   {&GMC_handle_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY,
     sizeof (struct GNUNET_MESH_ConnectionDestroy)},
-  {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE,
-    sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
-  {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE,
+  {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE,
     sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
   {&GMC_handle_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
     sizeof (struct GNUNET_MESH_ACK)},
@@ -415,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) +
@@ -644,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,16 +810,16 @@ queue_send (void *cls, size_t size, void *buf)
   /* Fill buf */
   switch (queue->type)
   {
-    case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
     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:
     case GNUNET_MESSAGE_TYPE_MESH_POLL:
       LOG (GNUNET_ERROR_TYPE_DEBUG,
                   "*   raw: %s\n",
-                  GNUNET_MESH_DEBUG_M2S (queue->type));
+                  GM_m2s (queue->type));
       data_size = send_core_data_raw (queue->cls, size, buf);
       break;
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
@@ -853,7 +855,7 @@ queue_send (void *cls, size_t size, void *buf)
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,
                 "Dropping message of type %s\n",
-                GNUNET_MESH_DEBUG_M2S (queue->type));
+                GM_m2s (queue->type));
     data_size = 0;
   }
 
@@ -918,28 +920,26 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
   if (GNUNET_YES == clear_cls)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "#   queue destroy type %s\n",
-                GNUNET_MESH_DEBUG_M2S (queue->type));
+                GM_m2s (queue->type));
     switch (queue->type)
     {
       case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
-      case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
         LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n");
         /* fall through */
-      case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
-      case GNUNET_MESSAGE_TYPE_MESH_ACK:
-      case GNUNET_MESSAGE_TYPE_MESH_POLL:
       case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
       case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
       case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
       case GNUNET_MESSAGE_TYPE_MESH_KX:
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "#   prebuilt message\n");;
+      case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
+      case GNUNET_MESSAGE_TYPE_MESH_ACK:
+      case GNUNET_MESSAGE_TYPE_MESH_POLL:
         GNUNET_free_non_null (queue->cls);
         break;
 
       default:
         GNUNET_break (0);
         LOG (GNUNET_ERROR_TYPE_ERROR, "#   type %s unknown!\n",
-                    GNUNET_MESH_DEBUG_M2S (queue->type));
+                    GM_m2s (queue->type));
     }
   }
   GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue);
@@ -990,7 +990,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "queue add %s %s towards %s (size %u) on c %p (%s)\n",
-       fwd ? "FWD" : "BCK",  GNUNET_MESH_DEBUG_M2S (type), GMP_2s(peer),
+       GM_f2s (fwd),  GM_m2s (type), GMP_2s(peer),
        size, c, GMC_2s (c));
   GNUNET_assert (NULL != c);
 
@@ -1080,7 +1080,7 @@ GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c)
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG,
                   "GMP_cancel_queue %s\n",
-                  GNUNET_MESH_DEBUG_M2S (q->type));
+                  GM_m2s (q->type));
       GMP_queue_destroy (q, GNUNET_YES);
 
       /* Get next from prev, q->next might be already freed:
@@ -1298,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;
@@ -1326,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
       {
@@ -1596,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.
  *
@@ -1610,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;
@@ -1698,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;
 }