Fixed a bug when adding a path to a peer who is already a relay in the tunnel
authorBart Polot <bart@net.in.tum.de>
Sat, 29 Oct 2011 00:45:10 +0000 (00:45 +0000)
committerBart Polot <bart@net.in.tum.de>
Sat, 29 Oct 2011 00:45:10 +0000 (00:45 +0000)
src/mesh/gnunet-service-mesh.c
src/mesh/mesh_tunnel_tree.c

index a3a9db942574ed7a017944220cabf1a6b90c5671..a8b132d7a11f1ba1e1ddd9933c69407ad8bf1a8e 100644 (file)
@@ -1286,6 +1286,12 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
   if (NULL != peer->path_head)
   {
     p = tree_get_path_to_peer(t->tree, peer->id);
+    if (NULL == p)
+    {
+      GNUNET_break (0);
+      return;
+    }
+
     if (p->length > 1)
     {
       send_create_path(peer, p, t);
@@ -1325,6 +1331,28 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
 }
 
 
+/**
+ * Task to delay the connection of a peer
+ *
+ * @param cls Closure (path info with tunnel and peer to connect).
+ *            Will be free'd on exection.
+ * @param tc TaskContext
+ */
+static void
+peer_info_connect_task (void *cls,
+                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct MeshPathInfo *path_info = cls;
+
+  if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
+  {
+    GNUNET_free (cls);
+  }
+  peer_info_connect (path_info->peer, path_info->t);
+  GNUNET_free (cls);
+}
+
+
 /**
  * Destroy the peer_info and free any allocated resources linked to it
  * 
@@ -1718,6 +1746,7 @@ void
 notify_peer_disconnected (const struct MeshTunnelTreeNode *n)
 {
   struct MeshPeerInfo *peer;
+  struct MeshPathInfo *path_info;
 
   if (NULL != n->t->client && NULL != nc)
   {
@@ -1730,7 +1759,10 @@ notify_peer_disconnected (const struct MeshTunnelTreeNode *n)
                                                 &msg.header, GNUNET_NO);
   }
   peer = peer_info_get_short(n->peer);
-  peer_info_connect(peer, n->t);
+  path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
+  path_info->peer = peer;
+  path_info->t = n->t;
+  GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info);
 }
 
 
index 16a9dbd8ec145075a63ffd5c413ca86ad71a8c5c..50f6dc5c7948bf2eee4634f8d14dbc0be269097f 100644 (file)
@@ -516,6 +516,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
   GNUNET_PEER_Id myid = t->me->peer;
 
   n = tree_find_peer(t->me, peer);
+  if (NULL == n)
+    return NULL;
   p = path_new(0);
 
   /* Building the path (inverted!) */