diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-07-24 09:51:16 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-07-24 09:51:16 +0000 |
commit | 53ef0ba7b541c2417bc34b6d38cca105d40b67f0 (patch) | |
tree | fc00a3ad69077d276bbd3e15ca8667fbaea0296f /src | |
parent | 51d896e8b7185cb069cd34c7d213b72b84d67a03 (diff) | |
download | gnunet-53ef0ba7b541c2417bc34b6d38cca105d40b67f0.tar.gz gnunet-53ef0ba7b541c2417bc34b6d38cca105d40b67f0.zip |
xvine:fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 356 |
1 files changed, 197 insertions, 159 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index f5787d116..976e2be75 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -66,7 +66,7 @@ | |||
66 | /** | 66 | /** |
67 | * How long to wait before sending another find finger trail request | 67 | * How long to wait before sending another find finger trail request |
68 | */ | 68 | */ |
69 | #define DHT_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 69 | #define DHT_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * How long at most to wait for transmission of a request to a friend ? | 72 | * How long at most to wait for transmission of a request to a friend ? |
@@ -776,7 +776,9 @@ struct FingerInfo | |||
776 | 776 | ||
777 | 777 | ||
778 | /** | 778 | /** |
779 | * Data structure to keep track of closest peer seen so far in find_successor() | 779 | * Stores information about the peer which is closest to destination_finger_value. |
780 | * 'closest' can be either successor or predecessor depending on is_predecessor | ||
781 | * flag. | ||
780 | */ | 782 | */ |
781 | struct Closest_Peer | 783 | struct Closest_Peer |
782 | { | 784 | { |
@@ -792,7 +794,7 @@ struct Closest_Peer | |||
792 | 794 | ||
793 | /** | 795 | /** |
794 | * Trail id to reach to peer. | 796 | * Trail id to reach to peer. |
795 | * In case peer is my identity or friend, it is set to NULL. | 797 | * In case peer is my identity or friend, it is set to 0. |
796 | */ | 798 | */ |
797 | struct GNUNET_HashCode trail_id; | 799 | struct GNUNET_HashCode trail_id; |
798 | 800 | ||
@@ -967,6 +969,7 @@ process_friend_queue (struct FriendInfo *peer) | |||
967 | GNUNET_break (NULL != peer->th); | 969 | GNUNET_break (NULL != peer->th); |
968 | } | 970 | } |
969 | 971 | ||
972 | |||
970 | /** | 973 | /** |
971 | * Construct a trail setup message and forward it to target_friend | 974 | * Construct a trail setup message and forward it to target_friend |
972 | * @param source_peer Peer which wants to setup the trail | 975 | * @param source_peer Peer which wants to setup the trail |
@@ -1098,6 +1101,7 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer | |||
1098 | tsrm->ulitmate_destination_finger_value = | 1101 | tsrm->ulitmate_destination_finger_value = |
1099 | GNUNET_htonll (ultimate_destination_finger_value); | 1102 | GNUNET_htonll (ultimate_destination_finger_value); |
1100 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; | 1103 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; |
1104 | |||
1101 | if (trail_length > 0) | 1105 | if (trail_length > 0) |
1102 | { | 1106 | { |
1103 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1107 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -1568,7 +1572,8 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1568 | for (i = 0; i < trail_length; i++) | 1572 | for (i = 0; i < trail_length; i++) |
1569 | { | 1573 | { |
1570 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) | 1574 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) |
1571 | lowest_index = i; | 1575 | //lowest_index = i; |
1576 | return i; | ||
1572 | } | 1577 | } |
1573 | 1578 | ||
1574 | return lowest_index; | 1579 | return lowest_index; |
@@ -1579,13 +1584,13 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1579 | * Check if the friend is congested or have reached maximum number of trails | 1584 | * Check if the friend is congested or have reached maximum number of trails |
1580 | * it can be part of of. | 1585 | * it can be part of of. |
1581 | * @param friend Friend to be checked. | 1586 | * @param friend Friend to be checked. |
1582 | * @return #GNUNET_YES if friend is not congested or have not crossed threshold. | 1587 | * @return #GNUNET_NO if friend is not congested or have not crossed threshold. |
1583 | * #GNUNET_NO if friend is either congested or have crossed threshold | 1588 | * #GNUNET_YES if friend is either congested or have crossed threshold |
1584 | */ | 1589 | */ |
1585 | static int | 1590 | static int |
1586 | is_friend_congested (struct FriendInfo *friend) | 1591 | is_friend_congested (struct FriendInfo *friend) |
1587 | { | 1592 | { |
1588 | if ((friend->trails_count < TRAILS_THROUGH_FRIEND_THRESHOLD) && | 1593 | if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && |
1589 | ((0 == GNUNET_TIME_absolute_get_remaining | 1594 | ((0 == GNUNET_TIME_absolute_get_remaining |
1590 | (friend->congestion_timestamp).rel_value_us))) | 1595 | (friend->congestion_timestamp).rel_value_us))) |
1591 | return GNUNET_NO; | 1596 | return GNUNET_NO; |
@@ -1614,7 +1619,7 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1, | |||
1614 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); | 1619 | memcpy (&peer2_value, peer2, sizeof (uint64_t)); |
1615 | peer1_value = GNUNET_ntohll (peer1_value); | 1620 | peer1_value = GNUNET_ntohll (peer1_value); |
1616 | peer2_value = GNUNET_ntohll (peer2_value); | 1621 | peer2_value = GNUNET_ntohll (peer2_value); |
1617 | 1622 | ||
1618 | if (peer1_value == value) | 1623 | if (peer1_value == value) |
1619 | { | 1624 | { |
1620 | return peer1; | 1625 | return peer1; |
@@ -1683,19 +1688,27 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1, | |||
1683 | if (peer1_value < peer2_value) | 1688 | if (peer1_value < peer2_value) |
1684 | { | 1689 | { |
1685 | if ((peer1_value < value) && (value < peer2_value)) | 1690 | if ((peer1_value < value) && (value < peer2_value)) |
1691 | { | ||
1686 | return peer1; | 1692 | return peer1; |
1693 | } | ||
1687 | else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || | 1694 | else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || |
1688 | ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer1_value))) | 1695 | ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer1_value))) |
1696 | { | ||
1689 | return peer2; | 1697 | return peer2; |
1698 | } | ||
1690 | } | 1699 | } |
1691 | 1700 | ||
1692 | if (peer2_value < peer1_value) | 1701 | if (peer2_value < peer1_value) |
1693 | { | 1702 | { |
1694 | if ((peer2_value < value) && (value < peer1_value)) | 1703 | if ((peer2_value < value) && (value < peer1_value)) |
1704 | { | ||
1695 | return peer2; | 1705 | return peer2; |
1706 | } | ||
1696 | else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || | 1707 | else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || |
1697 | ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer2_value))) | 1708 | ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer2_value))) |
1709 | { | ||
1698 | return peer1; | 1710 | return peer1; |
1711 | } | ||
1699 | } | 1712 | } |
1700 | return NULL; | 1713 | return NULL; |
1701 | } | 1714 | } |
@@ -1712,7 +1725,9 @@ test_friend_peermap_print () | |||
1712 | struct GNUNET_PeerIdentity print_peer; | 1725 | struct GNUNET_PeerIdentity print_peer; |
1713 | struct GNUNET_PeerIdentity key_ret; | 1726 | struct GNUNET_PeerIdentity key_ret; |
1714 | int i; | 1727 | int i; |
1715 | FPRINTF (stderr,_("\nSUPU************ FRIEND_PEERMAP")); | 1728 | |
1729 | print_peer = my_identity; | ||
1730 | FPRINTF (stderr,_("\nSUPU************ FRIEND_PEERMAP of %s"),GNUNET_i2s(&print_peer)); | ||
1716 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 1731 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
1717 | 1732 | ||
1718 | for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++) | 1733 | for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++) |
@@ -1741,8 +1756,8 @@ test_finger_table_print() | |||
1741 | int i; | 1756 | int i; |
1742 | //int j; | 1757 | //int j; |
1743 | //int k; | 1758 | //int k; |
1744 | 1759 | print_peer = my_identity; | |
1745 | FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE")); | 1760 | FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE of %s"),GNUNET_i2s(&print_peer)); |
1746 | for (i = 0; i < MAX_FINGERS; i++) | 1761 | for (i = 0; i < MAX_FINGERS; i++) |
1747 | { | 1762 | { |
1748 | finger = &finger_table[i]; | 1763 | finger = &finger_table[i]; |
@@ -1754,7 +1769,7 @@ test_finger_table_print() | |||
1754 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"), | 1769 | FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"), |
1755 | __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count); | 1770 | __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count); |
1756 | 1771 | ||
1757 | 1772 | #if 0 | |
1758 | for (j = 0; j < finger->trails_count; j++) | 1773 | for (j = 0; j < finger->trails_count; j++) |
1759 | { | 1774 | { |
1760 | trail = &finger->trail_list[j]; | 1775 | trail = &finger->trail_list[j]; |
@@ -1768,8 +1783,8 @@ test_finger_table_print() | |||
1768 | element = element->next; | 1783 | element = element->next; |
1769 | } | 1784 | } |
1770 | } | 1785 | } |
1786 | #endif | ||
1771 | } | 1787 | } |
1772 | |||
1773 | } | 1788 | } |
1774 | #endif | 1789 | #endif |
1775 | 1790 | ||
@@ -1794,6 +1809,7 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1, | |||
1794 | if (1 == is_predecessor) | 1809 | if (1 == is_predecessor) |
1795 | { | 1810 | { |
1796 | closest_peer = select_closest_predecessor (peer1, peer2, value); | 1811 | closest_peer = select_closest_predecessor (peer1, peer2, value); |
1812 | |||
1797 | } | 1813 | } |
1798 | else | 1814 | else |
1799 | { | 1815 | { |
@@ -1825,9 +1841,6 @@ select_finger_trail (struct FingerInfo *finger) | |||
1825 | unsigned int j = 0; | 1841 | unsigned int j = 0; |
1826 | 1842 | ||
1827 | finger_trail = GNUNET_new (struct Selected_Finger_Trail); | 1843 | finger_trail = GNUNET_new (struct Selected_Finger_Trail); |
1828 | |||
1829 | /* It can never happen that we have a finger (which is not a friend or my identity), | ||
1830 | and we don't have a trail to reach to it. */ | ||
1831 | GNUNET_assert (finger->trails_count > 0); | 1844 | GNUNET_assert (finger->trails_count > 0); |
1832 | 1845 | ||
1833 | for (i = 0; i < finger->trails_count; i++) | 1846 | for (i = 0; i < finger->trails_count; i++) |
@@ -1836,10 +1849,8 @@ select_finger_trail (struct FingerInfo *finger) | |||
1836 | 1849 | ||
1837 | /* No trail stored at this index. */ | 1850 | /* No trail stored at this index. */ |
1838 | if (GNUNET_NO == iterator->is_present) | 1851 | if (GNUNET_NO == iterator->is_present) |
1839 | { | ||
1840 | continue; | 1852 | continue; |
1841 | } | 1853 | |
1842 | |||
1843 | GNUNET_assert (NULL != | 1854 | GNUNET_assert (NULL != |
1844 | (friend = | 1855 | (friend = |
1845 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1856 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -1851,23 +1862,18 @@ select_finger_trail (struct FingerInfo *finger) | |||
1851 | j++; | 1862 | j++; |
1852 | continue; | 1863 | continue; |
1853 | } | 1864 | } |
1854 | /* This is the first time we enter the loop. Set finger trail length to | 1865 | |
1855 | * trail length of this trail. */ | ||
1856 | if (!flag) | 1866 | if (!flag) |
1857 | { | 1867 | { |
1858 | flag = 1; | 1868 | flag = 1; |
1859 | finger_trail->trail_length = iterator->trail_length; | 1869 | finger_trail->trail_length = iterator->trail_length; |
1860 | finger_trail->friend = *friend; | 1870 | finger_trail->friend = *friend; |
1861 | finger_trail->trail_id = iterator->trail_id; | 1871 | finger_trail->trail_id = iterator->trail_id; |
1862 | //memcmp (finger_trail->trail_id, &iterator->trail_id, sizeof (struct GNUNET_HashCode)); | ||
1863 | } | 1872 | } |
1864 | else if (finger_trail->trail_length > iterator->trail_length) | 1873 | else if (finger_trail->trail_length > iterator->trail_length) |
1865 | { | 1874 | { |
1866 | /* Check if the trail length of this trail is least seen so far. If yes then | ||
1867 | set finger_trail to this trail.*/ | ||
1868 | finger_trail->friend = *friend; | 1875 | finger_trail->friend = *friend; |
1869 | finger_trail->trail_id = iterator->trail_id; | 1876 | finger_trail->trail_id = iterator->trail_id; |
1870 | //memcmp (finger_trail->trail_id, &iterator->trail_id, sizeof (struct GNUNET_HashCode)); | ||
1871 | finger_trail->trail_length = iterator->trail_length; | 1877 | finger_trail->trail_length = iterator->trail_length; |
1872 | } | 1878 | } |
1873 | } | 1879 | } |
@@ -1902,7 +1908,6 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1902 | { | 1908 | { |
1903 | finger = &finger_table[i]; | 1909 | finger = &finger_table[i]; |
1904 | 1910 | ||
1905 | /* No valid entry at this index, go to next element.*/ | ||
1906 | if (GNUNET_NO == finger->is_present) | 1911 | if (GNUNET_NO == finger->is_present) |
1907 | continue; | 1912 | continue; |
1908 | 1913 | ||
@@ -1924,7 +1929,7 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1924 | { | 1929 | { |
1925 | continue; | 1930 | continue; |
1926 | } | 1931 | } |
1927 | /* We have a finger which not a friend, not my identity */ | 1932 | |
1928 | /* Choose one of the trail to reach to finger. */ | 1933 | /* Choose one of the trail to reach to finger. */ |
1929 | finger_trail = select_finger_trail (finger); | 1934 | finger_trail = select_finger_trail (finger); |
1930 | 1935 | ||
@@ -1938,18 +1943,18 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1938 | current_closest_peer->is_predecessor); | 1943 | current_closest_peer->is_predecessor); |
1939 | 1944 | ||
1940 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | 1945 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, |
1941 | closest_peer)) | 1946 | closest_peer)) |
1942 | { | 1947 | { |
1943 | current_closest_peer->best_known_destination = finger->finger_identity; | 1948 | current_closest_peer->best_known_destination = finger->finger_identity; |
1944 | current_closest_peer->next_hop = finger_trail->friend.id; | 1949 | current_closest_peer->next_hop = finger_trail->friend.id; |
1945 | current_closest_peer->trail_id = finger_trail->trail_id; | 1950 | current_closest_peer->trail_id = finger_trail->trail_id; |
1951 | //GNUNET_free(finger_trail);//FIXME: where should we free the finger trail. | ||
1946 | } | 1952 | } |
1947 | continue; | 1953 | continue; |
1948 | } | 1954 | } |
1949 | } | 1955 | } |
1950 | 1956 | ||
1951 | 1957 | ||
1952 | |||
1953 | /** | 1958 | /** |
1954 | * Compare friend entry with current successor. | 1959 | * Compare friend entry with current successor. |
1955 | * If friend identity and current_successor is same, then do nothing. | 1960 | * If friend identity and current_successor is same, then do nothing. |
@@ -1971,8 +1976,7 @@ compare_friend_and_current_closest_peer (void *cls, | |||
1971 | struct Closest_Peer *current_closest_peer = cls; | 1976 | struct Closest_Peer *current_closest_peer = cls; |
1972 | struct GNUNET_PeerIdentity *closest_peer; | 1977 | struct GNUNET_PeerIdentity *closest_peer; |
1973 | 1978 | ||
1974 | /* If friend is either congested or has crossed threshold, then don't consider | 1979 | /* Friend is either congested or has crossed threshold. */ |
1975 | * this friend.*/ | ||
1976 | if (GNUNET_YES == is_friend_congested (friend)) | 1980 | if (GNUNET_YES == is_friend_congested (friend)) |
1977 | return GNUNET_YES; | 1981 | return GNUNET_YES; |
1978 | 1982 | ||
@@ -2001,7 +2005,7 @@ compare_friend_and_current_closest_peer (void *cls, | |||
2001 | /** | 2005 | /** |
2002 | * Initialize current_successor to my_identity. | 2006 | * Initialize current_successor to my_identity. |
2003 | * @param my_identity My peer identity | 2007 | * @param my_identity My peer identity |
2004 | * @return current_successor | 2008 | * @return Updated closest_peer |
2005 | */ | 2009 | */ |
2006 | static struct Closest_Peer | 2010 | static struct Closest_Peer |
2007 | init_current_successor (struct GNUNET_PeerIdentity my_identity, | 2011 | init_current_successor (struct GNUNET_PeerIdentity my_identity, |
@@ -2021,14 +2025,19 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity, | |||
2021 | 2025 | ||
2022 | 2026 | ||
2023 | /** | 2027 | /** |
2024 | * Find the successor for destination_finger_value among my_identity, all my | 2028 | * FIXME: at the moment, there is not 100% get and put in case of non-malicious |
2025 | * friend and all my fingers. Don't consider friends or fingers which are either | 2029 | * peer. It could be because of the logic we wrote here. Verify if its correct. |
2030 | * If not then return immediate_successor. | ||
2031 | * | ||
2032 | * Find the successor for destination_finger_value among my_identity, my | ||
2033 | * friends and my fingers. Don't consider friends or fingers which are either | ||
2026 | * congested or have crossed the threshold. | 2034 | * congested or have crossed the threshold. |
2027 | * NOTE: In case a friend is also a finger, then it is always chosen as friend | 2035 | * NOTE: In case a friend is also a finger, then it is always chosen as friend |
2028 | * not a finger. | 2036 | * not a finger. |
2029 | * @param destination_finger_value Peer closest to this value will be the next successor. | 2037 | * @param destination_finger_value Peer closest to this value will be the next successor. |
2030 | * @param is_predecessor Are we looking for predecessor or finger? | 2038 | * @param is_predecessor Are we looking for predecessor or finger? |
2031 | * @return Successor | 2039 | * @return Successor It is never NULL, in case none of friend or finger is closest, |
2040 | * then we return my_identity. | ||
2032 | */ | 2041 | */ |
2033 | static struct Closest_Peer | 2042 | static struct Closest_Peer |
2034 | find_successor (uint64_t destination_finger_value, | 2043 | find_successor (uint64_t destination_finger_value, |
@@ -2040,7 +2049,7 @@ find_successor (uint64_t destination_finger_value, | |||
2040 | current_closest_peer = init_current_successor (my_identity, | 2049 | current_closest_peer = init_current_successor (my_identity, |
2041 | destination_finger_value, | 2050 | destination_finger_value, |
2042 | is_predecessor); | 2051 | is_predecessor); |
2043 | 2052 | ||
2044 | /* Compare each friend entry with current_successor and update current_successor | 2053 | /* Compare each friend entry with current_successor and update current_successor |
2045 | * with friend if its closest. */ | 2054 | * with friend if its closest. */ |
2046 | GNUNET_assert | 2055 | GNUNET_assert |
@@ -2048,11 +2057,11 @@ find_successor (uint64_t destination_finger_value, | |||
2048 | GNUNET_CONTAINER_multipeermap_iterate (friend_peermap, | 2057 | GNUNET_CONTAINER_multipeermap_iterate (friend_peermap, |
2049 | &compare_friend_and_current_closest_peer, | 2058 | &compare_friend_and_current_closest_peer, |
2050 | ¤t_closest_peer)); | 2059 | ¤t_closest_peer)); |
2051 | 2060 | ||
2052 | /* Compare each finger entry with current_successor and update current_successor | 2061 | /* Compare each finger entry with current_successor and update current_successor |
2053 | * with finger if its closest. */ | 2062 | * with finger if its closest. */ |
2054 | compare_finger_and_current_successor (¤t_closest_peer); | 2063 | compare_finger_and_current_successor (¤t_closest_peer); |
2055 | 2064 | ||
2056 | return current_closest_peer; | 2065 | return current_closest_peer; |
2057 | } | 2066 | } |
2058 | 2067 | ||
@@ -2110,7 +2119,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2110 | GNUNET_break (0); | 2119 | GNUNET_break (0); |
2111 | return; | 2120 | return; |
2112 | } | 2121 | } |
2113 | 2122 | ||
2114 | /* This is the first call made from clients file. So, we should search for the | 2123 | /* This is the first call made from clients file. So, we should search for the |
2115 | target_friend. */ | 2124 | target_friend. */ |
2116 | if (NULL == target_peer) | 2125 | if (NULL == target_peer) |
@@ -2212,12 +2221,12 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2212 | 2221 | ||
2213 | /* In this case we don't make get_path_length = 0, as we need get path to | 2222 | /* In this case we don't make get_path_length = 0, as we need get path to |
2214 | * return the message back to querying client. */ | 2223 | * return the message back to querying client. */ |
2215 | if (msize > GNUNET_SERVER_MAX_MESSAGE_SIZE) | 2224 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
2216 | { | 2225 | { |
2217 | GNUNET_break (0); | 2226 | GNUNET_break (0); |
2218 | return; | 2227 | return; |
2219 | } | 2228 | } |
2220 | 2229 | ||
2221 | /* This is the first time we got request from our own client file. */ | 2230 | /* This is the first time we got request from our own client file. */ |
2222 | if (NULL == target_peer) | 2231 | if (NULL == target_peer) |
2223 | { | 2232 | { |
@@ -2373,7 +2382,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2373 | 2382 | ||
2374 | /** | 2383 | /** |
2375 | * Randomly choose one of your friends (which is not congested and have not crossed | 2384 | * Randomly choose one of your friends (which is not congested and have not crossed |
2376 | * trail threshold) from the friends_peer map | 2385 | * trail threshold) from the friend_peermap |
2377 | * @return Friend Randomly chosen friend. | 2386 | * @return Friend Randomly chosen friend. |
2378 | * NULL in case friend peermap is empty, or all the friends are either | 2387 | * NULL in case friend peermap is empty, or all the friends are either |
2379 | * congested or have crossed trail threshold. | 2388 | * congested or have crossed trail threshold. |
@@ -2436,13 +2445,9 @@ select_random_friend () | |||
2436 | /** | 2445 | /** |
2437 | * Compute 64 bit value of finger_identity corresponding to a finger index using | 2446 | * Compute 64 bit value of finger_identity corresponding to a finger index using |
2438 | * chord formula. | 2447 | * chord formula. |
2439 | * For all fingers: | 2448 | * For all fingers, n.finger[i] = n + pow (2,i), |
2440 | * n.finger[i] = n + pow (2,i), | 2449 | * For predecessor, n.finger[PREDECESSOR_FINGER_ID] = n - 1, where |
2441 | * For predecessor | 2450 | * n = my_identity, i = finger_index, n.finger[i] = 64 bit finger value |
2442 | * n.finger[i] = n - 1, where | ||
2443 | * n = my_identity | ||
2444 | * i = finger_index. | ||
2445 | * n.finger[i] = 64 bit finger value | ||
2446 | * @param finger_index Index corresponding to which we calculate 64 bit value. | 2451 | * @param finger_index Index corresponding to which we calculate 64 bit value. |
2447 | * @return 64 bit value. | 2452 | * @return 64 bit value. |
2448 | */ | 2453 | */ |
@@ -2456,16 +2461,19 @@ compute_finger_identity_value (unsigned int finger_index) | |||
2456 | 2461 | ||
2457 | /* Are we looking for immediate predecessor? */ | 2462 | /* Are we looking for immediate predecessor? */ |
2458 | if (PREDECESSOR_FINGER_ID == finger_index) | 2463 | if (PREDECESSOR_FINGER_ID == finger_index) |
2459 | return (my_id64 -1); | 2464 | return (my_id64 - 1); |
2460 | else | 2465 | else |
2461 | return (my_id64 + (unsigned long) pow (2, finger_index)); | 2466 | { |
2467 | uint64_t add = (uint64_t)1 << finger_index; | ||
2468 | return (my_id64 + add); | ||
2469 | } | ||
2462 | } | 2470 | } |
2463 | 2471 | ||
2464 | 2472 | ||
2465 | /* | 2473 | /* |
2466 | * Choose a random friend. Start looking for the trail to reach to | 2474 | * Choose a random friend. Calculate the next finger identity to search,from |
2467 | * finger identity corresponding to current_search_finger_index through | 2475 | * current_search_finger_index. Start looking for the trail to reach to |
2468 | * this random friend. | 2476 | * finger identity through this random friend. |
2469 | * | 2477 | * |
2470 | * @param cls closure for this task | 2478 | * @param cls closure for this task |
2471 | * @param tc the context under which the task is running | 2479 | * @param tc the context under which the task is running |
@@ -2477,6 +2485,7 @@ send_find_finger_trail_message (void *cls, | |||
2477 | struct FriendInfo *target_friend; | 2485 | struct FriendInfo *target_friend; |
2478 | struct GNUNET_TIME_Relative next_send_time; | 2486 | struct GNUNET_TIME_Relative next_send_time; |
2479 | struct GNUNET_HashCode trail_id; | 2487 | struct GNUNET_HashCode trail_id; |
2488 | struct GNUNET_HashCode new_intermediate_trail_id; | ||
2480 | unsigned int is_predecessor; | 2489 | unsigned int is_predecessor; |
2481 | uint64_t finger_id_value; | 2490 | uint64_t finger_id_value; |
2482 | 2491 | ||
@@ -2509,8 +2518,8 @@ send_find_finger_trail_message (void *cls, | |||
2509 | /* Generate a unique trail id for trail we are trying to setup. */ | 2518 | /* Generate a unique trail id for trail we are trying to setup. */ |
2510 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 2519 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
2511 | &trail_id, sizeof (trail_id)); | 2520 | &trail_id, sizeof (trail_id)); |
2512 | struct GNUNET_HashCode new_intermediate_trail_id; | ||
2513 | memset(&new_intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); | 2521 | memset(&new_intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); |
2522 | |||
2514 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, | 2523 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, |
2515 | target_friend->id, target_friend, 0, NULL, | 2524 | target_friend->id, target_friend, 0, NULL, |
2516 | is_predecessor, trail_id, | 2525 | is_predecessor, trail_id, |
@@ -2866,7 +2875,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2866 | struct FriendInfo *first_trail_hop; | 2875 | struct FriendInfo *first_trail_hop; |
2867 | struct Trail *trail; | 2876 | struct Trail *trail; |
2868 | int i = 0; | 2877 | int i = 0; |
2869 | 2878 | ||
2870 | new_entry = GNUNET_new (struct FingerInfo); | 2879 | new_entry = GNUNET_new (struct FingerInfo); |
2871 | new_entry->finger_identity = finger_identity; | 2880 | new_entry->finger_identity = finger_identity; |
2872 | new_entry->finger_table_index = finger_table_index; | 2881 | new_entry->finger_table_index = finger_table_index; |
@@ -2965,9 +2974,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2965 | struct GNUNET_PeerIdentity *new_trail; | 2974 | struct GNUNET_PeerIdentity *new_trail; |
2966 | unsigned int i; | 2975 | unsigned int i; |
2967 | 2976 | ||
2968 | /* If I am my own finger identity, then we set trail_length = 0. | 2977 | /* I am my own finger. */ |
2969 | Note: Here we don't send trail compression message, as no peer in its | ||
2970 | trail added an entry in its routing table.*/ | ||
2971 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 2978 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
2972 | { | 2979 | { |
2973 | *new_trail_length = 0; | 2980 | *new_trail_length = 0; |
@@ -2979,6 +2986,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2979 | *new_trail_length = 0; | 2986 | *new_trail_length = 0; |
2980 | return NULL; | 2987 | return NULL; |
2981 | } | 2988 | } |
2989 | |||
2982 | /* If finger identity is a friend. */ | 2990 | /* If finger identity is a friend. */ |
2983 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) | 2991 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) |
2984 | { | 2992 | { |
@@ -2994,9 +3002,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
2994 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3002 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2995 | &trail[0]))); | 3003 | &trail[0]))); |
2996 | 3004 | ||
2997 | /* Before you send a trail compression, get the routing entry | 3005 | |
2998 | from you routing table. update the fields in routing table | ||
2999 | to update your next hop to finger identity. */ | ||
3000 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | 3006 | GDS_NEIGHBOURS_send_trail_compression (my_identity, |
3001 | trail_id, finger_identity, | 3007 | trail_id, finger_identity, |
3002 | target_friend); | 3008 | target_friend); |
@@ -3017,9 +3023,6 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3017 | (target_friend = | 3023 | (target_friend = |
3018 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3024 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3019 | &trail[0]))); | 3025 | &trail[0]))); |
3020 | GNUNET_assert (NULL != | ||
3021 | (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3022 | &trail[i]))); | ||
3023 | GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]); | 3026 | GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]); |
3024 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | 3027 | GDS_NEIGHBOURS_send_trail_compression (my_identity, |
3025 | trail_id, trail[i], | 3028 | trail_id, trail[i], |
@@ -3036,6 +3039,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3036 | i++; | 3039 | i++; |
3037 | } | 3040 | } |
3038 | *new_trail_length = j+1; | 3041 | *new_trail_length = j+1; |
3042 | GNUNET_assert((j+1) == (trail_length - 1)); //FIXME: remove it afterwards. | ||
3039 | return new_trail; | 3043 | return new_trail; |
3040 | } | 3044 | } |
3041 | } | 3045 | } |
@@ -3141,7 +3145,7 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | |||
3141 | unsigned int finger_table_index) | 3145 | unsigned int finger_table_index) |
3142 | { | 3146 | { |
3143 | struct FingerInfo *successor; | 3147 | struct FingerInfo *successor; |
3144 | 3148 | ||
3145 | if (finger_table_index != current_search_finger_index) | 3149 | if (finger_table_index != current_search_finger_index) |
3146 | return; | 3150 | return; |
3147 | 3151 | ||
@@ -3153,7 +3157,7 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | |||
3153 | { | 3157 | { |
3154 | /* Start looking for immediate predecessor. */ | 3158 | /* Start looking for immediate predecessor. */ |
3155 | current_search_finger_index = PREDECESSOR_FINGER_ID; | 3159 | current_search_finger_index = PREDECESSOR_FINGER_ID; |
3156 | 3160 | ||
3157 | /* If I am not my own successor, then send a verify successor message. */ | 3161 | /* If I am not my own successor, then send a verify successor message. */ |
3158 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 3162 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
3159 | { | 3163 | { |
@@ -3276,22 +3280,17 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3276 | 3280 | ||
3277 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ | 3281 | /* Get the finger_table_index corresponding to finger_value we got from network.*/ |
3278 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); | 3282 | finger_table_index = get_finger_table_index (finger_value, is_predecessor); |
3279 | 3283 | ||
3280 | /* Invalid finger_table_index. */ | 3284 | /* Invalid finger_table_index. */ |
3281 | if ((finger_table_index > PREDECESSOR_FINGER_ID)) | 3285 | if ((finger_table_index > PREDECESSOR_FINGER_ID)) |
3282 | { | 3286 | { |
3283 | GNUNET_break_op (0); | 3287 | GNUNET_break_op (0); |
3284 | return; | 3288 | return; |
3285 | } | 3289 | } |
3286 | 3290 | ||
3287 | 3291 | /* New entry same as successor. */ | |
3288 | //GDS_ROUTING_test_print(); | ||
3289 | /* If the new entry for any finger table index other than successor or predecessor | ||
3290 | * is same as successor then don't add it in finger table, | ||
3291 | * reset the current search finger index and exit. */ | ||
3292 | if ((0 != finger_table_index) && | 3292 | if ((0 != finger_table_index) && |
3293 | (PREDECESSOR_FINGER_ID != finger_table_index) && | 3293 | (PREDECESSOR_FINGER_ID != finger_table_index)) |
3294 | (finger_table_index == current_search_finger_index)) //FIXME; why do I check this cond? | ||
3295 | { | 3294 | { |
3296 | successor = &finger_table[0]; | 3295 | successor = &finger_table[0]; |
3297 | GNUNET_assert (GNUNET_YES == successor->is_present); | 3296 | GNUNET_assert (GNUNET_YES == successor->is_present); |
@@ -3429,7 +3428,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3429 | 3428 | ||
3430 | msize = ntohs (message->size); | 3429 | msize = ntohs (message->size); |
3431 | if (msize < sizeof (struct PeerPutMessage)) | 3430 | if (msize < sizeof (struct PeerPutMessage)) |
3432 | { | 3431 | { |
3433 | GNUNET_break_op (0); | 3432 | GNUNET_break_op (0); |
3434 | return GNUNET_OK; | 3433 | return GNUNET_OK; |
3435 | } | 3434 | } |
@@ -3760,17 +3759,25 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3760 | 3759 | ||
3761 | 3760 | ||
3762 | /** | 3761 | /** |
3763 | * | 3762 | * Find the next hop to pass trail setup message. First find the local best known |
3764 | * @param final_dest_finger_val | 3763 | * hop from your own identity, friends and finger. If you were part of trail, |
3765 | * @param intermediate_trail_id | 3764 | * then get the next hop from routing table. Compare next_hop from routing table |
3766 | * @param is_predecessor | 3765 | * and local best known hop, and return the closest one to final_dest_finger_val |
3767 | * @param current_dest | 3766 | * @param final_dest_finger_val 64 bit value of finger identity |
3768 | * @return | 3767 | * @param intermediate_trail_id If you are part of trail to reach to some other |
3768 | * finger, then it is the trail id to reach to | ||
3769 | * that finger, else set to 0. | ||
3770 | * @param is_predecessor Are we looking for closest successor or predecessor. | ||
3771 | * @param current_dest In case you are part of trail, then finger to which | ||
3772 | * we should forward the message. Else my own identity | ||
3773 | * @return Closest Peer for @a final_dest_finger_val | ||
3769 | */ | 3774 | */ |
3770 | static struct Closest_Peer | 3775 | static struct Closest_Peer |
3771 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, | 3776 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, |
3772 | struct GNUNET_HashCode intermediate_trail_id, | 3777 | struct GNUNET_HashCode intermediate_trail_id, |
3773 | unsigned int is_predecessor, | 3778 | unsigned int is_predecessor, |
3779 | struct GNUNET_PeerIdentity prev_hop, | ||
3780 | struct GNUNET_PeerIdentity source, | ||
3774 | struct GNUNET_PeerIdentity *current_dest) | 3781 | struct GNUNET_PeerIdentity *current_dest) |
3775 | { | 3782 | { |
3776 | struct Closest_Peer peer; | 3783 | struct Closest_Peer peer; |
@@ -3798,9 +3805,6 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
3798 | struct GNUNET_PeerIdentity *next_hop; | 3805 | struct GNUNET_PeerIdentity *next_hop; |
3799 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3806 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
3800 | GDS_ROUTING_SRC_TO_DEST); | 3807 | GDS_ROUTING_SRC_TO_DEST); |
3801 | /* FIXME: Here we found next_hop NULL from routing table, but we still | ||
3802 | * have a next_hop from find_successor should we not break and choose that | ||
3803 | * next_hop. */ | ||
3804 | GNUNET_assert (NULL != next_hop); | 3808 | GNUNET_assert (NULL != next_hop); |
3805 | 3809 | ||
3806 | peer.next_hop = *next_hop; | 3810 | peer.next_hop = *next_hop; |
@@ -3830,8 +3834,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3830 | struct FriendInfo *target_friend; | 3834 | struct FriendInfo *target_friend; |
3831 | struct GNUNET_PeerIdentity source; | 3835 | struct GNUNET_PeerIdentity source; |
3832 | uint64_t final_dest_finger_val; | 3836 | uint64_t final_dest_finger_val; |
3833 | //struct GNUNET_HashCode *new_intermediate_trail_id; | ||
3834 | //struct GNUNET_PeerIdentity *local_best_known_dest; | ||
3835 | struct GNUNET_HashCode intermediate_trail_id; | 3837 | struct GNUNET_HashCode intermediate_trail_id; |
3836 | struct GNUNET_HashCode trail_id; | 3838 | struct GNUNET_HashCode trail_id; |
3837 | unsigned int is_predecessor; | 3839 | unsigned int is_predecessor; |
@@ -3842,7 +3844,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3842 | if (msize < sizeof (struct PeerTrailSetupMessage)) | 3844 | if (msize < sizeof (struct PeerTrailSetupMessage)) |
3843 | { | 3845 | { |
3844 | GNUNET_break_op (0); | 3846 | GNUNET_break_op (0); |
3845 | return GNUNET_YES; | 3847 | return GNUNET_SYSERR; |
3846 | } | 3848 | } |
3847 | 3849 | ||
3848 | trail_setup = (const struct PeerTrailSetupMessage *) message; | 3850 | trail_setup = (const struct PeerTrailSetupMessage *) message; |
@@ -3867,9 +3869,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3867 | /* Is my routing table full? */ | 3869 | /* Is my routing table full? */ |
3868 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 3870 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
3869 | { | 3871 | { |
3870 | /* As my routing table is full, I can no longer handle any more trail | ||
3871 | * through me */ | ||
3872 | |||
3873 | GNUNET_assert (NULL != | 3872 | GNUNET_assert (NULL != |
3874 | (target_friend = | 3873 | (target_friend = |
3875 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 3874 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); |
@@ -3880,15 +3879,19 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3880 | CONGESTION_TIMEOUT); | 3879 | CONGESTION_TIMEOUT); |
3881 | return GNUNET_OK; | 3880 | return GNUNET_OK; |
3882 | } | 3881 | } |
3883 | |||
3884 | // new_intermediate_trail_id = GNUNET_new (struct GNUNET_HashCode); | ||
3885 | // local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity); | ||
3886 | 3882 | ||
3883 | /* If I was the source and got the message back, then set trail length to 0.*/ | ||
3884 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | ||
3885 | { | ||
3886 | trail_length = 0; | ||
3887 | } | ||
3887 | /* Get the next hop to forward the trail setup request. */ | 3888 | /* Get the next hop to forward the trail setup request. */ |
3888 | struct Closest_Peer next_peer = | 3889 | struct Closest_Peer next_peer = |
3889 | get_local_best_known_next_hop (final_dest_finger_val, | 3890 | get_local_best_known_next_hop (final_dest_finger_val, |
3890 | intermediate_trail_id, | 3891 | intermediate_trail_id, |
3891 | is_predecessor, | 3892 | is_predecessor, |
3893 | *peer, | ||
3894 | source, | ||
3892 | ¤t_dest); | 3895 | ¤t_dest); |
3893 | 3896 | ||
3894 | /* Am I the final destination? */ | 3897 | /* Am I the final destination? */ |
@@ -3900,36 +3903,64 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3900 | { | 3903 | { |
3901 | GDS_ROUTING_add (trail_id, *peer, my_identity); | 3904 | GDS_ROUTING_add (trail_id, *peer, my_identity); |
3902 | } | 3905 | } |
3903 | 3906 | ||
3904 | GNUNET_assert (NULL != | 3907 | if(trail_length > 0) |
3905 | (target_friend = | 3908 | { |
3906 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 3909 | GNUNET_assert (NULL != |
3910 | (target_friend = | ||
3911 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3912 | &trail_peer_list[trail_length-1]))); | ||
3913 | } | ||
3914 | else | ||
3915 | { | ||
3916 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | ||
3917 | { | ||
3918 | finger_table_add (my_identity, NULL, 0, is_predecessor, | ||
3919 | final_dest_finger_val, trail_id); | ||
3920 | return GNUNET_OK; | ||
3921 | } | ||
3922 | GNUNET_assert (NULL != | ||
3923 | (target_friend = | ||
3924 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source))); | ||
3925 | } | ||
3926 | |||
3907 | GDS_NEIGHBOURS_send_trail_setup_result (source, | 3927 | GDS_NEIGHBOURS_send_trail_setup_result (source, |
3908 | my_identity, | 3928 | my_identity, |
3909 | target_friend, trail_length, | 3929 | target_friend, trail_length, |
3910 | trail_peer_list, | 3930 | trail_peer_list, |
3911 | final_dest_finger_val, | 3931 | is_predecessor, |
3912 | is_predecessor, trail_id); | 3932 | final_dest_finger_val,trail_id); |
3913 | } | 3933 | } |
3914 | else | 3934 | else |
3915 | { | 3935 | { |
3916 | /* Add yourself to list of peers. */ | ||
3917 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | ||
3918 | |||
3919 | memcpy (peer_list, trail_peer_list, | ||
3920 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3921 | peer_list[trail_length] = my_identity; | ||
3922 | GNUNET_assert (NULL != | 3936 | GNUNET_assert (NULL != |
3923 | (target_friend = | 3937 | (target_friend = |
3924 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3938 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3925 | &next_peer.next_hop))); | 3939 | &next_peer.next_hop))); |
3926 | GDS_NEIGHBOURS_send_trail_setup (source, | ||
3927 | final_dest_finger_val, | ||
3928 | next_peer.best_known_destination, | ||
3929 | target_friend, trail_length + 1, peer_list, | ||
3930 | is_predecessor, trail_id, | ||
3931 | next_peer.trail_id); | ||
3932 | 3940 | ||
3941 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | ||
3942 | { | ||
3943 | /* Add yourself to list of peers. */ | ||
3944 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | ||
3945 | |||
3946 | memcpy (peer_list, trail_peer_list, | ||
3947 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3948 | peer_list[trail_length] = my_identity; | ||
3949 | |||
3950 | GDS_NEIGHBOURS_send_trail_setup (source, | ||
3951 | final_dest_finger_val, | ||
3952 | next_peer.best_known_destination, | ||
3953 | target_friend, trail_length + 1, peer_list, | ||
3954 | is_predecessor, trail_id, | ||
3955 | next_peer.trail_id); | ||
3956 | } | ||
3957 | else | ||
3958 | GDS_NEIGHBOURS_send_trail_setup (source, | ||
3959 | final_dest_finger_val, | ||
3960 | next_peer.best_known_destination, | ||
3961 | target_friend, 0, NULL, | ||
3962 | is_predecessor, trail_id, | ||
3963 | next_peer.trail_id); | ||
3933 | } | 3964 | } |
3934 | return GNUNET_OK; | 3965 | return GNUNET_OK; |
3935 | } | 3966 | } |
@@ -4051,7 +4082,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4051 | return GNUNET_OK; | 4082 | return GNUNET_OK; |
4052 | } | 4083 | } |
4053 | 4084 | ||
4054 | is_predecessor = htonl (trail_result->is_predecessor); | 4085 | is_predecessor = ntohl (trail_result->is_predecessor); |
4055 | querying_peer = trail_result->querying_peer; | 4086 | querying_peer = trail_result->querying_peer; |
4056 | finger_identity = trail_result->finger_identity; | 4087 | finger_identity = trail_result->finger_identity; |
4057 | trail_id = trail_result->trail_id; | 4088 | trail_id = trail_result->trail_id; |
@@ -4073,21 +4104,16 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4073 | #endif | 4104 | #endif |
4074 | 4105 | ||
4075 | /* Am I the one who initiated the query? */ | 4106 | /* Am I the one who initiated the query? */ |
4076 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, | 4107 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) |
4077 | &my_identity))) | ||
4078 | { | 4108 | { |
4079 | /* If I am not my own finger identity, then add routing table entry. */ | 4109 | /* If I am not my own finger identity, then add routing table entry. */ |
4080 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 4110 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
4081 | { | 4111 | { |
4082 | GDS_ROUTING_add (trail_id, my_identity, *peer); | 4112 | GDS_ROUTING_add (trail_id, my_identity, *peer); |
4083 | } | 4113 | } |
4084 | 4114 | ||
4085 | /* FIXME: Remove this assert later. */ | 4115 | finger_table_add (finger_identity, trail_peer_list, trail_length, |
4086 | GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4116 | is_predecessor, ulitmate_destination_finger_value, trail_id); |
4087 | peer)); | ||
4088 | finger_table_add (finger_identity, trail_peer_list, | ||
4089 | trail_length, ulitmate_destination_finger_value, | ||
4090 | is_predecessor, trail_id); | ||
4091 | return GNUNET_YES; | 4117 | return GNUNET_YES; |
4092 | } | 4118 | } |
4093 | 4119 | ||
@@ -4099,16 +4125,11 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4099 | return GNUNET_SYSERR; | 4125 | return GNUNET_SYSERR; |
4100 | } | 4126 | } |
4101 | 4127 | ||
4102 | /* FIXME: CHECK IF YOU ARE PRESENT MORE THAN ONCE IN THE TRAIL, IF YES | ||
4103 | THEN REMOVE ALL THE ENTRIES AND CHOOSE THE PEER THERE.*/ | ||
4104 | |||
4105 | if (my_index == 0) | 4128 | if (my_index == 0) |
4106 | next_hop = trail_result->querying_peer; | 4129 | next_hop = trail_result->querying_peer; |
4107 | else | 4130 | else |
4108 | next_hop = trail_peer_list[my_index - 1]; | 4131 | next_hop = trail_peer_list[my_index - 1]; |
4109 | 4132 | ||
4110 | /* If the querying_peer is its own finger, then don't add an entry in routing | ||
4111 | * table as querying peer will discard the trail. */ | ||
4112 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), | 4133 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), |
4113 | &(trail_result->finger_identity)))) | 4134 | &(trail_result->finger_identity)))) |
4114 | { | 4135 | { |
@@ -4158,8 +4179,6 @@ invert_trail (const struct GNUNET_PeerIdentity *trail, | |||
4158 | } | 4179 | } |
4159 | 4180 | ||
4160 | 4181 | ||
4161 | //FIXME: URGENT. | ||
4162 | |||
4163 | /** | 4182 | /** |
4164 | * Return the shortest trail to reach from me to my_predecessor. | 4183 | * Return the shortest trail to reach from me to my_predecessor. |
4165 | * @param current_trail Trail from source to me. | 4184 | * @param current_trail Trail from source to me. |
@@ -4257,7 +4276,7 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4257 | trail_to_new_predecessor = NULL; | 4276 | trail_to_new_predecessor = NULL; |
4258 | /* FIXME: check that you always add trail entry even if your finger is | 4277 | /* FIXME: check that you always add trail entry even if your finger is |
4259 | friend. */ | 4278 | friend. */ |
4260 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); | 4279 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); /*FIXME; Check that the corresponding pred adds entry also. */ |
4261 | GNUNET_assert (NULL != (target_friend = | 4280 | GNUNET_assert (NULL != (target_friend = |
4262 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4281 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4263 | &finger))); | 4282 | &finger))); |
@@ -4374,6 +4393,31 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4374 | } | 4393 | } |
4375 | 4394 | ||
4376 | 4395 | ||
4396 | /** | ||
4397 | * Check if the the peer from which we got the message is the valid peer from | ||
4398 | * which we should expect the message. | ||
4399 | * @param peer Peer from which we got the message. | ||
4400 | * @param trail_id Trail in which peer should be either my prev_hop or next_hop | ||
4401 | * depending on the @a trail_direction. | ||
4402 | * @param trail_direction Is trail from source to destination or opposite way. | ||
4403 | * @return #GNUNET_YES if Peer is valid. | ||
4404 | * #GNUNET_NO if Peer is not valid. | ||
4405 | */ | ||
4406 | static int | ||
4407 | is_sender_peer_valid (const struct GNUNET_PeerIdentity *peer, | ||
4408 | struct GNUNET_HashCode trail_id, | ||
4409 | enum GDS_ROUTING_trail_direction trail_direction) | ||
4410 | { | ||
4411 | struct GNUNET_PeerIdentity *peer_routing_table; | ||
4412 | |||
4413 | peer_routing_table = GDS_ROUTING_get_next_hop (trail_id, !trail_direction); | ||
4414 | |||
4415 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (peer, peer_routing_table)) | ||
4416 | return GNUNET_YES; | ||
4417 | else | ||
4418 | return GNUNET_NO; | ||
4419 | } | ||
4420 | |||
4377 | /* | 4421 | /* |
4378 | * Core handle for p2p verify successor messages. | 4422 | * Core handle for p2p verify successor messages. |
4379 | * @param cls closure | 4423 | * @param cls closure |
@@ -4401,9 +4445,6 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4401 | 4445 | ||
4402 | msize = ntohs (message->size); | 4446 | msize = ntohs (message->size); |
4403 | 4447 | ||
4404 | /* Here we pass trail to reach from source to successor, and in case successor | ||
4405 | * does not have any predecessor, then we will add source as my predecessor. | ||
4406 | * So we pass the trail along with trail id. */ | ||
4407 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) | 4448 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) |
4408 | { | 4449 | { |
4409 | GNUNET_break_op (0); | 4450 | GNUNET_break_op (0); |
@@ -4425,12 +4466,13 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4425 | successor = vsm->successor; | 4466 | successor = vsm->successor; |
4426 | trail = (struct GNUNET_PeerIdentity *)&vsm[1]; | 4467 | trail = (struct GNUNET_PeerIdentity *)&vsm[1]; |
4427 | 4468 | ||
4428 | //FIXME: we can have a check if peer is correct peer which should have | 4469 | if(GNUNET_NO == is_sender_peer_valid (peer,trail_id, GDS_ROUTING_SRC_TO_DEST)) |
4429 | // sent this message. use same function is_sender_peer_correct | 4470 | { |
4430 | // but specify direction so that the function can be used in other functions | 4471 | GNUNET_break_op(0); |
4431 | //also. | 4472 | return GNUNET_SYSERR; |
4473 | } | ||
4432 | 4474 | ||
4433 | /* I am not the successor of source_peer. Pass the message to next_hop on | 4475 | /* I am NOT the successor of source_peer. Pass the message to next_hop on |
4434 | * the trail. */ | 4476 | * the trail. */ |
4435 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) | 4477 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) |
4436 | { | 4478 | { |
@@ -4475,8 +4517,8 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4475 | else | 4517 | else |
4476 | { | 4518 | { |
4477 | trail_to_predecessor = GNUNET_new(struct GNUNET_PeerIdentity); | 4519 | trail_to_predecessor = GNUNET_new(struct GNUNET_PeerIdentity); |
4478 | trail_to_predecessor = NULL; | 4520 | trail_to_predecessor = NULL; |
4479 | trail_to_predecessor_length = 0; | 4521 | trail_to_predecessor_length = 0; |
4480 | } | 4522 | } |
4481 | GNUNET_assert (NULL != | 4523 | GNUNET_assert (NULL != |
4482 | (target_friend = | 4524 | (target_friend = |
@@ -4671,12 +4713,9 @@ compare_and_update_successor (struct GNUNET_PeerIdentity probable_successor, | |||
4671 | add_new_finger (probable_successor, trail_to_new_successor, | 4713 | add_new_finger (probable_successor, trail_to_new_successor, |
4672 | trail_to_new_successor_length, trail_id, 0); | 4714 | trail_to_new_successor_length, trail_id, 0); |
4673 | 4715 | ||
4674 | /* If probable successor is not a friend, then add an entry in your own | 4716 | |
4675 | routing table. */ | ||
4676 | if (trail_to_new_successor_length > 0) | 4717 | if (trail_to_new_successor_length > 0) |
4677 | { | 4718 | { |
4678 | /* FIXME: check that you always add trail entry even if your finger is | ||
4679 | friend. */ | ||
4680 | GDS_ROUTING_add (trail_id, my_identity, trail_to_new_successor[0]); | 4719 | GDS_ROUTING_add (trail_id, my_identity, trail_to_new_successor[0]); |
4681 | GNUNET_assert (NULL != | 4720 | GNUNET_assert (NULL != |
4682 | (target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4721 | (target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -4684,15 +4723,13 @@ compare_and_update_successor (struct GNUNET_PeerIdentity probable_successor, | |||
4684 | } | 4723 | } |
4685 | else | 4724 | else |
4686 | { | 4725 | { |
4687 | /* FIXME: check that you always add trail entry even if your finger is | ||
4688 | friend. */ | ||
4689 | GDS_ROUTING_add (trail_id, my_identity, probable_successor); | 4726 | GDS_ROUTING_add (trail_id, my_identity, probable_successor); |
4690 | GNUNET_assert (NULL != | 4727 | GNUNET_assert (NULL != |
4691 | (target_friend = | 4728 | (target_friend = |
4692 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4729 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4693 | &probable_successor))); | 4730 | &probable_successor))); |
4694 | } | 4731 | } |
4695 | //test_finger_table_print(); | 4732 | |
4696 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor, | 4733 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor, |
4697 | trail_from_curr_to_probable_successor, | 4734 | trail_from_curr_to_probable_successor, |
4698 | trail_from_curr_to_probable_successor_length, | 4735 | trail_from_curr_to_probable_successor_length, |
@@ -4839,7 +4876,7 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
4839 | GNUNET_break_op (0); | 4876 | GNUNET_break_op (0); |
4840 | return GNUNET_SYSERR; | 4877 | return GNUNET_SYSERR; |
4841 | } | 4878 | } |
4842 | if (trail_length == my_index) | 4879 | if ((trail_length-1) == my_index) //FIXMe: SHOULD IT BE TRAIL_LENGTH - 1.s |
4843 | next_hop = new_successor; | 4880 | next_hop = new_successor; |
4844 | else | 4881 | else |
4845 | next_hop = trail[my_index + 1]; | 4882 | next_hop = trail[my_index + 1]; |
@@ -4991,6 +5028,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
4991 | GNUNET_assert (NULL != | 5028 | GNUNET_assert (NULL != |
4992 | (target_friend = | 5029 | (target_friend = |
4993 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); | 5030 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))); |
5031 | |||
4994 | GDS_NEIGHBOURS_send_trail_setup (source, | 5032 | GDS_NEIGHBOURS_send_trail_setup (source, |
4995 | ultimate_destination_finger_value, | 5033 | ultimate_destination_finger_value, |
4996 | successor.best_known_destination, | 5034 | successor.best_known_destination, |
@@ -5020,7 +5058,7 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
5020 | size_t msize; | 5058 | size_t msize; |
5021 | 5059 | ||
5022 | msize = ntohs (message->size); | 5060 | msize = ntohs (message->size); |
5023 | /* Here we pass only the trail id. */ | 5061 | |
5024 | if (msize != sizeof (struct PeerTrailCompressionMessage)) | 5062 | if (msize != sizeof (struct PeerTrailCompressionMessage)) |
5025 | { | 5063 | { |
5026 | GNUNET_break_op (0); | 5064 | GNUNET_break_op (0); |
@@ -5029,9 +5067,7 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
5029 | 5067 | ||
5030 | trail_compression = (const struct PeerTrailCompressionMessage *) message; | 5068 | trail_compression = (const struct PeerTrailCompressionMessage *) message; |
5031 | trail_id = trail_compression->trail_id; | 5069 | trail_id = trail_compression->trail_id; |
5032 | //FIXME: again check if peer is the correct peer. same logic as | 5070 | |
5033 | //trail teardown make a generic function. | ||
5034 | |||
5035 | /* Am I the new first friend to reach to finger of this trail. */ | 5071 | /* Am I the new first friend to reach to finger of this trail. */ |
5036 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&trail_compression->new_first_friend, | 5072 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&trail_compression->new_first_friend, |
5037 | &my_identity))) | 5073 | &my_identity))) |
@@ -5039,6 +5075,7 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
5039 | GNUNET_assert (NULL != | 5075 | GNUNET_assert (NULL != |
5040 | (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5076 | (GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5041 | &trail_compression->source_peer))); | 5077 | &trail_compression->source_peer))); |
5078 | |||
5042 | /* Update your prev hop to source of this message. */ | 5079 | /* Update your prev hop to source of this message. */ |
5043 | GNUNET_assert (GNUNET_SYSERR != | 5080 | GNUNET_assert (GNUNET_SYSERR != |
5044 | (GDS_ROUTING_update_trail_prev_hop (trail_id, | 5081 | (GDS_ROUTING_update_trail_prev_hop (trail_id, |
@@ -5047,9 +5084,10 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p | |||
5047 | } | 5084 | } |
5048 | 5085 | ||
5049 | /* Pass the message to next hop to finally reach to new_first_friend. */ | 5086 | /* Pass the message to next hop to finally reach to new_first_friend. */ |
5050 | /* FIXME THIS FAILS.*/ | ||
5051 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); | 5087 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); |
5052 | if (NULL == next_hop) //FIXME: Assertion failure | 5088 | GDS_ROUTING_test_print(); |
5089 | |||
5090 | if (NULL == next_hop) | ||
5053 | { | 5091 | { |
5054 | GNUNET_break (0); | 5092 | GNUNET_break (0); |
5055 | return GNUNET_OK; | 5093 | return GNUNET_OK; |