ensure tunnels are shutdown at the right time during shutdown
authorChristian Grothoff <christian@grothoff.org>
Sat, 21 Jan 2017 23:10:26 +0000 (00:10 +0100)
committerChristian Grothoff <christian@grothoff.org>
Sat, 21 Jan 2017 23:10:26 +0000 (00:10 +0100)
src/cadet/cadet.conf.in
src/cadet/gnunet-service-cadet-new.c
src/cadet/gnunet-service-cadet-new_tunnels.c
src/cadet/gnunet-service-cadet-new_tunnels.h

index 1ee830dbf63bfd68bc8dce5c0e97201a255cc7b2..88f49fde8b8512bf297983cbf56a2b8899bc8b0e 100644 (file)
@@ -3,7 +3,7 @@ FORCESTART = YES
 AUTOSTART = @AUTOSTART@
 @JAVAPORT@PORT = 2096
 HOSTNAME = localhost
-BINARY = gnunet-service-cadet-new
+BINARY = gnunet-service-cadet
 ACCEPT_FROM = 127.0.0.1;
 ACCEPT_FROM6 = ::1;
 UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-cadet.sock
index 6ba0df69e4d6bb9d96c3bd5c356c63730c78cfcb..ff143b4b3e4692fc94cfb66c408b4dc45586e210 100644 (file)
@@ -310,6 +310,30 @@ GSC_bind (struct CadetClient *c,
 }
 
 
+/**
+ * Callback invoked on all peers to destroy all tunnels
+ * that may still exist.
+ *
+ * @param cls NULL
+ * @param pid identify of a peer
+ * @param value a `struct CadetPeer` that may still have a tunnel
+ * @return #GNUNET_OK (iterate over all entries)
+ */
+static int
+destroy_tunnels_now (void *cls,
+                     const struct GNUNET_PeerIdentity *pid,
+                     void *value)
+{
+  struct CadetPeer *cp = value;
+  struct CadetTunnel *t = GCP_get_tunnel (cp,
+                                          GNUNET_NO);
+
+  if (NULL != t)
+    GCT_destroy_tunnel_now (t);
+  return GNUNET_OK;
+}
+
+
 /**
  * Task run during shutdown.
  *
@@ -338,7 +362,10 @@ shutdown_task (void *cls)
     GNUNET_CONTAINER_multihashmap_destroy (loose_channels);
     loose_channels = NULL;
   }
-  /* All channels, connections and CORE must be down before this point. */
+  /* Destroy tunnels.  Note that all channels must be destroyed first! */
+  GCP_iterate_all (&destroy_tunnels_now,
+                   NULL);
+  /* All tunnels, channels, connections and CORE must be down before this point. */
   GCP_destroy_all_peers ();
   if (NULL != peers)
   {
index 73bbaf042e50e9e0bbaccd909af5d80b7e8dbad5..06c98fcee53abf8fda1cdd037219c58d78c5436e 100644 (file)
@@ -1558,6 +1558,21 @@ GCT_remove_channel (struct CadetTunnel *t,
 }
 
 
+/**
+ * Destroys the tunnel @a t now, without delay. Used during shutdown.
+ *
+ * @param t tunnel to destroy
+ */
+void
+GCT_destroy_tunnel_now (struct CadetTunnel *t)
+{
+  GNUNET_assert (0 ==
+                 GNUNET_CONTAINER_multihashmap32_size (t->channels));
+  GNUNET_SCHEDULER_cancel (t->destroy_task);
+  destroy_tunnel (t);
+}
+
+
 /**
  * It's been a while, we should try to redo the KX, if we can.
  *
index 3c88ae5f0ace1fd9d02715641956b167baad50c4..c867a9e820af7635f6c85323ef0d297be1b83f67 100644 (file)
@@ -98,6 +98,15 @@ struct CadetTunnel *
 GCT_create_tunnel (struct CadetPeer *destination);
 
 
+/**
+ * Destroys the tunnel @a t now, without delay. Used during shutdown.
+ *
+ * @param t tunnel to destroy
+ */
+void
+GCT_destroy_tunnel_now (struct CadetTunnel *t);
+
+
 /**
  * Add a @a connection to the @a tunnel.
  *