From: Bart Polot Date: Sat, 29 Oct 2011 00:45:10 +0000 (+0000) Subject: Fixed a bug when adding a path to a peer who is already a relay in the tunnel X-Git-Tag: initial-import-from-subversion-38251~16158 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=077ab2fba42dedd507ca9e6f6441b00fd46b0090;p=oweals%2Fgnunet.git Fixed a bug when adding a path to a peer who is already a relay in the tunnel --- diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index a3a9db942..a8b132d7a 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -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); } diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index 16a9dbd8e..50f6dc5c7 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c @@ -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!) */