- destroy channels when tunnels is being destroyed (but complain: channels should...
authorBart Polot <bart@net.in.tum.de>
Mon, 18 Nov 2013 19:10:50 +0000 (19:10 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 18 Nov 2013 19:10:50 +0000 (19:10 +0000)
src/mesh/gnunet-service-mesh_channel.c
src/mesh/gnunet-service-mesh_tunnel.c

index 059f1231b67876cd50d4c7e4e68d9eeb7f68d294..45c8c60448b5ee9cf95912a27ae07efd9b3a2239 100644 (file)
@@ -847,45 +847,6 @@ channel_save_copy (struct MeshChannel *ch,
 }
 
 
-/**
- * Destroy a channel and free all resources.
- *
- * @param ch Channel to destroy.
- */
-static void
-channel_destroy (struct MeshChannel *ch)
-{
-  struct MeshClient *c;
-
-  if (NULL == ch)
-    return;
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying channel %s:%u\n",
-              GMT_2s (ch->t), ch->gid);
-  GMCH_debug (ch);
-
-  c = ch->root;
-  if (NULL != c)
-  {
-    GML_channel_remove (c, ch->lid_root, ch);
-  }
-
-  c = ch->dest;
-  if (NULL != c)
-  {
-    GML_channel_remove (c, ch->lid_dest, ch);
-  }
-
-  channel_rel_free_all (ch->root_rel);
-  channel_rel_free_all (ch->dest_rel);
-
-  GMT_remove_channel (ch->t, ch);
-  GNUNET_STATISTICS_update (stats, "# channels", -1, GNUNET_NO);
-
-  GNUNET_free (ch);
-}
-
-
 /**
  * Create a new channel.
  *
@@ -1011,6 +972,53 @@ handle_loopback (struct MeshChannel *ch,
 /******************************************************************************/
 
 
+/**
+ * Destroy a channel and free all resources.
+ *
+ * @param ch Channel to destroy.
+ */
+void
+GMCH_destroy (struct MeshChannel *ch);
+
+/**
+ * Destroy a channel and free all resources.
+ *
+ * @param ch Channel to destroy.
+ */
+void
+GMCH_destroy (struct MeshChannel *ch)
+{
+  struct MeshClient *c;
+
+  if (NULL == ch)
+    return;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying channel %s:%u\n",
+              GMT_2s (ch->t), ch->gid);
+  GMCH_debug (ch);
+
+  c = ch->root;
+  if (NULL != c)
+  {
+    GML_channel_remove (c, ch->lid_root, ch);
+  }
+
+  c = ch->dest;
+  if (NULL != c)
+  {
+    GML_channel_remove (c, ch->lid_dest, ch);
+  }
+
+  channel_rel_free_all (ch->root_rel);
+  channel_rel_free_all (ch->dest_rel);
+
+  GMT_remove_channel (ch->t, ch);
+  GNUNET_STATISTICS_update (stats, "# channels", -1, GNUNET_NO);
+
+  GNUNET_free (ch);
+}
+
+
 /**
  * Get channel ID.
  *
@@ -1462,7 +1470,7 @@ GMCH_handle_local_destroy (struct MeshChannel *ch,
 
   t = ch->t;
   GMCH_send_destroy (ch);
-  channel_destroy (ch);
+  GMCH_destroy (ch);
   GMT_destroy_if_empty (t);
 }
 
@@ -1776,7 +1784,7 @@ GMCH_handle_create (struct MeshTunnel3 *t,
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG, "  not loopback: destroy now\n");
       channel_send_nack (ch);
-      channel_destroy (ch);
+      GMCH_destroy (ch);
     }
     return NULL;
   }
@@ -1809,7 +1817,7 @@ void
 GMCH_handle_nack (struct MeshChannel *ch)
 {
   send_client_nack (ch);
-  channel_destroy (ch);
+  GMCH_destroy (ch);
 }
 
 
@@ -1882,7 +1890,7 @@ GMCH_handle_destroy (struct MeshChannel *ch,
 
   t = ch->t;
   GMCH_send_destroy (ch);
-  channel_destroy (ch);
+  GMCH_destroy (ch);
   GMT_destroy_if_empty (t);
 }
 
index bc8aefcc2d175e76cec895120027ae2721e14d1b..7198a2474f972884a57c0707992381641d664ecb 100644 (file)
@@ -1639,8 +1639,11 @@ GMT_destroy_if_empty (struct MeshTunnel3 *t)
 void
 GMT_destroy (struct MeshTunnel3 *t)
 {
-  struct MeshTConnection *iter;
-  struct MeshTConnection *next;
+  struct MeshTConnection *iter_c;
+  struct MeshTConnection *next_c;
+  struct MeshTChannel *iter_ch;
+  struct MeshTChannel *next_ch;
+
 
   if (NULL == t)
     return;
@@ -1650,10 +1653,16 @@ GMT_destroy (struct MeshTunnel3 *t)
 //   if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &t->id, t))
 //     GNUNET_break (0);
 
-  for (iter = t->connection_head; NULL != iter; iter = next)
+  for (iter_c = t->connection_head; NULL != iter_c; iter_c = next_c)
   {
-    next = iter->next;
-    GMC_destroy (iter->c);
+    next_c = iter_c->next;
+    GMC_destroy (iter_c->c);
+  }
+  for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = next_ch)
+  {
+    next_ch = iter_ch->next;
+    GMCH_destroy (iter_ch->ch);
+    GNUNET_break (0);
   }
 
   GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO);