- doc
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_connection.c
index 5a40dbe43c7594c60832d8d9886e610c608092c0..47f55550322477613f7493fea492499b4b99b254 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 */
@@ -1450,8 +1450,8 @@ build_path_from_peer_ids (struct GNUNET_PeerIdentity *peers,
     }
     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);
@@ -1775,16 +1775,19 @@ GMC_handle_broken (void* cls,
   fwd = is_fwd (c, id);
   if (GMC_is_terminal (c, fwd))
   {
-    struct GNUNET_MessageHeader *msg;
-    struct MeshPeer *peer;
+    struct GNUNET_MessageHeader *out_msg;
+    struct MeshPeer *neighbor;
+    struct MeshPeer *endpoint;
 
-    peer = get_hop (c, !fwd);
+    neighbor = get_hop (c, !fwd);
+    endpoint = GMP_get_short (c->path->peers[c->path->length - 1]);
     path_invalidate (c->path);
+    GMP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2);
     c->state = MESH_CONNECTION_DESTROYED;
-    while (NULL != (msg = GMP_connection_pop (peer, c)))
+    while (NULL != (out_msg = GMP_connection_pop (neighbor, c)))
     {
       GNUNET_assert (NULL ==
-                     GMT_send_prebuilt_message (msg, c->t, NULL, GNUNET_YES,
+                     GMT_send_prebuilt_message (out_msg, c->t, NULL, GNUNET_YES,
                                                 NULL, NULL));
     }
 
@@ -2747,12 +2750,16 @@ GMC_is_sendable (struct MeshConnection *c, int fwd)
 {
   struct MeshFlowControl *fc;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, " checking sendability of %s traffic on %s\n",
+       GM_f2s (fwd), GMC_2s (c));
   if (NULL == c)
   {
     GNUNET_break (0);
     return GNUNET_YES;
   }
   fc = fwd ? &c->fwd_fc : &c->bck_fc;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, " last ack recv: %u, last pid sent: %u\n",
+       fc->last_ack_recv, fc->last_pid_sent);
   if (GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
     return GNUNET_YES;
   return GNUNET_NO;