From: Christian Grothoff Date: Wed, 1 Feb 2017 19:49:52 +0000 (+0100) Subject: preserve invariants while calling GCP_detatch_path while reorging paths X-Git-Tag: taler-0.2.1~204 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9ebc9fc29aa2626359cc88679baee38f2e31e4de;p=oweals%2Fgnunet.git preserve invariants while calling GCP_detatch_path while reorging paths --- diff --git a/src/cadet/gnunet-service-cadet-new_paths.c b/src/cadet/gnunet-service-cadet-new_paths.c index e2d8da687..14e7b75d5 100644 --- a/src/cadet/gnunet-service-cadet-new_paths.c +++ b/src/cadet/gnunet-service-cadet-new_paths.c @@ -233,6 +233,7 @@ GCPP_release (struct CadetPeerPath *path) GCPP_2s (path)); path->hn = NULL; entry = path->entries[path->entries_length - 1]; + GNUNET_assert (path == entry->path); while (1) { /* cut 'off' end of path */ @@ -247,6 +248,7 @@ GCPP_release (struct CadetPeerPath *path) /* see if new peer at the end likes this path any better */ entry = path->entries[path->entries_length - 1]; + GNUNET_assert (path == entry->path); path->hn = GCP_attach_path (entry->peer, path, path->entries_length - 1, @@ -386,7 +388,6 @@ extend_path (struct CadetPeerPath *path, int force) { unsigned int old_len = path->entries_length; - struct GNUNET_CONTAINER_HeapNode *hn; int i; /* Expand path */ @@ -412,18 +413,21 @@ extend_path (struct CadetPeerPath *path, /* If we extend an existing path, detach it from the old owner and re-attach to the new one */ - hn = NULL; + GCP_detach_path (path->entries[old_len-1]->peer, + path, + path->hn); + path->hn = NULL; for (i=num_peers-1;i>=0;i--) { struct CadetPeerPathEntry *entry = path->entries[old_len + i]; path->entries_length = old_len + i + 1; recalculate_path_desirability (path); - hn = GCP_attach_path (peers[i], - path, - old_len + (unsigned int) i, - GNUNET_YES); - if (NULL != hn) + path->hn = GCP_attach_path (peers[i], + path, + old_len + (unsigned int) i, + GNUNET_NO); + if (NULL != path->hn) break; GCP_path_entry_remove (entry->peer, entry, @@ -431,19 +435,20 @@ extend_path (struct CadetPeerPath *path, GNUNET_free (entry); path->entries[old_len + i] = NULL; } - if (NULL == hn) + if (NULL == path->hn) { /* none of the peers is interested in this path; - shrink path back */ + shrink path back and re-attach. */ GNUNET_array_grow (path->entries, path->entries_length, old_len); + path->hn = GCP_attach_path (path->entries[old_len - 1]->peer, + path, + old_len - 1, + GNUNET_YES); + GNUNET_assert (NULL != path->hn); return; } - GCP_detach_path (path->entries[old_len-1]->peer, - path, - path->hn); - path->hn = hn; LOG (GNUNET_ERROR_TYPE_DEBUG, "Extended path %s\n", GCPP_2s (path)); diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c index 070a0ac15..136ab8297 100644 --- a/src/cadet/gnunet-service-cadet-new_peer.c +++ b/src/cadet/gnunet-service-cadet-new_peer.c @@ -913,6 +913,7 @@ GCP_attach_path (struct CadetPeer *cp, GNUNET_CONTAINER_HeapCostType root_desirability; struct GNUNET_CONTAINER_HeapNode *hn; + GNUNET_assert (off == GCPP_get_length (path) - 1); GNUNET_assert (cp == GCPP_get_peer_at_offset (path, off)); if (NULL == cp->path_heap) @@ -972,7 +973,7 @@ GCP_attach_path (struct CadetPeer *cp, GCPP_get_length (root) - 1)) ) { /* Got plenty of paths to this destination, and this is a low-quality - one that we don't care, allow it to die. */ + one that we don't care about. Allow it to die. */ GNUNET_assert (root == GNUNET_CONTAINER_heap_remove_root (cp->path_heap)); GCPP_release (root);