- log
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_tunnel.c
index 7198a2474f972884a57c0707992381641d664ecb..a13d88fd53ad3a9ea3111eb5d973cd49fbc1e3f8 100644 (file)
@@ -395,7 +395,7 @@ get_connection_allowed (const struct MeshTConnection *tc)
  * @return GNUNET_OK if message is fine, GNUNET_SYSERR otherwise.
  */
 int
-check_ephemeral (struct MeshTunnel3 *t, 
+check_ephemeral (struct MeshTunnel3 *t,
                  const struct GNUNET_MESH_KX_Ephemeral *msg)
 {
   /* Check message size */
@@ -866,6 +866,27 @@ rekey (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
+/**
+ * Called only on shutdown, destroy every tunnel.
+ *
+ * @param cls Closure (unused).
+ * @param key Current public key.
+ * @param value Value in the hash map (tunnel).
+ *
+ * @return #GNUNET_YES, so we should continue to iterate,
+ */
+static int
+destroy_iterator (void *cls,
+                const struct GNUNET_PeerIdentity *key,
+                void *value)
+{
+  struct MeshTunnel3 *t = value;
+
+  GMT_destroy (t);
+  return GNUNET_YES;
+}
+
+
 /**
  * Demultiplex data per channel and call appropriate channel handler.
  *
@@ -1397,6 +1418,7 @@ GMT_shutdown (void)
     GNUNET_SCHEDULER_cancel (rekey_task);
     rekey_task = GNUNET_SCHEDULER_NO_TASK;
   }
+  GNUNET_CONTAINER_multipeermap_iterate (tunnels, &destroy_iterator, NULL);
   GNUNET_CONTAINER_multipeermap_destroy (tunnels);
 }
 
@@ -1601,6 +1623,7 @@ GMT_destroy_empty (struct MeshTunnel3 *t)
 {
   struct MeshTConnection *iter;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Tunnel empty: destroying scheduled\n");
   for (iter = t->connection_head; NULL != iter; iter = iter->next)
   {
     GMC_send_destroy (iter->c);
@@ -1644,14 +1667,14 @@ GMT_destroy (struct MeshTunnel3 *t)
   struct MeshTChannel *iter_ch;
   struct MeshTChannel *next_ch;
 
-
   if (NULL == t)
     return;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GMP_2s (t->peer));
 
-//   if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &t->id, t))
-//     GNUNET_break (0);
+  GNUNET_break (GNUNET_YES ==
+                GNUNET_CONTAINER_multipeermap_remove (tunnels,
+                                                      GMP_get_id (t->peer), t));
 
   for (iter_c = t->connection_head; NULL != iter_c; iter_c = next_c)
   {
@@ -1662,7 +1685,7 @@ GMT_destroy (struct MeshTunnel3 *t)
   {
     next_ch = iter_ch->next;
     GMCH_destroy (iter_ch->ch);
-    GNUNET_break (0);
+    /* Should only happen on shutdown, but it's ok. */
   }
 
   GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO);
@@ -1942,7 +1965,7 @@ GMT_send_connection_acks (struct MeshTunnel3 *t)
   unsigned int cs;
   unsigned int buffer;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Tunnel send connection ACKs on %s\n",
        GMT_2s (t));
 
@@ -1997,7 +2020,7 @@ GMT_send_connection_acks (struct MeshTunnel3 *t)
  * @param fwd Was this a FWD going message?
  * @param size Size of the message.
  */
-static void 
+static void
 message_sent (void *cls,
               struct MeshConnection *c,
               struct MeshConnectionQueue *q,
@@ -2205,4 +2228,4 @@ GMT_2s (const struct MeshTunnel3 *t)
     return "(NULL)";
 
   return GMP_2s (t->peer);
-}
\ No newline at end of file
+}