aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-22 16:33:01 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-22 16:33:01 +0100
commitf74bc79fcea9c0ecb5dc0af8e49764fd31e34d4d (patch)
treec5f0e066abaee41b47f1d682e38449d4f65168c9
parentceb48e10d23bd38df68d6487d0d0b1d85c7f9ba7 (diff)
downloadgnunet-f74bc79fcea9c0ecb5dc0af8e49764fd31e34d4d.tar.gz
gnunet-f74bc79fcea9c0ecb5dc0af8e49764fd31e34d4d.zip
fix shutdown logic
-rw-r--r--src/cadet/gnunet-service-cadet-new.c24
-rw-r--r--src/cadet/gnunet-service-cadet-new_core.c3
-rw-r--r--src/cadet/gnunet-service-cadet-new_paths.c15
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.c43
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.h10
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c6
6 files changed, 80 insertions, 21 deletions
diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c
index b0d8fc32d..2e431c034 100644
--- a/src/cadet/gnunet-service-cadet-new.c
+++ b/src/cadet/gnunet-service-cadet-new.c
@@ -335,6 +335,27 @@ destroy_tunnels_now (void *cls,
335 335
336 336
337/** 337/**
338 * Callback invoked on all peers to destroy all tunnels
339 * that may still exist.
340 *
341 * @param cls NULL
342 * @param pid identify of a peer
343 * @param value a `struct CadetPeer` that may still have a tunnel
344 * @return #GNUNET_OK (iterate over all entries)
345 */
346static int
347destroy_paths_now (void *cls,
348 const struct GNUNET_PeerIdentity *pid,
349 void *value)
350{
351 struct CadetPeer *cp = value;
352
353 GCP_drop_owned_paths (cp);
354 return GNUNET_OK;
355}
356
357
358/**
338 * Task run during shutdown. 359 * Task run during shutdown.
339 * 360 *
340 * @param cls unused 361 * @param cls unused
@@ -366,6 +387,9 @@ shutdown_task (void *cls)
366 GCP_iterate_all (&destroy_tunnels_now, 387 GCP_iterate_all (&destroy_tunnels_now,
367 NULL); 388 NULL);
368 /* All tunnels, channels, connections and CORE must be down before this point. */ 389 /* All tunnels, channels, connections and CORE must be down before this point. */
390 GCP_iterate_all (&destroy_paths_now,
391 NULL);
392 /* All paths, tunnels, channels, connections and CORE must be down before this point. */
369 GCP_destroy_all_peers (); 393 GCP_destroy_all_peers ();
370 if (NULL != peers) 394 if (NULL != peers)
371 { 395 {
diff --git a/src/cadet/gnunet-service-cadet-new_core.c b/src/cadet/gnunet-service-cadet-new_core.c
index 7cff68f4a..1e35a5102 100644
--- a/src/cadet/gnunet-service-cadet-new_core.c
+++ b/src/cadet/gnunet-service-cadet-new_core.c
@@ -476,7 +476,8 @@ handle_connection_create (void *cls,
476 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 476 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
477 path = GCPP_get_path_from_route (path_length - 1, 477 path = GCPP_get_path_from_route (path_length - 1,
478 pids); 478 pids);
479 GCT_add_inbound_connection (GCT_create_tunnel (origin), 479 GCT_add_inbound_connection (GCP_get_tunnel (origin,
480 GNUNET_YES),
480 &msg->cid, 481 &msg->cid,
481 path); 482 path);
482 return; 483 return;
diff --git a/src/cadet/gnunet-service-cadet-new_paths.c b/src/cadet/gnunet-service-cadet-new_paths.c
index d0df2a1f4..39658d4e8 100644
--- a/src/cadet/gnunet-service-cadet-new_paths.c
+++ b/src/cadet/gnunet-service-cadet-new_paths.c
@@ -55,13 +55,6 @@ struct CadetPeerPath
55 struct GNUNET_CONTAINER_HeapNode *hn; 55 struct GNUNET_CONTAINER_HeapNode *hn;
56 56
57 /** 57 /**
58 * Connections using this path, by destination peer
59 * (each hop of the path could correspond to an
60 * active connection).
61 */
62 struct GNUNET_CONTAINER_MultiPeerMap *connections;
63
64 /**
65 * Desirability of the path. How unique is it for the various peers 58 * Desirability of the path. How unique is it for the various peers
66 * on it? 59 * on it?
67 */ 60 */
@@ -185,9 +178,6 @@ path_destroy (struct CadetPeerPath *path)
185 LOG (GNUNET_ERROR_TYPE_DEBUG, 178 LOG (GNUNET_ERROR_TYPE_DEBUG,
186 "Destroying path %s\n", 179 "Destroying path %s\n",
187 GCPP_2s (path)); 180 GCPP_2s (path));
188 GNUNET_assert (0 ==
189 GNUNET_CONTAINER_multipeermap_size (path->connections));
190 GNUNET_CONTAINER_multipeermap_destroy (path->connections);
191 for (unsigned int i=0;i<path->entries_length;i++) 181 for (unsigned int i=0;i<path->entries_length;i++)
192 GNUNET_free (path->entries[i]); 182 GNUNET_free (path->entries[i]);
193 GNUNET_free (path->entries); 183 GNUNET_free (path->entries);
@@ -214,10 +204,7 @@ GCPP_release (struct CadetPeerPath *path)
214 entry = path->entries[path->entries_length - 1]; 204 entry = path->entries[path->entries_length - 1];
215 while (1) 205 while (1)
216 { 206 {
217 /* cut 'off' end of path, verifying it is not in use */ 207 /* cut 'off' end of path */
218 GNUNET_assert (NULL ==
219 GNUNET_CONTAINER_multipeermap_get (path->connections,
220 GCP_get_id (entry->peer)));
221 GCP_path_entry_remove (entry->peer, 208 GCP_path_entry_remove (entry->peer,
222 entry, 209 entry,
223 path->entries_length - 1); 210 path->entries_length - 1);
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c
index fa1cc9ed9..1505914a1 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.c
+++ b/src/cadet/gnunet-service-cadet-new_peer.c
@@ -40,7 +40,6 @@
40#include "gnunet_core_service.h" 40#include "gnunet_core_service.h"
41#include "gnunet_statistics_service.h" 41#include "gnunet_statistics_service.h"
42#include "cadet_protocol.h" 42#include "cadet_protocol.h"
43#include "cadet_path.h"
44#include "gnunet-service-cadet-new.h" 43#include "gnunet-service-cadet-new.h"
45#include "gnunet-service-cadet-new_connection.h" 44#include "gnunet-service-cadet-new_connection.h"
46#include "gnunet-service-cadet-new_dht.h" 45#include "gnunet-service-cadet-new_dht.h"
@@ -257,7 +256,8 @@ destroy_peer (void *cls)
257 cp->destroy_task = NULL; 256 cp->destroy_task = NULL;
258 GNUNET_assert (NULL == cp->t); 257 GNUNET_assert (NULL == cp->t);
259 GNUNET_assert (NULL == cp->core_mq); 258 GNUNET_assert (NULL == cp->core_mq);
260 GNUNET_assert (0 == cp->path_dll_length); 259 for (unsigned int i=0;i<cp->path_dll_length;i++)
260 GNUNET_assert (NULL == cp->path_heads[i]);
261 GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)); 261 GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections));
262 GNUNET_assert (GNUNET_YES == 262 GNUNET_assert (GNUNET_YES ==
263 GNUNET_CONTAINER_multipeermap_remove (peers, 263 GNUNET_CONTAINER_multipeermap_remove (peers,
@@ -284,7 +284,11 @@ destroy_peer (void *cls)
284 cp->connectivity_suggestion = NULL; 284 cp->connectivity_suggestion = NULL;
285 } 285 }
286 GNUNET_CONTAINER_multishortmap_destroy (cp->connections); 286 GNUNET_CONTAINER_multishortmap_destroy (cp->connections);
287 GNUNET_CONTAINER_heap_destroy (cp->path_heap); 287 if (NULL != cp->path_heap)
288 {
289 GNUNET_CONTAINER_heap_destroy (cp->path_heap);
290 cp->path_heap = NULL;
291 }
288 GNUNET_free_non_null (cp->hello); 292 GNUNET_free_non_null (cp->hello);
289 /* Peer should not be freed if paths exist; if there are no paths, 293 /* Peer should not be freed if paths exist; if there are no paths,
290 there ought to be no connections, and without connections, no 294 there ought to be no connections, and without connections, no
@@ -418,8 +422,9 @@ consider_peer_destroy (struct CadetPeer *cp)
418 cp); 422 cp);
419 return; 423 return;
420 } 424 }
421 if (0 < cp->path_dll_length) 425 for (unsigned int i=0;i<cp->path_dll_length;i++)
422 return; /* still relevant! */ 426 if (NULL != cp->path_heads[i])
427 return; /* still relevant! */
423 if (NULL != cp->hello) 428 if (NULL != cp->hello)
424 { 429 {
425 /* relevant only until HELLO expires */ 430 /* relevant only until HELLO expires */
@@ -628,6 +633,28 @@ GCP_destroy_all_peers ()
628 633
629 634
630/** 635/**
636 * Drop all paths owned by this peer, and do not
637 * allow new ones to be added: We are shutting down.
638 *
639 * @param cp peer to drop paths to
640 */
641void
642GCP_drop_owned_paths (struct CadetPeer *cp)
643{
644 struct CadetPeerPath *path;
645
646 LOG (GNUNET_ERROR_TYPE_DEBUG,
647 "Destroying all paths to %s\n",
648 GCP_2s (cp));
649 while (NULL != (path =
650 GNUNET_CONTAINER_heap_remove_root (cp->path_heap)))
651 GCPP_release (path);
652 GNUNET_CONTAINER_heap_destroy (cp->path_heap);
653 cp->path_heap = NULL;
654}
655
656
657/**
631 * Add an entry to the DLL of all of the paths that this peer is on. 658 * Add an entry to the DLL of all of the paths that this peer is on.
632 * 659 *
633 * @param cp peer to modify 660 * @param cp peer to modify
@@ -730,6 +757,12 @@ GCP_attach_path (struct CadetPeer *cp,
730 GNUNET_CONTAINER_HeapCostType root_desirability; 757 GNUNET_CONTAINER_HeapCostType root_desirability;
731 struct GNUNET_CONTAINER_HeapNode *hn; 758 struct GNUNET_CONTAINER_HeapNode *hn;
732 759
760 if (NULL == cp->path_heap)
761 {
762 /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */
763 GNUNET_assert (GNUNET_NO == force);
764 return NULL;
765 }
733 desirability = GCPP_get_desirability (path); 766 desirability = GCPP_get_desirability (path);
734 if (GNUNET_NO == force) 767 if (GNUNET_NO == force)
735 { 768 {
diff --git a/src/cadet/gnunet-service-cadet-new_peer.h b/src/cadet/gnunet-service-cadet-new_peer.h
index 8a1d3ed5c..aaaef15b8 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.h
+++ b/src/cadet/gnunet-service-cadet-new_peer.h
@@ -91,6 +91,16 @@ GCP_count_paths (const struct CadetPeer *cp);
91 91
92 92
93/** 93/**
94 * Drop all paths owned by this peer, and do not
95 * allow new ones to be added: We are shutting down.
96 *
97 * @param cp peer to drop paths to
98 */
99void
100GCP_drop_owned_paths (struct CadetPeer *cp);
101
102
103/**
94 * Peer path iterator. 104 * Peer path iterator.
95 * 105 *
96 * @param cls Closure. 106 * @param cls Closure.
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index 1afa451ec..a1a7b80fd 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -1601,7 +1601,11 @@ GCT_destroy_tunnel_now (struct CadetTunnel *t)
1601{ 1601{
1602 GNUNET_assert (0 == 1602 GNUNET_assert (0 ==
1603 GNUNET_CONTAINER_multihashmap32_size (t->channels)); 1603 GNUNET_CONTAINER_multihashmap32_size (t->channels));
1604 GNUNET_SCHEDULER_cancel (t->destroy_task); 1604 if (NULL != t->destroy_task)
1605 {
1606 GNUNET_SCHEDULER_cancel (t->destroy_task);
1607 t->destroy_task = NULL;
1608 }
1605 destroy_tunnel (t); 1609 destroy_tunnel (t);
1606} 1610}
1607 1611