From e6b80ab7b7de86928aafb7ccfd39a2019f256fd6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 22 Jan 2017 00:10:26 +0100 Subject: [PATCH] ensure tunnels are shutdown at the right time during shutdown --- src/cadet/cadet.conf.in | 2 +- src/cadet/gnunet-service-cadet-new.c | 29 +++++++++++++++++++- src/cadet/gnunet-service-cadet-new_tunnels.c | 15 ++++++++++ src/cadet/gnunet-service-cadet-new_tunnels.h | 9 ++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/cadet/cadet.conf.in b/src/cadet/cadet.conf.in index 1ee830dbf..88f49fde8 100644 --- a/src/cadet/cadet.conf.in +++ b/src/cadet/cadet.conf.in @@ -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 diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index 6ba0df69e..ff143b4b3 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -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) { diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c index 73bbaf042..06c98fcee 100644 --- a/src/cadet/gnunet-service-cadet-new_tunnels.c +++ b/src/cadet/gnunet-service-cadet-new_tunnels.c @@ -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. * diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.h b/src/cadet/gnunet-service-cadet-new_tunnels.h index 3c88ae5f0..c867a9e82 100644 --- a/src/cadet/gnunet-service-cadet-new_tunnels.h +++ b/src/cadet/gnunet-service-cadet-new_tunnels.h @@ -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. * -- 2.25.1