diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-06-12 15:57:53 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-06-12 15:57:53 +0000 |
commit | 8ebccaa1b926a4fe1cbe2f4b2cd2089cc8e666a0 (patch) | |
tree | efc96529b56b147a1f96f535265f7322a3e402ec | |
parent | 5037ac322b2fcfa1bf8beca205173e5c2f6b35b3 (diff) | |
download | gnunet-8ebccaa1b926a4fe1cbe2f4b2cd2089cc8e666a0.tar.gz gnunet-8ebccaa1b926a4fe1cbe2f4b2cd2089cc8e666a0.zip |
Xvine_DHT: Minor fixes
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 426 |
1 files changed, 235 insertions, 191 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 9c28d6851..ba4d13a56 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -53,6 +53,11 @@ | |||
53 | * 2. Now souce and destination of a trail also stores the trail entries for | 53 | * 2. Now souce and destination of a trail also stores the trail entries for |
54 | * which they are end point. Make these changes in case of gds_routing_add() | 54 | * which they are end point. Make these changes in case of gds_routing_add() |
55 | * 3. Should we append xvine in message which are of xvine dht? | 55 | * 3. Should we append xvine in message which are of xvine dht? |
56 | * 4. make sure you are adding trail for end point of trail everywhere. | ||
57 | * 5. Should we increment the trail count of a friend which is a finger. | ||
58 | * 6. You have two variables - current_search_finger_index and finger map index | ||
59 | * , now you need to understand should you update current_search_finger_index | ||
60 | * based on finger map index. Make these two variables clear in their functionality. | ||
56 | */ | 61 | */ |
57 | 62 | ||
58 | /** | 63 | /** |
@@ -762,7 +767,7 @@ struct FingerInfo | |||
762 | /** | 767 | /** |
763 | * Index in finger peer map | 768 | * Index in finger peer map |
764 | */ | 769 | */ |
765 | uint32_t finger_map_index; | 770 | uint32_t finger_table_index; |
766 | 771 | ||
767 | /** | 772 | /** |
768 | * Number of trails setup so far for this finger. | 773 | * Number of trails setup so far for this finger. |
@@ -1793,27 +1798,27 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1, | |||
1793 | */ | 1798 | */ |
1794 | /** | 1799 | /** |
1795 | * Select the closest peer among two peers (which should not be same) | 1800 | * Select the closest peer among two peers (which should not be same) |
1796 | * with respect to value and finger_map_index | 1801 | * with respect to value and finger_table_index |
1797 | * @param peer1 First peer | 1802 | * @param peer1 First peer |
1798 | * @param peer2 Second peer | 1803 | * @param peer2 Second peer |
1799 | * @param value Value relative to which we find the closest | 1804 | * @param value Value relative to which we find the closest |
1800 | * @param finger_map_index Index in finger map. If equal to PREDECESSOR_FINGER_ID, | 1805 | * @param finger_table_index Index in finger map. If equal to PREDECESSOR_FINGER_ID, |
1801 | * then we use different logic than other | 1806 | * then we use different logic than other |
1802 | * finger_map_index | 1807 | * finger_table_index |
1803 | * @return Closest peer among two peers. | 1808 | * @return Closest peer among two peers. |
1804 | */ | 1809 | */ |
1805 | static struct GNUNET_PeerIdentity * | 1810 | static struct GNUNET_PeerIdentity * |
1806 | select_closest_peer (struct GNUNET_PeerIdentity *peer1, | 1811 | select_closest_peer (struct GNUNET_PeerIdentity *peer1, |
1807 | struct GNUNET_PeerIdentity *peer2, | 1812 | struct GNUNET_PeerIdentity *peer2, |
1808 | uint64_t value, | 1813 | uint64_t value, |
1809 | unsigned int finger_map_index) | 1814 | unsigned int finger_table_index) |
1810 | { | 1815 | { |
1811 | struct GNUNET_PeerIdentity *closest_peer; | 1816 | struct GNUNET_PeerIdentity *closest_peer; |
1812 | /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id) | 1817 | /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id) |
1813 | and [current_successor->id, friend_id). Check in which range value lies. | 1818 | and [current_successor->id, friend_id). Check in which range value lies. |
1814 | Also, check for wrap around. Set the value of current_successor accordingly.*/ | 1819 | Also, check for wrap around. Set the value of current_successor accordingly.*/ |
1815 | 1820 | ||
1816 | if (PREDECESSOR_FINGER_ID == finger_map_index) | 1821 | if (PREDECESSOR_FINGER_ID == finger_table_index) |
1817 | closest_peer = select_closest_predecessor (peer1, peer2, value); | 1822 | closest_peer = select_closest_predecessor (peer1, peer2, value); |
1818 | else | 1823 | else |
1819 | closest_peer = select_closest_finger (peer1, peer2, value); | 1824 | closest_peer = select_closest_finger (peer1, peer2, value); |
@@ -1844,6 +1849,9 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1844 | { | 1849 | { |
1845 | finger = &finger_table[i]; | 1850 | finger = &finger_table[i]; |
1846 | 1851 | ||
1852 | if (GNUNET_NO == finger->is_present) | ||
1853 | continue; | ||
1854 | |||
1847 | /* If I am my own finger, then ignore this finger. */ | 1855 | /* If I am my own finger, then ignore this finger. */ |
1848 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1856 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1849 | &my_identity)) | 1857 | &my_identity)) |
@@ -1851,12 +1859,16 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1851 | 1859 | ||
1852 | /* If finger is friend. */ | 1860 | /* If finger is friend. */ |
1853 | if (NULL != (friend = GNUNET_CONTAINER_multipeermap_get | 1861 | if (NULL != (friend = GNUNET_CONTAINER_multipeermap_get |
1854 | (friend_peermap, &finger->finger_identity))) | 1862 | (friend_peermap, &finger->finger_identity))) |
1855 | { | 1863 | { |
1856 | if (GNUNET_YES == is_friend_congested (friend)) | 1864 | if (GNUNET_YES == is_friend_congested (friend)) |
1857 | continue; | 1865 | continue; |
1858 | 1866 | ||
1859 | /* If not congested then compare it with current_successor. */ | 1867 | /* If not congested then compare it with current_successor. */ |
1868 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | ||
1869 | ¤t_closest_peer->best_known_destination)) | ||
1870 | continue; | ||
1871 | |||
1860 | closest_peer = select_closest_peer (&finger->finger_identity, | 1872 | closest_peer = select_closest_peer (&finger->finger_identity, |
1861 | ¤t_closest_peer->best_known_destination, | 1873 | ¤t_closest_peer->best_known_destination, |
1862 | current_closest_peer->destination_finger_value, | 1874 | current_closest_peer->destination_finger_value, |
@@ -1956,6 +1968,7 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity, | |||
1956 | 1968 | ||
1957 | 1969 | ||
1958 | /** | 1970 | /** |
1971 | * FIXME: first check if the finger == closest_peer then don't do anything. | ||
1959 | * Find the successor for destination_finger_value among my_identity, all my | 1972 | * Find the successor for destination_finger_value among my_identity, all my |
1960 | * friend and all my fingers. Don't consider friends or fingers | 1973 | * friend and all my fingers. Don't consider friends or fingers |
1961 | * which are congested or have crossed the threshold. | 1974 | * which are congested or have crossed the threshold. |
@@ -2413,7 +2426,6 @@ send_find_finger_trail_message (void *cls, | |||
2413 | 2426 | ||
2414 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 2427 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
2415 | &trail_id, sizeof (trail_id)); | 2428 | &trail_id, sizeof (trail_id)); |
2416 | |||
2417 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, | 2429 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, |
2418 | target_friend->id, target_friend, 0, NULL, | 2430 | target_friend->id, target_friend, 0, NULL, |
2419 | is_predecessor, trail_id, NULL); | 2431 | is_predecessor, trail_id, NULL); |
@@ -2607,6 +2619,14 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2607 | If it is NULL, it means that path is broken, then remove the trail. | 2619 | If it is NULL, it means that path is broken, then remove the trail. |
2608 | return a value to calling function so that if all trails are removed, | 2620 | return a value to calling function so that if all trails are removed, |
2609 | then remove finger. */ | 2621 | then remove finger. */ |
2622 | /* We should decerement the friend trail count here. */ | ||
2623 | struct FriendInfo *friend; | ||
2624 | |||
2625 | GNUNET_assert (NULL != (friend = | ||
2626 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2627 | &trail->trail_head->peer))); | ||
2628 | |||
2629 | friend->trails_count--; | ||
2610 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, | 2630 | GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, |
2611 | GDS_ROUTING_SRC_TO_DEST, | 2631 | GDS_ROUTING_SRC_TO_DEST, |
2612 | &trail->trail_head->peer); | 2632 | &trail->trail_head->peer); |
@@ -2620,58 +2640,18 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2620 | static void | 2640 | static void |
2621 | send_all_finger_trails_teardown (struct FingerInfo *finger) | 2641 | send_all_finger_trails_teardown (struct FingerInfo *finger) |
2622 | { | 2642 | { |
2623 | struct Trail *trail_list_iterator; | 2643 | struct Trail *trail; |
2624 | int i; | 2644 | int i; |
2625 | 2645 | ||
2626 | /* FIXME: here we should check if we really need this check or not. | ||
2627 | because the calling function should have checked this already. Verify*/ | ||
2628 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, &my_identity) | ||
2629 | || (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2630 | &finger->finger_identity))) | ||
2631 | return; | ||
2632 | |||
2633 | for (i = 0; i < finger->trails_count; i++) | ||
2634 | { | ||
2635 | trail_list_iterator = &finger->trail_list[i]; | ||
2636 | send_trail_teardown (finger, trail_list_iterator); | ||
2637 | } | ||
2638 | } | ||
2639 | |||
2640 | |||
2641 | /** | ||
2642 | * Decrement the trail count of the first friend to reach the finger | ||
2643 | * In case finger is the friend, then decrement its trail count. | ||
2644 | * @param finger | ||
2645 | */ | ||
2646 | static void | ||
2647 | decrement_friend_trail_count (struct FingerInfo *finger) | ||
2648 | { | ||
2649 | struct Trail *trail_list_iterator; | ||
2650 | struct FriendInfo *target_friend; | ||
2651 | int i = 0; | ||
2652 | |||
2653 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | ||
2654 | &my_identity)) | ||
2655 | return; | ||
2656 | |||
2657 | for (i = 0; i < finger->trails_count; i++) | 2646 | for (i = 0; i < finger->trails_count; i++) |
2658 | { | 2647 | { |
2659 | trail_list_iterator = &finger->trail_list[i]; | 2648 | trail = &finger->trail_list[i]; |
2660 | if (trail_list_iterator->trail_length > 0) | 2649 | if (trail->trail_length > 0) |
2661 | target_friend = | 2650 | { |
2662 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2651 | /* decerement the friend trails count. */ |
2663 | &trail_list_iterator->trail_head->peer); | 2652 | send_trail_teardown (finger, trail); |
2664 | else | 2653 | } |
2665 | target_friend = | ||
2666 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2667 | &finger->finger_identity); | ||
2668 | |||
2669 | // check target_friend for NULL | ||
2670 | /* FIXME: we have removed first_friend_trail_count field. */ | ||
2671 | target_friend->trails_count--; | ||
2672 | //trail_list_iterator->first_friend_trail_count--; | ||
2673 | } | 2654 | } |
2674 | return; | ||
2675 | } | 2655 | } |
2676 | 2656 | ||
2677 | 2657 | ||
@@ -2701,66 +2681,65 @@ free_trail (struct Trail *trail) | |||
2701 | static void | 2681 | static void |
2702 | free_finger (struct FingerInfo *finger) | 2682 | free_finger (struct FingerInfo *finger) |
2703 | { | 2683 | { |
2704 | struct Trail *trail_list_iterator; | 2684 | struct Trail *trail; |
2705 | 2685 | ||
2706 | unsigned int i; | 2686 | unsigned int i; |
2707 | 2687 | ||
2708 | for (i = 0; i < finger->trails_count; i++) | 2688 | for (i = 0; i < finger->trails_count; i++) |
2709 | { | 2689 | { |
2710 | trail_list_iterator = &finger->trail_list[i]; | 2690 | trail = &finger->trail_list[i]; |
2711 | free_trail (trail_list_iterator); | 2691 | free_trail (trail); |
2712 | } | 2692 | } |
2713 | GNUNET_free (finger); | 2693 | GNUNET_free (finger); |
2714 | } | 2694 | } |
2715 | 2695 | ||
2716 | 2696 | ||
2717 | /** | 2697 | /** |
2718 | * Add a new entry in finger hashmap at finger_map_index | 2698 | * Add a new entry in finger table at finger_table_index. |
2699 | * In case finger identity is me or a friend, then don't add a trail. | ||
2700 | * In case a finger is a friend, then increment the trails count of the friend. | ||
2719 | * @param finger_identity Peer Identity of new finger | 2701 | * @param finger_identity Peer Identity of new finger |
2720 | * @param finger_trail Trail to reach from me to finger (excluding both end points). | 2702 | * @param finger_trail Trail to reach from me to finger (excluding both end points). |
2721 | * @param finger_trail_length Total number of peers in @a finger_trail. | 2703 | * @param finger_trail_length Total number of peers in @a finger_trail. |
2722 | * @param trail_id Unique identifier of the trail. | 2704 | * @param trail_id Unique identifier of the trail. |
2723 | * @param finger_map_index Index in finger hashmap. | 2705 | * @param finger_table_index Index in finger table. |
2724 | * @return #GNUNET_OK if new entry is added | ||
2725 | * #GNUNET_NO -- FIXME: need to check what value does hahsmap put | ||
2726 | * returns on failure. | ||
2727 | */ | 2706 | */ |
2728 | static int | 2707 | static void |
2729 | add_new_finger (struct GNUNET_PeerIdentity finger_identity, | 2708 | add_new_finger (struct GNUNET_PeerIdentity finger_identity, |
2730 | const struct GNUNET_PeerIdentity *finger_trail, | 2709 | const struct GNUNET_PeerIdentity *finger_trail, |
2731 | unsigned int finger_trail_length, | 2710 | unsigned int finger_trail_length, |
2732 | struct GNUNET_HashCode trail_id, | 2711 | struct GNUNET_HashCode trail_id, |
2733 | unsigned int finger_map_index) | 2712 | unsigned int finger_table_index) |
2734 | { | 2713 | { |
2735 | struct FingerInfo *new_entry; | 2714 | struct FingerInfo *new_entry; |
2736 | struct FriendInfo *first_trail_hop; | 2715 | struct FriendInfo *first_trail_hop; |
2737 | struct Trail *first_trail; | 2716 | struct Trail *trail; |
2738 | int i = 0; | 2717 | int i = 0; |
2739 | 2718 | ||
2740 | new_entry = GNUNET_new (struct FingerInfo); | 2719 | new_entry = GNUNET_new (struct FingerInfo); |
2741 | new_entry->finger_identity = finger_identity; | 2720 | new_entry->finger_identity = finger_identity; |
2742 | new_entry->finger_map_index = finger_map_index; | 2721 | new_entry->finger_table_index = finger_table_index; |
2743 | new_entry->trails_count = 1; | ||
2744 | new_entry->is_present = GNUNET_YES; | 2722 | new_entry->is_present = GNUNET_YES; |
2745 | 2723 | ||
2724 | /* Finger is not my identity. */ | ||
2746 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 2725 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
2747 | { | 2726 | { |
2748 | if (finger_trail_length > 0) | 2727 | if (finger_trail_length == 0) |
2749 | { | ||
2750 | first_trail_hop = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2751 | &finger_trail[0]); | ||
2752 | } | ||
2753 | else | ||
2754 | { | 2728 | { |
2755 | first_trail_hop = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2729 | first_trail_hop = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2756 | &finger_identity); | 2730 | &finger_identity); |
2731 | first_trail_hop->trails_count++; | ||
2732 | finger_table[finger_table_index] = *new_entry; | ||
2733 | return; | ||
2757 | } | 2734 | } |
2758 | 2735 | ||
2736 | first_trail_hop = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2737 | &finger_trail[0]); | ||
2738 | new_entry->trails_count = 1; | ||
2759 | first_trail_hop->trails_count++; | 2739 | first_trail_hop->trails_count++; |
2760 | first_trail = &new_entry->trail_list[0]; | 2740 | |
2761 | /* FIXME: We have removed this field. */ | 2741 | /* Copy the finger trail into trail. */ |
2762 | //first_trail->first_friend_trail_count = first_trail_hop->trails_count; | 2742 | trail = GNUNET_new (struct Trail); |
2763 | |||
2764 | while (i < finger_trail_length) | 2743 | while (i < finger_trail_length) |
2765 | { | 2744 | { |
2766 | struct Trail_Element *element = GNUNET_new (struct Trail_Element); | 2745 | struct Trail_Element *element = GNUNET_new (struct Trail_Element); |
@@ -2768,15 +2747,20 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2768 | element->next = NULL; | 2747 | element->next = NULL; |
2769 | element->prev = NULL; | 2748 | element->prev = NULL; |
2770 | element->peer = finger_trail[i]; | 2749 | element->peer = finger_trail[i]; |
2771 | GNUNET_CONTAINER_DLL_insert_tail (first_trail->trail_head, | 2750 | GNUNET_CONTAINER_DLL_insert_tail (trail->trail_head, |
2772 | first_trail->trail_tail, | 2751 | trail->trail_tail, |
2773 | element); | 2752 | element); |
2774 | i++; | 2753 | i++; |
2775 | } | 2754 | } |
2755 | /* Add trail to trail list. */ | ||
2756 | new_entry->trail_list[0].trail_head = trail->trail_head; | ||
2757 | new_entry->trail_list[0].trail_tail = trail->trail_tail; | ||
2758 | new_entry->trail_list[0].trail_length = finger_trail_length; | ||
2759 | new_entry->trail_list[0].trail_id = trail_id; | ||
2776 | } | 2760 | } |
2777 | 2761 | ||
2778 | finger_table[finger_map_index] = *new_entry; | 2762 | finger_table[finger_table_index] = *new_entry; |
2779 | return GNUNET_YES; | 2763 | return; |
2780 | } | 2764 | } |
2781 | 2765 | ||
2782 | 2766 | ||
@@ -2803,19 +2787,23 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2803 | struct GNUNET_PeerIdentity *new_trail; | 2787 | struct GNUNET_PeerIdentity *new_trail; |
2804 | int i; | 2788 | int i; |
2805 | 2789 | ||
2806 | new_trail = GNUNET_new (struct GNUNET_PeerIdentity); | 2790 | /* If I am my own finger identity, then we set trail_length = 0. |
2791 | Note: Here we don't send trail compression message, as no peer in its | ||
2792 | trail added an entry in its routing table.*/ | ||
2807 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 2793 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
2808 | { | 2794 | { |
2809 | *new_trail_length = 0; | 2795 | *new_trail_length = 0; |
2810 | return NULL; | 2796 | return NULL; |
2811 | } | 2797 | } |
2812 | 2798 | ||
2799 | /* If finger identity is a friend. */ | ||
2813 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) | 2800 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) |
2814 | { | 2801 | { |
2802 | /* If there is trail to reach this finger/friend */ | ||
2815 | if (trail_length > 0) | 2803 | if (trail_length > 0) |
2816 | { | 2804 | { |
2817 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2805 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2818 | &trail[0]); | 2806 | &trail[0]); |
2819 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | 2807 | GDS_NEIGHBOURS_send_trail_compression (my_identity, |
2820 | trail_id, finger_identity, | 2808 | trail_id, finger_identity, |
2821 | target_friend); | 2809 | target_friend); |
@@ -2824,8 +2812,10 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2824 | return NULL; | 2812 | return NULL; |
2825 | } | 2813 | } |
2826 | 2814 | ||
2815 | /* For other cases, when its neither a friend nor my own identity.*/ | ||
2827 | for (i = trail_length - 1; i > 0; i--) | 2816 | for (i = trail_length - 1; i > 0; i--) |
2828 | { | 2817 | { |
2818 | /* If the element at this index in trail is a friend. */ | ||
2829 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &trail[i])) | 2819 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &trail[i])) |
2830 | { | 2820 | { |
2831 | struct FriendInfo *target_friend; | 2821 | struct FriendInfo *target_friend; |
@@ -2838,8 +2828,8 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2838 | target_friend); | 2828 | target_friend); |
2839 | 2829 | ||
2840 | 2830 | ||
2841 | /* Copy the trail from index i to index trail_length -1 and change | 2831 | /* Copy the trail from index i to index (trail_length -1) into a new trail |
2842 | trail length and return */ | 2832 | * and update new trail length */ |
2843 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * i); | 2833 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * i); |
2844 | while (i < trail_length) | 2834 | while (i < trail_length) |
2845 | { | 2835 | { |
@@ -2848,10 +2838,13 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2848 | i++; | 2838 | i++; |
2849 | } | 2839 | } |
2850 | *new_trail_length = j+1; | 2840 | *new_trail_length = j+1; |
2851 | break; | ||
2852 | return new_trail; | 2841 | return new_trail; |
2853 | } | 2842 | } |
2854 | } | 2843 | } |
2844 | |||
2845 | /* If we found no other friend except the first hop, return the original | ||
2846 | trail back.*/ | ||
2847 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
2855 | *new_trail_length = trail_length; | 2848 | *new_trail_length = trail_length; |
2856 | memcpy (new_trail, new_trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 2849 | memcpy (new_trail, new_trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
2857 | return new_trail; | 2850 | return new_trail; |
@@ -2908,118 +2901,142 @@ send_verify_successor_message (struct FingerInfo *successor) | |||
2908 | successor->finger_identity, | 2901 | successor->finger_identity, |
2909 | trail_id, trail, trail_length, | 2902 | trail_id, trail, trail_length, |
2910 | target_friend); | 2903 | target_friend); |
2911 | GNUNET_free_non_null (trail); | 2904 | GNUNET_free (trail); |
2912 | } | 2905 | } |
2913 | } | 2906 | } |
2914 | 2907 | ||
2915 | 2908 | ||
2916 | /** | 2909 | /** |
2917 | * FIXME: Is it safe to assume that current_search_finger_index == finger_map_index? | 2910 | * FIXME" clear abstraction of current search finger index and finger map index. |
2911 | * it never goes to 63. I don't know why | ||
2918 | * Update the current search finger index. | 2912 | * Update the current search finger index. |
2919 | */ | 2913 | */ |
2920 | static void | 2914 | static void |
2921 | update_current_search_finger_index (struct GNUNET_PeerIdentity new_finger_identity) | 2915 | update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity) |
2922 | { | 2916 | { |
2923 | struct FingerInfo *successor; | 2917 | struct FingerInfo *successor; |
2924 | 2918 | ||
2925 | successor = &finger_table[0]; | 2919 | successor = &finger_table[0]; |
2926 | 2920 | if (GNUNET_NO == successor->is_present) | |
2921 | GNUNET_break(0); | ||
2922 | |||
2923 | /* We were looking for immediate successor. */ | ||
2927 | if (0 == current_search_finger_index) | 2924 | if (0 == current_search_finger_index) |
2928 | { | 2925 | { |
2926 | /* Start looking for immediate predecessor. */ | ||
2929 | current_search_finger_index = PREDECESSOR_FINGER_ID; | 2927 | current_search_finger_index = PREDECESSOR_FINGER_ID; |
2930 | 2928 | ||
2931 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &new_finger_identity)) | 2929 | /* If I am not my own successor, then send a verify successor message. */ |
2930 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | ||
2932 | { | 2931 | { |
2933 | send_verify_successor_message (successor); | 2932 | send_verify_successor_message (successor); |
2934 | } | 2933 | } |
2934 | return; | ||
2935 | } | 2935 | } |
2936 | else if (0 == GNUNET_CRYPTO_cmp_peer_identity (&new_finger_identity, | 2936 | |
2937 | &(successor->finger_identity))) | 2937 | current_search_finger_index = current_search_finger_index - 1; |
2938 | { | 2938 | return; |
2939 | current_search_finger_index = 0; | ||
2940 | } | ||
2941 | else | ||
2942 | current_search_finger_index = current_search_finger_index - 1; | ||
2943 | } | 2939 | } |
2944 | 2940 | ||
2941 | |||
2945 | /** | 2942 | /** |
2946 | * FIXME: Is it sage to assume that finger_map_index == current_search_finger_index | 2943 | * Calculate finger_table_index from initial 64 bit finger identity value that |
2947 | * Calculate finger_map_index from initial value that we send in trail setup | 2944 | * we send in trail setup message. |
2948 | * message. | ||
2949 | * @param ultimate_destination_finger_value Value that we calculated from our | 2945 | * @param ultimate_destination_finger_value Value that we calculated from our |
2950 | * identity and finger_map_index. | 2946 | * identity and finger_table_index. |
2951 | * @param is_predecessor Is the entry for predecessor or not. | 2947 | * @param is_predecessor Is the entry for predecessor or not? |
2952 | * @return finger_map_index which is a value between 0 <= finger_map_index <= 64 | 2948 | * @return finger_table_index Value between 0 <= finger_table_index <= 64 |
2953 | * -1, if no valid finger_map_index is found. | 2949 | * -1, if no valid finger_table_index is found. |
2954 | */ | 2950 | */ |
2955 | static int | 2951 | static int |
2956 | get_finger_map_index (uint64_t ultimate_destination_finger_value, | 2952 | get_finger_table_index (uint64_t ultimate_destination_finger_value, |
2957 | unsigned int is_predecessor) | 2953 | unsigned int is_predecessor) |
2958 | { | 2954 | { |
2959 | uint64_t my_id64; | 2955 | uint64_t my_id64; |
2960 | int finger_map_index; | 2956 | int diff; |
2957 | unsigned int finger_table_index; | ||
2961 | 2958 | ||
2962 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 2959 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
2963 | my_id64 = GNUNET_ntohll (my_id64); | 2960 | my_id64 = GNUNET_ntohll (my_id64); |
2964 | 2961 | ||
2962 | /* Is this a predecessor finger? */ | ||
2965 | if (1 == is_predecessor) | 2963 | if (1 == is_predecessor) |
2966 | { | 2964 | { |
2967 | if(1 == (my_id64 - ultimate_destination_finger_value)) | 2965 | diff = my_id64 - ultimate_destination_finger_value; |
2968 | finger_map_index = PREDECESSOR_FINGER_ID; | 2966 | if (1 == diff) |
2967 | finger_table_index = PREDECESSOR_FINGER_ID; | ||
2968 | else | ||
2969 | finger_table_index = PREDECESSOR_FINGER_ID + 1; //error value | ||
2970 | |||
2969 | } | 2971 | } |
2970 | else | 2972 | else |
2971 | { | 2973 | { |
2972 | if (1 == (ultimate_destination_finger_value - my_id64)) | 2974 | diff = ultimate_destination_finger_value - my_id64; |
2973 | { | 2975 | finger_table_index = (log10 (diff))/(log10 (2)); |
2974 | finger_map_index = 0; | ||
2975 | } | ||
2976 | else | ||
2977 | { | ||
2978 | finger_map_index = log (ultimate_destination_finger_value - my_id64); | ||
2979 | } | ||
2980 | } | 2976 | } |
2981 | 2977 | ||
2982 | if (finger_map_index > PREDECESSOR_FINGER_ID) | 2978 | return finger_table_index; |
2983 | finger_map_index = -1; | ||
2984 | |||
2985 | return finger_map_index; | ||
2986 | } | 2979 | } |
2987 | 2980 | ||
2988 | 2981 | ||
2989 | /** | 2982 | /** |
2990 | * | 2983 | * Remove finger and its associated data structures from finger table. |
2991 | * @param finger | 2984 | * @param finger Finger to be removed. |
2992 | */ | 2985 | */ |
2993 | static void | 2986 | static void |
2994 | remove_existing_finger (struct FingerInfo *finger) | 2987 | remove_existing_finger (struct FingerInfo *finger) |
2995 | { | 2988 | { |
2996 | GNUNET_assert (0 != | 2989 | struct FriendInfo *friend; |
2997 | GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | ||
2998 | &finger->finger_identity)); | ||
2999 | 2990 | ||
3000 | send_all_finger_trails_teardown (finger); | 2991 | GNUNET_assert (GNUNET_YES == finger->is_present); |
3001 | decrement_friend_trail_count (finger); | 2992 | /* If I am my own finger, then we have no trails. */ |
2993 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | ||
2994 | &my_identity)) | ||
2995 | { | ||
2996 | GNUNET_free (finger); | ||
2997 | return; | ||
2998 | } | ||
2999 | |||
3000 | /* If finger is a friend, then decrement the trail count and free the finger. */ | ||
3001 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3002 | &finger->finger_identity); | ||
3003 | if (NULL != friend) | ||
3004 | { | ||
3005 | friend->trails_count--; | ||
3006 | GNUNET_free (finger); | ||
3007 | return; | ||
3008 | } | ||
3002 | 3009 | ||
3010 | /* For all other fingers, send trail teardown across all the trails to reach | ||
3011 | finger, and free the finger. */ | ||
3012 | send_all_finger_trails_teardown (finger); | ||
3003 | free_finger (finger); | 3013 | free_finger (finger); |
3014 | return; | ||
3004 | } | 3015 | } |
3005 | 3016 | ||
3006 | 3017 | ||
3007 | /** | 3018 | /** |
3008 | * Check if there is already an entry in finger peermap for given finger map index. | 3019 | * -- Check if there is already an entry in finger_table at finger_table_index. |
3009 | * If yes, then select the closest finger. If new and existing finger are same, | 3020 | * We get the finger_table_index from 64bit finger value we got from the network. |
3010 | * the check if you can store more trails. If yes then add trail, else keep the best | 3021 | * -- If yes, then select the closest finger. |
3011 | * trails to reach to the finger. If the new finger is closest, add it. | 3022 | * -- If new and existing finger are same, then check if you can store more |
3012 | * Then, update current_search_finger_index. | 3023 | * trails. |
3024 | * -- If yes then add trail, else keep the best trails to reach to the | ||
3025 | * finger. | ||
3026 | * -- If the new finger is closest, remove the existing entry, send trail | ||
3027 | * teardown message across all the trails to reach the existing entry. | ||
3028 | * Add the trail. | ||
3029 | * -- If new and existing finger are different, and existing finger is same | ||
3030 | * then do nothing. | ||
3031 | * Update current_search_finger_index. | ||
3013 | * @param new_finger_identity Peer Identity of new finger | 3032 | * @param new_finger_identity Peer Identity of new finger |
3014 | * @param new_finger_trail Trail to reach the new finger | 3033 | * @param new_finger_trail Trail to reach the new finger |
3015 | * @param new_finger_length Total number of peers in @a new_finger_trail. | 3034 | * @param new_finger_length Total number of peers in @a new_finger_trail. |
3016 | * @param is_predecessor Is this entry for predecessor in finger_peermap. | 3035 | * @param is_predecessor Is this entry for predecessor in finger_peermap. |
3017 | * @param new_finger_trail_id Unique identifier of @new_finger_trail. | 3036 | * @param finger_value 64 bit value of finger identity that we got from network. |
3018 | * @return #GNUNET_YES if the new entry is added | 3037 | * @param finger_trail_id Unique identifier of @finger_trail. |
3019 | * #GNUNET_NO if new entry is not added, either it was discarded or | ||
3020 | * it was same as existing finger at finger map index. | ||
3021 | */ | 3038 | */ |
3022 | static int | 3039 | static void |
3023 | finger_table_add (struct GNUNET_PeerIdentity finger_identity, | 3040 | finger_table_add (struct GNUNET_PeerIdentity finger_identity, |
3024 | const struct GNUNET_PeerIdentity *finger_trail, | 3041 | const struct GNUNET_PeerIdentity *finger_trail, |
3025 | unsigned int finger_trail_length, | 3042 | unsigned int finger_trail_length, |
@@ -3029,36 +3046,49 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3029 | { | 3046 | { |
3030 | struct FingerInfo *existing_finger; | 3047 | struct FingerInfo *existing_finger; |
3031 | struct GNUNET_PeerIdentity *closest_peer; | 3048 | struct GNUNET_PeerIdentity *closest_peer; |
3032 | int updated_finger_trail_length; | ||
3033 | struct GNUNET_PeerIdentity *updated_trail; | 3049 | struct GNUNET_PeerIdentity *updated_trail; |
3034 | unsigned int finger_map_index; | 3050 | struct FingerInfo *successor; |
3035 | unsigned int new_entry_added; | 3051 | int updated_finger_trail_length; |
3036 | 3052 | unsigned int finger_table_index; | |
3037 | new_entry_added = GNUNET_NO; | ||
3038 | 3053 | ||
3039 | finger_map_index = get_finger_map_index (finger_value, | 3054 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ |
3040 | is_predecessor); | 3055 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); |
3041 | 3056 | ||
3042 | if (-1 == finger_map_index) | 3057 | /* Invalid finger_table_index. */ |
3058 | if ((finger_table_index > PREDECESSOR_FINGER_ID) || (finger_table_index < 0)) | ||
3043 | { | 3059 | { |
3044 | GNUNET_break_op (0); | 3060 | GNUNET_break_op (0); |
3045 | return GNUNET_SYSERR; | 3061 | return; |
3046 | } | 3062 | } |
3063 | |||
3047 | updated_finger_trail_length = finger_trail_length; | 3064 | updated_finger_trail_length = finger_trail_length; |
3048 | updated_trail = | 3065 | updated_trail = |
3049 | scan_and_compress_trail (finger_identity, finger_trail, | 3066 | scan_and_compress_trail (finger_identity, finger_trail, |
3050 | finger_trail_length, finger_trail_id, | 3067 | finger_trail_length, finger_trail_id, |
3051 | &updated_finger_trail_length); | 3068 | &updated_finger_trail_length); |
3069 | |||
3070 | /* If the new entry is same as successor then don't add it in finger table, | ||
3071 | reset the current search finger index and exit. */ | ||
3072 | if ((0 != finger_table_index) && (PREDECESSOR_FINGER_ID != finger_table_index)) | ||
3073 | { | ||
3074 | successor = &finger_table[0]; | ||
3075 | GNUNET_assert (GNUNET_YES == successor->is_present); | ||
3076 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | ||
3077 | &successor->finger_identity)) | ||
3078 | { | ||
3079 | current_search_finger_index = 0; | ||
3080 | return; | ||
3081 | } | ||
3082 | } | ||
3052 | 3083 | ||
3053 | existing_finger = &finger_table[finger_map_index]; | 3084 | existing_finger = &finger_table[finger_table_index]; |
3054 | 3085 | /* No entry present in finger_table for given finger map index. */ | |
3055 | /* No entry present in finger hashmap for given finger map index. */ | ||
3056 | if (GNUNET_NO == existing_finger->is_present) | 3086 | if (GNUNET_NO == existing_finger->is_present) |
3057 | { | 3087 | { |
3058 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, | 3088 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, |
3059 | finger_trail_id, finger_map_index); | 3089 | finger_trail_id, finger_table_index); |
3060 | update_current_search_finger_index (finger_identity); | 3090 | update_current_search_finger_index (finger_identity); |
3061 | return GNUNET_YES; | 3091 | return; |
3062 | } | 3092 | } |
3063 | 3093 | ||
3064 | /* If existing entry and finger identity are not same. */ | 3094 | /* If existing entry and finger identity are not same. */ |
@@ -3067,15 +3097,14 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3067 | { | 3097 | { |
3068 | closest_peer = select_closest_peer (&existing_finger->finger_identity, | 3098 | closest_peer = select_closest_peer (&existing_finger->finger_identity, |
3069 | &finger_identity, | 3099 | &finger_identity, |
3070 | finger_value, finger_map_index); | 3100 | finger_value, finger_table_index); |
3071 | 3101 | ||
3072 | /* If the new finger is the closest peer. */ | 3102 | /* If the new finger is the closest peer. */ |
3073 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer)) | 3103 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer)) |
3074 | { | 3104 | { |
3075 | remove_existing_finger (existing_finger); | 3105 | remove_existing_finger (existing_finger); |
3076 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, | 3106 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, |
3077 | finger_trail_id, finger_map_index); | 3107 | finger_trail_id, finger_table_index); |
3078 | new_entry_added = GNUNET_YES; | ||
3079 | } | 3108 | } |
3080 | } | 3109 | } |
3081 | else | 3110 | else |
@@ -3083,15 +3112,14 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3083 | /* If both new and existing entry are same as my_identity, then do nothing. */ | 3112 | /* If both new and existing entry are same as my_identity, then do nothing. */ |
3084 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), | 3113 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), |
3085 | &my_identity)) | 3114 | &my_identity)) |
3086 | { | 3115 | return; |
3087 | return GNUNET_NO; | ||
3088 | } | ||
3089 | 3116 | ||
3090 | /* If the existing finger is not a friend. */ | 3117 | /* If the existing finger is not a friend. */ |
3091 | if (NULL == | 3118 | if (NULL == |
3092 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3119 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3093 | &(existing_finger->finger_identity))) | 3120 | &existing_finger->finger_identity)) |
3094 | { | 3121 | { |
3122 | /* If there is space to store more trails. */ | ||
3095 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) | 3123 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) |
3096 | add_new_trail (existing_finger, updated_trail, | 3124 | add_new_trail (existing_finger, updated_trail, |
3097 | finger_trail_length, finger_trail_id); | 3125 | finger_trail_length, finger_trail_id); |
@@ -3099,11 +3127,9 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3099 | select_and_replace_trail (existing_finger, updated_trail, | 3127 | select_and_replace_trail (existing_finger, updated_trail, |
3100 | finger_trail_length, finger_trail_id); | 3128 | finger_trail_length, finger_trail_id); |
3101 | } | 3129 | } |
3102 | new_entry_added = GNUNET_NO; | ||
3103 | } | 3130 | } |
3104 | |||
3105 | update_current_search_finger_index (finger_identity); | 3131 | update_current_search_finger_index (finger_identity); |
3106 | return new_entry_added; | 3132 | return; |
3107 | } | 3133 | } |
3108 | 3134 | ||
3109 | 3135 | ||
@@ -3605,6 +3631,11 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3605 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, | 3631 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, |
3606 | &my_identity))) | 3632 | &my_identity))) |
3607 | { | 3633 | { |
3634 | /* If I was not the source of this message for which now I am destination.*/ | ||
3635 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | ||
3636 | { | ||
3637 | GDS_ROUTING_add (trail_id, *peer, my_identity); | ||
3638 | } | ||
3608 | if (0 == trail_length) | 3639 | if (0 == trail_length) |
3609 | memcpy (&next_peer, &source, sizeof (struct GNUNET_PeerIdentity)); | 3640 | memcpy (&next_peer, &source, sizeof (struct GNUNET_PeerIdentity)); |
3610 | else | 3641 | else |
@@ -3774,6 +3805,11 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
3774 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, | 3805 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, |
3775 | &my_identity))) | 3806 | &my_identity))) |
3776 | { | 3807 | { |
3808 | /* If I am not my own finger identity.*/ | ||
3809 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | ||
3810 | { | ||
3811 | GDS_ROUTING_add (trail_id, my_identity, *peer); | ||
3812 | } | ||
3777 | finger_table_add (finger_identity, trail_peer_list, | 3813 | finger_table_add (finger_identity, trail_peer_list, |
3778 | trail_length, ulitmate_destination_finger_value, | 3814 | trail_length, ulitmate_destination_finger_value, |
3779 | is_predecessor, trail_id); | 3815 | is_predecessor, trail_id); |
@@ -4621,6 +4657,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_peer, | |||
4621 | struct Trail *trail; | 4657 | struct Trail *trail; |
4622 | 4658 | ||
4623 | matching_trails_count = 0; | 4659 | matching_trails_count = 0; |
4660 | |||
4624 | for (i = 0; i < remove_finger->trails_count; i++) | 4661 | for (i = 0; i < remove_finger->trails_count; i++) |
4625 | { | 4662 | { |
4626 | trail = &remove_finger->trail_list[i]; | 4663 | trail = &remove_finger->trail_list[i]; |
@@ -4639,6 +4676,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_peer, | |||
4639 | 4676 | ||
4640 | 4677 | ||
4641 | /** | 4678 | /** |
4679 | * FIXME: check that you are not sending trail teardown for trail length = 0 | ||
4642 | * Iterate over finger_table entries. Check if disconnected_peer is a finger. If | 4680 | * Iterate over finger_table entries. Check if disconnected_peer is a finger. If |
4643 | * yes then free that entry. | 4681 | * yes then free that entry. |
4644 | * Check if disconnected peer is the first friend in the trail to reach to a finger. | 4682 | * Check if disconnected peer is the first friend in the trail to reach to a finger. |
@@ -4654,43 +4692,44 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
4654 | { | 4692 | { |
4655 | struct FingerInfo *remove_finger; | 4693 | struct FingerInfo *remove_finger; |
4656 | int i; | 4694 | int i; |
4657 | int matching_trails_count; | 4695 | int removed_trails_count; |
4658 | 4696 | ||
4659 | for (i = 0; i < MAX_FINGERS; i++) | 4697 | for (i = 0; i < MAX_FINGERS; i++) |
4660 | { | 4698 | { |
4661 | remove_finger = &finger_table[i]; | ||
4662 | 4699 | ||
4700 | remove_finger = &finger_table[i]; | ||
4701 | |||
4702 | /* No finger stored at this trail index. */ | ||
4663 | if (GNUNET_NO == remove_finger->is_present) | 4703 | if (GNUNET_NO == remove_finger->is_present) |
4664 | continue; | 4704 | continue; |
4665 | 4705 | ||
4666 | /* I am my own finger, then ignore this finger. */ | 4706 | /* I am my own finger, then ignore this finger. */ |
4667 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, &my_identity)) | 4707 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_finger->finger_identity, |
4708 | &my_identity)) | ||
4709 | continue; | ||
4710 | |||
4711 | if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
4712 | &remove_finger->finger_identity))) | ||
4668 | continue; | 4713 | continue; |
4669 | 4714 | ||
4670 | /* Is disconnected peer my finger? */ | 4715 | /* Is disconnected peer my finger? */ |
4671 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, | 4716 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, |
4672 | &remove_finger->finger_identity)) | 4717 | &remove_finger->finger_identity)) |
4673 | { | 4718 | { |
4719 | finger_table[i].is_present = GNUNET_NO; | ||
4674 | memset ((void *)&finger_table[i], 0, sizeof (struct FingerInfo)); | 4720 | memset ((void *)&finger_table[i], 0, sizeof (struct FingerInfo)); |
4675 | /* We don't call send_find_finger_trail, as we have no trail to reach to | 4721 | /* No trail to reach this finger, don't send trail_teardown message. */ |
4676 | a finger. */ | ||
4677 | GNUNET_free (remove_finger); | 4722 | GNUNET_free (remove_finger); |
4678 | continue; | 4723 | continue; |
4679 | |||
4680 | } | 4724 | } |
4681 | 4725 | ||
4682 | /* Iterate over the list of trails to reach to remove_finger.*/ | 4726 | /* Iterate over the list of remove_finger's trails. Check if first friend |
4683 | matching_trails_count = remove_matching_trails (disconnected_peer, remove_finger); | 4727 | in any of the trail is disconnected_peer. */ |
4728 | removed_trails_count = remove_matching_trails (disconnected_peer, remove_finger); | ||
4684 | 4729 | ||
4685 | /* All the trails of the finger has disconnected peer as the first friend, | 4730 | /* All the finger trails has disconnected peer as the first friend, |
4686 | so free the finger. */ | 4731 | so free the finger. */ |
4687 | /* FIXME; Here we assume that only in case of a finger which is a friend or | 4732 | if (removed_trails_count == remove_finger->trails_count) |
4688 | my_identity only then trails count is 0. and we will not reach here in | ||
4689 | those cases. So, we can free the finger. Verify that we don't increment | ||
4690 | the trail count in case of finger == friend or my_ienity. */ | ||
4691 | remove_finger->trails_count = | ||
4692 | remove_finger->trails_count - matching_trails_count; | ||
4693 | if (0 == remove_finger->trails_count) | ||
4694 | { | 4733 | { |
4695 | GNUNET_free (remove_finger); | 4734 | GNUNET_free (remove_finger); |
4696 | } | 4735 | } |
@@ -4711,8 +4750,7 @@ handle_core_disconnect (void *cls, | |||
4711 | struct FriendInfo *remove_friend; | 4750 | struct FriendInfo *remove_friend; |
4712 | 4751 | ||
4713 | /* If disconnected to own identity, then return. */ | 4752 | /* If disconnected to own identity, then return. */ |
4714 | if (0 == memcmp (&my_identity, peer, | 4753 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
4715 | sizeof (struct GNUNET_PeerIdentity))) | ||
4716 | return; | 4754 | return; |
4717 | 4755 | ||
4718 | GNUNET_assert (NULL != (remove_friend = | 4756 | GNUNET_assert (NULL != (remove_friend = |
@@ -4721,14 +4759,13 @@ handle_core_disconnect (void *cls, | |||
4721 | /* Remove fingers with peer as first friend or if peer is a finger. */ | 4759 | /* Remove fingers with peer as first friend or if peer is a finger. */ |
4722 | remove_matching_fingers (peer); | 4760 | remove_matching_fingers (peer); |
4723 | 4761 | ||
4724 | /* Remove any trail of which peer is a part of. */ | 4762 | /* Remove any trail from routing table of which peer is a part of. */ |
4725 | GDS_ROUTING_remove_trail_by_peer (peer); | 4763 | GDS_ROUTING_remove_trail_by_peer (peer); |
4726 | 4764 | ||
4727 | GNUNET_assert (GNUNET_YES == | 4765 | GNUNET_assert (GNUNET_YES == |
4728 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 4766 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, |
4729 | peer, | 4767 | peer, |
4730 | remove_friend)); | 4768 | remove_friend)); |
4731 | |||
4732 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 4769 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) |
4733 | return; | 4770 | return; |
4734 | 4771 | ||
@@ -4739,6 +4776,7 @@ handle_core_disconnect (void *cls, | |||
4739 | } | 4776 | } |
4740 | else | 4777 | else |
4741 | GNUNET_break (0); | 4778 | GNUNET_break (0); |
4779 | |||
4742 | } | 4780 | } |
4743 | 4781 | ||
4744 | 4782 | ||
@@ -4777,7 +4815,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
4777 | peer_identity, friend, | 4815 | peer_identity, friend, |
4778 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4816 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4779 | 4817 | ||
4780 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ | 4818 | |
4819 | /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ | ||
4781 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) | 4820 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) |
4782 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 4821 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); |
4783 | } | 4822 | } |
@@ -4806,7 +4845,10 @@ finger_table_init () | |||
4806 | int i; | 4845 | int i; |
4807 | 4846 | ||
4808 | for(i = 0; i < MAX_FINGERS; i++) | 4847 | for(i = 0; i < MAX_FINGERS; i++) |
4848 | { | ||
4809 | finger_table[i].is_present = GNUNET_NO; | 4849 | finger_table[i].is_present = GNUNET_NO; |
4850 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | ||
4851 | } | ||
4810 | } | 4852 | } |
4811 | 4853 | ||
4812 | 4854 | ||
@@ -4865,12 +4907,14 @@ GDS_NEIGHBOURS_done (void) | |||
4865 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); | 4907 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); |
4866 | friend_peermap = NULL; | 4908 | friend_peermap = NULL; |
4867 | 4909 | ||
4910 | #if 0 | ||
4868 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) | 4911 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) |
4869 | { | 4912 | { |
4870 | GNUNET_break (0); | 4913 | GNUNET_break (0); |
4871 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 4914 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
4872 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | 4915 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; |
4873 | } | 4916 | } |
4917 | #endif | ||
4874 | } | 4918 | } |
4875 | 4919 | ||
4876 | 4920 | ||