diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-16 09:14:53 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-16 09:14:53 +0000 |
commit | a952bdf9866ced9e04c756e1b079dea6ddd1970b (patch) | |
tree | 64e83187596a4820605c7be12427261d9972e632 /src | |
parent | 34e40e006af57ec7cb7c69acf0273321550117dd (diff) | |
download | gnunet-a952bdf9866ced9e04c756e1b079dea6ddd1970b.tar.gz gnunet-a952bdf9866ced9e04c756e1b079dea6ddd1970b.zip |
Remove the messages of disconnected peer from pending queue.
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 149 |
1 files changed, 116 insertions, 33 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 1f2a87da0..d086345fb 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -681,6 +681,8 @@ struct FriendInfo | |||
681 | */ | 681 | */ |
682 | struct GNUNET_TIME_Absolute congestion_timestamp; | 682 | struct GNUNET_TIME_Absolute congestion_timestamp; |
683 | 683 | ||
684 | |||
685 | // TODO : Change name of head and tail to pending_messages_list_head and so. | ||
684 | /** | 686 | /** |
685 | * Head of pending messages to be sent to this friend. | 687 | * Head of pending messages to be sent to this friend. |
686 | */ | 688 | */ |
@@ -1059,9 +1061,10 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1059 | } | 1061 | } |
1060 | 1062 | ||
1061 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1063 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1064 | // TODO: Create a new macro for timeout value of pending messages | ||
1062 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 1065 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
1063 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; | 1066 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; |
1064 | pending->msg = &tsm->header; | 1067 | pending->msg = &(tsm->header); |
1065 | tsm->header.size = htons (msize); | 1068 | tsm->header.size = htons (msize); |
1066 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP); | 1069 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP); |
1067 | tsm->final_destination_finger_value = GNUNET_htonll (ultimate_destination_finger_value); | 1070 | tsm->final_destination_finger_value = GNUNET_htonll (ultimate_destination_finger_value); |
@@ -1628,7 +1631,7 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1628 | static int | 1631 | static int |
1629 | is_friend_congested (struct FriendInfo *friend) | 1632 | is_friend_congested (struct FriendInfo *friend) |
1630 | { | 1633 | { |
1631 | if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && | 1634 | if (( friend->trails_count < TRAILS_THROUGH_FRIEND_THRESHOLD) && |
1632 | ((0 == GNUNET_TIME_absolute_get_remaining | 1635 | ((0 == GNUNET_TIME_absolute_get_remaining |
1633 | (friend->congestion_timestamp).rel_value_us))) | 1636 | (friend->congestion_timestamp).rel_value_us))) |
1634 | return GNUNET_NO; | 1637 | return GNUNET_NO; |
@@ -1657,6 +1660,8 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1, | |||
1657 | peer1_value = GNUNET_ntohll (peer1_value); | 1660 | peer1_value = GNUNET_ntohll (peer1_value); |
1658 | peer2_value = GNUNET_ntohll (peer2_value); | 1661 | peer2_value = GNUNET_ntohll (peer2_value); |
1659 | 1662 | ||
1663 | // TODO: Can use a simpler (to understand) idea here! | ||
1664 | |||
1660 | if (peer1_value == value) | 1665 | if (peer1_value == value) |
1661 | { | 1666 | { |
1662 | return peer1; | 1667 | return peer1; |
@@ -1859,6 +1864,8 @@ test_finger_table_print() | |||
1859 | * @param is_predecessor Is value a predecessor or any other finger. | 1864 | * @param is_predecessor Is value a predecessor or any other finger. |
1860 | * @return Closest peer among two peers. | 1865 | * @return Closest peer among two peers. |
1861 | */ | 1866 | */ |
1867 | |||
1868 | // TODO: URGENT! Change return type to value instead of pointer | ||
1862 | const static struct GNUNET_PeerIdentity * | 1869 | const static struct GNUNET_PeerIdentity * |
1863 | select_closest_peer (const struct GNUNET_PeerIdentity *peer1, | 1870 | select_closest_peer (const struct GNUNET_PeerIdentity *peer1, |
1864 | const struct GNUNET_PeerIdentity *peer2, | 1871 | const struct GNUNET_PeerIdentity *peer2, |
@@ -1871,6 +1878,7 @@ select_closest_peer (const struct GNUNET_PeerIdentity *peer1, | |||
1871 | if (1 == is_predecessor) | 1878 | if (1 == is_predecessor) |
1872 | return select_closest_predecessor (peer1, peer2, value); | 1879 | return select_closest_predecessor (peer1, peer2, value); |
1873 | 1880 | ||
1881 | // TODO: Change name to something like select_closest_successor!! | ||
1874 | return select_closest_finger (peer1, peer2, value); | 1882 | return select_closest_finger (peer1, peer2, value); |
1875 | } | 1883 | } |
1876 | 1884 | ||
@@ -1886,11 +1894,49 @@ select_closest_peer (const struct GNUNET_PeerIdentity *peer1, | |||
1886 | * @return struct Selected_Finger_Trail which contains the first friend , trail id | 1894 | * @return struct Selected_Finger_Trail which contains the first friend , trail id |
1887 | * and trail length. NULL in case none of the trails are free. | 1895 | * and trail length. NULL in case none of the trails are free. |
1888 | */ | 1896 | */ |
1897 | static struct Trail * | ||
1898 | select_finger_trail (struct FingerInfo *finger) | ||
1899 | { | ||
1900 | struct FriendInfo *friend; | ||
1901 | struct Trail *current_finger_trail; | ||
1902 | struct Trail *best_trail = NULL; | ||
1903 | unsigned int i; | ||
1904 | |||
1905 | GNUNET_assert (finger->trails_count > 0); | ||
1906 | |||
1907 | for (i = 0; i < finger->trails_count; i++) | ||
1908 | { | ||
1909 | current_finger_trail = &finger->trail_list[i]; | ||
1910 | |||
1911 | /* No trail stored at this index. */ | ||
1912 | if (GNUNET_NO == current_finger_trail->is_present) | ||
1913 | continue; | ||
1914 | |||
1915 | GNUNET_assert (NULL != | ||
1916 | (friend = | ||
1917 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
1918 | ¤t_finger_trail->trail_head->peer))); | ||
1919 | |||
1920 | /* First friend to reach trail is not free. */ | ||
1921 | if (GNUNET_YES == is_friend_congested (friend)) | ||
1922 | continue; | ||
1923 | |||
1924 | if (NULL == best_trail || | ||
1925 | best_trail->trail_length > current_finger_trail->trail_length) | ||
1926 | { | ||
1927 | best_trail = current_finger_trail; | ||
1928 | } | ||
1929 | } | ||
1930 | |||
1931 | return best_trail; | ||
1932 | } | ||
1933 | |||
1934 | #if 0 | ||
1889 | static struct Selected_Finger_Trail * | 1935 | static struct Selected_Finger_Trail * |
1890 | select_finger_trail (struct FingerInfo *finger) | 1936 | select_finger_trail (struct FingerInfo *finger) |
1891 | { | 1937 | { |
1892 | struct FriendInfo *friend; | 1938 | struct FriendInfo *friend; |
1893 | struct Trail *iterator; | 1939 | struct Trail *current_finger_trail; |
1894 | struct Selected_Finger_Trail *finger_trail; | 1940 | struct Selected_Finger_Trail *finger_trail; |
1895 | unsigned int i; | 1941 | unsigned int i; |
1896 | unsigned int flag = 0; | 1942 | unsigned int flag = 0; |
@@ -1901,16 +1947,16 @@ select_finger_trail (struct FingerInfo *finger) | |||
1901 | 1947 | ||
1902 | for (i = 0; i < finger->trails_count; i++) | 1948 | for (i = 0; i < finger->trails_count; i++) |
1903 | { | 1949 | { |
1904 | iterator = &finger->trail_list[i]; | 1950 | current_finger_trail = &finger->trail_list[i]; |
1905 | 1951 | ||
1906 | /* No trail stored at this index. */ | 1952 | /* No trail stored at this index. */ |
1907 | if (GNUNET_NO == iterator->is_present) | 1953 | if (GNUNET_NO == current_finger_trail->is_present) |
1908 | continue; | 1954 | continue; |
1909 | 1955 | ||
1910 | GNUNET_assert (NULL != | 1956 | GNUNET_assert (NULL != |
1911 | (friend = | 1957 | (friend = |
1912 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 1958 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
1913 | &iterator->trail_head->peer))); | 1959 | ¤t_finger_trail->trail_head->peer))); |
1914 | 1960 | ||
1915 | /* First friend to reach trail is not free. */ | 1961 | /* First friend to reach trail is not free. */ |
1916 | if (GNUNET_YES == is_friend_congested (friend)) | 1962 | if (GNUNET_YES == is_friend_congested (friend)) |
@@ -1922,15 +1968,15 @@ select_finger_trail (struct FingerInfo *finger) | |||
1922 | if (!flag) | 1968 | if (!flag) |
1923 | { | 1969 | { |
1924 | flag = 1; | 1970 | flag = 1; |
1925 | finger_trail->trail_length = iterator->trail_length; | 1971 | finger_trail->trail_length = current_finger_trail->trail_length; |
1926 | finger_trail->friend = *friend; | 1972 | finger_trail->friend = *friend; |
1927 | finger_trail->trail_id = iterator->trail_id; | 1973 | finger_trail->trail_id = current_finger_trail->trail_id; |
1928 | } | 1974 | } |
1929 | else if (finger_trail->trail_length > iterator->trail_length) | 1975 | else if (finger_trail->trail_length > current_finger_trail->trail_length) |
1930 | { | 1976 | { |
1931 | finger_trail->friend = *friend; | 1977 | finger_trail->friend = *friend; |
1932 | finger_trail->trail_id = iterator->trail_id; | 1978 | finger_trail->trail_id = current_finger_trail->trail_id; |
1933 | finger_trail->trail_length = iterator->trail_length; | 1979 | finger_trail->trail_length = current_finger_trail->trail_length; |
1934 | } | 1980 | } |
1935 | } | 1981 | } |
1936 | 1982 | ||
@@ -1941,6 +1987,7 @@ select_finger_trail (struct FingerInfo *finger) | |||
1941 | 1987 | ||
1942 | return finger_trail; | 1988 | return finger_trail; |
1943 | } | 1989 | } |
1990 | #endif | ||
1944 | 1991 | ||
1945 | 1992 | ||
1946 | /** | 1993 | /** |
@@ -1956,9 +2003,12 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1956 | { | 2003 | { |
1957 | struct FingerInfo *finger; | 2004 | struct FingerInfo *finger; |
1958 | const struct GNUNET_PeerIdentity *closest_peer; | 2005 | const struct GNUNET_PeerIdentity *closest_peer; |
1959 | struct Selected_Finger_Trail *finger_trail; | 2006 | struct Trail *finger_trail; |
1960 | int i; | 2007 | int i; |
1961 | 2008 | ||
2009 | // TODO: Instead of iterating over all fingers, calculate the finger index | ||
2010 | // using "value" of my id and current closest peer id. | ||
2011 | |||
1962 | /* Iterate over finger table. */ | 2012 | /* Iterate over finger table. */ |
1963 | for (i = 0; i < MAX_FINGERS; i++) | 2013 | for (i = 0; i < MAX_FINGERS; i++) |
1964 | { | 2014 | { |
@@ -1979,8 +2029,8 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
1979 | /* FIXME: I think a peer should not select itself as its own identity ever. | 2029 | /* FIXME: I think a peer should not select itself as its own identity ever. |
1980 | But it does select. Find out why??*/ | 2030 | But it does select. Find out why??*/ |
1981 | //GNUNET_break (0); | 2031 | //GNUNET_break (0); |
1982 | //continue; | 2032 | continue; |
1983 | return; | 2033 | //return; |
1984 | } | 2034 | } |
1985 | 2035 | ||
1986 | /* If finger is a friend, then do nothing. As we have already checked | 2036 | /* If finger is a friend, then do nothing. As we have already checked |
@@ -2005,10 +2055,9 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer) | |||
2005 | if (NULL == finger_trail) | 2055 | if (NULL == finger_trail) |
2006 | continue; | 2056 | continue; |
2007 | 2057 | ||
2008 | current_closest_peer->best_known_destination = finger->finger_identity; | 2058 | current_closest_peer->best_known_destination = *closest_peer; |
2009 | current_closest_peer->next_hop = finger_trail->friend.id; | 2059 | current_closest_peer->next_hop = finger_trail->trail_head->peer; |
2010 | current_closest_peer->trail_id = finger_trail->trail_id; | 2060 | current_closest_peer->trail_id = finger_trail->trail_id; |
2011 | GNUNET_free(finger_trail); | ||
2012 | } | 2061 | } |
2013 | continue; | 2062 | continue; |
2014 | } | 2063 | } |
@@ -2122,6 +2171,7 @@ find_successor (uint64_t destination_finger_value, | |||
2122 | 2171 | ||
2123 | /* Compare each finger entry with current_successor and update current_successor | 2172 | /* Compare each finger entry with current_successor and update current_successor |
2124 | * with finger if its closest. */ | 2173 | * with finger if its closest. */ |
2174 | // TODO: Change function name to "compare_finger_and_current_closest_peer" | ||
2125 | compare_finger_and_current_successor (¤t_closest_peer); | 2175 | compare_finger_and_current_successor (¤t_closest_peer); |
2126 | 2176 | ||
2127 | return current_closest_peer; | 2177 | return current_closest_peer; |
@@ -2517,6 +2567,7 @@ select_random_friend () | |||
2517 | for (j = 0; j < index ; j++) | 2567 | for (j = 0; j < index ; j++) |
2518 | GNUNET_assert (GNUNET_YES == | 2568 | GNUNET_assert (GNUNET_YES == |
2519 | GNUNET_CONTAINER_multipeermap_iterator_next (iter, NULL, NULL)); | 2569 | GNUNET_CONTAINER_multipeermap_iterator_next (iter, NULL, NULL)); |
2570 | |||
2520 | do | 2571 | do |
2521 | { | 2572 | { |
2522 | /* Reset the index in friend peermap to 0 as we reached to the end. */ | 2573 | /* Reset the index in friend peermap to 0 as we reached to the end. */ |
@@ -2535,7 +2586,7 @@ select_random_friend () | |||
2535 | (const void **)&friend)); | 2586 | (const void **)&friend)); |
2536 | 2587 | ||
2537 | /* This friend is not congested and has not crossed trail threshold. */ | 2588 | /* This friend is not congested and has not crossed trail threshold. */ |
2538 | if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && | 2589 | if ((friend->trails_count < TRAILS_THROUGH_FRIEND_THRESHOLD) && |
2539 | (0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_timestamp).rel_value_us)) | 2590 | (0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_timestamp).rel_value_us)) |
2540 | { | 2591 | { |
2541 | break; | 2592 | break; |
@@ -2564,6 +2615,7 @@ compute_finger_identity_value (unsigned int finger_index) | |||
2564 | uint64_t my_id64; | 2615 | uint64_t my_id64; |
2565 | 2616 | ||
2566 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 2617 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
2618 | // TODO: Check how and if to use ntohll | ||
2567 | my_id64 = GNUNET_ntohll (my_id64); | 2619 | my_id64 = GNUNET_ntohll (my_id64); |
2568 | 2620 | ||
2569 | /* Are we looking for immediate predecessor? */ | 2621 | /* Are we looking for immediate predecessor? */ |
@@ -2576,8 +2628,10 @@ compute_finger_identity_value (unsigned int finger_index) | |||
2576 | } | 2628 | } |
2577 | } | 2629 | } |
2578 | 2630 | ||
2631 | //TODO move at top, write comment. | ||
2579 | static struct GNUNET_TIME_Relative next_send_time; | 2632 | static struct GNUNET_TIME_Relative next_send_time; |
2580 | 2633 | ||
2634 | |||
2581 | /* | 2635 | /* |
2582 | * Choose a random friend. Calculate the next finger identity to search,from | 2636 | * Choose a random friend. Calculate the next finger identity to search,from |
2583 | * current_search_finger_index. Start looking for the trail to reach to | 2637 | * current_search_finger_index. Start looking for the trail to reach to |
@@ -2591,7 +2645,6 @@ send_find_finger_trail_message (void *cls, | |||
2591 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2645 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2592 | { | 2646 | { |
2593 | struct FriendInfo *target_friend; | 2647 | struct FriendInfo *target_friend; |
2594 | //struct GNUNET_TIME_Relative next_send_time; | ||
2595 | struct GNUNET_HashCode trail_id; | 2648 | struct GNUNET_HashCode trail_id; |
2596 | struct GNUNET_HashCode intermediate_trail_id; | 2649 | struct GNUNET_HashCode intermediate_trail_id; |
2597 | unsigned int is_predecessor; | 2650 | unsigned int is_predecessor; |
@@ -2981,11 +3034,13 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
2981 | struct Trail *trail; | 3034 | struct Trail *trail; |
2982 | int i = 0; | 3035 | int i = 0; |
2983 | 3036 | ||
3037 | if(0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | ||
3038 | GNUNET_assert (NULL != GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST)); | ||
2984 | new_entry = GNUNET_new (struct FingerInfo); | 3039 | new_entry = GNUNET_new (struct FingerInfo); |
2985 | new_entry->finger_identity = finger_identity; | 3040 | new_entry->finger_identity = finger_identity; |
2986 | new_entry->finger_table_index = finger_table_index; | 3041 | new_entry->finger_table_index = finger_table_index; |
2987 | new_entry->is_present = GNUNET_YES; | 3042 | new_entry->is_present = GNUNET_YES; |
2988 | 3043 | ||
2989 | /* If the new entry is my own identity. */ | 3044 | /* If the new entry is my own identity. */ |
2990 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | 3045 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
2991 | &finger_identity)) | 3046 | &finger_identity)) |
@@ -3132,14 +3187,14 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3132 | 3187 | ||
3133 | /* Copy the trail from index i to index (trail_length -1) into a new trail | 3188 | /* Copy the trail from index i to index (trail_length -1) into a new trail |
3134 | * and update new trail length */ | 3189 | * and update new trail length */ |
3135 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length - i)); | 3190 | *new_trail_length = trail_length - i; |
3191 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (*new_trail_length)); | ||
3136 | while (i < trail_length) | 3192 | while (i < trail_length) |
3137 | { | 3193 | { |
3138 | memcpy (&new_trail[j], &trail[i], sizeof(struct GNUNET_PeerIdentity)); | 3194 | memcpy (&new_trail[j], &trail[i], sizeof(struct GNUNET_PeerIdentity)); |
3139 | j++; | 3195 | j++; |
3140 | i++; | 3196 | i++; |
3141 | } | 3197 | } |
3142 | *new_trail_length = j+1; | ||
3143 | return new_trail; | 3198 | return new_trail; |
3144 | } | 3199 | } |
3145 | } | 3200 | } |
@@ -3200,6 +3255,8 @@ send_verify_successor_message (void *cls, | |||
3200 | GNUNET_assert (GNUNET_YES == trail->is_present); | 3255 | GNUNET_assert (GNUNET_YES == trail->is_present); |
3201 | 3256 | ||
3202 | trail_id = trail->trail_id; | 3257 | trail_id = trail->trail_id; |
3258 | |||
3259 | GNUNET_assert (NULL != GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST)); | ||
3203 | trail_length = trail->trail_length; | 3260 | trail_length = trail->trail_length; |
3204 | 3261 | ||
3205 | if (trail_length > 0) | 3262 | if (trail_length > 0) |
@@ -3359,6 +3416,11 @@ remove_existing_finger (struct FingerInfo *existing_finger, | |||
3359 | struct FingerInfo *finger; | 3416 | struct FingerInfo *finger; |
3360 | 3417 | ||
3361 | finger = &finger_table[finger_table_index]; | 3418 | finger = &finger_table[finger_table_index]; |
3419 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | ||
3420 | &existing_finger->finger_identity)); | ||
3421 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | ||
3422 | &my_identity)); | ||
3423 | return; | ||
3362 | GNUNET_assert (GNUNET_YES == finger->is_present); | 3424 | GNUNET_assert (GNUNET_YES == finger->is_present); |
3363 | 3425 | ||
3364 | /* If I am my own finger, then we have no trails. */ | 3426 | /* If I am my own finger, then we have no trails. */ |
@@ -4048,14 +4110,15 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4048 | } | 4110 | } |
4049 | 4111 | ||
4050 | trail_setup = (const struct PeerTrailSetupMessage *) message; | 4112 | trail_setup = (const struct PeerTrailSetupMessage *) message; |
4051 | trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ | ||
4052 | sizeof (struct GNUNET_PeerIdentity); | ||
4053 | if ((msize - sizeof (struct PeerTrailSetupMessage)) % | 4113 | if ((msize - sizeof (struct PeerTrailSetupMessage)) % |
4054 | sizeof (struct GNUNET_PeerIdentity) != 0) | 4114 | sizeof (struct GNUNET_PeerIdentity) != 0) |
4055 | { | 4115 | { |
4056 | GNUNET_break_op (0); | 4116 | GNUNET_break_op (0); |
4057 | return GNUNET_OK; | 4117 | return GNUNET_OK; |
4058 | } | 4118 | } |
4119 | trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ | ||
4120 | sizeof (struct GNUNET_PeerIdentity); | ||
4121 | |||
4059 | 4122 | ||
4060 | GNUNET_STATISTICS_update (GDS_stats, | 4123 | GNUNET_STATISTICS_update (GDS_stats, |
4061 | gettext_noop | 4124 | gettext_noop |
@@ -4073,7 +4136,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4073 | 4136 | ||
4074 | /* Did the friend insert its ID in the trail list? */ | 4137 | /* Did the friend insert its ID in the trail list? */ |
4075 | if (trail_length > 0 && | 4138 | if (trail_length > 0 && |
4076 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer))) | 4139 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (struct GNUNET_PeerIdentity))) |
4077 | { | 4140 | { |
4078 | GNUNET_break_op (0); | 4141 | GNUNET_break_op (0); |
4079 | return GNUNET_SYSERR; | 4142 | return GNUNET_SYSERR; |
@@ -4122,19 +4185,14 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4122 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&next_peer.best_known_destination, | 4185 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&next_peer.best_known_destination, |
4123 | &my_identity))) | 4186 | &my_identity))) |
4124 | { | 4187 | { |
4125 | /* If I was not the source of this message for which now I am destination */ | ||
4126 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | ||
4127 | { | ||
4128 | GDS_ROUTING_add (trail_id, *peer, my_identity); | ||
4129 | } | ||
4130 | |||
4131 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | 4188 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) |
4132 | { | 4189 | { |
4133 | finger_table_add (my_identity, NULL, 0, is_predecessor, | 4190 | finger_table_add (my_identity, NULL, 0, is_predecessor, |
4134 | final_dest_finger_val, trail_id); | 4191 | final_dest_finger_val, trail_id); |
4135 | return GNUNET_OK; | 4192 | return GNUNET_OK; |
4136 | } | 4193 | } |
4137 | 4194 | ||
4195 | GDS_ROUTING_add (trail_id, *peer, my_identity); | ||
4138 | if (trail_length > 0) | 4196 | if (trail_length > 0) |
4139 | target_friend = | 4197 | target_friend = |
4140 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4198 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -5775,6 +5833,8 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5775 | } | 5833 | } |
5776 | 5834 | ||
5777 | 5835 | ||
5836 | //FIXME: Free the messages of peer from pending qeue. Refere to | ||
5837 | //neighbours file. | ||
5778 | /** | 5838 | /** |
5779 | * Method called whenever a peer disconnects. | 5839 | * Method called whenever a peer disconnects. |
5780 | * | 5840 | * |
@@ -5786,7 +5846,9 @@ handle_core_disconnect (void *cls, | |||
5786 | const struct GNUNET_PeerIdentity *peer) | 5846 | const struct GNUNET_PeerIdentity *peer) |
5787 | { | 5847 | { |
5788 | struct FriendInfo *remove_friend; | 5848 | struct FriendInfo *remove_friend; |
5789 | 5849 | struct P2PPendingMessage *pos; | |
5850 | unsigned int discarded; | ||
5851 | |||
5790 | /* If disconnected to own identity, then return. */ | 5852 | /* If disconnected to own identity, then return. */ |
5791 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 5853 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
5792 | return; | 5854 | return; |
@@ -5821,6 +5883,26 @@ handle_core_disconnect (void *cls, | |||
5821 | else | 5883 | else |
5822 | GNUNET_break (0); | 5884 | GNUNET_break (0); |
5823 | 5885 | ||
5886 | /* Remove all the messages queued in pending list of this peer is discarded.*/ | ||
5887 | if (remove_friend->th != NULL) | ||
5888 | { | ||
5889 | GNUNET_CORE_notify_transmit_ready_cancel(remove_friend->th); | ||
5890 | remove_friend->th = NULL; | ||
5891 | } | ||
5892 | |||
5893 | discarded = 0; | ||
5894 | while (NULL != (pos = remove_friend->head)) | ||
5895 | { | ||
5896 | GNUNET_CONTAINER_DLL_remove (remove_friend->head, remove_friend->tail, pos); | ||
5897 | discarded++; | ||
5898 | GNUNET_free (pos); | ||
5899 | } | ||
5900 | |||
5901 | GNUNET_STATISTICS_update (GDS_stats, | ||
5902 | gettext_noop | ||
5903 | ("# Queued messages discarded (peer disconnected)"), | ||
5904 | discarded, GNUNET_NO); | ||
5905 | GNUNET_free (remove_friend); | ||
5824 | } | 5906 | } |
5825 | 5907 | ||
5826 | 5908 | ||
@@ -5937,6 +6019,7 @@ GDS_NEIGHBOURS_init (void) | |||
5937 | if (NULL == core_api) | 6019 | if (NULL == core_api) |
5938 | return GNUNET_SYSERR; | 6020 | return GNUNET_SYSERR; |
5939 | 6021 | ||
6022 | //TODO: check size of this peer map? | ||
5940 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 6023 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
5941 | finger_table_init (); | 6024 | finger_table_init (); |
5942 | 6025 | ||