aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c274
1 files changed, 175 insertions, 99 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 883c2b163..9c28d6851 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -52,6 +52,7 @@
52 * hashing. 52 * hashing.
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 */ 56 */
56 57
57/** 58/**
@@ -753,6 +754,12 @@ struct FingerInfo
753 struct GNUNET_PeerIdentity finger_identity; 754 struct GNUNET_PeerIdentity finger_identity;
754 755
755 /** 756 /**
757 * FIXME: Better name
758 * Is there any valid entry for this finger.
759 */
760 unsigned int is_present;
761
762 /**
756 * Index in finger peer map 763 * Index in finger peer map
757 */ 764 */
758 uint32_t finger_map_index; 765 uint32_t finger_map_index;
@@ -1653,6 +1660,7 @@ select_finger_trail (struct FingerInfo *finger)
1653 1660
1654 1661
1655/** 1662/**
1663 * FIXME; not handling the wrap around logic correctly.
1656 * Select closest finger to value. 1664 * Select closest finger to value.
1657 * @param peer1 First peer 1665 * @param peer1 First peer
1658 * @param peer2 Second peer 1666 * @param peer2 Second peer
@@ -1664,31 +1672,61 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1664 struct GNUNET_PeerIdentity *peer2, 1672 struct GNUNET_PeerIdentity *peer2,
1665 uint64_t value) 1673 uint64_t value)
1666{ 1674{
1667#if 0
1668 uint64_t peer1_value; 1675 uint64_t peer1_value;
1669 uint64_t peer2_value; 1676 uint64_t peer2_value;
1670 1677
1671 memcpy (&peer1_value, peer1, sizeof (uint64_t)); 1678 memcpy (&peer1_value, peer1, sizeof (uint64_t));
1672 memcpy (&peer2_value, peer2, sizeof (uint64_t)); 1679 memcpy (&peer2_value, peer2, sizeof (uint64_t));
1673 1680
1674 if ((peer1_value <= value) && (value <= peer2_value)) 1681 if (peer1_value == value)
1675 return peer2; 1682 {
1676 else if ((peer2_value <= value) && (value <= peer1_value))
1677 return peer1;
1678 else if ((peer1_value <= peer2_value) && (peer2_value <= value))
1679 return peer1;
1680 else if ((peer2_value <= peer1_value) && (peer1_value <= value))
1681 return peer2;
1682 else if ((value <= peer1_value) && (peer1_value <= peer2_value))
1683 return peer1; 1683 return peer1;
1684 else /*if ((value <= peer2_value) && (peer2_value <= peer1_value))*/ 1684 }
1685
1686 if (peer2_value == value)
1687 {
1685 return peer2; 1688 return peer2;
1686#endif 1689 }
1690
1691 if (peer1_value < peer2_value)
1692 {
1693 if ((peer1_value < value) && (value < peer2_value))
1694 {
1695 return peer2;
1696 }
1697 else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1698 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer1_value)))
1699 {
1700 return peer1;
1701 }
1702 }
1703
1704 if (peer2_value < peer1_value)
1705 {
1706 if ((peer2_value < value) && (value < peer1_value))
1707 {
1708 return peer1;
1709 }
1710 else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1711 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer2_value)))
1712 {
1713 return peer2;
1714 }
1715 }
1687 return NULL; 1716 return NULL;
1688} 1717}
1689 1718
1690 1719
1691/** 1720/**
1721 * FIMXE: COMPLETE THE LOGIC.
1722 * my_id = 0
1723 * finger = 5
1724 * key = 3
1725 * [0,5) → my_id
1726 * [5,0) → finger
1727 *
1728 * 0 <= key < 5, so my_id 0 is the predecessor.
1729 * peer1 != peer2 ever.
1692 * Select closest predecessor to value. 1730 * Select closest predecessor to value.
1693 * @param peer1 First peer 1731 * @param peer1 First peer
1694 * @param peer2 Second peer 1732 * @param peer2 Second peer
@@ -1700,14 +1738,35 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
1700 struct GNUNET_PeerIdentity *peer2, 1738 struct GNUNET_PeerIdentity *peer2,
1701 uint64_t value) 1739 uint64_t value)
1702{ 1740{
1703 #if 0
1704 uint64_t peer1_value; 1741 uint64_t peer1_value;
1705 uint64_t peer2_value; 1742 uint64_t peer2_value;
1706 1743
1707 memcpy (&peer1_value, peer1, sizeof (uint64_t)); 1744 memcpy (&peer1_value, peer1, sizeof (uint64_t));
1708 memcpy (&peer2_value, peer2, sizeof (uint64_t)); 1745 memcpy (&peer2_value, peer2, sizeof (uint64_t));
1709 1746
1710#endif 1747 if (peer1_value == value)
1748 return peer1;
1749
1750 if (peer2_value == value)
1751 return peer2;
1752
1753 if (peer1_value < peer2_value)
1754 {
1755 if ((peer1_value < value) && (value < peer2_value))
1756 return peer1;
1757 else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1758 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer1_value)))
1759 return peer2;
1760 }
1761
1762 if (peer2_value < peer1_value)
1763 {
1764 if ((peer2_value < value) && (value < peer1_value))
1765 return peer2;
1766 else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1767 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer2_value)))
1768 return peer1;
1769 }
1711 return NULL; 1770 return NULL;
1712} 1771}
1713 1772
@@ -1723,6 +1782,16 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
1723 * finger_table_add also while choosing the closest one among new and existing 1782 * finger_table_add also while choosing the closest one among new and existing
1724 * one. */ 1783 * one. */
1725/** 1784/**
1785 * my_id = 0
1786 * finger = 5
1787 * key = 3
1788 * [0,5) → my_id
1789 * [5,0) → finger
1790
1791 * 0 <= key < 5, so key should go to 5.
1792
1793 */
1794/**
1726 * Select the closest peer among two peers (which should not be same) 1795 * Select the closest peer among two peers (which should not be same)
1727 * with respect to value and finger_map_index 1796 * with respect to value and finger_map_index
1728 * @param peer1 First peer 1797 * @param peer1 First peer
@@ -1743,6 +1812,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1743 /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id) 1812 /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id)
1744 and [current_successor->id, friend_id). Check in which range value lies. 1813 and [current_successor->id, friend_id). Check in which range value lies.
1745 Also, check for wrap around. Set the value of current_successor accordingly.*/ 1814 Also, check for wrap around. Set the value of current_successor accordingly.*/
1815
1746 if (PREDECESSOR_FINGER_ID == finger_map_index) 1816 if (PREDECESSOR_FINGER_ID == finger_map_index)
1747 closest_peer = select_closest_predecessor (peer1, peer2, value); 1817 closest_peer = select_closest_predecessor (peer1, peer2, value);
1748 else 1818 else
@@ -1753,6 +1823,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1753 1823
1754 1824
1755/** 1825/**
1826 * FIXME: better names and more refactoring.
1756 * Compare FINGER entry with current successor. If finger's first friend of all 1827 * Compare FINGER entry with current successor. If finger's first friend of all
1757 * its trail is not congested and has not crossed trail threshold, then check 1828 * its trail is not congested and has not crossed trail threshold, then check
1758 * if finger peer identity is closer to final_destination_finger_value than 1829 * if finger peer identity is closer to final_destination_finger_value than
@@ -1761,7 +1832,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1761 * @return 1832 * @return
1762 */ 1833 */
1763static struct Closest_Peer * 1834static struct Closest_Peer *
1764compare_finger_and_current_successor (struct Closest_Peer *current_successor) 1835compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1765{ 1836{
1766 struct FingerInfo *finger; 1837 struct FingerInfo *finger;
1767 struct FriendInfo *friend; 1838 struct FriendInfo *friend;
@@ -1787,14 +1858,14 @@ compare_finger_and_current_successor (struct Closest_Peer *current_successor)
1787 1858
1788 /* If not congested then compare it with current_successor. */ 1859 /* If not congested then compare it with current_successor. */
1789 closest_peer = select_closest_peer (&finger->finger_identity, 1860 closest_peer = select_closest_peer (&finger->finger_identity,
1790 &current_successor->best_known_destination, 1861 &current_closest_peer->best_known_destination,
1791 current_successor->destination_finger_value, 1862 current_closest_peer->destination_finger_value,
1792 current_successor->is_predecessor); 1863 current_closest_peer->is_predecessor);
1793 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 1864 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1794 closest_peer)) 1865 closest_peer))
1795 { 1866 {
1796 current_successor->best_known_destination = finger->finger_identity; 1867 current_closest_peer->best_known_destination = finger->finger_identity;
1797 current_successor->next_hop = finger->finger_identity; 1868 current_closest_peer->next_hop = finger->finger_identity;
1798 } 1869 }
1799 continue; 1870 continue;
1800 } 1871 }
@@ -1807,19 +1878,19 @@ compare_finger_and_current_successor (struct Closest_Peer *current_successor)
1807 continue; 1878 continue;
1808 1879
1809 closest_peer = select_closest_peer (&finger->finger_identity, 1880 closest_peer = select_closest_peer (&finger->finger_identity,
1810 &current_successor->best_known_destination, 1881 &current_closest_peer->best_known_destination,
1811 current_successor->destination_finger_value, 1882 current_closest_peer->destination_finger_value,
1812 current_successor->is_predecessor); 1883 current_closest_peer->is_predecessor);
1813 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 1884 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1814 closest_peer)) 1885 closest_peer))
1815 { 1886 {
1816 current_successor->best_known_destination = finger->finger_identity; 1887 current_closest_peer->best_known_destination = finger->finger_identity;
1817 current_successor->next_hop = finger_trail->friend.id; 1888 current_closest_peer->next_hop = finger_trail->friend.id;
1818 current_successor->trail_id = finger_trail->trail_id; 1889 current_closest_peer->trail_id = finger_trail->trail_id;
1819 } 1890 }
1820 continue; 1891 continue;
1821 } 1892 }
1822 return current_successor; 1893 return current_closest_peer;
1823} 1894}
1824 1895
1825 1896
@@ -1835,28 +1906,29 @@ compare_finger_and_current_successor (struct Closest_Peer *current_successor)
1835 * #GNUNET_NO if not. 1906 * #GNUNET_NO if not.
1836 */ 1907 */
1837static int 1908static int
1838compare_friend_and_current_successor (void *cls, 1909compare_friend_and_current_closest_peer (void *cls,
1839 const struct GNUNET_PeerIdentity *key, 1910 const struct GNUNET_PeerIdentity *key,
1840 void *value) 1911 void *value)
1841{ 1912{
1842 struct FriendInfo *friend = cls; 1913 struct FriendInfo *friend = value;
1843 struct Closest_Peer *current_successor = value; 1914 struct Closest_Peer *current_closest_peer = cls;
1844 struct GNUNET_PeerIdentity *closest_peer; 1915 struct GNUNET_PeerIdentity *closest_peer;
1845 1916
1846 if (GNUNET_YES == is_friend_congested (friend)) 1917 if (GNUNET_YES == is_friend_congested (friend))
1847 return GNUNET_YES; 1918 return GNUNET_YES;
1848
1849 closest_peer = select_closest_peer (&friend->id,
1850 &current_successor->best_known_destination,
1851 current_successor->destination_finger_value,
1852 current_successor->is_predecessor);
1853 1919
1920 closest_peer = select_closest_peer (&friend->id,
1921 &current_closest_peer->best_known_destination,
1922 current_closest_peer->destination_finger_value,
1923 current_closest_peer->is_predecessor);
1924
1854 /* If friend is the closest successor. */ 1925 /* If friend is the closest successor. */
1855 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, closest_peer)) 1926 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, closest_peer))
1856 { 1927 {
1857 current_successor->best_known_destination = friend->id; 1928 current_closest_peer->best_known_destination = friend->id;
1858 current_successor->next_hop = friend->id; 1929 current_closest_peer->next_hop = friend->id;
1859 } 1930 }
1931
1860 return GNUNET_YES; 1932 return GNUNET_YES;
1861} 1933}
1862 1934
@@ -1870,16 +1942,16 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity,
1870 uint64_t destination_finger_value, 1942 uint64_t destination_finger_value,
1871 unsigned int is_predecessor) 1943 unsigned int is_predecessor)
1872{ 1944{
1873 struct Closest_Peer *current_successor; 1945 struct Closest_Peer *current_closest_peer;
1874 1946
1875 current_successor = GNUNET_new (struct Closest_Peer); 1947 current_closest_peer = GNUNET_new (struct Closest_Peer);
1876 memset (&current_successor->trail_id, 0, sizeof (current_successor->trail_id)); 1948 memset (&current_closest_peer->trail_id, 0, sizeof (current_closest_peer->trail_id));
1877 current_successor->destination_finger_value = destination_finger_value; 1949 current_closest_peer->destination_finger_value = destination_finger_value;
1878 current_successor->is_predecessor = is_predecessor; 1950 current_closest_peer->is_predecessor = is_predecessor;
1879 current_successor->next_hop = my_identity; 1951 current_closest_peer->next_hop = my_identity;
1880 current_successor->best_known_destination = my_identity; 1952 current_closest_peer->best_known_destination = my_identity;
1881 1953
1882 return current_successor; 1954 return current_closest_peer;
1883} 1955}
1884 1956
1885 1957
@@ -1909,29 +1981,30 @@ find_successor (uint64_t destination_finger_value,
1909 struct GNUNET_HashCode *new_intermediate_trail_id, 1981 struct GNUNET_HashCode *new_intermediate_trail_id,
1910 unsigned int is_predecessor) 1982 unsigned int is_predecessor)
1911{ 1983{
1912 struct Closest_Peer *current_successor; 1984 struct Closest_Peer *current_closest_peer;
1913 struct GNUNET_PeerIdentity *next_hop; 1985 struct GNUNET_PeerIdentity *next_hop;
1914
1915 /* Initialize current_successor to my_identity. */
1916 current_successor = init_current_successor (my_identity,
1917 destination_finger_value,
1918 is_predecessor);
1919 1986
1987 /* Initialize current_successor to my_identity. */
1988 current_closest_peer = init_current_successor (my_identity,
1989 destination_finger_value,
1990 is_predecessor);
1991
1920 /* Compare each friend entry with current_successor and update current_successor 1992 /* Compare each friend entry with current_successor and update current_successor
1921 * with friend if its closest. */ 1993 * with friend if its closest. */
1922 GNUNET_assert (GNUNET_SYSERR != 1994 GNUNET_assert (GNUNET_SYSERR !=
1923 GNUNET_CONTAINER_multipeermap_iterate (friend_peermap, 1995 GNUNET_CONTAINER_multipeermap_iterate (friend_peermap,
1924 &compare_friend_and_current_successor, 1996 &compare_friend_and_current_closest_peer,
1925 current_successor)); 1997 current_closest_peer));
1926 1998
1927 /* Compare each finger entry with current_successor and update current_successor 1999 /* Compare each finger entry with current_successor and update current_successor
1928 * with finger if its closest. */ 2000 * with finger if its closest. */
1929 compare_finger_and_current_successor (current_successor); 2001 compare_finger_and_current_successor (current_closest_peer);
2002
2003 *local_best_known_destination = current_closest_peer->best_known_destination;
2004 new_intermediate_trail_id = &current_closest_peer->trail_id;
2005 next_hop = GNUNET_new (struct GNUNET_PeerIdentity);
2006 *next_hop = current_closest_peer->next_hop;
1930 2007
1931 local_best_known_destination = &current_successor->best_known_destination;
1932 new_intermediate_trail_id = &current_successor->trail_id;
1933 next_hop = &current_successor->next_hop;
1934
1935 return next_hop; 2008 return next_hop;
1936} 2009}
1937 2010
@@ -2266,7 +2339,7 @@ select_random_friend ()
2266 (const void **)&friend)); 2339 (const void **)&friend));
2267 2340
2268 2341
2269 if ((TRAILS_THROUGH_FRIEND_THRESHOLD == friend->trails_count) && 2342 if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) &&
2270 (0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_timestamp).rel_value_us)) 2343 (0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_timestamp).rel_value_us))
2271 { 2344 {
2272 break; 2345 break;
@@ -2334,12 +2407,13 @@ send_find_finger_trail_message (void *cls,
2334 2407
2335 finger_id_value = compute_finger_identity_value (current_search_finger_index); 2408 finger_id_value = compute_finger_identity_value (current_search_finger_index);
2336 if (PREDECESSOR_FINGER_ID == current_search_finger_index) 2409 if (PREDECESSOR_FINGER_ID == current_search_finger_index)
2337 is_predecessor = 0;
2338 else
2339 is_predecessor = 1; 2410 is_predecessor = 1;
2411 else
2412 is_predecessor = 0;
2340 2413
2341 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, 2414 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
2342 &trail_id, sizeof (trail_id)); 2415 &trail_id, sizeof (trail_id));
2416
2343 GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, 2417 GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value,
2344 target_friend->id, target_friend, 0, NULL, 2418 target_friend->id, target_friend, 0, NULL,
2345 is_predecessor, trail_id, NULL); 2419 is_predecessor, trail_id, NULL);
@@ -2667,7 +2741,8 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2667 new_entry->finger_identity = finger_identity; 2741 new_entry->finger_identity = finger_identity;
2668 new_entry->finger_map_index = finger_map_index; 2742 new_entry->finger_map_index = finger_map_index;
2669 new_entry->trails_count = 1; 2743 new_entry->trails_count = 1;
2670 2744 new_entry->is_present = GNUNET_YES;
2745
2671 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) 2746 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity))
2672 { 2747 {
2673 if (finger_trail_length > 0) 2748 if (finger_trail_length > 0)
@@ -2882,25 +2957,31 @@ get_finger_map_index (uint64_t ultimate_destination_finger_value,
2882 unsigned int is_predecessor) 2957 unsigned int is_predecessor)
2883{ 2958{
2884 uint64_t my_id64; 2959 uint64_t my_id64;
2885 unsigned int finger_map_index; 2960 int finger_map_index;
2886 2961
2887 finger_map_index = -1;
2888 memcpy (&my_id64, &my_identity, sizeof (uint64_t)); 2962 memcpy (&my_id64, &my_identity, sizeof (uint64_t));
2963 my_id64 = GNUNET_ntohll (my_id64);
2889 2964
2890 if (is_predecessor) 2965 if (1 == is_predecessor)
2891 { 2966 {
2892 if(1 == (my_id64 - ultimate_destination_finger_value)) 2967 if(1 == (my_id64 - ultimate_destination_finger_value))
2893 finger_map_index = PREDECESSOR_FINGER_ID; 2968 finger_map_index = PREDECESSOR_FINGER_ID;
2894 } 2969 }
2895 else 2970 else
2896 { 2971 {
2897 finger_map_index = log (ultimate_destination_finger_value - my_id64); 2972 if (1 == (ultimate_destination_finger_value - my_id64))
2973 {
2974 finger_map_index = 0;
2975 }
2976 else
2977 {
2978 finger_map_index = log (ultimate_destination_finger_value - my_id64);
2979 }
2898 } 2980 }
2899 2981
2900 if ((finger_map_index > PREDECESSOR_FINGER_ID) || 2982 if (finger_map_index > PREDECESSOR_FINGER_ID)
2901 (finger_map_index == current_search_finger_index))
2902 finger_map_index = -1; 2983 finger_map_index = -1;
2903 2984
2904 return finger_map_index; 2985 return finger_map_index;
2905} 2986}
2906 2987
@@ -2918,6 +2999,7 @@ remove_existing_finger (struct FingerInfo *finger)
2918 2999
2919 send_all_finger_trails_teardown (finger); 3000 send_all_finger_trails_teardown (finger);
2920 decrement_friend_trail_count (finger); 3001 decrement_friend_trail_count (finger);
3002
2921 free_finger (finger); 3003 free_finger (finger);
2922} 3004}
2923 3005
@@ -2971,7 +3053,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
2971 existing_finger = &finger_table[finger_map_index]; 3053 existing_finger = &finger_table[finger_map_index];
2972 3054
2973 /* No entry present in finger hashmap for given finger map index. */ 3055 /* No entry present in finger hashmap for given finger map index. */
2974 if (NULL == existing_finger) 3056 if (GNUNET_NO == existing_finger->is_present)
2975 { 3057 {
2976 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, 3058 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length,
2977 finger_trail_id, finger_map_index); 3059 finger_trail_id, finger_map_index);
@@ -3457,7 +3539,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3457{ 3539{
3458 const struct PeerTrailSetupMessage *trail_setup; 3540 const struct PeerTrailSetupMessage *trail_setup;
3459 const struct GNUNET_PeerIdentity *trail_peer_list; 3541 const struct GNUNET_PeerIdentity *trail_peer_list;
3460 struct GNUNET_PeerIdentity local_best_known_dest; 3542 struct GNUNET_PeerIdentity *local_best_known_dest;
3461 struct GNUNET_PeerIdentity current_dest; 3543 struct GNUNET_PeerIdentity current_dest;
3462 struct GNUNET_PeerIdentity *next_hop_towards_local_best_known_dest; 3544 struct GNUNET_PeerIdentity *next_hop_towards_local_best_known_dest;
3463 struct GNUNET_PeerIdentity next_peer; 3545 struct GNUNET_PeerIdentity next_peer;
@@ -3509,17 +3591,18 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3509 return GNUNET_OK; 3591 return GNUNET_OK;
3510 } 3592 }
3511 3593
3594 local_best_known_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
3512 /* Get the next hop to forward the trail setup request. */ 3595 /* Get the next hop to forward the trail setup request. */
3513 next_hop_towards_local_best_known_dest = 3596 next_hop_towards_local_best_known_dest =
3514 get_local_best_known_next_hop (final_dest_finger_val, 3597 get_local_best_known_next_hop (final_dest_finger_val,
3515 &local_best_known_dest, 3598 local_best_known_dest,
3516 &new_intermediate_trail_id, 3599 &new_intermediate_trail_id,
3517 intermediate_trail_id, 3600 intermediate_trail_id,
3518 is_predecessor, 3601 is_predecessor,
3519 &current_dest); 3602 &current_dest);
3520 3603
3521 /* Am I the final destination? */ 3604 /* Am I the final destination? */
3522 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&local_best_known_dest, 3605 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest,
3523 &my_identity))) 3606 &my_identity)))
3524 { 3607 {
3525 if (0 == trail_length) 3608 if (0 == trail_length)
@@ -3547,7 +3630,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3547 next_hop_towards_local_best_known_dest); 3630 next_hop_towards_local_best_known_dest);
3548 GDS_NEIGHBOURS_send_trail_setup (source, 3631 GDS_NEIGHBOURS_send_trail_setup (source,
3549 final_dest_finger_val, 3632 final_dest_finger_val,
3550 local_best_known_dest, 3633 *local_best_known_dest,
3551 target_friend, trail_length + 1, peer_list, 3634 target_friend, trail_length + 1, peer_list,
3552 is_predecessor, trail_id, 3635 is_predecessor, trail_id,
3553 &new_intermediate_trail_id); 3636 &new_intermediate_trail_id);
@@ -3675,6 +3758,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
3675 trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; 3758 trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1];
3676 ulitmate_destination_finger_value = 3759 ulitmate_destination_finger_value =
3677 GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); 3760 GNUNET_ntohll (trail_result->ulitmate_destination_finger_value);
3761
3678 /* FIXME: here we are calculating my_index and comparing also in this function. 3762 /* FIXME: here we are calculating my_index and comparing also in this function.
3679 And we are doing it again here in this function. Re factor the code. */ 3763 And we are doing it again here in this function. Re factor the code. */
3680 /* Ensure that sender peer is the peer from which we were expecting the message. */ 3764 /* Ensure that sender peer is the peer from which we were expecting the message. */
@@ -4128,7 +4212,9 @@ handle_dht_p2p_verify_successor_result(void *cls,
4128 return GNUNET_OK; 4212 return GNUNET_OK;
4129} 4213}
4130 4214
4131/* Core handle for p2p notify new successor messages. 4215
4216/*
4217 * Core handle for p2p notify new successor messages.
4132 * @param cls closure 4218 * @param cls closure
4133 * @param message message 4219 * @param message message
4134 * @param peer peer identity this notification is about 4220 * @param peer peer identity this notification is about
@@ -4139,13 +4225,6 @@ handle_dht_p2p_notify_new_successor(void *cls,
4139 const struct GNUNET_PeerIdentity *peer, 4225 const struct GNUNET_PeerIdentity *peer,
4140 const struct GNUNET_MessageHeader *message) 4226 const struct GNUNET_MessageHeader *message)
4141{ 4227{
4142 /*
4143 * 1. Check if you are the new successor. Add in routing table, get the next
4144 * hop from trail and pass the message.
4145 * 2. if you are the new successor, then
4146 * 2.1 use the same function as in verify successor and do the same
4147 * things again.
4148 */
4149 const struct PeerNotifyNewSuccessorMessage *nsm; 4228 const struct PeerNotifyNewSuccessorMessage *nsm;
4150 struct GNUNET_PeerIdentity *trail; 4229 struct GNUNET_PeerIdentity *trail;
4151 struct GNUNET_PeerIdentity source; 4230 struct GNUNET_PeerIdentity source;
@@ -4581,7 +4660,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
4581 { 4660 {
4582 remove_finger = &finger_table[i]; 4661 remove_finger = &finger_table[i];
4583 4662
4584 if (NULL == remove_finger) 4663 if (GNUNET_NO == remove_finger->is_present)
4585 continue; 4664 continue;
4586 4665
4587 /* I am my own finger, then ignore this finger. */ 4666 /* I am my own finger, then ignore this finger. */
@@ -4612,7 +4691,9 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
4612 remove_finger->trails_count = 4691 remove_finger->trails_count =
4613 remove_finger->trails_count - matching_trails_count; 4692 remove_finger->trails_count - matching_trails_count;
4614 if (0 == remove_finger->trails_count) 4693 if (0 == remove_finger->trails_count)
4615 GNUNET_free (remove_finger); 4694 {
4695 GNUNET_free (remove_finger);
4696 }
4616 } 4697 }
4617} 4698}
4618 4699
@@ -4725,16 +4806,11 @@ finger_table_init ()
4725 int i; 4806 int i;
4726 4807
4727 for(i = 0; i < MAX_FINGERS; i++) 4808 for(i = 0; i < MAX_FINGERS; i++)
4728 memset ((void *)&finger_table[i], 0, sizeof (struct FingerInfo)); 4809 finger_table[i].is_present = GNUNET_NO;
4729} 4810}
4730 4811
4731 4812
4732/** 4813/**
4733 * FIXME:
4734 * 2. Should we append messages for X-Vine dht with something to show that they
4735 * are used only by X_Vine dht.??
4736 * 3. check if message size of some function remain constant then add
4737 * sizeof (message) n place of 0.
4738 * Initialize neighbours subsystem. 4814 * Initialize neighbours subsystem.
4739 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 4815 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
4740 */ 4816 */