aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-06-23 16:04:02 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-06-23 16:04:02 +0000
commit8877e26ec3ed4ad5e901ceef5a5f944dca1866c0 (patch)
treef839c7cc372e768b9c14d94ad1e077e73d867c57 /src
parentb362c44283de83700432d668d1b03496623f6792 (diff)
downloadgnunet-8877e26ec3ed4ad5e901ceef5a5f944dca1866c0.tar.gz
gnunet-8877e26ec3ed4ad5e901ceef5a5f944dca1866c0.zip
xvine:bug fix
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c246
-rw-r--r--src/dht/gnunet-service-xdht_routing.c5
2 files changed, 123 insertions, 128 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 7ce0473cf..75cce84a8 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -1017,11 +1017,12 @@ GDS_NEIGHBOURS_get_friend (struct GNUNET_PeerIdentity peer)
1017 * @param ultimate_destination_finger_value Peer identity closest to this value 1017 * @param ultimate_destination_finger_value Peer identity closest to this value
1018 * will be finger to @a source_peer 1018 * will be finger to @a source_peer
1019 * @param best_known_destination Best known destination (could be finger or friend) 1019 * @param best_known_destination Best known destination (could be finger or friend)
1020 * which should get this message. 1020 * which should get this message. In case it is
1021 * friend, then it is same as target_friend
1021 * @param target_friend Friend to which message is forwarded now. 1022 * @param target_friend Friend to which message is forwarded now.
1022 * @param trail_length Total number of peers in trail setup so far. 1023 * @param trail_length Total number of peers in trail setup so far.
1023 * @param trail_peer_list Trail setup so far 1024 * @param trail_peer_list Trail setup so far
1024 * @param is_predecessor Is source_peer looking for trail to a predecessor or not. 1025 * @param is_predecessor Is @a source_peer looking for trail to a predecessor or not.
1025 * @param trail_id Unique identifier for the trail we are trying to setup. 1026 * @param trail_id Unique identifier for the trail we are trying to setup.
1026 * @param intermediate_trail_id Trail id of intermediate trail to reach to 1027 * @param intermediate_trail_id Trail id of intermediate trail to reach to
1027 * best_known_destination when its a finger. If not 1028 * best_known_destination when its a finger. If not
@@ -1613,29 +1614,27 @@ search_my_index (const struct GNUNET_PeerIdentity *trail,
1613 return -1; 1614 return -1;
1614} 1615}
1615 1616
1617
1616/** 1618/**
1617 * Check if the friend is congested or have reached maximum number of trails 1619 * Check if the friend is congested or have reached maximum number of trails
1618 * it can be part of of. 1620 * it can be part of of.
1619 * @param friend Friend to be chechked. 1621 * @param friend Friend to be checked.
1620 * @return #GNUNET_YES if friend is not congested or have not crossed threshold. 1622 * @return #GNUNET_YES if friend is not congested or have not crossed threshold.
1621 * #GNUNET_NO if friend is either congested or have crossed threshold 1623 * #GNUNET_NO if friend is either congested or have crossed threshold
1622 */ 1624 */
1623static int 1625static int
1624is_friend_congested (struct FriendInfo *friend) 1626is_friend_congested (struct FriendInfo *friend)
1625{ 1627{
1626 if ((friend->trails_count == TRAILS_THROUGH_FRIEND_THRESHOLD)|| 1628 if ((friend->trails_count < TRAILS_THROUGH_FRIEND_THRESHOLD) &&
1627 ((0 != GNUNET_TIME_absolute_get_remaining 1629 ((0 == GNUNET_TIME_absolute_get_remaining
1628 (friend->congestion_timestamp).rel_value_us))) 1630 (friend->congestion_timestamp).rel_value_us)))
1629 return GNUNET_YES;
1630 else
1631 return GNUNET_NO; 1631 return GNUNET_NO;
1632 else
1633 return GNUNET_YES;
1632} 1634}
1633 1635
1634 1636
1635/** 1637/**
1636 * FIXME: here we should also check if iterator is null or not. It can be NULL
1637 * only if we insert randomly at locations. But as we are using trails_count
1638 * as the parameter, it should not happen.
1639 * Iterate over the list of all the trails of a finger. In case the first 1638 * Iterate over the list of all the trails of a finger. In case the first
1640 * friend to reach the finger has reached trail threshold or is congested, 1639 * friend to reach the finger has reached trail threshold or is congested,
1641 * then don't select it. In case there multiple available good trails to reach 1640 * then don't select it. In case there multiple available good trails to reach
@@ -1653,29 +1652,52 @@ select_finger_trail (struct FingerInfo *finger)
1653 struct Trail *iterator; 1652 struct Trail *iterator;
1654 struct Selected_Finger_Trail *finger_trail; 1653 struct Selected_Finger_Trail *finger_trail;
1655 unsigned int i; 1654 unsigned int i;
1656 1655 unsigned int flag = 0;
1656 unsigned int j = 0;
1657
1657 finger_trail = GNUNET_new (struct Selected_Finger_Trail); 1658 finger_trail = GNUNET_new (struct Selected_Finger_Trail);
1659
1660 /* It can never happen that we have a finger (which is not a friend or my identity),
1661 and we don't have a trail to reach to it. */
1662 GNUNET_assert (finger->trails_count > 0);
1658 1663
1659 for (i = 0; i < finger->trails_count; i++) 1664 for (i = 0; i < finger->trails_count; i++)
1660 { 1665 {
1661 iterator = &finger->trail_list[i]; 1666 iterator = &finger->trail_list[i];
1667
1668 /* No trail stored at this index. */
1669 if (GNUNET_NO == iterator->is_present)
1670 continue;
1671
1662 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 1672 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
1663 &iterator->trail_head->peer); 1673 &iterator->trail_head->peer);
1674
1675 /* First friend to reach trail is not free. */
1664 if (GNUNET_YES == is_friend_congested (friend)) 1676 if (GNUNET_YES == is_friend_congested (friend))
1677 {
1678 j++;
1665 continue; 1679 continue;
1666 1680 }
1667 /* Check if the trail length of this trail is least seen so far. If yes then 1681 /* This is the first time we enter the loop. Set finger trail length to
1668 set finger_trail to this trail.*/ 1682 * trail length of this trail. */
1669 if (finger_trail->trail_length > iterator->trail_length) 1683 if (!flag)
1670 { 1684 {
1685 flag = 1;
1686 finger_trail->trail_length = iterator->trail_length;
1687 }
1688 else if (finger_trail->trail_length > iterator->trail_length)
1689 {
1690 /* Check if the trail length of this trail is least seen so far. If yes then
1691 set finger_trail to this trail.*/
1671 finger_trail->friend = *friend; 1692 finger_trail->friend = *friend;
1672 finger_trail->trail_id = iterator->trail_id; 1693 finger_trail->trail_id = iterator->trail_id;
1673 finger_trail->trail_length = iterator->trail_length; 1694 finger_trail->trail_length = iterator->trail_length;
1674 } 1695 }
1675 } 1696 }
1676 1697
1677 /* No trail found. */ 1698 /* All the first friend in all the trails to reach to finger are either
1678 if (i == finger->trails_count) 1699 congested or have crossed trail threshold. */
1700 if (j == finger->trails_count)
1679 return NULL; 1701 return NULL;
1680 1702
1681 return finger_trail; 1703 return finger_trail;
@@ -1745,20 +1767,11 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1745 1767
1746 1768
1747/** 1769/**
1748 * FIMXE: COMPLETE THE LOGIC.
1749 * my_id = 0
1750 * finger = 5
1751 * key = 3
1752 * [0,5) → my_id
1753 * [5,0) → finger
1754 *
1755 * 0 <= key < 5, so my_id 0 is the predecessor.
1756 * peer1 != peer2 ever.
1757 * Select closest predecessor to value. 1770 * Select closest predecessor to value.
1758 * @param peer1 First peer 1771 * @param peer1 First peer
1759 * @param peer2 Second peer 1772 * @param peer2 Second peer
1760 * @param value Value to be compare 1773 * @param value Value to be compare
1761 * @return Closest peer 1774 * @return Peer which precedes value in the network.
1762 */ 1775 */
1763static struct GNUNET_PeerIdentity * 1776static struct GNUNET_PeerIdentity *
1764select_closest_predecessor (struct GNUNET_PeerIdentity *peer1, 1777select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
@@ -1800,29 +1813,10 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
1800} 1813}
1801 1814
1802 1815
1803/* FIXME: select closest peer w.r.t. value. [finger->friend_id, current_successor->id)
1804 and [current_successor->id, finger->friend_id). Check in which range value lies.
1805 Also, check for wrap around. But this will give you the immediate predecessor
1806 For example. if we have 0,1,6 and I am 0 and one of my finger is 6. Then
1807 for 1, we will have ranges like [0,6) and [6,0) 1 lies in range from [0,6)
1808 but successor is 6 not 0 as 6 is > than 1. If you are the closest one,
1809 then set the values
1810 in current_successor. Want to write a generic code so that it is used in
1811 * finger_table_add also while choosing the closest one among new and existing
1812 * one. */
1813/**
1814 * my_id = 0
1815 * finger = 5
1816 * key = 3
1817 * [0,5) → my_id
1818 * [5,0) → finger
1819
1820 * 0 <= key < 5, so key should go to 5.
1821
1822 */
1823/** 1816/**
1824 * Select the closest peer among two peers (which should not be same) 1817 * Select the closest peer among two peers (which should not be same)
1825 * with respect to value and finger_table_index 1818 * with respect to value and finger_table_index
1819 * NOTE: peer1 != peer2
1826 * @param peer1 First peer 1820 * @param peer1 First peer
1827 * @param peer2 Second peer 1821 * @param peer2 Second peer
1828 * @param value Value relative to which we find the closest 1822 * @param value Value relative to which we find the closest
@@ -1838,10 +1832,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1838 unsigned int finger_table_index) 1832 unsigned int finger_table_index)
1839{ 1833{
1840 struct GNUNET_PeerIdentity *closest_peer; 1834 struct GNUNET_PeerIdentity *closest_peer;
1841 1835
1842 /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id)
1843 and [current_successor->id, friend_id). Check in which range value lies.
1844 Also, check for wrap around. Set the value of current_successor accordingly.*/
1845 if (PREDECESSOR_FINGER_ID == finger_table_index) 1836 if (PREDECESSOR_FINGER_ID == finger_table_index)
1846 closest_peer = select_closest_predecessor (peer1, peer2, value); 1837 closest_peer = select_closest_predecessor (peer1, peer2, value);
1847 else 1838 else
@@ -1852,8 +1843,6 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1852 1843
1853 1844
1854/** 1845/**
1855 * FIXME: free every memory allocated using malloc before the function ends
1856 * i.e. trail.
1857 * FIXME: better names and more refactoring. 1846 * FIXME: better names and more refactoring.
1858 * Compare FINGER entry with current successor. If finger's first friend of all 1847 * Compare FINGER entry with current successor. If finger's first friend of all
1859 * its trail is not congested and has not crossed trail threshold, then check 1848 * its trail is not congested and has not crossed trail threshold, then check
@@ -1868,20 +1857,22 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1868 struct FingerInfo *finger; 1857 struct FingerInfo *finger;
1869 struct FriendInfo *friend; 1858 struct FriendInfo *friend;
1870 struct GNUNET_PeerIdentity *closest_peer; 1859 struct GNUNET_PeerIdentity *closest_peer;
1860 struct Selected_Finger_Trail *finger_trail;
1871 int i; 1861 int i;
1872 1862
1863 /* Iterate over finger table. */
1873 for (i = 0; i < MAX_FINGERS; i++) 1864 for (i = 0; i < MAX_FINGERS; i++)
1874 { 1865 {
1875 struct Selected_Finger_Trail *finger_trail;
1876
1877 finger = &finger_table[i]; 1866 finger = &finger_table[i];
1878 1867
1868 /* No valid entry at this index, go to next element.*/
1879 if (GNUNET_NO == finger->is_present) 1869 if (GNUNET_NO == finger->is_present)
1880 continue; 1870 continue;
1881 1871
1882 /* If my identity is same as current closest peer then don't consider me*/ 1872 /* If my identity is same as current closest peer then don't consider me*/
1883 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 1873 if (0 ==
1884 &current_closest_peer->best_known_destination)) 1874 GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1875 &current_closest_peer->best_known_destination))
1885 continue; 1876 continue;
1886 1877
1887 /* If I am my own finger, then ignore this finger. */ 1878 /* If I am my own finger, then ignore this finger. */
@@ -1889,31 +1880,14 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1889 &my_identity)) 1880 &my_identity))
1890 continue; 1881 continue;
1891 1882
1892 /* If finger is friend. */ 1883 /* If finger is a friend, then do nothing. As we have already checked
1893 if (NULL != (friend = GNUNET_CONTAINER_multipeermap_get 1884 * for each friend in compare_friend_and_current_successor(). */
1894 (friend_peermap, &finger->finger_identity))) 1885 if (NULL !=
1895 { 1886 (friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
1896 if (GNUNET_YES == is_friend_congested (friend)) 1887 &finger->finger_identity)))
1897 continue;
1898
1899 /* If not congested then compare it with current_successor. */
1900 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1901 &current_closest_peer->best_known_destination))
1902 continue;
1903
1904 closest_peer = select_closest_peer (&finger->finger_identity,
1905 &current_closest_peer->best_known_destination,
1906 current_closest_peer->destination_finger_value,
1907 current_closest_peer->is_predecessor);
1908 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1909 closest_peer))
1910 {
1911 current_closest_peer->best_known_destination = finger->finger_identity;
1912 current_closest_peer->next_hop = finger->finger_identity;
1913 }
1914 continue; 1888 continue;
1915 }
1916 1889
1890 /* We have a finger which not a friend, not my identity */
1917 /* Choose one of the trail to reach to finger. */ 1891 /* Choose one of the trail to reach to finger. */
1918 finger_trail = select_finger_trail (finger); 1892 finger_trail = select_finger_trail (finger);
1919 1893
@@ -1921,29 +1895,29 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1921 if (NULL == finger_trail) 1895 if (NULL == finger_trail)
1922 continue; 1896 continue;
1923 1897
1924 closest_peer = select_closest_peer (&finger->finger_identity, 1898 closest_peer = select_closest_peer (&finger->finger_identity,
1925 &current_closest_peer->best_known_destination, 1899 &current_closest_peer->best_known_destination,
1926 current_closest_peer->destination_finger_value, 1900 current_closest_peer->destination_finger_value,
1927 current_closest_peer->is_predecessor); 1901 current_closest_peer->is_predecessor);
1928 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 1902 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1929 closest_peer)) 1903 closest_peer))
1930 { 1904 {
1931 current_closest_peer->best_known_destination = finger->finger_identity; 1905 current_closest_peer->best_known_destination = finger->finger_identity;
1932 current_closest_peer->next_hop = finger_trail->friend.id; 1906 current_closest_peer->next_hop = finger_trail->friend.id;
1933 current_closest_peer->trail_id = finger_trail->trail_id; 1907 current_closest_peer->trail_id = finger_trail->trail_id;
1934 } 1908 }
1935 GNUNET_free (finger_trail); 1909 continue;
1936 continue;
1937 } 1910 }
1938 return current_closest_peer; 1911 return current_closest_peer;
1939} 1912}
1940 1913
1941 1914
1942/** 1915/**
1943 * Compare friend entry with current successor. If friend is not congested and 1916 * Compare friend entry with current successor.
1944 * has not crossed trail threshold, then check if friend peer identity is 1917 * If friend identity and current_successor is same, then do nothing.
1945 * closer to final_destination_finger_value than current_successor. If yes 1918 * If friend is not congested and has not crossed trail threshold, then check
1946 * then update current_successor. 1919 * if friend peer identity is closer to final_destination_finger_value than
1920 * current_successor. If yes then update current_successor.
1947 * @param cls closure 1921 * @param cls closure
1948 * @param key current public key 1922 * @param key current public key
1949 * @param value struct Closest_Peer 1923 * @param value struct Closest_Peer
@@ -1959,12 +1933,15 @@ compare_friend_and_current_closest_peer (void *cls,
1959 struct Closest_Peer *current_closest_peer = cls; 1933 struct Closest_Peer *current_closest_peer = cls;
1960 struct GNUNET_PeerIdentity *closest_peer; 1934 struct GNUNET_PeerIdentity *closest_peer;
1961 1935
1936 /* If friend is either congested or has crossed threshold, then don't consider
1937 * this friend.*/
1962 if (GNUNET_YES == is_friend_congested (friend)) 1938 if (GNUNET_YES == is_friend_congested (friend))
1963 return GNUNET_YES; 1939 return GNUNET_YES;
1964 1940
1941 /* If current_closest_peer and friend identity are same, then do nothing.*/
1965 if (0 == 1942 if (0 ==
1966 GNUNET_CRYPTO_cmp_peer_identity (&friend->id, 1943 GNUNET_CRYPTO_cmp_peer_identity (&friend->id,
1967 &current_closest_peer->best_known_destination)) 1944 &current_closest_peer->best_known_destination))
1968 return GNUNET_YES; 1945 return GNUNET_YES;
1969 1946
1970 closest_peer = select_closest_peer (&friend->id, 1947 closest_peer = select_closest_peer (&friend->id,
@@ -1972,7 +1949,7 @@ compare_friend_and_current_closest_peer (void *cls,
1972 current_closest_peer->destination_finger_value, 1949 current_closest_peer->destination_finger_value,
1973 current_closest_peer->is_predecessor); 1950 current_closest_peer->is_predecessor);
1974 1951
1975 /* If friend is the closest successor. */ 1952 /* Is friend the closest successor? */
1976 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, closest_peer)) 1953 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, closest_peer))
1977 { 1954 {
1978 current_closest_peer->best_known_destination = friend->id; 1955 current_closest_peer->best_known_destination = friend->id;
@@ -1982,6 +1959,7 @@ compare_friend_and_current_closest_peer (void *cls,
1982 return GNUNET_YES; 1959 return GNUNET_YES;
1983} 1960}
1984 1961
1962
1985/** 1963/**
1986 * Initialize current_successor to my_identity. 1964 * Initialize current_successor to my_identity.
1987 * @param my_identity My peer identity 1965 * @param my_identity My peer identity
@@ -2006,20 +1984,20 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity,
2006 1984
2007 1985
2008/** 1986/**
2009 * FIXME: first check if the finger == closest_peer then don't do anything. 1987 * FIXME: can we just send gnunet_peeridentit and not gnunet_peeridentity *?
2010 * Find the successor for destination_finger_value among my_identity, all my 1988 * Find the successor for destination_finger_value among my_identity, all my
2011 * friend and all my fingers. Don't consider friends or fingers 1989 * friend and all my fingers. Don't consider friends or fingers which are either
2012 * which are congested or have crossed the threshold. 1990 * congested or have crossed the threshold.
2013 * @param destination_finger_value Peer closest to this value will be the next successor. 1991 * @param destination_finger_value Peer closest to this value will be the next successor.
2014 * @param local_best_known_destination [out] Updated to my_identity if I am the 1992 * @param local_best_known_destination[out] Updated to my_identity if I am the
2015 * final destination. Updated to friend 1993 * final destination. Updated to friend
2016 * identity in case a friend is successor, 1994 * identity in case a friend is successor,
2017 * updated to first friend to reach to finger 1995 * updated to finger in case finger is the
2018 * in case finger is the destination. 1996 * destination.
2019 * @param new_intermediate_trail_id [out] In case a finger is the 1997 * @param new_intermediate_trail_id[out] In case a finger is the
2020 * @a local_best_known_destination, 1998 * @a local_best_known_destination,
2021 * then it is the trail to reach it. Else 1999 * then it is the trail to reach it. Else
2022 * default set to 0. 2000 * default set to 0.
2023 * @param is_predecessor Are we looking for predecessor or finger? 2001 * @param is_predecessor Are we looking for predecessor or finger?
2024 * @return Next hop to reach to local_best_known_destination. In case my_identity 2002 * @return Next hop to reach to local_best_known_destination. In case my_identity
2025 * or a friend is a local_best_known_destination, then 2003 * or a friend is a local_best_known_destination, then
@@ -2042,10 +2020,11 @@ find_successor (uint64_t destination_finger_value,
2042 2020
2043 /* Compare each friend entry with current_successor and update current_successor 2021 /* Compare each friend entry with current_successor and update current_successor
2044 * with friend if its closest. */ 2022 * with friend if its closest. */
2045 GNUNET_assert (GNUNET_SYSERR != 2023 GNUNET_assert
2046 GNUNET_CONTAINER_multipeermap_iterate (friend_peermap, 2024 (GNUNET_SYSERR !=
2047 &compare_friend_and_current_closest_peer, 2025 GNUNET_CONTAINER_multipeermap_iterate (friend_peermap,
2048 current_closest_peer)); 2026 &compare_friend_and_current_closest_peer,
2027 current_closest_peer));
2049 2028
2050 /* Compare each finger entry with current_successor and update current_successor 2029 /* Compare each finger entry with current_successor and update current_successor
2051 * with finger if its closest. */ 2030 * with finger if its closest. */
@@ -2391,17 +2370,21 @@ select_random_friend ()
2391 struct FriendInfo *friend; 2370 struct FriendInfo *friend;
2392 2371
2393 current_size = GNUNET_CONTAINER_multipeermap_size (friend_peermap); 2372 current_size = GNUNET_CONTAINER_multipeermap_size (friend_peermap);
2373
2374 /* No friends.*/
2394 if (0 == current_size) 2375 if (0 == current_size)
2395 return NULL; 2376 return NULL;
2396 2377
2397 index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, current_size); 2378 index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, current_size);
2398 iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); 2379 iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
2399 2380
2381 /* Iterate till you don't reach to index. */
2400 for (j = 0; j < index ; j++) 2382 for (j = 0; j < index ; j++)
2401 GNUNET_assert (GNUNET_YES == 2383 GNUNET_assert (GNUNET_YES ==
2402 GNUNET_CONTAINER_multipeermap_iterator_next (iter, NULL, NULL)); 2384 GNUNET_CONTAINER_multipeermap_iterator_next (iter, NULL, NULL));
2403 do 2385 do
2404 { 2386 {
2387 /* Reset the index in friend peermap to 0 as we reached to the end. */
2405 if (j == current_size) 2388 if (j == current_size)
2406 { 2389 {
2407 j = 0; 2390 j = 0;
@@ -2409,10 +2392,12 @@ select_random_friend ()
2409 iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); 2392 iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
2410 2393
2411 } 2394 }
2395
2396 /* Get the friend stored at the index, j*/
2412 GNUNET_assert (GNUNET_YES == 2397 GNUNET_assert (GNUNET_YES ==
2413 GNUNET_CONTAINER_multipeermap_iterator_next (iter, 2398 GNUNET_CONTAINER_multipeermap_iterator_next (iter,
2414 &key_ret, 2399 &key_ret,
2415 (const void **)&friend)); 2400 (const void **)&friend));
2416 2401
2417 /* This friend is not congested and has not crossed trail threshold. */ 2402 /* This friend is not congested and has not crossed trail threshold. */
2418 if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && 2403 if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) &&
@@ -2485,8 +2470,8 @@ send_find_finger_trail_message (void *cls,
2485 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, 2470 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message,
2486 NULL); 2471 NULL);
2487 2472
2488 /* My own routing table is all full. I can not store any more trails for which 2473 /* No space in my routing table. (Source and destination peers also store entries
2489 I am source. */ 2474 * in their routing table). */
2490 if (GNUNET_YES == GDS_ROUTING_threshold_reached()) 2475 if (GNUNET_YES == GDS_ROUTING_threshold_reached())
2491 return; 2476 return;
2492 2477
@@ -3714,8 +3699,9 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
3714 3699
3715/** 3700/**
3716 * Get the best known next destination (local_dest) among your fingers, friends 3701 * Get the best known next destination (local_dest) among your fingers, friends
3717 * and my identity. If @a current_dest is some other peer and not me, then 3702 * and my identity. In case I was part of trail to reach to some other destination
3718 * compare curent_dest and local_dest. 3703 * (current_dest), then compare current_dest and local_dest, and choose the
3704 * closest peer.
3719 * @param final_dest_finger_value Peer closest to this value will be 3705 * @param final_dest_finger_value Peer closest to this value will be
3720 * @a local_best_known_dest 3706 * @a local_best_known_dest
3721 * @param local_best_known_dest[out] Updated to peer identity which is closest to 3707 * @param local_best_known_dest[out] Updated to peer identity which is closest to
@@ -3783,7 +3769,8 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_value,
3783} 3769}
3784 3770
3785 3771
3786/* Core handle for PeerTrailSetupMessage. 3772/*
3773 * Core handle for PeerTrailSetupMessage.
3787 * @param cls closure 3774 * @param cls closure
3788 * @param message message 3775 * @param message message
3789 * @param peer peer identity this notification is about 3776 * @param peer peer identity this notification is about
@@ -3838,6 +3825,8 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3838 /* Is my routing table full? */ 3825 /* Is my routing table full? */
3839 if (GNUNET_YES == GDS_ROUTING_threshold_reached()) 3826 if (GNUNET_YES == GDS_ROUTING_threshold_reached())
3840 { 3827 {
3828 /* As my routing table is full, I can no longer handle any more trail
3829 * through me */
3841 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 3830 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
3842 GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, 3831 GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val,
3843 my_identity, is_predecessor, 3832 my_identity, is_predecessor,
@@ -3847,7 +3836,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3847 return GNUNET_OK; 3836 return GNUNET_OK;
3848 } 3837 }
3849 3838
3850 local_best_known_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 3839 local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity);
3851 3840
3852 /* Get the next hop to forward the trail setup request. */ 3841 /* Get the next hop to forward the trail setup request. */
3853 next_hop_towards_local_best_known_dest = 3842 next_hop_towards_local_best_known_dest =
@@ -3867,6 +3856,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3867 { 3856 {
3868 GDS_ROUTING_add (trail_id, *peer, my_identity); 3857 GDS_ROUTING_add (trail_id, *peer, my_identity);
3869 } 3858 }
3859
3870 if (0 == trail_length) 3860 if (0 == trail_length)
3871 memcpy (&next_peer, &source, sizeof (struct GNUNET_PeerIdentity)); 3861 memcpy (&next_peer, &source, sizeof (struct GNUNET_PeerIdentity));
3872 else 3862 else
@@ -3885,7 +3875,8 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3885 /* Add yourself to list of peers. */ 3875 /* Add yourself to list of peers. */
3886 struct GNUNET_PeerIdentity peer_list[trail_length + 1]; 3876 struct GNUNET_PeerIdentity peer_list[trail_length + 1];
3887 3877
3888 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 3878 memcpy (peer_list, trail_peer_list,
3879 trail_length * sizeof (struct GNUNET_PeerIdentity));
3889 peer_list[trail_length] = my_identity; 3880 peer_list[trail_length] = my_identity;
3890 target_friend = 3881 target_friend =
3891 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3882 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
@@ -5013,13 +5004,13 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
5013 /* Check if peer is the real peer from which we should get this message.*/ 5004 /* Check if peer is the real peer from which we should get this message.*/
5014 /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ 5005 /* Get the prev_hop for this trail by getting the next hop in opposite direction. */
5015 /* FIXME: is using negation of trail direction correct. */ 5006 /* FIXME: is using negation of trail direction correct. */
5016 prev_hop = GDS_ROUTING_get_next_hop (trail_id, !trail_direction); 5007 GNUNET_assert (NULL != (prev_hop =
5008 GDS_ROUTING_get_next_hop (trail_id, !trail_direction)));
5017 if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer)) 5009 if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer))
5018 { 5010 {
5019 GNUNET_break (0); 5011 GNUNET_break (0);
5020 return GNUNET_SYSERR; 5012 return GNUNET_SYSERR;
5021 } 5013 }
5022 GNUNET_free_non_null (prev_hop);
5023 5014
5024 next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); 5015 next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction);
5025 if (NULL == next_hop) 5016 if (NULL == next_hop)
@@ -5036,7 +5027,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
5036 5027
5037 /* If not final destination, then send a trail teardown message to next hop.*/ 5028 /* If not final destination, then send a trail teardown message to next hop.*/
5038 GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, next_hop); 5029 GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, next_hop);
5039 GNUNET_free (next_hop); 5030 //GNUNET_free_non_null (next_hop);
5040 return GNUNET_OK; 5031 return GNUNET_OK;
5041} 5032}
5042 5033
@@ -5350,13 +5341,14 @@ finger_table_init ()
5350 int i; 5341 int i;
5351 int j; 5342 int j;
5352 5343
5344 /* FIXME: here we have set the whole entry of finger table to 0, so do we
5345 * need to initialize the trails to 0 */
5353 for(i = 0; i < MAX_FINGERS; i++) 5346 for(i = 0; i < MAX_FINGERS; i++)
5354 { 5347 {
5355 finger_table[i].is_present = GNUNET_NO; 5348 finger_table[i].is_present = GNUNET_NO;
5356 for (j = 0; j < MAXIMUM_TRAILS_PER_FINGER; j++) 5349 for (j = 0; j < MAXIMUM_TRAILS_PER_FINGER; j++)
5357 finger_table[i].trail_list[j].is_present = GNUNET_NO; 5350 finger_table[i].trail_list[j].is_present = GNUNET_NO;
5358 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); 5351 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i]));
5359
5360 } 5352 }
5361} 5353}
5362 5354
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c
index 102ea404b..063bb13a5 100644
--- a/src/dht/gnunet-service-xdht_routing.c
+++ b/src/dht/gnunet-service-xdht_routing.c
@@ -251,7 +251,10 @@ GDS_ROUTING_test_print (void)
251void 251void
252GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer) 252GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer)
253{ 253{
254 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size(routing_table) > 0); 254 /* No entries in my routing table. */
255 if (0 == GNUNET_CONTAINER_multihashmap_size(routing_table))
256 return;
257
255 GNUNET_CONTAINER_multihashmap_iterate (routing_table, &remove_matching_trails, 258 GNUNET_CONTAINER_multihashmap_iterate (routing_table, &remove_matching_trails,
256 (void *)peer); 259 (void *)peer);
257} 260}