diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-16 19:31:31 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-16 19:31:40 +0100 |
commit | e66a9b07d76995c00dab4c62ef22c73d2a3d7aaf (patch) | |
tree | 669832e718b17f957c596b9fb0ccfc6e232ef7d1 /src/cadet/gnunet-service-cadet-new_peer.c | |
parent | 64ae3fa79fb69de77eee7497922af2f79cbf7de4 (diff) | |
download | gnunet-e66a9b07d76995c00dab4c62ef22c73d2a3d7aaf.tar.gz gnunet-e66a9b07d76995c00dab4c62ef22c73d2a3d7aaf.zip |
finish logic to maintain paths
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_peer.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet-new_peer.c | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c index 8c8b23820..9878c540e 100644 --- a/src/cadet/gnunet-service-cadet-new_peer.c +++ b/src/cadet/gnunet-service-cadet-new_peer.c | |||
@@ -385,19 +385,22 @@ GCP_path_entry_remove (struct CadetPeer *cp, | |||
385 | * has plenty of paths, return NULL. | 385 | * has plenty of paths, return NULL. |
386 | * | 386 | * |
387 | * @param cp peer to which the @a path leads to | 387 | * @param cp peer to which the @a path leads to |
388 | * @param path a path looking for an owner | 388 | * @param path a path looking for an owner; may not be fully initialized yet! |
389 | * @param off offset of @a cp in @a path | ||
389 | * @return NULL if this peer does not care to become a new owner, | 390 | * @return NULL if this peer does not care to become a new owner, |
390 | * otherwise the node in the peer's path heap for the @a path. | 391 | * otherwise the node in the peer's path heap for the @a path. |
391 | */ | 392 | */ |
392 | struct GNUNET_CONTAINER_HeapNode * | 393 | struct GNUNET_CONTAINER_HeapNode * |
393 | GCP_attach_path (struct CadetPeer *cp, | 394 | GCP_attach_path (struct CadetPeer *cp, |
394 | struct CadetPeerPath *path) | 395 | struct CadetPeerPath *path, |
396 | unsigned int off) | ||
395 | { | 397 | { |
396 | GNUNET_CONTAINER_HeapCostType desirability; | 398 | GNUNET_CONTAINER_HeapCostType desirability; |
397 | struct CadetPeerPath *root; | 399 | struct CadetPeerPath *root; |
398 | GNUNET_CONTAINER_HeapCostType root_desirability; | 400 | GNUNET_CONTAINER_HeapCostType root_desirability; |
399 | struct GNUNET_CONTAINER_HeapNode *hn; | 401 | struct GNUNET_CONTAINER_HeapNode *hn; |
400 | 402 | ||
403 | /* FIXME: desirability is not yet initialized; tricky! */ | ||
401 | desirability = GCPP_get_desirability (path); | 404 | desirability = GCPP_get_desirability (path); |
402 | if (GNUNET_NO == | 405 | if (GNUNET_NO == |
403 | GNUNET_CONTAINER_heap_peek2 (cp->path_heap, | 406 | GNUNET_CONTAINER_heap_peek2 (cp->path_heap, |
@@ -443,24 +446,21 @@ GCP_attach_path (struct CadetPeer *cp, | |||
443 | 446 | ||
444 | 447 | ||
445 | /** | 448 | /** |
446 | * Function called when the DHT finds a @a path to the peer (@a cls). | 449 | * This peer can no longer own @a path as the path |
450 | * has been extended and a peer further down the line | ||
451 | * is now the new owner. | ||
447 | * | 452 | * |
448 | * @param cls the `struct CadetPeer` | 453 | * @param cp old owner of the @a path |
449 | * @param path the path that was found | 454 | * @param path path where the ownership is lost |
455 | * @param hn note in @a cp's path heap that must be deleted | ||
450 | */ | 456 | */ |
451 | static void | 457 | void |
452 | dht_result_cb (void *cls, | 458 | GCP_detach_path (struct CadetPeer *cp, |
453 | struct CadetPeerPath *path) | 459 | struct CadetPeerPath *path, |
460 | struct GNUNET_CONTAINER_HeapNode *hn) | ||
454 | { | 461 | { |
455 | struct CadetPeer *cp = cls; | 462 | GNUNET_assert (path == |
456 | struct GNUNET_CONTAINER_HeapNode *hn; | 463 | GNUNET_CONTAINER_heap_remove_node (hn)); |
457 | |||
458 | hn = GCP_attach_path (cp, | ||
459 | path); | ||
460 | if (NULL == hn) | ||
461 | return; | ||
462 | GCPP_acquire (path, | ||
463 | hn); | ||
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
@@ -502,9 +502,7 @@ consider_peer_activate (struct CadetPeer *cp) | |||
502 | if ( (NULL == cp->search_h) && | 502 | if ( (NULL == cp->search_h) && |
503 | (DESIRED_CONNECTIONS_PER_TUNNEL < cp->num_paths) ) | 503 | (DESIRED_CONNECTIONS_PER_TUNNEL < cp->num_paths) ) |
504 | cp->search_h | 504 | cp->search_h |
505 | = GCD_search (&cp->pid, | 505 | = GCD_search (&cp->pid); |
506 | &dht_result_cb, | ||
507 | cp); | ||
508 | } | 506 | } |
509 | else | 507 | else |
510 | { | 508 | { |
@@ -640,6 +638,41 @@ GCP_iterate_paths (struct CadetPeer *peer, | |||
640 | 638 | ||
641 | 639 | ||
642 | /** | 640 | /** |
641 | * Iterate over the paths to @a peer where | ||
642 | * @a peer is at distance @a dist from us. | ||
643 | * | ||
644 | * @param peer Peer to get path info. | ||
645 | * @param dist desired distance of @a peer to us on the path | ||
646 | * @param callback Function to call for every path. | ||
647 | * @param callback_cls Closure for @a callback. | ||
648 | * @return Number of iterated paths. | ||
649 | */ | ||
650 | unsigned int | ||
651 | GCP_iterate_paths_at (struct CadetPeer *peer, | ||
652 | unsigned int dist, | ||
653 | GCP_PathIterator callback, | ||
654 | void *callback_cls) | ||
655 | { | ||
656 | unsigned int ret = 0; | ||
657 | |||
658 | if (dist<peer->path_dll_length) | ||
659 | return 0; | ||
660 | for (struct CadetPeerPathEntry *pe = peer->path_heads[dist]; | ||
661 | NULL != pe; | ||
662 | pe = pe->next) | ||
663 | { | ||
664 | if (GNUNET_NO == | ||
665 | callback (callback_cls, | ||
666 | pe->path, | ||
667 | dist)) | ||
668 | return ret; | ||
669 | ret++; | ||
670 | } | ||
671 | return ret; | ||
672 | } | ||
673 | |||
674 | |||
675 | /** | ||
643 | * Get the tunnel towards a peer. | 676 | * Get the tunnel towards a peer. |
644 | * | 677 | * |
645 | * @param peer Peer to get from. | 678 | * @param peer Peer to get from. |