aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-01 20:49:52 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-01 20:49:52 +0100
commit9ebc9fc29aa2626359cc88679baee38f2e31e4de (patch)
tree65bb564f761fbfb1f87b3ed0920c0f846c449316
parent7c8c596991f6397ec3ca1911638acb2de721c7a7 (diff)
downloadgnunet-9ebc9fc29aa2626359cc88679baee38f2e31e4de.tar.gz
gnunet-9ebc9fc29aa2626359cc88679baee38f2e31e4de.zip
preserve invariants while calling GCP_detatch_path while reorging paths
-rw-r--r--src/cadet/gnunet-service-cadet-new_paths.c31
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.c3
2 files changed, 20 insertions, 14 deletions
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)
233 GCPP_2s (path)); 233 GCPP_2s (path));
234 path->hn = NULL; 234 path->hn = NULL;
235 entry = path->entries[path->entries_length - 1]; 235 entry = path->entries[path->entries_length - 1];
236 GNUNET_assert (path == entry->path);
236 while (1) 237 while (1)
237 { 238 {
238 /* cut 'off' end of path */ 239 /* cut 'off' end of path */
@@ -247,6 +248,7 @@ GCPP_release (struct CadetPeerPath *path)
247 248
248 /* see if new peer at the end likes this path any better */ 249 /* see if new peer at the end likes this path any better */
249 entry = path->entries[path->entries_length - 1]; 250 entry = path->entries[path->entries_length - 1];
251 GNUNET_assert (path == entry->path);
250 path->hn = GCP_attach_path (entry->peer, 252 path->hn = GCP_attach_path (entry->peer,
251 path, 253 path,
252 path->entries_length - 1, 254 path->entries_length - 1,
@@ -386,7 +388,6 @@ extend_path (struct CadetPeerPath *path,
386 int force) 388 int force)
387{ 389{
388 unsigned int old_len = path->entries_length; 390 unsigned int old_len = path->entries_length;
389 struct GNUNET_CONTAINER_HeapNode *hn;
390 int i; 391 int i;
391 392
392 /* Expand path */ 393 /* Expand path */
@@ -412,18 +413,21 @@ extend_path (struct CadetPeerPath *path,
412 413
413 /* If we extend an existing path, detach it from the 414 /* If we extend an existing path, detach it from the
414 old owner and re-attach to the new one */ 415 old owner and re-attach to the new one */
415 hn = NULL; 416 GCP_detach_path (path->entries[old_len-1]->peer,
417 path,
418 path->hn);
419 path->hn = NULL;
416 for (i=num_peers-1;i>=0;i--) 420 for (i=num_peers-1;i>=0;i--)
417 { 421 {
418 struct CadetPeerPathEntry *entry = path->entries[old_len + i]; 422 struct CadetPeerPathEntry *entry = path->entries[old_len + i];
419 423
420 path->entries_length = old_len + i + 1; 424 path->entries_length = old_len + i + 1;
421 recalculate_path_desirability (path); 425 recalculate_path_desirability (path);
422 hn = GCP_attach_path (peers[i], 426 path->hn = GCP_attach_path (peers[i],
423 path, 427 path,
424 old_len + (unsigned int) i, 428 old_len + (unsigned int) i,
425 GNUNET_YES); 429 GNUNET_NO);
426 if (NULL != hn) 430 if (NULL != path->hn)
427 break; 431 break;
428 GCP_path_entry_remove (entry->peer, 432 GCP_path_entry_remove (entry->peer,
429 entry, 433 entry,
@@ -431,19 +435,20 @@ extend_path (struct CadetPeerPath *path,
431 GNUNET_free (entry); 435 GNUNET_free (entry);
432 path->entries[old_len + i] = NULL; 436 path->entries[old_len + i] = NULL;
433 } 437 }
434 if (NULL == hn) 438 if (NULL == path->hn)
435 { 439 {
436 /* none of the peers is interested in this path; 440 /* none of the peers is interested in this path;
437 shrink path back */ 441 shrink path back and re-attach. */
438 GNUNET_array_grow (path->entries, 442 GNUNET_array_grow (path->entries,
439 path->entries_length, 443 path->entries_length,
440 old_len); 444 old_len);
445 path->hn = GCP_attach_path (path->entries[old_len - 1]->peer,
446 path,
447 old_len - 1,
448 GNUNET_YES);
449 GNUNET_assert (NULL != path->hn);
441 return; 450 return;
442 } 451 }
443 GCP_detach_path (path->entries[old_len-1]->peer,
444 path,
445 path->hn);
446 path->hn = hn;
447 LOG (GNUNET_ERROR_TYPE_DEBUG, 452 LOG (GNUNET_ERROR_TYPE_DEBUG,
448 "Extended path %s\n", 453 "Extended path %s\n",
449 GCPP_2s (path)); 454 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,
913 GNUNET_CONTAINER_HeapCostType root_desirability; 913 GNUNET_CONTAINER_HeapCostType root_desirability;
914 struct GNUNET_CONTAINER_HeapNode *hn; 914 struct GNUNET_CONTAINER_HeapNode *hn;
915 915
916 GNUNET_assert (off == GCPP_get_length (path) - 1);
916 GNUNET_assert (cp == GCPP_get_peer_at_offset (path, 917 GNUNET_assert (cp == GCPP_get_peer_at_offset (path,
917 off)); 918 off));
918 if (NULL == cp->path_heap) 919 if (NULL == cp->path_heap)
@@ -972,7 +973,7 @@ GCP_attach_path (struct CadetPeer *cp,
972 GCPP_get_length (root) - 1)) ) 973 GCPP_get_length (root) - 1)) )
973 { 974 {
974 /* Got plenty of paths to this destination, and this is a low-quality 975 /* Got plenty of paths to this destination, and this is a low-quality
975 one that we don't care, allow it to die. */ 976 one that we don't care about. Allow it to die. */
976 GNUNET_assert (root == 977 GNUNET_assert (root ==
977 GNUNET_CONTAINER_heap_remove_root (cp->path_heap)); 978 GNUNET_CONTAINER_heap_remove_root (cp->path_heap));
978 GCPP_release (root); 979 GCPP_release (root);