From 1a2b9898a2c18e10c587072d7a10ac48fc8e956c Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 20 Oct 2011 12:49:52 +0000 Subject: [PATCH] Fixed bugs in tunnel destruction chain --- src/mesh/gnunet-service-mesh.c | 42 ++++++++++++++++++++++++++++++++-- src/mesh/mesh_api_new.c | 1 - 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index cb7602b90..3108d9149 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -787,6 +787,7 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, /** * Notify the client that owns the tunnel that a peer has connected to it + * (the requested path to it has been confirmed). * * @param t Tunnel whose owner to notify * @param id Short id of the peer that has connected @@ -805,6 +806,24 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id) } +/** + * Notify all clients (not depending on registration status) that the incoming + * tunnel is no longer valid. + * + * @param t Tunnel that was destroyed. + */ +static void +send_clients_tunnel_destroy (struct MeshTunnel *t) +{ + struct GNUNET_MESH_TunnelMessage msg; + + msg.header.size = htons (sizeof (msg)); + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); + msg.tunnel_id = htonl (t->local_tid); + GNUNET_SERVER_notification_context_broadcast(nc, &msg.header, GNUNET_NO); +} + + /** * Function called to notify a client about the socket * being ready to queue more data. "buf" will be @@ -1777,7 +1796,11 @@ tunnel_send_multicast (struct MeshTunnel *t, GNUNET_assert (NULL != t->tree->me); n = t->tree->me->children_head; if (NULL == n) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MESH: no children in the tree, no one to send.\n"); return 0; + } copies = GNUNET_malloc (sizeof (unsigned int)); for (*copies = 0; NULL != n; n = n->next) (*copies)++; @@ -1836,7 +1859,7 @@ tunnel_send_destroy (struct MeshTunnel *t) msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY); - msg.oid = my_full_id; + GNUNET_PEER_resolve (t->id.oid, &msg.oid); msg.tid = htonl (t->id.tid); tunnel_send_multicast (t, &msg.header); } @@ -2558,6 +2581,10 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, "MESH: Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer)); msg = (struct GNUNET_MESH_TunnelDestroy *) message; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MESH: for tunnel %s [%u]\n", + GNUNET_i2s (&msg->oid), + ntohl (msg->tid)); t = tunnel_get (&msg->oid, ntohl (msg->tid)); if (NULL == t) { @@ -2565,6 +2592,16 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break_op (0); return GNUNET_OK; } + if (t->id.oid == myid) + { + GNUNET_break_op (0); + return GNUNET_OK; + } + if (t->local_tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) + { + /* Tunnel was incoming, notify clients */ + send_clients_tunnel_destroy (t); + } tunnel_send_destroy (t); tunnel_destroy (t); return GNUNET_OK; @@ -3376,7 +3413,8 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client, MESH_TunnelNumber tid; GNUNET_HashCode hash; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: destroying tunnel\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MESH: Got a DESTROY TUNNEL from client!\n"); /* Sanity check for client registration */ if (NULL == (c = client_get (client))) diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index df5461080..81933e858 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c @@ -796,7 +796,6 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h, if (NULL == t) { - GNUNET_break (0); return; } if (0 == t->owner) -- 2.25.1