diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-21 21:42:04 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-21 21:42:04 +0000 |
commit | 28a7927307f5919892c4df4cf475f0d06bb60830 (patch) | |
tree | 88968f8d11d1d4c0195a14901dbe8e3dc593bead /src | |
parent | 54bf1a260ef7fdebee97779b08faf062b1b0f02c (diff) | |
download | gnunet-28a7927307f5919892c4df4cf475f0d06bb60830.tar.gz gnunet-28a7927307f5919892c4df4cf475f0d06bb60830.zip |
Code refactoring
Handling the case where friend which is a finger may have trail len > 0
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 475 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.c | 2 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 22 |
3 files changed, 250 insertions, 249 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 0fa70075d..d4d640a82 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -854,6 +854,17 @@ static struct GNUNET_CORE_Handle *core_api; | |||
854 | static unsigned int current_search_finger_index; | 854 | static unsigned int current_search_finger_index; |
855 | 855 | ||
856 | /** | 856 | /** |
857 | * Time duration to schedule find finger trail task. | ||
858 | */ | ||
859 | static struct GNUNET_TIME_Relative find_finger_trail_task_next_send_time; | ||
860 | |||
861 | /** | ||
862 | * Time duration to schedule verify successor task. | ||
863 | */ | ||
864 | static struct GNUNET_TIME_Relative verify_successor_next_send_time; | ||
865 | |||
866 | /* Below variables are used only for testing, and statistics collection. */ | ||
867 | /** | ||
857 | * Should we store our topology predecessor and successor IDs into statistics? | 868 | * Should we store our topology predecessor and successor IDs into statistics? |
858 | */ | 869 | */ |
859 | unsigned int track_topology; | 870 | unsigned int track_topology; |
@@ -865,14 +876,11 @@ unsigned int track_topology; | |||
865 | unsigned int act_malicious; | 876 | unsigned int act_malicious; |
866 | 877 | ||
867 | /** | 878 | /** |
868 | * Time duration to schedule find finger trail task. | 879 | * Count of fingers found. Ideally we should have O(logn) fingers for a |
880 | * stable network. | ||
869 | */ | 881 | */ |
870 | static struct GNUNET_TIME_Relative find_finger_trail_task_next_send_time; | 882 | static unsigned int total_fingers_found; |
871 | 883 | ||
872 | /** | ||
873 | * Time duration to schedule verify successor task. | ||
874 | */ | ||
875 | static struct GNUNET_TIME_Relative verify_successor_next_send_time; | ||
876 | 884 | ||
877 | /** | 885 | /** |
878 | * Called when core is ready to send a message we asked for | 886 | * Called when core is ready to send a message we asked for |
@@ -1046,7 +1054,7 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1046 | tsm->is_predecessor = htonl (is_predecessor); | 1054 | tsm->is_predecessor = htonl (is_predecessor); |
1047 | tsm->trail_id = trail_id; | 1055 | tsm->trail_id = trail_id; |
1048 | tsm->intermediate_trail_id = intermediate_trail_id; | 1056 | tsm->intermediate_trail_id = intermediate_trail_id; |
1049 | 1057 | ||
1050 | if (trail_length > 0) | 1058 | if (trail_length > 0) |
1051 | { | 1059 | { |
1052 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 1060 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
@@ -1674,7 +1682,7 @@ select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, | |||
1674 | // } | 1682 | // } |
1675 | } | 1683 | } |
1676 | 1684 | ||
1677 | 1685 | #if 0 | |
1678 | /** | 1686 | /** |
1679 | * | 1687 | * |
1680 | * | 1688 | * |
@@ -1695,7 +1703,7 @@ test_print_trail (struct GNUNET_PeerIdentity *trail, | |||
1695 | __FILE__, __func__,__LINE__,i,GNUNET_i2s(&print_peer)); | 1703 | __FILE__, __func__,__LINE__,i,GNUNET_i2s(&print_peer)); |
1696 | } | 1704 | } |
1697 | } | 1705 | } |
1698 | 1706 | #endif | |
1699 | 1707 | ||
1700 | #if 0 | 1708 | #if 0 |
1701 | /** | 1709 | /** |
@@ -1807,8 +1815,8 @@ select_closest_peer (const struct GNUNET_PeerIdentity *peer1, | |||
1807 | * to Finger, choose the one with shortest trail length. | 1815 | * to Finger, choose the one with shortest trail length. |
1808 | * Note: We use length as parameter. But we can use any other suitable parameter | 1816 | * Note: We use length as parameter. But we can use any other suitable parameter |
1809 | * also. | 1817 | * also. |
1810 | * @param finger Finger | 1818 | * @param finger Finger Finger whose trail we have to select. |
1811 | * @return Trail | 1819 | * @return Trail Selected Trail. |
1812 | */ | 1820 | */ |
1813 | static struct Trail * | 1821 | static struct Trail * |
1814 | select_finger_trail (struct FingerInfo *finger) | 1822 | select_finger_trail (struct FingerInfo *finger) |
@@ -1819,7 +1827,6 @@ select_finger_trail (struct FingerInfo *finger) | |||
1819 | unsigned int i; | 1827 | unsigned int i; |
1820 | 1828 | ||
1821 | GNUNET_assert (finger->trails_count > 0); | 1829 | GNUNET_assert (finger->trails_count > 0); |
1822 | |||
1823 | for (i = 0; i < finger->trails_count; i++) | 1830 | for (i = 0; i < finger->trails_count; i++) |
1824 | { | 1831 | { |
1825 | current_finger_trail = &finger->trail_list[i]; | 1832 | current_finger_trail = &finger->trail_list[i]; |
@@ -1828,10 +1835,6 @@ select_finger_trail (struct FingerInfo *finger) | |||
1828 | if (GNUNET_NO == current_finger_trail->is_present) | 1835 | if (GNUNET_NO == current_finger_trail->is_present) |
1829 | continue; | 1836 | continue; |
1830 | 1837 | ||
1831 | /* SUPUS: I am not changing anything here. as i assume that in case we have | ||
1832 | a finger which is friend and we have trail length = 0, then it will | ||
1833 | be the first friend to which we send the request. As I have removed | ||
1834 | the condition in trail setup where we check for source is a friend. */ | ||
1835 | GNUNET_assert (NULL != | 1838 | GNUNET_assert (NULL != |
1836 | (friend = | 1839 | (friend = |
1837 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1840 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -1876,9 +1879,6 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe | |||
1876 | if (GNUNET_NO == finger->is_present) | 1879 | if (GNUNET_NO == finger->is_present) |
1877 | continue; | 1880 | continue; |
1878 | 1881 | ||
1879 | /* SUPUS: As we have friend stored as finger also, it may happen that | ||
1880 | * friend corresponding to this finger has been chosen as the best | ||
1881 | * known destination, then just move to next element. */ | ||
1882 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1882 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1883 | ¤t_closest_peer->best_known_destination)) | 1883 | ¤t_closest_peer->best_known_destination)) |
1884 | continue; | 1884 | continue; |
@@ -1888,12 +1888,7 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe | |||
1888 | &my_identity)) | 1888 | &my_identity)) |
1889 | continue; | 1889 | continue; |
1890 | 1890 | ||
1891 | /* If finger is a friend, then do nothing. As we have already checked | 1891 | /* If finger is a friend, we have already checked it in previous function. */ |
1892 | * for each friend in compare_friend_and_current_successor(). | ||
1893 | * SUPUS: Here we have all the friends in the friend table. So even if | ||
1894 | * that friend is a finger, we have checked it with trail length = 0. | ||
1895 | * So its okay. No need to change anything here. Note: finger may have | ||
1896 | * trail length > 0 but its okay. */ | ||
1897 | if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1892 | if (NULL != (GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
1898 | &finger->finger_identity))) | 1893 | &finger->finger_identity))) |
1899 | { | 1894 | { |
@@ -1905,8 +1900,6 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe | |||
1905 | current_closest_peer->destination_finger_value, | 1900 | current_closest_peer->destination_finger_value, |
1906 | current_closest_peer->is_predecessor); | 1901 | current_closest_peer->is_predecessor); |
1907 | 1902 | ||
1908 | /* SUPUS: Ideally if finger is a friend, but with trail length > 0, then | ||
1909 | also we have already handled the case in above condition. */ | ||
1910 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&finger->finger_identity, &closest_peer)) | 1903 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&finger->finger_identity, &closest_peer)) |
1911 | { | 1904 | { |
1912 | /* Choose one of the trail to reach to finger. */ | 1905 | /* Choose one of the trail to reach to finger. */ |
@@ -1998,23 +1991,19 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity, | |||
1998 | 1991 | ||
1999 | 1992 | ||
2000 | /** | 1993 | /** |
2001 | * FIXME: at the moment, there is not 100% get and put in case of non-malicious | 1994 | * Find locally best known peer, among your own identity, friend and finger list, |
2002 | * peer. It could be because of the logic we wrote here. Verify if its correct. | 1995 | * which is closest to given destination_finger_value. |
2003 | * If not then return immediate_successor. | 1996 | * |
2004 | * | ||
2005 | * Find the successor for destination_finger_value among my_identity, my | ||
2006 | * friends and my fingers. Don't consider friends or fingers which are either | ||
2007 | * congested or have crossed the threshold. | ||
2008 | * NOTE: In case a friend is also a finger, then it is always chosen as friend | 1997 | * NOTE: In case a friend is also a finger, then it is always chosen as friend |
2009 | * not a finger. | 1998 | * not a finger. |
2010 | * @param destination_finger_value Peer closest to this value will be the next successor. | 1999 | * @param destination_finger_value Peer closest to this value will be the next destination. |
2011 | * @param is_predecessor Are we looking for predecessor or finger? | 2000 | * @param is_predecessor Are we looking for predecessor or finger? |
2012 | * @return Successor It is never NULL, in case none of friend or finger is closest, | 2001 | * @return Closest_Peer that contains all the relevant field to reach to |
2013 | * then we return my_identity. | 2002 | * @a destination_finger_value |
2014 | */ | 2003 | */ |
2015 | static struct Closest_Peer | 2004 | static struct Closest_Peer |
2016 | find_successor (uint64_t destination_finger_value, | 2005 | find_local_best_known_next_hop (uint64_t destination_finger_value, |
2017 | unsigned int is_predecessor) | 2006 | unsigned int is_predecessor) |
2018 | { | 2007 | { |
2019 | struct Closest_Peer current_closest_peer; | 2008 | struct Closest_Peer current_closest_peer; |
2020 | 2009 | ||
@@ -2150,7 +2139,8 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
2150 | 2139 | ||
2151 | memcpy (&key_value, key, sizeof (uint64_t)); | 2140 | memcpy (&key_value, key, sizeof (uint64_t)); |
2152 | key_value = GNUNET_ntohll (key_value); | 2141 | key_value = GNUNET_ntohll (key_value); |
2153 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 2142 | successor = find_local_best_known_next_hop (key_value, |
2143 | GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
2154 | best_known_dest = successor.best_known_destination; | 2144 | best_known_dest = successor.best_known_destination; |
2155 | next_hop = successor.next_hop; | 2145 | next_hop = successor.next_hop; |
2156 | intermediate_trail_id = successor.trail_id; | 2146 | intermediate_trail_id = successor.trail_id; |
@@ -2293,7 +2283,8 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key, | |||
2293 | memcpy (&key_value, key, sizeof (uint64_t)); | 2283 | memcpy (&key_value, key, sizeof (uint64_t)); |
2294 | key_value = GNUNET_ntohll (key_value); | 2284 | key_value = GNUNET_ntohll (key_value); |
2295 | 2285 | ||
2296 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 2286 | successor = find_local_best_known_next_hop (key_value, |
2287 | GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
2297 | 2288 | ||
2298 | best_known_dest = successor.best_known_destination; | 2289 | best_known_dest = successor.best_known_destination; |
2299 | intermediate_trail_id = successor.trail_id; | 2290 | intermediate_trail_id = successor.trail_id; |
@@ -2529,9 +2520,8 @@ send_find_finger_trail_message (void *cls, | |||
2529 | unsigned int is_predecessor = 0; | 2520 | unsigned int is_predecessor = 0; |
2530 | uint64_t finger_id_value; | 2521 | uint64_t finger_id_value; |
2531 | 2522 | ||
2532 | /* Schedule another send_find_finger_trail_message task. When we have seen | 2523 | /* Schedule another send_find_finger_trail_message task. After one round of |
2533 | * one round of fingers, then this time is exponentially backoff to reduce | 2524 | * finger search, this time is exponentially backoff. */ |
2534 | * traffic caused by this task. */ | ||
2535 | find_finger_trail_task_next_send_time.rel_value_us = | 2525 | find_finger_trail_task_next_send_time.rel_value_us = |
2536 | find_finger_trail_task_next_send_time.rel_value_us + | 2526 | find_finger_trail_task_next_send_time.rel_value_us + |
2537 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 2527 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -2541,7 +2531,7 @@ send_find_finger_trail_message (void *cls, | |||
2541 | &send_find_finger_trail_message, | 2531 | &send_find_finger_trail_message, |
2542 | NULL); | 2532 | NULL); |
2543 | 2533 | ||
2544 | /* No space in my routing table. (Source and destination peers also store entries | 2534 | /* No space in my routing table. (Source and destination peers also store entries |
2545 | * in their routing table). */ | 2535 | * in their routing table). */ |
2546 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 2536 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
2547 | return; | 2537 | return; |
@@ -2591,10 +2581,11 @@ select_and_replace_trail (struct FingerInfo *finger, | |||
2591 | unsigned int new_trail_length, | 2581 | unsigned int new_trail_length, |
2592 | struct GNUNET_HashCode new_trail_id) | 2582 | struct GNUNET_HashCode new_trail_id) |
2593 | { | 2583 | { |
2594 | struct Trail *trail; | 2584 | struct Trail *current_trail; |
2595 | unsigned int largest_trail_length; | 2585 | unsigned int largest_trail_length; |
2596 | unsigned int largest_trail_index; | 2586 | unsigned int largest_trail_index; |
2597 | struct Trail_Element *trail_element; | 2587 | struct Trail_Element *trail_element; |
2588 | struct GNUNET_PeerIdentity *next_hop; | ||
2598 | unsigned int i; | 2589 | unsigned int i; |
2599 | 2590 | ||
2600 | largest_trail_length = new_trail_length; | 2591 | largest_trail_length = new_trail_length; |
@@ -2604,10 +2595,11 @@ select_and_replace_trail (struct FingerInfo *finger, | |||
2604 | 2595 | ||
2605 | for (i = 0; i < finger->trails_count; i++) | 2596 | for (i = 0; i < finger->trails_count; i++) |
2606 | { | 2597 | { |
2607 | trail = &finger->trail_list[i]; | 2598 | current_trail = &finger->trail_list[i]; |
2608 | if (trail->trail_length > largest_trail_length) | 2599 | GNUNET_assert (GNUNET_YES == current_trail->is_present); |
2600 | if (current_trail->trail_length > largest_trail_length) | ||
2609 | { | 2601 | { |
2610 | largest_trail_length = trail->trail_length; | 2602 | largest_trail_length = current_trail->trail_length; |
2611 | largest_trail_index = i; | 2603 | largest_trail_index = i; |
2612 | } | 2604 | } |
2613 | } | 2605 | } |
@@ -2615,23 +2607,22 @@ select_and_replace_trail (struct FingerInfo *finger, | |||
2615 | /* New trail is not better than existing ones. Send trail teardown. */ | 2607 | /* New trail is not better than existing ones. Send trail teardown. */ |
2616 | if (largest_trail_index == (MAXIMUM_TRAILS_PER_FINGER + 1)) | 2608 | if (largest_trail_index == (MAXIMUM_TRAILS_PER_FINGER + 1)) |
2617 | { | 2609 | { |
2618 | struct GNUNET_PeerIdentity next_hop; | 2610 | next_hop = GDS_ROUTING_get_next_hop (new_trail_id, GDS_ROUTING_SRC_TO_DEST); |
2619 | |||
2620 | memcpy (&next_hop, &new_trail[0], sizeof(struct GNUNET_PeerIdentity)); | ||
2621 | GDS_ROUTING_remove_trail (new_trail_id); | 2611 | GDS_ROUTING_remove_trail (new_trail_id); |
2622 | GDS_NEIGHBOURS_send_trail_teardown (new_trail_id, | 2612 | GDS_NEIGHBOURS_send_trail_teardown (new_trail_id, |
2623 | GDS_ROUTING_SRC_TO_DEST, | 2613 | GDS_ROUTING_SRC_TO_DEST, |
2624 | next_hop); | 2614 | *next_hop); |
2625 | return; | 2615 | return; |
2626 | } | 2616 | } |
2627 | 2617 | ||
2628 | /* Send trail teardown message across the replaced trail. */ | 2618 | /* Send trail teardown message across the replaced trail. */ |
2629 | struct Trail *replace_trail = &finger->trail_list[largest_trail_index]; | 2619 | struct Trail *replace_trail = &finger->trail_list[largest_trail_index]; |
2630 | 2620 | next_hop = GDS_ROUTING_get_next_hop (replace_trail->trail_id, GDS_ROUTING_SRC_TO_DEST); | |
2631 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (replace_trail->trail_id)); | 2621 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (replace_trail->trail_id)); |
2632 | GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id, | 2622 | GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id, |
2633 | GDS_ROUTING_SRC_TO_DEST, | 2623 | GDS_ROUTING_SRC_TO_DEST, |
2634 | replace_trail->trail_head->peer); | 2624 | *next_hop); |
2625 | |||
2635 | /* Free the trail. */ | 2626 | /* Free the trail. */ |
2636 | while (NULL != (trail_element = replace_trail->trail_head)) | 2627 | while (NULL != (trail_element = replace_trail->trail_head)) |
2637 | { | 2628 | { |
@@ -2672,7 +2663,7 @@ is_new_trail_unique (struct FingerInfo *existing_finger, | |||
2672 | const struct GNUNET_PeerIdentity *new_trail, | 2663 | const struct GNUNET_PeerIdentity *new_trail, |
2673 | unsigned int trail_length) | 2664 | unsigned int trail_length) |
2674 | { | 2665 | { |
2675 | struct Trail *trail; | 2666 | struct Trail *current_trail; |
2676 | struct Trail_Element *trail_element; | 2667 | struct Trail_Element *trail_element; |
2677 | int i; | 2668 | int i; |
2678 | int j; | 2669 | int j; |
@@ -2682,18 +2673,18 @@ is_new_trail_unique (struct FingerInfo *existing_finger, | |||
2682 | /* Iterate over list of trails. */ | 2673 | /* Iterate over list of trails. */ |
2683 | for (i = 0; i < existing_finger->trails_count; i++) | 2674 | for (i = 0; i < existing_finger->trails_count; i++) |
2684 | { | 2675 | { |
2685 | trail = &(existing_finger->trail_list[i]); | 2676 | current_trail = &(existing_finger->trail_list[i]); |
2686 | GNUNET_assert (GNUNET_YES == trail->is_present); | 2677 | if(GNUNET_NO == current_trail->is_present) |
2678 | continue; | ||
2687 | 2679 | ||
2688 | /* New trail and existing trail length are not same. */ | 2680 | /* New trail and existing trail length are not same. */ |
2689 | if (trail->trail_length != trail_length) | 2681 | if (current_trail->trail_length != trail_length) |
2690 | { | 2682 | { |
2691 | return GNUNET_YES; | 2683 | return GNUNET_YES; |
2692 | } | 2684 | } |
2693 | 2685 | ||
2694 | trail_element = trail->trail_head; | 2686 | trail_element = current_trail->trail_head; |
2695 | GNUNET_assert (trail_element != NULL); | 2687 | for (j = 0; j < current_trail->trail_length; j++) |
2696 | for (j = 0; j < trail->trail_length; j++) | ||
2697 | { | 2688 | { |
2698 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&new_trail[j], | 2689 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&new_trail[j], |
2699 | &trail_element->peer)) | 2690 | &trail_element->peer)) |
@@ -2706,13 +2697,86 @@ is_new_trail_unique (struct FingerInfo *existing_finger, | |||
2706 | return GNUNET_NO; | 2697 | return GNUNET_NO; |
2707 | } | 2698 | } |
2708 | 2699 | ||
2700 | /** | ||
2701 | * FIXME; In case of multiple trails, we may have a case where a trail from in | ||
2702 | * between has been removed, then we should try to find a free slot , not simply | ||
2703 | * add a trail at then end of the list. | ||
2704 | * Add a new trail at a free slot in trail array of existing finger. | ||
2705 | * @param existing_finger Finger | ||
2706 | * @param new_finger_trail New trail from me to finger, NOT including endpoints | ||
2707 | * @param new_finger_trail_length Total number of peers in @a new_finger_trail | ||
2708 | * @param new_finger_trail_id Unique identifier of the trail. | ||
2709 | */ | ||
2710 | static void | ||
2711 | add_new_trail (struct FingerInfo *existing_finger, | ||
2712 | const struct GNUNET_PeerIdentity *new_trail, | ||
2713 | unsigned int new_trail_length, | ||
2714 | struct GNUNET_HashCode new_trail_id) | ||
2715 | { | ||
2716 | struct FriendInfo *friend; | ||
2717 | struct Trail *trail; | ||
2718 | unsigned int i; | ||
2719 | int free_slot = -1; | ||
2720 | |||
2721 | if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, | ||
2722 | new_trail_length)) | ||
2723 | return; | ||
2724 | |||
2725 | for (i = 0; i < existing_finger->trails_count; i++) | ||
2726 | { | ||
2727 | if (GNUNET_NO == existing_finger->trail_list[i].is_present) | ||
2728 | { | ||
2729 | free_slot = i; | ||
2730 | break; | ||
2731 | } | ||
2732 | } | ||
2733 | |||
2734 | if (-1 == free_slot) | ||
2735 | free_slot = i; | ||
2736 | |||
2737 | trail = &existing_finger->trail_list[free_slot]; | ||
2738 | GNUNET_assert (GNUNET_NO == trail->is_present); | ||
2739 | trail->trail_id = new_trail_id; | ||
2740 | trail->trail_length = new_trail_length; | ||
2741 | existing_finger->trails_count++; | ||
2742 | trail->is_present = GNUNET_YES; | ||
2743 | if (0 == new_trail_length) | ||
2744 | { | ||
2745 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2746 | &existing_finger->finger_identity); | ||
2747 | } | ||
2748 | else | ||
2749 | { | ||
2750 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2751 | &new_trail[0]); | ||
2752 | } | ||
2753 | |||
2754 | friend->trails_count++; | ||
2755 | for (i = 0; i < new_trail_length; i++) | ||
2756 | { | ||
2757 | struct Trail_Element *element; | ||
2709 | 2758 | ||
2759 | element = GNUNET_new (struct Trail_Element); | ||
2760 | element->peer = new_trail[i]; | ||
2761 | GNUNET_CONTAINER_DLL_insert_tail (trail->trail_head, | ||
2762 | trail->trail_tail, | ||
2763 | element); | ||
2764 | } | ||
2765 | |||
2766 | existing_finger->trail_list[free_slot].trail_head = trail->trail_head; | ||
2767 | existing_finger->trail_list[free_slot].trail_tail = trail->trail_tail; | ||
2768 | existing_finger->trail_list[free_slot].trail_length = new_trail_length; | ||
2769 | existing_finger->trail_list[free_slot].trail_id = new_trail_id; | ||
2770 | existing_finger->trail_list[free_slot].is_present = GNUNET_YES; | ||
2771 | } | ||
2772 | |||
2773 | |||
2774 | #if 0 | ||
2710 | /** | 2775 | /** |
2711 | * FIXME; In case of multiple trails, we may have a case where a trail from in | 2776 | * FIXME; In case of multiple trails, we may have a case where a trail from in |
2712 | * between has been removed, then we should try to find a free slot , not simply | 2777 | * between has been removed, then we should try to find a free slot , not simply |
2713 | * add a trail at then end of the list. | 2778 | * add a trail at then end of the list. |
2714 | * Add a new trail to existing finger. This function is called only when finger | 2779 | * Add a new trail at a free slot in trail array of existing finger. |
2715 | * is not my own identity or a friend. | ||
2716 | * @param existing_finger Finger | 2780 | * @param existing_finger Finger |
2717 | * @param new_finger_trail New trail from me to finger, NOT including endpoints | 2781 | * @param new_finger_trail New trail from me to finger, NOT including endpoints |
2718 | * @param new_finger_trail_length Total number of peers in @a new_finger_trail | 2782 | * @param new_finger_trail_length Total number of peers in @a new_finger_trail |
@@ -2731,9 +2795,7 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2731 | 2795 | ||
2732 | if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, | 2796 | if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, |
2733 | new_trail_length)) | 2797 | new_trail_length)) |
2734 | { | ||
2735 | return; | 2798 | return; |
2736 | } | ||
2737 | 2799 | ||
2738 | index = existing_finger->trails_count; | 2800 | index = existing_finger->trails_count; |
2739 | trail = &existing_finger->trail_list[index]; | 2801 | trail = &existing_finger->trail_list[index]; |
@@ -2769,11 +2831,9 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2769 | existing_finger->trail_list[index].trail_id = new_trail_id; | 2831 | existing_finger->trail_list[index].trail_id = new_trail_id; |
2770 | existing_finger->trail_list[index].is_present = GNUNET_YES; | 2832 | existing_finger->trail_list[index].is_present = GNUNET_YES; |
2771 | } | 2833 | } |
2772 | 2834 | #endif | |
2773 | 2835 | ||
2774 | /** | 2836 | /** |
2775 | * FIXME Check if this function is called for opposite direction if yes then | ||
2776 | * take it as parameter. | ||
2777 | * Get the next hop to send trail teardown message from routing table and | 2837 | * Get the next hop to send trail teardown message from routing table and |
2778 | * then delete the entry from routing table. Send trail teardown message for a | 2838 | * then delete the entry from routing table. Send trail teardown message for a |
2779 | * specific trail of a finger. | 2839 | * specific trail of a finger. |
@@ -2790,29 +2850,16 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2790 | 2850 | ||
2791 | next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, | 2851 | next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, |
2792 | GDS_ROUTING_SRC_TO_DEST); | 2852 | GDS_ROUTING_SRC_TO_DEST); |
2793 | |||
2794 | if (NULL == next_hop) | 2853 | if (NULL == next_hop) |
2795 | { | 2854 | { |
2796 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line", | 2855 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line=%d,traillength = %d", |
2797 | GNUNET_i2s(&my_identity), GNUNET_h2s(&trail->trail_id), __LINE__); | 2856 | GNUNET_i2s(&my_identity), GNUNET_h2s(&trail->trail_id), __LINE__,trail->trail_length); |
2798 | GNUNET_break(0); | ||
2799 | return; | 2857 | return; |
2800 | } | 2858 | } |
2801 | |||
2802 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 2859 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
2803 | &my_identity)); | 2860 | &my_identity)); |
2804 | 2861 | ||
2805 | /*FIXME: here was an assertion that trail->is_present = GNUNET_YES. But it | 2862 | GNUNET_assert(GNUNET_YES == trail->is_present); |
2806 | used to fail. We have removed assertion with a condition, just for now. | ||
2807 | Find out the reason why assertion failed. */ | ||
2808 | if (trail->is_present == GNUNET_NO) | ||
2809 | { | ||
2810 | DEBUG(" trail id %s of peer %s is not present to send a trail teardown message., line", | ||
2811 | GNUNET_i2s(&my_identity), GNUNET_h2s(&trail->trail_id), __LINE__); | ||
2812 | return; | ||
2813 | } | ||
2814 | |||
2815 | /* Finger is not a friend. */ | ||
2816 | if (trail->trail_length > 0) | 2863 | if (trail->trail_length > 0) |
2817 | { | 2864 | { |
2818 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2865 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -2833,8 +2880,6 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2833 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id) | 2880 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id) |
2834 | && (0 == trail->trail_length)) | 2881 | && (0 == trail->trail_length)) |
2835 | { | 2882 | { |
2836 | //FIXME HERE WE GOT NEXT HOP FRM ROUTING TABLE, AND TRAIL ENGTH - 0, IT ITS | ||
2837 | // THE CASE WEHERE WE SET IT TO 0. | ||
2838 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", | 2883 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", |
2839 | __LINE__,GNUNET_h2s(&trail->trail_id), GNUNET_i2s(&my_identity),trail->trail_length); | 2884 | __LINE__,GNUNET_h2s(&trail->trail_id), GNUNET_i2s(&my_identity),trail->trail_length); |
2840 | return; | 2885 | return; |
@@ -2858,12 +2903,13 @@ send_all_finger_trails_teardown (struct FingerInfo *finger) | |||
2858 | for (i = 0; i < finger->trails_count; i++) | 2903 | for (i = 0; i < finger->trails_count; i++) |
2859 | { | 2904 | { |
2860 | struct Trail *trail; | 2905 | struct Trail *trail; |
2861 | |||
2862 | trail = &finger->trail_list[i]; | 2906 | trail = &finger->trail_list[i]; |
2863 | GNUNET_assert (trail->is_present == GNUNET_YES); | 2907 | if (GNUNET_YES == trail->is_present); |
2864 | send_trail_teardown (finger, trail); | 2908 | { |
2865 | trail->is_present = GNUNET_NO; | 2909 | send_trail_teardown (finger, trail); |
2866 | } | 2910 | trail->is_present = GNUNET_NO; |
2911 | } | ||
2912 | } | ||
2867 | } | 2913 | } |
2868 | 2914 | ||
2869 | 2915 | ||
@@ -2952,12 +2998,9 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2952 | return; | 2998 | return; |
2953 | } | 2999 | } |
2954 | 3000 | ||
2955 | /* If finger is a friend, then we don't actually have a trail. | 3001 | /* Finger is a friend. */ |
2956 | * Just a trail id */ | 3002 | if (0 == finger_trail_length) |
2957 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2958 | &finger_identity)) | ||
2959 | { | 3003 | { |
2960 | //FIXME: HERE WE SET TRAIL LENGTH TO 0, EVEN THOUGH IT HAS ENTRIES. | ||
2961 | new_entry->trail_list[0].trail_id = trail_id; | 3004 | new_entry->trail_list[0].trail_id = trail_id; |
2962 | new_entry->trails_count = 1; | 3005 | new_entry->trails_count = 1; |
2963 | new_entry->trail_list[0].is_present = GNUNET_YES; | 3006 | new_entry->trail_list[0].is_present = GNUNET_YES; |
@@ -2980,8 +3023,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2980 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3023 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2981 | &finger_trail[0]))); | 3024 | &finger_trail[0]))); |
2982 | new_entry->trails_count = 1; | 3025 | new_entry->trails_count = 1; |
2983 | first_trail_hop->trails_count++; | 3026 | first_trail_hop->trails_count++; |
2984 | GNUNET_assert (finger_trail_length != 0); | ||
2985 | /* Copy the finger trail into trail. */ | 3027 | /* Copy the finger trail into trail. */ |
2986 | trail = GNUNET_new (struct Trail); | 3028 | trail = GNUNET_new (struct Trail); |
2987 | for(i = 0; i < finger_trail_length; i++) | 3029 | for(i = 0; i < finger_trail_length; i++) |
@@ -2996,7 +3038,6 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2996 | element); | 3038 | element); |
2997 | } | 3039 | } |
2998 | 3040 | ||
2999 | |||
3000 | /* Add trail to trail list. */ | 3041 | /* Add trail to trail list. */ |
3001 | new_entry->trail_list[0].trail_head = trail->trail_head; | 3042 | new_entry->trail_list[0].trail_head = trail->trail_head; |
3002 | new_entry->trail_list[0].trail_tail = trail->trail_tail; | 3043 | new_entry->trail_list[0].trail_tail = trail->trail_tail; |
@@ -3022,24 +3063,19 @@ send_verify_successor_message (void *cls, | |||
3022 | { | 3063 | { |
3023 | struct FriendInfo *target_friend; | 3064 | struct FriendInfo *target_friend; |
3024 | struct GNUNET_HashCode trail_id; | 3065 | struct GNUNET_HashCode trail_id; |
3025 | int i; | ||
3026 | struct Trail *trail; | 3066 | struct Trail *trail; |
3027 | struct Trail_Element *element; | 3067 | struct Trail_Element *element; |
3028 | unsigned int trail_length; | 3068 | unsigned int trail_length; |
3029 | unsigned int j = 0; | 3069 | unsigned int i = 0; |
3030 | struct FingerInfo *successor; | 3070 | struct FingerInfo *successor; |
3031 | 3071 | ||
3032 | /* Schedule another send_find_finger_trail_message task. | 3072 | /* After one round of verify successor, we do back off. */ |
3033 | verify_successor_next_send_time.rel_value_us = | ||
3034 | verify_successor_next_send_time.rel_value_us + | ||
3035 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
3036 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us);*/ | ||
3037 | send_verify_successor_task = | 3073 | send_verify_successor_task = |
3038 | GNUNET_SCHEDULER_add_delayed (verify_successor_next_send_time, | 3074 | GNUNET_SCHEDULER_add_delayed (verify_successor_next_send_time, |
3039 | &send_verify_successor_message, | 3075 | &send_verify_successor_message, |
3040 | NULL); | 3076 | NULL); |
3041 | |||
3042 | successor = &finger_table[0]; | 3077 | successor = &finger_table[0]; |
3078 | /* Among all the trails to reach to successor, select first one which is present.*/ | ||
3043 | for (i = 0; i < successor->trails_count; i++) | 3079 | for (i = 0; i < successor->trails_count; i++) |
3044 | { | 3080 | { |
3045 | trail = &successor->trail_list[i]; | 3081 | trail = &successor->trail_list[i]; |
@@ -3053,10 +3089,8 @@ send_verify_successor_message (void *cls, | |||
3053 | 3089 | ||
3054 | GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | 3090 | GNUNET_assert(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3055 | &successor->finger_identity)); | 3091 | &successor->finger_identity)); |
3056 | |||
3057 | /* Trail stored at this index. */ | 3092 | /* Trail stored at this index. */ |
3058 | GNUNET_assert (GNUNET_YES == trail->is_present); | 3093 | GNUNET_assert (GNUNET_YES == trail->is_present); |
3059 | |||
3060 | trail_id = trail->trail_id; | 3094 | trail_id = trail->trail_id; |
3061 | if (NULL == GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST)) | 3095 | if (NULL == GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST)) |
3062 | { | 3096 | { |
@@ -3066,19 +3100,16 @@ send_verify_successor_message (void *cls, | |||
3066 | return; | 3100 | return; |
3067 | } | 3101 | } |
3068 | trail_length = trail->trail_length; | 3102 | trail_length = trail->trail_length; |
3069 | |||
3070 | if (trail_length > 0) | 3103 | if (trail_length > 0) |
3071 | { | 3104 | { |
3072 | /* Copy the trail into peer list. */ | 3105 | /* Copy the trail into peer list. */ |
3073 | struct GNUNET_PeerIdentity peer_list[trail_length]; | 3106 | struct GNUNET_PeerIdentity peer_list[trail_length]; |
3074 | |||
3075 | element = trail->trail_head; | 3107 | element = trail->trail_head; |
3076 | for(j = 0; j < trail_length; j++) | 3108 | for(i = 0; i < trail_length; i++) |
3077 | { | 3109 | { |
3078 | peer_list[j] = element->peer; | 3110 | peer_list[i] = element->peer; |
3079 | element = element->next; | 3111 | element = element->next; |
3080 | } | 3112 | } |
3081 | |||
3082 | GNUNET_assert (NULL != (target_friend = | 3113 | GNUNET_assert (NULL != (target_friend = |
3083 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3114 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3084 | &peer_list[0]))); | 3115 | &peer_list[0]))); |
@@ -3086,7 +3117,6 @@ send_verify_successor_message (void *cls, | |||
3086 | successor->finger_identity, | 3117 | successor->finger_identity, |
3087 | trail_id, peer_list, trail_length, | 3118 | trail_id, peer_list, trail_length, |
3088 | target_friend); | 3119 | target_friend); |
3089 | return; | ||
3090 | } | 3120 | } |
3091 | else | 3121 | else |
3092 | { | 3122 | { |
@@ -3097,7 +3127,6 @@ send_verify_successor_message (void *cls, | |||
3097 | successor->finger_identity, | 3127 | successor->finger_identity, |
3098 | trail_id, NULL, 0, | 3128 | trail_id, NULL, 0, |
3099 | target_friend); | 3129 | target_friend); |
3100 | return; | ||
3101 | } | 3130 | } |
3102 | } | 3131 | } |
3103 | 3132 | ||
@@ -3105,12 +3134,11 @@ send_verify_successor_message (void *cls, | |||
3105 | /** | 3134 | /** |
3106 | * FIXME: should this be a periodic task, incrementing the search finger index? | 3135 | * FIXME: should this be a periodic task, incrementing the search finger index? |
3107 | * Update the current search finger index. | 3136 | * Update the current search finger index. |
3108 | * | 3137 | * @a finger_identity |
3109 | * FIXME document parameters! | 3138 | * @a finger_table_index |
3110 | */ | 3139 | */ |
3111 | static void | 3140 | static void |
3112 | update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | 3141 | update_current_search_finger_index (unsigned int finger_table_index) |
3113 | unsigned int finger_table_index) | ||
3114 | { | 3142 | { |
3115 | struct FingerInfo *successor; | 3143 | struct FingerInfo *successor; |
3116 | 3144 | ||
@@ -3124,10 +3152,8 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | |||
3124 | /* We were looking for immediate successor. */ | 3152 | /* We were looking for immediate successor. */ |
3125 | if (0 == current_search_finger_index) | 3153 | if (0 == current_search_finger_index) |
3126 | { | 3154 | { |
3127 | /* Start looking for immediate predecessor. */ | ||
3128 | current_search_finger_index = PREDECESSOR_FINGER_ID; | 3155 | current_search_finger_index = PREDECESSOR_FINGER_ID; |
3129 | 3156 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &successor->finger_identity)) | |
3130 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | ||
3131 | { | 3157 | { |
3132 | if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task) | 3158 | if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task) |
3133 | { | 3159 | { |
@@ -3289,7 +3315,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3289 | return; | 3315 | return; |
3290 | } | 3316 | } |
3291 | 3317 | ||
3292 | /* New entry same as successor. */ | 3318 | /* Check if new entry is same as successor. */ |
3293 | if ((0 != finger_table_index) && | 3319 | if ((0 != finger_table_index) && |
3294 | (PREDECESSOR_FINGER_ID != finger_table_index)) | 3320 | (PREDECESSOR_FINGER_ID != finger_table_index)) |
3295 | { | 3321 | { |
@@ -3305,6 +3331,11 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3305 | find_finger_trail_task_next_send_time = | 3331 | find_finger_trail_task_next_send_time = |
3306 | GNUNET_TIME_STD_BACKOFF(find_finger_trail_task_next_send_time); | 3332 | GNUNET_TIME_STD_BACKOFF(find_finger_trail_task_next_send_time); |
3307 | current_search_finger_index = 0; | 3333 | current_search_finger_index = 0; |
3334 | GNUNET_STATISTICS_update (GDS_stats, | ||
3335 | gettext_noop | ||
3336 | ("# FINGERS_COUNT"), (int64_t) total_fingers_found, | ||
3337 | GNUNET_NO); | ||
3338 | total_fingers_found = 0; | ||
3308 | return; | 3339 | return; |
3309 | } | 3340 | } |
3310 | 3341 | ||
@@ -3317,21 +3348,20 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3317 | return; | 3348 | return; |
3318 | } | 3349 | } |
3319 | } | 3350 | } |
3320 | 3351 | ||
3352 | total_fingers_found++; | ||
3321 | existing_finger = &finger_table[finger_table_index]; | 3353 | existing_finger = &finger_table[finger_table_index]; |
3322 | 3354 | ||
3323 | /* No entry present in finger_table for given finger map index. */ | 3355 | /* No entry present in finger_table for given finger map index. */ |
3324 | if (GNUNET_NO == existing_finger->is_present) | 3356 | if (GNUNET_NO == existing_finger->is_present) |
3325 | { | 3357 | { |
3326 | add_new_finger (finger_identity, finger_trail, | 3358 | add_new_finger (finger_identity, finger_trail, |
3327 | finger_trail_length, | 3359 | finger_trail_length, |
3328 | finger_trail_id, finger_table_index); | 3360 | finger_trail_id, finger_table_index); |
3329 | update_current_search_finger_index (finger_identity, | 3361 | update_current_search_finger_index (finger_table_index); |
3330 | finger_table_index); | ||
3331 | return; | 3362 | return; |
3332 | } | 3363 | } |
3333 | 3364 | ||
3334 | |||
3335 | /* If existing entry and finger identity are not same. */ | 3365 | /* If existing entry and finger identity are not same. */ |
3336 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), | 3366 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), |
3337 | &finger_identity)) | 3367 | &finger_identity)) |
@@ -3373,22 +3403,16 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3373 | { | 3403 | { |
3374 | return; | 3404 | return; |
3375 | } | 3405 | } |
3376 | /* If the existing finger is not a friend. */ | 3406 | |
3377 | if (NULL == | 3407 | /* If there is space to store more trails. */ |
3378 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3408 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) |
3379 | &existing_finger->finger_identity)) | ||
3380 | { | ||
3381 | /* If there is space to store more trails. */ | ||
3382 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) | ||
3383 | add_new_trail (existing_finger, finger_trail, | 3409 | add_new_trail (existing_finger, finger_trail, |
3384 | finger_trail_length, finger_trail_id); | 3410 | finger_trail_length, finger_trail_id); |
3385 | else | 3411 | else |
3386 | select_and_replace_trail (existing_finger, finger_trail, | 3412 | select_and_replace_trail (existing_finger, finger_trail, |
3387 | finger_trail_length, finger_trail_id); | 3413 | finger_trail_length, finger_trail_id); |
3388 | |||
3389 | } | ||
3390 | } | 3414 | } |
3391 | update_current_search_finger_index (finger_identity, finger_table_index); | 3415 | update_current_search_finger_index (finger_table_index); |
3392 | return; | 3416 | return; |
3393 | } | 3417 | } |
3394 | 3418 | ||
@@ -3564,7 +3588,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3564 | { | 3588 | { |
3565 | struct Closest_Peer successor; | 3589 | struct Closest_Peer successor; |
3566 | key_value = GNUNET_ntohll (key_value); | 3590 | key_value = GNUNET_ntohll (key_value); |
3567 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 3591 | successor = find_local_best_known_next_hop (key_value, |
3592 | GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
3568 | next_hop = GNUNET_new (struct GNUNET_PeerIdentity); | 3593 | next_hop = GNUNET_new (struct GNUNET_PeerIdentity); |
3569 | *next_hop = successor.next_hop; | 3594 | *next_hop = successor.next_hop; |
3570 | intermediate_trail_id = successor.trail_id; | 3595 | intermediate_trail_id = successor.trail_id; |
@@ -3715,7 +3740,8 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3715 | { | 3740 | { |
3716 | struct Closest_Peer successor; | 3741 | struct Closest_Peer successor; |
3717 | 3742 | ||
3718 | successor = find_successor (key_value, GDS_FINGER_TYPE_NON_PREDECESSOR); | 3743 | successor = find_local_best_known_next_hop (key_value, |
3744 | GDS_FINGER_TYPE_NON_PREDECESSOR); | ||
3719 | next_hop = GNUNET_new (struct GNUNET_PeerIdentity); | 3745 | next_hop = GNUNET_new (struct GNUNET_PeerIdentity); |
3720 | *next_hop = successor.next_hop; | 3746 | *next_hop = successor.next_hop; |
3721 | best_known_dest = successor.best_known_destination; | 3747 | best_known_dest = successor.best_known_destination; |
@@ -3848,6 +3874,7 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3848 | * finger, then it is the trail id to reach to | 3874 | * finger, then it is the trail id to reach to |
3849 | * that finger, else set to 0. | 3875 | * that finger, else set to 0. |
3850 | * @param is_predecessor Are we looking for closest successor or predecessor. | 3876 | * @param is_predecessor Are we looking for closest successor or predecessor. |
3877 | * @param source Source of trail setup message. | ||
3851 | * @param current_dest In case you are part of trail, then finger to which | 3878 | * @param current_dest In case you are part of trail, then finger to which |
3852 | * we should forward the message. Else my own identity | 3879 | * we should forward the message. Else my own identity |
3853 | * @return Closest Peer for @a final_dest_finger_val | 3880 | * @return Closest Peer for @a final_dest_finger_val |
@@ -3856,24 +3883,22 @@ static struct Closest_Peer | |||
3856 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, | 3883 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, |
3857 | struct GNUNET_HashCode intermediate_trail_id, | 3884 | struct GNUNET_HashCode intermediate_trail_id, |
3858 | unsigned int is_predecessor, | 3885 | unsigned int is_predecessor, |
3859 | struct GNUNET_PeerIdentity prev_hop, | ||
3860 | struct GNUNET_PeerIdentity source, | 3886 | struct GNUNET_PeerIdentity source, |
3861 | struct GNUNET_PeerIdentity *current_dest) | 3887 | struct GNUNET_PeerIdentity *current_dest) |
3862 | { | 3888 | { |
3863 | struct Closest_Peer peer; | 3889 | struct Closest_Peer peer; |
3864 | 3890 | ||
3865 | /* Find a local best known peer. */ | 3891 | peer = find_local_best_known_next_hop (final_dest_finger_val, is_predecessor); |
3866 | peer = find_successor (final_dest_finger_val, is_predecessor);//FIXME: chnage to better name | ||
3867 | 3892 | ||
3868 | /* Am I just a part of a trail towards a finger (current_destination)? */ | 3893 | /* Am I just a part of a trail towards a finger (current_destination)? */ |
3869 | /* Select best successor among one found locally and current_destination | ||
3870 | * that we got from network.*/ | ||
3871 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest) && | 3894 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest) && |
3872 | 0 != GNUNET_CRYPTO_cmp_peer_identity (&peer.best_known_destination, | 3895 | 0 != GNUNET_CRYPTO_cmp_peer_identity (&peer.best_known_destination, |
3873 | current_dest)) | 3896 | current_dest)) |
3874 | { | 3897 | { |
3875 | struct GNUNET_PeerIdentity closest_peer; | 3898 | struct GNUNET_PeerIdentity closest_peer; |
3876 | 3899 | ||
3900 | /* Select best successor among one found locally and current_destination | ||
3901 | * that we got from network.*/ | ||
3877 | closest_peer = select_closest_peer (&peer.best_known_destination, | 3902 | closest_peer = select_closest_peer (&peer.best_known_destination, |
3878 | current_dest, | 3903 | current_dest, |
3879 | final_dest_finger_val, | 3904 | final_dest_finger_val, |
@@ -3920,11 +3945,11 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3920 | struct GNUNET_PeerIdentity current_dest; | 3945 | struct GNUNET_PeerIdentity current_dest; |
3921 | struct FriendInfo *target_friend; | 3946 | struct FriendInfo *target_friend; |
3922 | struct GNUNET_PeerIdentity source; | 3947 | struct GNUNET_PeerIdentity source; |
3923 | uint64_t final_dest_finger_val; | ||
3924 | struct GNUNET_HashCode intermediate_trail_id; | 3948 | struct GNUNET_HashCode intermediate_trail_id; |
3925 | struct GNUNET_HashCode trail_id; | 3949 | struct GNUNET_HashCode trail_id; |
3926 | unsigned int is_predecessor; | 3950 | unsigned int is_predecessor; |
3927 | uint32_t trail_length; | 3951 | uint32_t trail_length; |
3952 | uint64_t final_dest_finger_val; | ||
3928 | int i; | 3953 | int i; |
3929 | size_t msize; | 3954 | size_t msize; |
3930 | 3955 | ||
@@ -3958,7 +3983,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3958 | source = trail_setup->source_peer; | 3983 | source = trail_setup->source_peer; |
3959 | is_predecessor = ntohl (trail_setup->is_predecessor); | 3984 | is_predecessor = ntohl (trail_setup->is_predecessor); |
3960 | intermediate_trail_id = trail_setup->intermediate_trail_id; | 3985 | intermediate_trail_id = trail_setup->intermediate_trail_id; |
3961 | 3986 | ||
3962 | /* Did the friend insert its ID in the trail list? */ | 3987 | /* Did the friend insert its ID in the trail list? */ |
3963 | if (trail_length > 0 && | 3988 | if (trail_length > 0 && |
3964 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (struct GNUNET_PeerIdentity))) | 3989 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (struct GNUNET_PeerIdentity))) |
@@ -3973,15 +3998,13 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3973 | trail_length = 0; | 3998 | trail_length = 0; |
3974 | } | 3999 | } |
3975 | 4000 | ||
3976 | /* SUPUS: remove the check that source is a friend, because again source | ||
3977 | may become aware about it later. and by that time lookup may fail. */ | ||
3978 | |||
3979 | /* Check if you are present in the trail seen so far? */ | 4001 | /* Check if you are present in the trail seen so far? */ |
3980 | for (i = 0; i < trail_length ; i++) | 4002 | for (i = 0; i < trail_length ; i++) |
3981 | { | 4003 | { |
3982 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) | 4004 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) |
3983 | { | 4005 | { |
3984 | trail_length = i; /* Check that you add yourself again */ | 4006 | /* We will add ourself later in code, if NOT destination. */ |
4007 | trail_length = i; | ||
3985 | break; | 4008 | break; |
3986 | } | 4009 | } |
3987 | } | 4010 | } |
@@ -3997,14 +4020,12 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3997 | target_friend = | 4020 | target_friend = |
3998 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4021 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3999 | &source); | 4022 | &source); |
4000 | |||
4001 | if(NULL == target_friend) | 4023 | if(NULL == target_friend) |
4002 | { | 4024 | { |
4003 | DEBUG ("\n friend not found"); | 4025 | DEBUG ("\n friend not found"); |
4004 | GNUNET_break(0); | 4026 | GNUNET_break(0); |
4005 | return GNUNET_OK; | 4027 | return GNUNET_OK; |
4006 | } | 4028 | } |
4007 | |||
4008 | GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, | 4029 | GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, |
4009 | my_identity, is_predecessor, | 4030 | my_identity, is_predecessor, |
4010 | trail_peer_list, trail_length, | 4031 | trail_peer_list, trail_length, |
@@ -4018,7 +4039,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4018 | get_local_best_known_next_hop (final_dest_finger_val, | 4039 | get_local_best_known_next_hop (final_dest_finger_val, |
4019 | intermediate_trail_id, | 4040 | intermediate_trail_id, |
4020 | is_predecessor, | 4041 | is_predecessor, |
4021 | *peer, | ||
4022 | source, | 4042 | source, |
4023 | ¤t_dest); | 4043 | ¤t_dest); |
4024 | 4044 | ||
@@ -4040,7 +4060,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4040 | else | 4060 | else |
4041 | target_friend = | 4061 | target_friend = |
4042 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); | 4062 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); |
4043 | |||
4044 | if (NULL == target_friend) | 4063 | if (NULL == target_friend) |
4045 | { | 4064 | { |
4046 | GNUNET_break_op (0); | 4065 | GNUNET_break_op (0); |
@@ -4064,7 +4083,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4064 | GNUNET_break (0); | 4083 | GNUNET_break (0); |
4065 | return GNUNET_OK; | 4084 | return GNUNET_OK; |
4066 | } | 4085 | } |
4067 | |||
4068 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 4086 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) |
4069 | { | 4087 | { |
4070 | /* Add yourself to list of peers. */ | 4088 | /* Add yourself to list of peers. */ |
@@ -4509,14 +4527,16 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4509 | &trail_to_new_predecessor_id, | 4527 | &trail_to_new_predecessor_id, |
4510 | sizeof (trail_to_new_predecessor_id)); | 4528 | sizeof (trail_to_new_predecessor_id)); |
4511 | 4529 | ||
4512 | /* Finger is a friend. */ | 4530 | if (0 == trail_length) |
4513 | if (trail_length == 0) | ||
4514 | { | 4531 | { |
4515 | trail_to_new_predecessor = NULL; | 4532 | trail_to_new_predecessor = NULL; |
4516 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); | 4533 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); |
4517 | GNUNET_assert (NULL != (target_friend = | 4534 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger); |
4518 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4535 | if (NULL == target_friend) |
4519 | &finger))); | 4536 | { |
4537 | GNUNET_break (0); | ||
4538 | return; | ||
4539 | } | ||
4520 | } | 4540 | } |
4521 | else | 4541 | else |
4522 | { | 4542 | { |
@@ -4524,7 +4544,6 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4524 | endpoints.*/ | 4544 | endpoints.*/ |
4525 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 4545 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, |
4526 | &trail[trail_length-1])); | 4546 | &trail[trail_length-1])); |
4527 | |||
4528 | trail_to_new_predecessor = invert_trail (trail, trail_length); | 4547 | trail_to_new_predecessor = invert_trail (trail, trail_length); |
4529 | 4548 | ||
4530 | /* Add an entry in your routing table. */ | 4549 | /* Add an entry in your routing table. */ |
@@ -4535,9 +4554,6 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4535 | GNUNET_assert (NULL != (target_friend = | 4554 | GNUNET_assert (NULL != (target_friend = |
4536 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4555 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4537 | &trail_to_new_predecessor[0]))); | 4556 | &trail_to_new_predecessor[0]))); |
4538 | GNUNET_assert (NULL != ( | ||
4539 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
4540 | &trail[trail_length - 1]))); | ||
4541 | } | 4557 | } |
4542 | 4558 | ||
4543 | /* Add entry in routing table of all peers that are part of trail from me | 4559 | /* Add entry in routing table of all peers that are part of trail from me |
@@ -4754,6 +4770,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4754 | struct GNUNET_PeerIdentity *trail_to_new_successor; | 4770 | struct GNUNET_PeerIdentity *trail_to_new_successor; |
4755 | 4771 | ||
4756 | /* Probable successor is a friend */ | 4772 | /* Probable successor is a friend */ |
4773 | /* SUPUS: Here should I worry about friend,*/ | ||
4757 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4774 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4758 | &probable_successor)) | 4775 | &probable_successor)) |
4759 | { | 4776 | { |
@@ -4776,7 +4793,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4776 | *trail_to_new_successor_length); | 4793 | *trail_to_new_successor_length); |
4777 | 4794 | ||
4778 | 4795 | ||
4779 | for(j = 0;j < *trail_to_new_successor_length;i++,j++) | 4796 | for(j = 0; j < *trail_to_new_successor_length; i++,j++) |
4780 | { | 4797 | { |
4781 | trail_to_new_successor[j] = trail_me_to_probable_successor[i]; | 4798 | trail_to_new_successor[j] = trail_me_to_probable_successor[i]; |
4782 | } | 4799 | } |
@@ -4836,6 +4853,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4836 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&closest_peer , | 4853 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&closest_peer , |
4837 | ¤t_successor->finger_identity)) | 4854 | ¤t_successor->finger_identity)) |
4838 | { | 4855 | { |
4856 | //FIXME: Is this a good place to return the stats. | ||
4839 | if ((NULL != GDS_stats)) | 4857 | if ((NULL != GDS_stats)) |
4840 | { | 4858 | { |
4841 | char *my_id_str; | 4859 | char *my_id_str; |
@@ -4906,8 +4924,6 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4906 | 4924 | ||
4907 | 4925 | ||
4908 | /* | 4926 | /* |
4909 | * FIXME: Check for duplicate elements everywhere when you are making | ||
4910 | * trails. | ||
4911 | * Core handle for p2p verify successor result messages. | 4927 | * Core handle for p2p verify successor result messages. |
4912 | * @param cls closure | 4928 | * @param cls closure |
4913 | * @param message message | 4929 | * @param message message |
@@ -4932,8 +4948,6 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4932 | size_t msize; | 4948 | size_t msize; |
4933 | 4949 | ||
4934 | msize = ntohs (message->size); | 4950 | msize = ntohs (message->size); |
4935 | /* We send a trail to reach from old successor to new successor, if | ||
4936 | * old_successor != new_successor.*/ | ||
4937 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) | 4951 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) |
4938 | { | 4952 | { |
4939 | GNUNET_break_op (0); | 4953 | GNUNET_break_op (0); |
@@ -4941,16 +4955,15 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4941 | } | 4955 | } |
4942 | 4956 | ||
4943 | vsrm = (const struct PeerVerifySuccessorResultMessage *) message; | 4957 | vsrm = (const struct PeerVerifySuccessorResultMessage *) message; |
4944 | trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/ | ||
4945 | sizeof (struct GNUNET_PeerIdentity); | ||
4946 | |||
4947 | if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) % | 4958 | if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) % |
4948 | sizeof (struct GNUNET_PeerIdentity) != 0) | 4959 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4949 | { | 4960 | { |
4950 | GNUNET_break_op (0); | 4961 | GNUNET_break_op (0); |
4951 | return GNUNET_OK; | 4962 | return GNUNET_OK; |
4952 | } | 4963 | } |
4953 | 4964 | trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/ | |
4965 | sizeof (struct GNUNET_PeerIdentity); | ||
4966 | |||
4954 | GNUNET_STATISTICS_update (GDS_stats, | 4967 | GNUNET_STATISTICS_update (GDS_stats, |
4955 | gettext_noop | 4968 | gettext_noop |
4956 | ("# Bytes received from other peers"), msize, | 4969 | ("# Bytes received from other peers"), msize, |
@@ -4963,11 +4976,12 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4963 | probable_successor = vsrm->probable_successor; | 4976 | probable_successor = vsrm->probable_successor; |
4964 | current_successor = vsrm->current_successor; | 4977 | current_successor = vsrm->current_successor; |
4965 | 4978 | ||
4966 | verify_successor_next_send_time = | ||
4967 | GNUNET_TIME_STD_BACKOFF(verify_successor_next_send_time); | ||
4968 | /* I am the querying_peer. */ | 4979 | /* I am the querying_peer. */ |
4969 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) | 4980 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) |
4970 | { | 4981 | { |
4982 | /* As we completed one round of verify successor, we can do backoff. */ | ||
4983 | verify_successor_next_send_time = | ||
4984 | GNUNET_TIME_STD_BACKOFF(verify_successor_next_send_time); | ||
4971 | compare_and_update_successor (current_successor, | 4985 | compare_and_update_successor (current_successor, |
4972 | probable_successor, trail, trail_length); | 4986 | probable_successor, trail, trail_length); |
4973 | return GNUNET_OK; | 4987 | return GNUNET_OK; |
@@ -4977,6 +4991,7 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
4977 | if(NULL == (next_hop = | 4991 | if(NULL == (next_hop = |
4978 | GDS_ROUTING_get_next_hop (trail_id, trail_direction))) | 4992 | GDS_ROUTING_get_next_hop (trail_id, trail_direction))) |
4979 | { | 4993 | { |
4994 | //FIXME: Urgent in what case this is possible? | ||
4980 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line", | 4995 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line", |
4981 | GNUNET_i2s(&my_identity), GNUNET_h2s(&trail_id), __LINE__); | 4996 | GNUNET_i2s(&my_identity), GNUNET_h2s(&trail_id), __LINE__); |
4982 | GNUNET_break_op(0); | 4997 | GNUNET_break_op(0); |
@@ -5022,24 +5037,20 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
5022 | uint32_t trail_length; | 5037 | uint32_t trail_length; |
5023 | 5038 | ||
5024 | msize = ntohs (message->size); | 5039 | msize = ntohs (message->size); |
5025 | |||
5026 | /* We have the trail to reach from source to new successor. */ | ||
5027 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) | 5040 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) |
5028 | { | 5041 | { |
5029 | GNUNET_break_op (0); | 5042 | GNUNET_break_op (0); |
5030 | return GNUNET_YES; | 5043 | return GNUNET_YES; |
5031 | } | 5044 | } |
5032 | |||
5033 | nsm = (const struct PeerNotifyNewSuccessorMessage *) message; | 5045 | nsm = (const struct PeerNotifyNewSuccessorMessage *) message; |
5034 | trail_length = (msize - sizeof (struct PeerNotifyNewSuccessorMessage))/ | ||
5035 | sizeof (struct GNUNET_PeerIdentity); | ||
5036 | if ((msize - sizeof (struct PeerNotifyNewSuccessorMessage)) % | 5046 | if ((msize - sizeof (struct PeerNotifyNewSuccessorMessage)) % |
5037 | sizeof (struct GNUNET_PeerIdentity) != 0) | 5047 | sizeof (struct GNUNET_PeerIdentity) != 0) |
5038 | { | 5048 | { |
5039 | GNUNET_break_op (0); | 5049 | GNUNET_break_op (0); |
5040 | return GNUNET_OK; | 5050 | return GNUNET_OK; |
5041 | } | 5051 | } |
5042 | 5052 | trail_length = (msize - sizeof (struct PeerNotifyNewSuccessorMessage))/ | |
5053 | sizeof (struct GNUNET_PeerIdentity); | ||
5043 | GNUNET_STATISTICS_update (GDS_stats, | 5054 | GNUNET_STATISTICS_update (GDS_stats, |
5044 | gettext_noop | 5055 | gettext_noop |
5045 | ("# Bytes received from other peers"), msize, | 5056 | ("# Bytes received from other peers"), msize, |
@@ -5083,10 +5094,18 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
5083 | else | 5094 | else |
5084 | next_hop = trail[my_index + 1]; | 5095 | next_hop = trail[my_index + 1]; |
5085 | /* Add an entry in routing table for trail from source to its new successor. */ | 5096 | /* Add an entry in routing table for trail from source to its new successor. */ |
5086 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); | 5097 | if (GNUNET_SYSERR == GDS_ROUTING_add (trail_id, *peer, next_hop)) |
5087 | GNUNET_assert (NULL != | 5098 | { |
5088 | (target_friend = | 5099 | GNUNET_break(0); |
5089 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | 5100 | return GNUNET_OK; |
5101 | } | ||
5102 | target_friend = | ||
5103 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | ||
5104 | if (NULL == target_friend) | ||
5105 | { | ||
5106 | GNUNET_break(0); | ||
5107 | return GNUNET_OK; | ||
5108 | } | ||
5090 | GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail, | 5109 | GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail, |
5091 | trail_length, | 5110 | trail_length, |
5092 | trail_id, target_friend); | 5111 | trail_id, target_friend); |
@@ -5193,7 +5212,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5193 | } | 5212 | } |
5194 | 5213 | ||
5195 | struct Closest_Peer successor; | 5214 | struct Closest_Peer successor; |
5196 | successor = find_successor (ultimate_destination_finger_value, is_predecessor); | 5215 | successor = find_local_best_known_next_hop (ultimate_destination_finger_value, is_predecessor); |
5197 | 5216 | ||
5198 | /* Am I the final destination? */ | 5217 | /* Am I the final destination? */ |
5199 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, | 5218 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, |
@@ -5436,27 +5455,27 @@ static int | |||
5436 | remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | 5455 | remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, |
5437 | struct FingerInfo *finger) | 5456 | struct FingerInfo *finger) |
5438 | { | 5457 | { |
5458 | struct GNUNET_PeerIdentity *next_hop; | ||
5459 | struct FriendInfo *remove_friend; | ||
5460 | struct Trail *current_trail; | ||
5439 | unsigned int matching_trails_count = 0; | 5461 | unsigned int matching_trails_count = 0; |
5440 | int i; | 5462 | int i; |
5441 | 5463 | ||
5442 | /* Iterate over all the trails of finger. */ | 5464 | /* Iterate over all the trails of finger. */ |
5443 | for (i = 0; i < finger->trails_count; i++) | 5465 | for (i = 0; i < finger->trails_count; i++) |
5444 | { | 5466 | { |
5445 | struct Trail *current_trail; | ||
5446 | current_trail = &finger->trail_list[i]; | 5467 | current_trail = &finger->trail_list[i]; |
5447 | //FIXME: This assertion fails if we have gap in trail list from o to trails count. | 5468 | if (GNUNET_NO == current_trail->is_present) |
5448 | GNUNET_assert (GNUNET_YES == current_trail->is_present); | 5469 | continue; |
5470 | |||
5449 | /* First friend to reach to finger is disconnected_peer. */ | 5471 | /* First friend to reach to finger is disconnected_peer. */ |
5450 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_trail->trail_head->peer, | 5472 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_trail->trail_head->peer, |
5451 | disconnected_friend)) | 5473 | disconnected_friend)) |
5452 | { | 5474 | { |
5453 | struct GNUNET_PeerIdentity *next_hop; | 5475 | remove_friend = |
5454 | struct FriendInfo *remove_friend; | ||
5455 | |||
5456 | GNUNET_assert (NULL != | ||
5457 | (remove_friend = | ||
5458 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5476 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5459 | disconnected_friend))); | 5477 | disconnected_friend); |
5478 | GNUNET_assert (NULL != remove_friend); | ||
5460 | next_hop = GDS_ROUTING_get_next_hop (current_trail->trail_id, | 5479 | next_hop = GDS_ROUTING_get_next_hop (current_trail->trail_id, |
5461 | GDS_ROUTING_SRC_TO_DEST); | 5480 | GDS_ROUTING_SRC_TO_DEST); |
5462 | 5481 | ||
@@ -5467,7 +5486,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | |||
5467 | if (NULL != next_hop) | 5486 | if (NULL != next_hop) |
5468 | { | 5487 | { |
5469 | GNUNET_assert (0 == (GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, | 5488 | GNUNET_assert (0 == (GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, |
5470 | next_hop))); | 5489 | next_hop))); |
5471 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (current_trail->trail_id)); | 5490 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (current_trail->trail_id)); |
5472 | } | 5491 | } |
5473 | matching_trails_count++; | 5492 | matching_trails_count++; |
@@ -5495,7 +5514,6 @@ static void | |||
5495 | remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | 5514 | remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) |
5496 | { | 5515 | { |
5497 | struct FingerInfo *current_finger; | 5516 | struct FingerInfo *current_finger; |
5498 | struct FriendInfo *remove_friend; | ||
5499 | int removed_trails_count; | 5517 | int removed_trails_count; |
5500 | int i; | 5518 | int i; |
5501 | 5519 | ||
@@ -5504,39 +5522,19 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5504 | { | 5522 | { |
5505 | current_finger = &finger_table[i]; | 5523 | current_finger = &finger_table[i]; |
5506 | 5524 | ||
5507 | /* No finger stored at this trail index. */ | 5525 | /* No finger stored at this trail index or I am the finger. */ |
5508 | if ((GNUNET_NO == current_finger->is_present) || | 5526 | if ((GNUNET_NO == current_finger->is_present) || |
5509 | (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_finger->finger_identity, | 5527 | (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_finger->finger_identity, |
5510 | &my_identity))) | 5528 | &my_identity))) |
5511 | continue; | 5529 | continue; |
5512 | 5530 | ||
5513 | /* Is disconnected_peer a finger? */ | 5531 | /* Is disconnected_peer a finger? */ |
5514 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, | 5532 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer, |
5515 | ¤t_finger->finger_identity)) | 5533 | ¤t_finger->finger_identity)) |
5516 | { | 5534 | { |
5517 | struct GNUNET_PeerIdentity *next_hop; | 5535 | remove_existing_finger (current_finger, i); |
5518 | struct GNUNET_HashCode trail_id; | ||
5519 | |||
5520 | GNUNET_assert (0 == current_finger->trail_list[0].trail_length); | ||
5521 | GNUNET_assert (GNUNET_YES == (current_finger->trail_list[0].is_present)); | ||
5522 | trail_id = current_finger->trail_list[0].trail_id; | ||
5523 | |||
5524 | if(NULL != | ||
5525 | (next_hop = | ||
5526 | GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST))) | ||
5527 | { | ||
5528 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | ||
5529 | GNUNET_assert (NULL != | ||
5530 | (remove_friend = | ||
5531 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
5532 | disconnected_peer))); | ||
5533 | } | ||
5534 | current_finger->trail_list[0].is_present = GNUNET_NO; | ||
5535 | current_finger->is_present = GNUNET_NO; | ||
5536 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | ||
5537 | continue; | ||
5538 | } | 5536 | } |
5539 | 5537 | ||
5540 | /* If finger is a friend but not disconnected_friend, then continue. */ | 5538 | /* If finger is a friend but not disconnected_friend, then continue. */ |
5541 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5539 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5542 | ¤t_finger->finger_identity)) | 5540 | ¤t_finger->finger_identity)) |
@@ -5648,15 +5646,17 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
5648 | 5646 | ||
5649 | friend = GNUNET_new (struct FriendInfo); | 5647 | friend = GNUNET_new (struct FriendInfo); |
5650 | friend->id = *peer_identity; | 5648 | friend->id = *peer_identity; |
5649 | |||
5651 | GNUNET_assert (GNUNET_OK == | 5650 | GNUNET_assert (GNUNET_OK == |
5652 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | 5651 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, |
5653 | peer_identity, friend, | 5652 | peer_identity, friend, |
5654 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 5653 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
5655 | 5654 | ||
5656 | /* SUPUS: We should add a congestion timestamp on the friend, so that it is | 5655 | /* FIXME: now we are not making a distinction between fingers which are friends |
5657 | selected after some time out. This is to ensure that both peers have added | 5656 | * also.But later, we should add a congestion timestamp on the friend, so that it is |
5658 | each other as their friend. */ | 5657 | * selected after some time out. This is to ensure that both peers have added |
5659 | /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ | 5658 | * each other as their friend. */ |
5659 | /* Got a first connection, good time to start with FIND FINGER TRAIL requests...*/ | ||
5660 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) | 5660 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) |
5661 | { | 5661 | { |
5662 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 5662 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); |
@@ -5735,11 +5735,12 @@ GDS_NEIGHBOURS_init (void) | |||
5735 | verify_successor_next_send_time.rel_value_us = | 5735 | verify_successor_next_send_time.rel_value_us = |
5736 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + | 5736 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + |
5737 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 5737 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
5738 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us); | 5738 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); |
5739 | 5739 | ||
5740 | return GNUNET_OK; | 5740 | return GNUNET_OK; |
5741 | } | 5741 | } |
5742 | 5742 | ||
5743 | |||
5743 | /** | 5744 | /** |
5744 | * Free the memory held up by trails of a finger. | 5745 | * Free the memory held up by trails of a finger. |
5745 | */ | 5746 | */ |
@@ -5751,15 +5752,10 @@ delete_finger_table_entries() | |||
5751 | 5752 | ||
5752 | for(i = 0; i < MAX_FINGERS; i++) | 5753 | for(i = 0; i < MAX_FINGERS; i++) |
5753 | { | 5754 | { |
5754 | if(GNUNET_NO == finger_table[i].is_present) | 5755 | if(GNUNET_YES == finger_table[i].is_present) |
5755 | continue; | ||
5756 | |||
5757 | /* FREE ALL THE TRAILS. */ | ||
5758 | /* SUPUS: Here in free trail, it will delete the entry | ||
5759 | if there is a trail with trail length != 0.OKAY */ | ||
5760 | for(j = 0; j < finger_table[i].trails_count; j++) | ||
5761 | { | 5756 | { |
5762 | free_trail(&finger_table[i].trail_list[i]); | 5757 | for(j = 0; j < finger_table[i].trails_count; j++) |
5758 | free_trail(&finger_table[i].trail_list[i]); | ||
5763 | } | 5759 | } |
5764 | } | 5760 | } |
5765 | } | 5761 | } |
@@ -5778,7 +5774,6 @@ GDS_NEIGHBOURS_done (void) | |||
5778 | core_api = NULL; | 5774 | core_api = NULL; |
5779 | 5775 | ||
5780 | delete_finger_table_entries(); | 5776 | delete_finger_table_entries(); |
5781 | |||
5782 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); | 5777 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); |
5783 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); | 5778 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); |
5784 | friend_peermap = NULL; | 5779 | friend_peermap = NULL; |
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c index f56928f27..e03dfa13b 100644 --- a/src/dht/gnunet-service-xdht_routing.c +++ b/src/dht/gnunet-service-xdht_routing.c | |||
@@ -134,7 +134,6 @@ GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode trail_id, | |||
134 | struct RoutingTrail *trail; | 134 | struct RoutingTrail *trail; |
135 | 135 | ||
136 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); | 136 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); |
137 | |||
138 | if (NULL == trail) | 137 | if (NULL == trail) |
139 | { | 138 | { |
140 | /* If a friend got disconnected and we removed all the entry from the | 139 | /* If a friend got disconnected and we removed all the entry from the |
@@ -166,7 +165,6 @@ GDS_ROUTING_remove_trail (const struct GNUNET_HashCode remove_trail_id) | |||
166 | struct RoutingTrail *remove_entry; | 165 | struct RoutingTrail *remove_entry; |
167 | 166 | ||
168 | remove_entry = GNUNET_CONTAINER_multihashmap_get (routing_table, &remove_trail_id); | 167 | remove_entry = GNUNET_CONTAINER_multihashmap_get (routing_table, &remove_trail_id); |
169 | |||
170 | if (NULL == remove_entry) | 168 | if (NULL == remove_entry) |
171 | return GNUNET_NO; | 169 | return GNUNET_NO; |
172 | 170 | ||
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 00ddb61a4..a2bb1fca1 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -394,6 +394,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
394 | GNUNET_free (a_ctx); | 394 | GNUNET_free (a_ctx); |
395 | a_ctx = NULL; | 395 | a_ctx = NULL; |
396 | } | 396 | } |
397 | //FIXME: Should we collect stats only for put/get not for other messages. | ||
397 | if(NULL != bandwidth_stats_op) | 398 | if(NULL != bandwidth_stats_op) |
398 | GNUNET_TESTBED_operation_done (bandwidth_stats_op); | 399 | GNUNET_TESTBED_operation_done (bandwidth_stats_op); |
399 | bandwidth_stats_op = NULL; | 400 | bandwidth_stats_op = NULL; |
@@ -588,7 +589,7 @@ delayed_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
588 | } | 589 | } |
589 | get_ac->nrefs++; | 590 | get_ac->nrefs++; |
590 | ac->get_ac = get_ac; | 591 | ac->get_ac = get_ac; |
591 | DEBUG ("PUT_REQUEST_START key %s \n", GNUNET_h2s((struct GNUNET_HashCode *)ac->put_data)); | 592 | DEBUG ("GET_REQUEST_START key %s \n", GNUNET_h2s((struct GNUNET_HashCode *)ac->put_data)); |
592 | ac->dht_get = GNUNET_DHT_get_start (ac->dht, | 593 | ac->dht_get = GNUNET_DHT_get_start (ac->dht, |
593 | GNUNET_BLOCK_TYPE_TEST, | 594 | GNUNET_BLOCK_TYPE_TEST, |
594 | &get_ac->hash, | 595 | &get_ac->hash, |
@@ -821,7 +822,10 @@ successor_stats_cont (void *cls, | |||
821 | key = val; | 822 | key = val; |
822 | val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap, | 823 | val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap, |
823 | key); | 824 | key); |
824 | GNUNET_assert(NULL != val); | 825 | if(NULL == val) |
826 | { | ||
827 | break; | ||
828 | } | ||
825 | /* Remove the entry from hashmap. This is done to take care of loop. */ | 829 | /* Remove the entry from hashmap. This is done to take care of loop. */ |
826 | if (GNUNET_NO == | 830 | if (GNUNET_NO == |
827 | GNUNET_CONTAINER_multihashmap_remove (successor_peer_hashmap, | 831 | GNUNET_CONTAINER_multihashmap_remove (successor_peer_hashmap, |
@@ -841,6 +845,8 @@ successor_stats_cont (void *cls, | |||
841 | { | 845 | { |
842 | DEBUG("CIRCLE COMPLETED after %u tries", tries); | 846 | DEBUG("CIRCLE COMPLETED after %u tries", tries); |
843 | //FIXME: FREE HASHMAP. | 847 | //FIXME: FREE HASHMAP. |
848 | //FIXME: If circle is done, then check that finger table of all the peers | ||
849 | //are fill atleast O(log N) and then start with the experiments. | ||
844 | if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) | 850 | if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) |
845 | start_profiling(); | 851 | start_profiling(); |
846 | return; | 852 | return; |
@@ -849,7 +855,7 @@ successor_stats_cont (void *cls, | |||
849 | { | 855 | { |
850 | if (max_searches == ++tries) | 856 | if (max_searches == ++tries) |
851 | { | 857 | { |
852 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
853 | "Maximum tries %u exceeded while checking successor TOTAL TRIES %u" | 859 | "Maximum tries %u exceeded while checking successor TOTAL TRIES %u" |
854 | " cirle formation. Exiting\n", | 860 | " cirle formation. Exiting\n", |
855 | max_searches,tries); | 861 | max_searches,tries); |
@@ -865,10 +871,12 @@ successor_stats_cont (void *cls, | |||
865 | 871 | ||
866 | return; | 872 | return; |
867 | } | 873 | } |
868 | 874 | else | |
869 | flag = 0; | 875 | { |
870 | successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay, &collect_stats, cls); | 876 | flag = 0; |
871 | } | 877 | successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay, &collect_stats, cls); |
878 | } | ||
879 | } | ||
872 | } | 880 | } |
873 | 881 | ||
874 | 882 | ||