Add info about peer's paths on ACK of a path
authorBart Polot <bart@net.in.tum.de>
Mon, 14 Nov 2011 17:27:00 +0000 (17:27 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 14 Nov 2011 17:27:00 +0000 (17:27 +0000)
src/mesh/gnunet-service-mesh.c

index bcf6a400b6537541ef60b0cdc38fe59a3b67522d..e8b7ed7a09a1f6e0f1a6166ff573ea501568f06d 100644 (file)
@@ -1521,6 +1521,12 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path,
     path_destroy (path);
     return;
   }
+  if (path->peers[path->length - 1] != peer_info->id)
+  {
+    GNUNET_break (0);
+    path_destroy (path);
+    return;
+  }
   if (path->length <= 2 && GNUNET_NO == trusted)
   {
     /* Only allow CORE to tell us about direct paths */
@@ -3047,7 +3053,9 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
   struct GNUNET_MESH_PathACK *msg;
   struct GNUNET_PeerIdentity id;
   struct MeshPeerInfo *peer_info;
+  struct MeshPeerPath *p;
   struct MeshTunnel *t;
+  unsigned int i;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path ACK msg [%s]\n",
               GNUNET_i2s (&my_full_id));
@@ -3059,6 +3067,21 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
     return GNUNET_OK;
   }
 
+  /* Add paths to peers */
+  peer_info = peer_info_get (&msg->peer_id);
+  p = tree_get_path_to_peer(t->tree, peer_info->id);
+  for (i = 1; i < p->length && p->peers[i] != myid; i++) /* skip'em */;
+  for (i++; i < p->length; i++)
+  {
+    struct MeshPeerInfo *aux;
+    struct MeshPeerPath *copy;
+
+    aux = peer_info_get_short(p->peers[i]);
+    copy = path_duplicate(p);
+    copy->length = i;
+    peer_info_add_path(aux, copy, 0);
+  }
+
   /* Message for us? */
   if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity)))
   {
@@ -3073,7 +3096,6 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
       GNUNET_DHT_get_stop (t->dht_get_type);
       t->dht_get_type = NULL;
     }
-    peer_info = peer_info_get (&msg->peer_id);
     if (tree_get_status(t->tree, peer_info->id) != MESH_PEER_READY)
     {
       tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);