- fix handling of duplicate incoming channel create with respect to queued retransmis...
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_connection.c
index b33737eba7fd5138bb88484b2e110f9818c28f37..5a87db99a676a07ccf13120a2a6ccc40751d9888 100644 (file)
@@ -855,7 +855,7 @@ send_broken2 (struct GNUNET_MeshHash *connection_id,
   msg->peer2 = *id2;
   neighbor = GMP_get_short (peer_id);
   GMP_queue_add (neighbor, msg,
-                 GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED,
+                 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN,
                  sizeof (struct GNUNET_MESH_ConnectionBroken),
                  NULL, GNUNET_SYSERR, /* connection, fwd */
                  NULL, NULL); /* continuation */
@@ -1443,15 +1443,15 @@ build_path_from_peer_ids (struct GNUNET_PeerIdentity *peers,
       if (path->peers[j] == shortid)
       {
         LOG (GNUNET_ERROR_TYPE_DEBUG, "    already exists at pos %u\n", j);
-        offset += i - j;
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "    offset now\n", offset);
+        offset = i - j;
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "    offset now %u\n", offset);
         GNUNET_PEER_change_rc (shortid, -1);
       }
     }
     LOG (GNUNET_ERROR_TYPE_DEBUG, "    storing at %u\n", i - offset);
     path->peers[i - offset] = shortid;
-    if (path->peers[i] == myid)
-      *own_pos = i;
+    if (path->peers[i - offset] == myid)
+      *own_pos = i - offset;
   }
   path->length -= offset;
 
@@ -1588,7 +1588,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
   orig_peer = GMP_get (&id[0]);
 
   /* Is it a connection to us? */
-  if (c->own_pos == size - 1)
+  if (c->own_pos == path->length - 1)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  It's for us!\n");
     GMP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_YES);
@@ -1741,7 +1741,7 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
 
 
 /**
- * Core handler for notifications of broken paths
+ * Core handler for notifications of broken connections.
  *
  * @param cls Closure (unused).
  * @param id Peer identity of sending neighbor.
@@ -1768,18 +1768,30 @@ GMC_handle_broken (void* cls,
   c = connection_get (&msg->cid);
   if (NULL == c)
   {
-    GNUNET_break_op (0);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  duplicate CONNECTION_BROKEN\n");
     return GNUNET_OK;
   }
 
   fwd = is_fwd (c, id);
   if (GMC_is_terminal (c, fwd))
   {
+    struct GNUNET_MessageHeader *out_msg;
+    struct MeshPeer *neighbor;
+    struct MeshPeer *endpoint;
+
+    neighbor = get_hop (c, !fwd);
+    endpoint = GMP_get_short (c->path->peers[c->path->length - 1]);
     path_invalidate (c->path);
-    if (0 < c->pending_messages)
-      c->destroy = GNUNET_YES;
-    else
-      GMC_destroy (c);
+    GMP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2);
+    c->state = MESH_CONNECTION_DESTROYED;
+    while (NULL != (out_msg = GMP_connection_pop (neighbor, c)))
+    {
+      GNUNET_assert (NULL ==
+                     GMT_send_prebuilt_message (out_msg, c->t, NULL, GNUNET_YES,
+                                                NULL, NULL));
+    }
+
+    GMC_destroy (c);
   }
   else
   {
@@ -2351,7 +2363,7 @@ GMC_init (const struct GNUNET_CONFIGURATION_Handle *c)
     return;
   }
   create_connection_time = GNUNET_TIME_UNIT_SECONDS;
-  connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
+  connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
 }