aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-xdht_neighbours.c
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-07-06 20:50:45 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-07-06 20:50:45 +0000
commit206232b063d2c1792320bc430bf06c2b6786821a (patch)
treee73118095186e7cb79e8144d1a3420fa43048d18 /src/dht/gnunet-service-xdht_neighbours.c
parenteff58a1bc9e2bd1555290baa8ab5a39ba4aa1b61 (diff)
downloadgnunet-206232b063d2c1792320bc430bf06c2b6786821a.tar.gz
gnunet-206232b063d2c1792320bc430bf06c2b6786821a.zip
xvine: Fixes
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c478
1 files changed, 277 insertions, 201 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 261262fc5..9a5ea3c0e 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -886,7 +886,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
886 struct P2PPendingMessage *pending; 886 struct P2PPendingMessage *pending;
887 size_t off; 887 size_t off;
888 size_t msize; 888 size_t msize;
889 889
890 peer->th = NULL; 890 peer->th = NULL;
891 while ((NULL != (pending = peer->head)) && 891 while ((NULL != (pending = peer->head)) &&
892 (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us)) 892 (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us))
@@ -916,10 +916,10 @@ core_transmit_notify (void *cls, size_t size, void *buf)
916 while ((NULL != (pending = peer->head)) && 916 while ((NULL != (pending = peer->head)) &&
917 (size - off >= (msize = ntohs (pending->msg->size)))) 917 (size - off >= (msize = ntohs (pending->msg->size))))
918 { 918 {
919 GNUNET_STATISTICS_update (GDS_stats, 919 /*GNUNET_STATISTICS_update (GDS_stats,
920 gettext_noop 920 gettext_noop
921 ("# Bytes transmitted to other peers"), msize, 921 ("# Bytes transmitted to other peers"), msize,
922 GNUNET_NO); 922 GNUNET_NO);*/
923 memcpy (&cbuf[off], pending->msg, msize); 923 memcpy (&cbuf[off], pending->msg, msize);
924 off += msize; 924 off += msize;
925 peer->pending_count--; 925 peer->pending_count--;
@@ -954,12 +954,12 @@ process_friend_queue (struct FriendInfo *peer)
954 return; 954 return;
955 if (NULL != peer->th) 955 if (NULL != peer->th)
956 return; 956 return;
957 957
958 GNUNET_STATISTICS_update (GDS_stats, 958 GNUNET_STATISTICS_update (GDS_stats,
959 gettext_noop 959 gettext_noop
960 ("# Bytes of bandwidth requested from core"), 960 ("# Bytes of bandwidth requested from core"),
961 ntohs (pending->msg->size), GNUNET_NO); 961 ntohs (pending->msg->size), GNUNET_NO);
962 962
963 peer->th = 963 peer->th =
964 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, 964 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO,
965 pending->importance, 965 pending->importance,
@@ -1033,7 +1033,7 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer,
1033 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1033 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
1034 1, GNUNET_NO); 1034 1, GNUNET_NO);
1035 } 1035 }
1036 1036
1037 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1037 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1038 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1038 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
1039 tsm = (struct PeerTrailSetupMessage *) &pending[1]; 1039 tsm = (struct PeerTrailSetupMessage *) &pending[1];
@@ -1056,7 +1056,7 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer,
1056 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; 1056 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1];
1057 memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); 1057 memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity));
1058 } 1058 }
1059 1059
1060 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1060 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1061 target_friend->pending_count++; 1061 target_friend->pending_count++;
1062 process_friend_queue (target_friend); 1062 process_friend_queue (target_friend);
@@ -1178,7 +1178,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer,
1178 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1178 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
1179 1, GNUNET_NO); 1179 1, GNUNET_NO);
1180 } 1180 }
1181 1181
1182 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1182 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1183 pending->importance = 0; 1183 pending->importance = 0;
1184 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1184 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
@@ -1231,7 +1231,8 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1231 struct GNUNET_PeerIdentity *peer_list; 1231 struct GNUNET_PeerIdentity *peer_list;
1232 size_t msize; 1232 size_t msize;
1233 1233
1234 msize = sizeof (struct PeerVerifySuccessorMessage); 1234 msize = sizeof (struct PeerVerifySuccessorMessage) +
1235 (trail_length * sizeof (struct GNUNET_PeerIdentity));;
1235 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1236 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1236 { 1237 {
1237 GNUNET_break (0); 1238 GNUNET_break (0);
@@ -1243,7 +1244,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1243 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1244 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
1244 1, GNUNET_NO); 1245 1, GNUNET_NO);
1245 } 1246 }
1246 1247
1247 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1248 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1248 pending->importance = 0; /* FIXME */ 1249 pending->importance = 0; /* FIXME */
1249 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1250 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
@@ -1255,7 +1256,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1255 vsm->successor = successor; 1256 vsm->successor = successor;
1256 vsm->trail_id = trail_id; 1257 vsm->trail_id = trail_id;
1257 1258
1258 if (trail_length > 0) 1259 if (trail_length != 0)
1259 { 1260 {
1260 peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; 1261 peer_list = (struct GNUNET_PeerIdentity *) &vsm[1];
1261 memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1262 memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity));
@@ -1296,8 +1297,10 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
1296 return; 1297 return;
1297 } 1298 }
1298 1299
1299 GNUNET_assert (NULL != (target_friend = 1300 /*FIXME:In what case friend can be null. ?*/
1301 if (NULL == (target_friend =
1300 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &peer))); 1302 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &peer)));
1303 return;
1301 1304
1302 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) 1305 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
1303 { 1306 {
@@ -1552,7 +1555,7 @@ GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer,
1552 gettext_noop ("# P2P messages dropped due to full queue"), 1555 gettext_noop ("# P2P messages dropped due to full queue"),
1553 1, GNUNET_NO); 1556 1, GNUNET_NO);
1554 } 1557 }
1555 1558
1556 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1559 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1557 pending->importance = 0; /* FIXME */ 1560 pending->importance = 0; /* FIXME */
1558 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1561 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
@@ -1572,7 +1575,8 @@ GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer,
1572 1575
1573 1576
1574/** 1577/**
1575 * Search my location in trail. 1578 * Search my location in trail. In case I am present more than once in the
1579 * trail (can happen during trail setup), then return my lowest index.
1576 * @param trail List of peers 1580 * @param trail List of peers
1577 * @return my_index if found 1581 * @return my_index if found
1578 * -1 if no entry found. 1582 * -1 if no entry found.
@@ -1582,14 +1586,15 @@ search_my_index (const struct GNUNET_PeerIdentity *trail,
1582 int trail_length) 1586 int trail_length)
1583{ 1587{
1584 int i; 1588 int i;
1585 1589 int lowest_index = -1;
1590
1586 for (i = 0; i < trail_length; i++) 1591 for (i = 0; i < trail_length; i++)
1587 { 1592 {
1588 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) 1593 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i]))
1589 return i; 1594 lowest_index = i;
1590 } 1595 }
1591 1596
1592 return -1; 1597 return lowest_index;
1593} 1598}
1594 1599
1595 1600
@@ -1719,6 +1724,76 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
1719 return NULL; 1724 return NULL;
1720} 1725}
1721 1726
1727#if 0
1728/**
1729 * This is a test function to print all the entries of friend table.
1730 */
1731static void
1732test_friend_peermap_print ()
1733{
1734 struct FriendInfo *friend;
1735 struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter;
1736 struct GNUNET_PeerIdentity print_peer;
1737 struct GNUNET_PeerIdentity key_ret;
1738 int i;
1739
1740 friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
1741
1742 for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++)
1743 {
1744 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (friend_iter,
1745 &key_ret,
1746 (const void **)&friend))
1747 {
1748 memcpy (&print_peer, &key_ret, sizeof (struct GNUNET_PeerIdentity));
1749 FPRINTF (stderr,_("\nSUPU %s, %s, %d, friend = %s, friend->trails_count = %d"),
1750 __FILE__, __func__,__LINE__, GNUNET_i2s(&print_peer), friend->trails_count);
1751 }
1752 }
1753}
1754
1755/**
1756 * This is a test function, to print all the entries of finger table.
1757 */
1758static void
1759test_finger_table_print()
1760{
1761 struct FingerInfo *finger;
1762 struct GNUNET_PeerIdentity print_peer;
1763 struct Trail *trail;
1764 int i;
1765 int j;
1766 int k;
1767
1768 FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE"));
1769 for (i = 0; i < MAX_FINGERS; i++)
1770 {
1771 finger = &finger_table[i];
1772
1773 if (GNUNET_NO == finger->is_present)
1774 continue;
1775
1776 print_peer = finger->finger_identity;
1777 FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"),
1778 __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count);
1779
1780
1781 for (j = 0; j < finger->trails_count; j++)
1782 {
1783 trail = &finger->trail_list[j];
1784 FPRINTF (stderr,_("\nSUPU %s, %s, %d, trail_id[%d]=%s"),__FILE__, __func__,__LINE__,j, GNUNET_h2s(&trail->trail_id));
1785 struct Trail_Element *element;
1786 element = trail->trail_head;
1787 for (k = 0; k < trail->trail_length; k++)
1788 {
1789 print_peer = element->peer;
1790 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer));
1791 element = element->next;
1792 }
1793 }
1794 }
1795}
1796#endif
1722 1797
1723/** 1798/**
1724 * Select the closest peer among two peers (which should not be same) 1799 * Select the closest peer among two peers (which should not be same)
@@ -1739,10 +1814,13 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1739 struct GNUNET_PeerIdentity *closest_peer; 1814 struct GNUNET_PeerIdentity *closest_peer;
1740 1815
1741 if (1 == is_predecessor) 1816 if (1 == is_predecessor)
1817 {
1742 closest_peer = select_closest_predecessor (peer1, peer2, value); 1818 closest_peer = select_closest_predecessor (peer1, peer2, value);
1819 }
1743 else 1820 else
1821 {
1744 closest_peer = select_closest_finger (peer1, peer2, value); 1822 closest_peer = select_closest_finger (peer1, peer2, value);
1745 1823 }
1746 return closest_peer; 1824 return closest_peer;
1747} 1825}
1748 1826
@@ -1767,7 +1845,7 @@ select_finger_trail (struct FingerInfo *finger)
1767 unsigned int i; 1845 unsigned int i;
1768 unsigned int flag = 0; 1846 unsigned int flag = 0;
1769 unsigned int j = 0; 1847 unsigned int j = 0;
1770 1848
1771 finger_trail = GNUNET_new (struct Selected_Finger_Trail); 1849 finger_trail = GNUNET_new (struct Selected_Finger_Trail);
1772 1850
1773 /* It can never happen that we have a finger (which is not a friend or my identity), 1851 /* It can never happen that we have a finger (which is not a friend or my identity),
@@ -1824,49 +1902,9 @@ select_finger_trail (struct FingerInfo *finger)
1824 return finger_trail; 1902 return finger_trail;
1825} 1903}
1826 1904
1827#if 0 1905
1828/** 1906
1829 * This is a test function, to print all the entries of finger table. 1907
1830 */
1831static void
1832test_finger_table_print()
1833{
1834 struct FingerInfo *finger;
1835 struct GNUNET_PeerIdentity print_peer;
1836 struct Trail *trail;
1837 int i;
1838 int j;
1839 int k;
1840
1841 FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE"));
1842 for (i = 0; i < MAX_FINGERS; i++)
1843 {
1844 finger = &finger_table[i];
1845
1846 if (GNUNET_NO == finger->is_present)
1847 continue;
1848
1849 print_peer = finger->finger_identity;
1850 FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"),
1851 __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count);
1852
1853
1854 for (j = 0; j < finger->trails_count; j++)
1855 {
1856 trail = &finger->trail_list[j];
1857 FPRINTF (stderr,_("\nSUPU %s, %s, %d, trail_id[%d]=%s"),__FILE__, __func__,__LINE__,j, GNUNET_h2s(&trail->trail_id));
1858 struct Trail_Element *element;
1859 element = trail->trail_head;
1860 for (k = 0; k < trail->trail_length; k++)
1861 {
1862 print_peer = element->peer;
1863 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer));
1864 element = element->next;
1865 }
1866 }
1867 }
1868}
1869#endif
1870 1908
1871/** 1909/**
1872 * Compare FINGER entry with current successor. If finger's first friend of all 1910 * Compare FINGER entry with current successor. If finger's first friend of all
@@ -1995,7 +2033,7 @@ init_current_successor (struct GNUNET_PeerIdentity my_identity,
1995 unsigned int is_predecessor) 2033 unsigned int is_predecessor)
1996{ 2034{
1997 struct Closest_Peer *current_closest_peer; 2035 struct Closest_Peer *current_closest_peer;
1998 2036
1999 current_closest_peer = GNUNET_new (struct Closest_Peer); 2037 current_closest_peer = GNUNET_new (struct Closest_Peer);
2000 //memset (&current_closest_peer->trail_id, 0, sizeof (current_closest_peer->trail_id)); 2038 //memset (&current_closest_peer->trail_id, 0, sizeof (current_closest_peer->trail_id));
2001 current_closest_peer->trail_id = NULL; 2039 current_closest_peer->trail_id = NULL;
@@ -2056,13 +2094,20 @@ find_successor (uint64_t destination_finger_value,
2056 compare_finger_and_current_successor (current_closest_peer); 2094 compare_finger_and_current_successor (current_closest_peer);
2057 *local_best_known_destination = current_closest_peer->best_known_destination; 2095 *local_best_known_destination = current_closest_peer->best_known_destination;
2058 if (current_closest_peer->trail_id != NULL) 2096 if (current_closest_peer->trail_id != NULL)
2059 *new_intermediate_trail_id = *current_closest_peer->trail_id; 2097 {
2098 /* FIXME I was assigning values but if address is NULL, then how do we assing. */
2099 memcpy (new_intermediate_trail_id,current_closest_peer->trail_id,sizeof (struct GNUNET_HashCode));
2100 }
2101
2060 next_hop = GNUNET_new (struct GNUNET_PeerIdentity); 2102 next_hop = GNUNET_new (struct GNUNET_PeerIdentity);
2061 *next_hop = current_closest_peer->next_hop; 2103 *next_hop = current_closest_peer->next_hop;
2062 return next_hop; 2104 return next_hop;
2063} 2105}
2064 2106
2065 2107
2108
2109
2110
2066/** 2111/**
2067 * Construct a Put message and send it to target_peer. 2112 * Construct a Put message and send it to target_peer.
2068 * @param key Key for the content 2113 * @param key Key for the content
@@ -2144,6 +2189,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2144 (target_friend = 2189 (target_friend =
2145 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); 2190 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2146 } 2191 }
2192
2147 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2193 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2148 pending->timeout = expiration_time; 2194 pending->timeout = expiration_time;
2149 ppm = (struct PeerPutMessage *) &pending[1]; 2195 ppm = (struct PeerPutMessage *) &pending[1];
@@ -2225,6 +2271,9 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2225 GNUNET_break (0); 2271 GNUNET_break (0);
2226 return; 2272 return;
2227 } 2273 }
2274 //test_friend_peermap_print();
2275 //test_finger_table_print();
2276
2228 /* This is the first time we got request from our own client file. */ 2277 /* This is the first time we got request from our own client file. */
2229 if (NULL == target_peer) 2278 if (NULL == target_peer)
2230 { 2279 {
@@ -2262,7 +2311,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2262 (target_friend = 2311 (target_friend =
2263 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); 2312 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2264 } 2313 }
2265 2314
2266 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2315 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2267 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 2316 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
2268 pending->importance = 0; /* FIXME */ 2317 pending->importance = 0; /* FIXME */
@@ -2352,7 +2401,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
2352 put_path, type, data_size, data); 2401 put_path, type, data_size, data);
2353 return; 2402 return;
2354 } 2403 }
2355 2404
2356 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2405 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2357 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 2406 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
2358 pending->importance = 0; 2407 pending->importance = 0;
@@ -2701,6 +2750,8 @@ add_new_trail (struct FingerInfo *existing_finger,
2701 existing_finger->trails_count++; 2750 existing_finger->trails_count++;
2702 trail_list_iterator->is_present = GNUNET_YES; 2751 trail_list_iterator->is_present = GNUNET_YES;
2703 2752
2753 GNUNET_assert (NULL == (GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2754 &existing_finger->finger_identity)));
2704 /* If finger is a friend then we never call this function. */ 2755 /* If finger is a friend then we never call this function. */
2705 GNUNET_assert (new_trail_length > 0); 2756 GNUNET_assert (new_trail_length > 0);
2706 2757
@@ -2711,8 +2762,8 @@ add_new_trail (struct FingerInfo *existing_finger,
2711 for (i = 0; i < new_trail_length; i++) 2762 for (i = 0; i < new_trail_length; i++)
2712 { 2763 {
2713 struct Trail_Element *element; 2764 struct Trail_Element *element;
2765
2714 element = GNUNET_new (struct Trail_Element); 2766 element = GNUNET_new (struct Trail_Element);
2715
2716 element->peer = new_trail[i]; 2767 element->peer = new_trail[i];
2717 GNUNET_CONTAINER_DLL_insert_tail (trail_list_iterator->trail_head, 2768 GNUNET_CONTAINER_DLL_insert_tail (trail_list_iterator->trail_head,
2718 trail_list_iterator->trail_tail, 2769 trail_list_iterator->trail_tail,
@@ -2740,22 +2791,30 @@ send_trail_teardown (struct FingerInfo *finger,
2740 struct FriendInfo *friend; 2791 struct FriendInfo *friend;
2741 struct GNUNET_PeerIdentity *next_hop; 2792 struct GNUNET_PeerIdentity *next_hop;
2742 2793
2794
2743 GNUNET_assert (NULL != 2795 GNUNET_assert (NULL !=
2744 (next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, 2796 (next_hop = GDS_ROUTING_get_next_hop (trail->trail_id,
2745 GDS_ROUTING_SRC_TO_DEST))); 2797 GDS_ROUTING_SRC_TO_DEST)));
2746 2798
2747 GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 2799 GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
2748 &my_identity)); 2800 &my_identity));
2801 //GDS_ROUTING_test_print();
2802 GNUNET_assert (trail->is_present == GNUNET_YES);
2803
2804 /* Finger is not a friend. */
2749 if (trail->trail_length > 0) 2805 if (trail->trail_length > 0)
2806 {
2750 GNUNET_assert (NULL != (friend = 2807 GNUNET_assert (NULL != (friend =
2751 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2808 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2752 &trail->trail_head->peer))); 2809 &trail->trail_head->peer)));
2810 }
2753 else 2811 else
2754 { 2812 {
2755 GNUNET_assert (NULL != (friend = 2813 GNUNET_assert (NULL != (friend =
2756 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2814 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2757 &finger->finger_identity))); 2815 &finger->finger_identity)));
2758 } 2816 }
2817
2759 GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id)); 2818 GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id));
2760 GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); 2819 GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id));
2761 friend->trails_count--; 2820 friend->trails_count--;
@@ -2773,7 +2832,7 @@ static void
2773send_all_finger_trails_teardown (struct FingerInfo *finger) 2832send_all_finger_trails_teardown (struct FingerInfo *finger)
2774{ 2833{
2775 unsigned int i; 2834 unsigned int i;
2776 2835
2777 for (i = 0; i < finger->trails_count; i++) 2836 for (i = 0; i < finger->trails_count; i++)
2778 { 2837 {
2779 struct Trail *trail; 2838 struct Trail *trail;
@@ -2800,6 +2859,7 @@ free_trail (struct Trail *trail)
2800 GNUNET_CONTAINER_DLL_remove (trail->trail_head, 2859 GNUNET_CONTAINER_DLL_remove (trail->trail_head,
2801 trail->trail_tail, 2860 trail->trail_tail,
2802 trail_element); 2861 trail_element);
2862
2803 GNUNET_free_non_null (trail_element); 2863 GNUNET_free_non_null (trail_element);
2804 } 2864 }
2805 trail->trail_head = NULL; 2865 trail->trail_head = NULL;
@@ -2864,7 +2924,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2864 struct FriendInfo *first_trail_hop; 2924 struct FriendInfo *first_trail_hop;
2865 struct Trail *trail; 2925 struct Trail *trail;
2866 int i = 0; 2926 int i = 0;
2867 2927
2868 new_entry = GNUNET_new (struct FingerInfo); 2928 new_entry = GNUNET_new (struct FingerInfo);
2869 new_entry->finger_identity = finger_identity; 2929 new_entry->finger_identity = finger_identity;
2870 new_entry->finger_table_index = finger_table_index; 2930 new_entry->finger_table_index = finger_table_index;
@@ -2875,6 +2935,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2875 { 2935 {
2876 new_entry->trails_count = 0; 2936 new_entry->trails_count = 0;
2877 finger_table[finger_table_index] = *new_entry; 2937 finger_table[finger_table_index] = *new_entry;
2938 GNUNET_free (new_entry);
2878 return; 2939 return;
2879 } 2940 }
2880 2941
@@ -2894,7 +2955,9 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2894 (first_trail_hop = 2955 (first_trail_hop =
2895 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2956 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2896 &finger_identity))); 2957 &finger_identity)));
2958
2897 first_trail_hop->trails_count++; 2959 first_trail_hop->trails_count++;
2960 GNUNET_free (new_entry);
2898 return; 2961 return;
2899 } 2962 }
2900 2963
@@ -2931,8 +2994,8 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2931 new_entry->trail_list[0].trail_id = trail_id; 2994 new_entry->trail_list[0].trail_id = trail_id;
2932 new_entry->trail_list[0].is_present = GNUNET_YES; 2995 new_entry->trail_list[0].is_present = GNUNET_YES;
2933 finger_table[finger_table_index] = *new_entry; 2996 finger_table[finger_table_index] = *new_entry;
2934 GNUNET_free (new_entry); 2997 //GNUNET_free (new_entry);
2935 GNUNET_free (trail); 2998 //GNUNET_free (trail);
2936 return; 2999 return;
2937} 3000}
2938 3001
@@ -2969,6 +3032,11 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2969 return NULL; 3032 return NULL;
2970 } 3033 }
2971 3034
3035 if (0 == trail_length)
3036 {
3037 *new_trail_length = 0;
3038 return NULL;
3039 }
2972 /* If finger identity is a friend. */ 3040 /* If finger identity is a friend. */
2973 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) 3041 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity))
2974 { 3042 {
@@ -2977,6 +3045,8 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2977 /* If there is trail to reach this finger/friend */ 3045 /* If there is trail to reach this finger/friend */
2978 if (trail_length > 0) 3046 if (trail_length > 0)
2979 { 3047 {
3048 /* Finger is your first friend. */
3049 GDS_ROUTING_update_trail_next_hop (trail_id, finger_identity);
2980 GNUNET_assert (NULL != 3050 GNUNET_assert (NULL !=
2981 (target_friend = 3051 (target_friend =
2982 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3052 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
@@ -3016,7 +3086,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
3016 3086
3017 /* Copy the trail from index i to index (trail_length -1) into a new trail 3087 /* Copy the trail from index i to index (trail_length -1) into a new trail
3018 * and update new trail length */ 3088 * and update new trail length */
3019 new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * i); 3089 new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length - i));
3020 while (i < trail_length) 3090 while (i < trail_length)
3021 { 3091 {
3022 memcpy (&new_trail[j], &trail[i], sizeof(struct GNUNET_PeerIdentity)); 3092 memcpy (&new_trail[j], &trail[i], sizeof(struct GNUNET_PeerIdentity));
@@ -3071,46 +3141,52 @@ send_verify_successor_message (struct FingerInfo *successor)
3071 struct FriendInfo *target_friend; 3141 struct FriendInfo *target_friend;
3072 struct GNUNET_HashCode trail_id; 3142 struct GNUNET_HashCode trail_id;
3073 int i; 3143 int i;
3074 3144 struct Trail *trail;
3075 for (i = 0; i < successor->trails_count; i++) 3145 struct Trail_Element *element;
3076 { 3146 unsigned int trail_length;
3077 struct Trail *trail; 3147 unsigned int j = 0;
3078 struct Trail_Element *element; 3148
3079 unsigned int trail_length; 3149 i = 0;
3080 unsigned int j = 0; 3150 trail = &successor->trail_list[i];
3081
3082 trail = &successor->trail_list[i];
3083 3151
3084 /* No trail stored at this index. */ 3152 /* Trail stored at this index. */
3085 if (GNUNET_YES == trail->is_present) 3153 GNUNET_assert (GNUNET_YES == trail->is_present);
3086 continue;
3087 3154
3088 trail_id = trail->trail_id; 3155 trail_id = trail->trail_id;
3089 trail_length = trail->trail_length; 3156 trail_length = trail->trail_length;
3157
3158 if (trail_length > 0)
3159 {
3160 /* Copy the trail into peer list. */
3161 struct GNUNET_PeerIdentity peer_list[trail_length];
3090 3162
3091 /* Copy the trail into peer list. */
3092 element = trail->trail_head; 3163 element = trail->trail_head;
3093 struct GNUNET_PeerIdentity peer_list[trail_length];
3094 while (j < trail_length) 3164 while (j < trail_length)
3095 { 3165 {
3096 peer_list[j] = element->peer; 3166 peer_list[j] = element->peer;
3097 element = element->next; 3167 element = element->next;
3098 j++; 3168 j++;
3099 } 3169 }
3100 3170
3101 if (trail_length > 0) 3171 GNUNET_assert (NULL != (target_friend =
3102 GNUNET_assert (NULL != (target_friend = 3172 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3103 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3173 &peer_list[0])));
3104 &peer_list[0])));
3105 else
3106 GNUNET_assert (NULL != (target_friend =
3107 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3108 &successor->finger_identity)));
3109 GDS_NEIGHBOURS_send_verify_successor_message (my_identity, 3174 GDS_NEIGHBOURS_send_verify_successor_message (my_identity,
3110 successor->finger_identity, 3175 successor->finger_identity,
3111 trail_id, peer_list, trail_length, 3176 trail_id, peer_list, trail_length,
3112 target_friend); 3177 target_friend);
3113 3178 return;
3179 }
3180 else
3181 {
3182 GNUNET_assert (NULL != (target_friend =
3183 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3184 &successor->finger_identity)));
3185 GDS_NEIGHBOURS_send_verify_successor_message (my_identity,
3186 successor->finger_identity,
3187 trail_id, NULL, 0,
3188 target_friend);
3189 return;
3114 } 3190 }
3115} 3191}
3116 3192
@@ -3128,8 +3204,7 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity,
3128 return; 3204 return;
3129 3205
3130 successor = &finger_table[0]; 3206 successor = &finger_table[0];
3131 if (GNUNET_NO == successor->is_present) 3207 GNUNET_assert (GNUNET_YES == successor->is_present);
3132 GNUNET_break(0);
3133 3208
3134 /* We were looking for immediate successor. */ 3209 /* We were looking for immediate successor. */
3135 if (0 == current_search_finger_index) 3210 if (0 == current_search_finger_index)
@@ -3196,7 +3271,8 @@ get_finger_table_index (uint64_t ultimate_destination_finger_value,
3196 * @param finger Finger to be removed. 3271 * @param finger Finger to be removed.
3197 */ 3272 */
3198static void 3273static void
3199remove_existing_finger (struct FingerInfo *existing_finger, unsigned int finger_table_index) 3274remove_existing_finger (struct FingerInfo *existing_finger,
3275 unsigned int finger_table_index)
3200{ 3276{
3201 struct FingerInfo *finger; 3277 struct FingerInfo *finger;
3202 3278
@@ -3208,7 +3284,8 @@ remove_existing_finger (struct FingerInfo *existing_finger, unsigned int finger_
3208 &my_identity)) 3284 &my_identity))
3209 { 3285 {
3210 finger->is_present = GNUNET_NO; 3286 finger->is_present = GNUNET_NO;
3211 memset ((void *)&finger_table[finger_table_index], 0, sizeof (finger_table[finger_table_index])); 3287 memset ((void *)&finger_table[finger_table_index], 0,
3288 sizeof (finger_table[finger_table_index]));
3212 return; 3289 return;
3213 } 3290 }
3214 3291
@@ -3219,36 +3296,9 @@ remove_existing_finger (struct FingerInfo *existing_finger, unsigned int finger_
3219 return; 3296 return;
3220} 3297}
3221 3298
3222#if 0
3223/**
3224 * This is a test function to print all the entries of friend table.
3225 */
3226static void
3227test_friend_peermap_print ()
3228{
3229 struct FriendInfo *friend;
3230 struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter;
3231 struct GNUNET_PeerIdentity print_peer;
3232 struct GNUNET_PeerIdentity key_ret;
3233 int i;
3234
3235 friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
3236
3237 for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++)
3238 {
3239 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (friend_iter,
3240 &key_ret,
3241 (const void **)&friend))
3242 {
3243 memcpy (&print_peer, &key_ret, sizeof (struct GNUNET_PeerIdentity));
3244 FPRINTF (stderr,_("\nSUPU %s, %s, %d, friend = %s, friend->trails_count = %d"),
3245 __FILE__, __func__,__LINE__, GNUNET_i2s(&print_peer), friend->trails_count);
3246 }
3247 }
3248}
3249#endif
3250 3299
3251/** 3300/**
3301 * FIXME: Check for memory leaks.
3252 * Check if there is already an entry in finger_table at finger_table_index. 3302 * Check if there is already an entry in finger_table at finger_table_index.
3253 * We get the finger_table_index from 64bit finger value we got from the network. 3303 * We get the finger_table_index from 64bit finger value we got from the network.
3254 * -- If yes, then select the closest finger. 3304 * -- If yes, then select the closest finger.
@@ -3279,7 +3329,6 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3279{ 3329{
3280 struct FingerInfo *existing_finger; 3330 struct FingerInfo *existing_finger;
3281 struct GNUNET_PeerIdentity *closest_peer; 3331 struct GNUNET_PeerIdentity *closest_peer;
3282 struct GNUNET_PeerIdentity *updated_trail;
3283 struct FingerInfo *successor; 3332 struct FingerInfo *successor;
3284 int updated_finger_trail_length; 3333 int updated_finger_trail_length;
3285 unsigned int finger_table_index; 3334 unsigned int finger_table_index;
@@ -3293,7 +3342,8 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3293 GNUNET_break_op (0); 3342 GNUNET_break_op (0);
3294 return; 3343 return;
3295 } 3344 }
3296 3345 //test_finger_table_print();
3346 //s test_friend_peermap_print();
3297 /* If the new entry for any finger table index other than successor or predecessor 3347 /* If the new entry for any finger table index other than successor or predecessor
3298 * is same as successor then don't add it in finger table, 3348 * is same as successor then don't add it in finger table,
3299 * reset the current search finger index and exit. */ 3349 * reset the current search finger index and exit. */
@@ -3312,22 +3362,23 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3312 } 3362 }
3313 3363
3314 existing_finger = &finger_table[finger_table_index]; 3364 existing_finger = &finger_table[finger_table_index];
3315
3316 /* Shorten the trail if possible. */
3317 updated_finger_trail_length = finger_trail_length;
3318 updated_trail =
3319 scan_and_compress_trail (finger_identity, finger_trail,
3320 finger_trail_length, finger_trail_id,
3321 &updated_finger_trail_length);
3322 3365
3323 /* No entry present in finger_table for given finger map index. */ 3366 /* No entry present in finger_table for given finger map index. */
3324 if (GNUNET_NO == existing_finger->is_present) 3367 if (GNUNET_NO == existing_finger->is_present)
3325 { 3368 {
3369 struct GNUNET_PeerIdentity *updated_trail;
3370
3371 /* Shorten the trail if possible. */
3372 updated_finger_trail_length = finger_trail_length;
3373 updated_trail =
3374 scan_and_compress_trail (finger_identity, finger_trail,
3375 finger_trail_length, finger_trail_id,
3376 &updated_finger_trail_length);
3326 add_new_finger (finger_identity, updated_trail, 3377 add_new_finger (finger_identity, updated_trail,
3327 updated_finger_trail_length, 3378 updated_finger_trail_length,
3328 finger_trail_id, finger_table_index); 3379 finger_trail_id, finger_table_index);
3329 update_current_search_finger_index (finger_identity, finger_table_index); 3380 update_current_search_finger_index (finger_identity,
3330 GNUNET_free_non_null (updated_trail); 3381 finger_table_index);
3331 return; 3382 return;
3332 } 3383 }
3333 3384
@@ -3344,9 +3395,18 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3344 /* If the new finger is the closest peer. */ 3395 /* If the new finger is the closest peer. */
3345 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer)) 3396 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, closest_peer))
3346 { 3397 {
3398 struct GNUNET_PeerIdentity *updated_trail;
3399 /* Shorten the trail if possible. */
3400 updated_finger_trail_length = finger_trail_length;
3401 updated_trail =
3402 scan_and_compress_trail (finger_identity, finger_trail,
3403 finger_trail_length, finger_trail_id,
3404 &updated_finger_trail_length);
3405
3347 remove_existing_finger (existing_finger, finger_table_index); 3406 remove_existing_finger (existing_finger, finger_table_index);
3348 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, 3407 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length,
3349 finger_trail_id, finger_table_index); 3408 finger_trail_id, finger_table_index);
3409
3350 } 3410 }
3351 else 3411 else
3352 { 3412 {
@@ -3354,10 +3414,10 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3354 across the trail setup in routing table of all the peers. */ 3414 across the trail setup in routing table of all the peers. */
3355 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &my_identity)) 3415 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &my_identity))
3356 { 3416 {
3357 if (updated_finger_trail_length > 0) 3417 if (finger_trail_length > 0)
3358 GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, 3418 GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id,
3359 GDS_ROUTING_SRC_TO_DEST, 3419 GDS_ROUTING_SRC_TO_DEST,
3360 updated_trail[0]); 3420 finger_trail[0]);
3361 else 3421 else
3362 GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, 3422 GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id,
3363 GDS_ROUTING_SRC_TO_DEST, 3423 GDS_ROUTING_SRC_TO_DEST,
@@ -3371,7 +3431,6 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3371 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), 3431 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity),
3372 &my_identity)) 3432 &my_identity))
3373 { 3433 {
3374 GNUNET_free_non_null (updated_trail);
3375 return; 3434 return;
3376 } 3435 }
3377 /* If the existing finger is not a friend. */ 3436 /* If the existing finger is not a friend. */
@@ -3379,17 +3438,25 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3379 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3438 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3380 &existing_finger->finger_identity)) 3439 &existing_finger->finger_identity))
3381 { 3440 {
3441 struct GNUNET_PeerIdentity *updated_trail;
3442
3443 /* Shorten the trail if possible. */
3444 updated_finger_trail_length = finger_trail_length;
3445 updated_trail =
3446 scan_and_compress_trail (finger_identity, finger_trail,
3447 finger_trail_length, finger_trail_id,
3448 &updated_finger_trail_length);
3382 /* If there is space to store more trails. */ 3449 /* If there is space to store more trails. */
3383 if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) 3450 if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER)
3384 add_new_trail (existing_finger, updated_trail, 3451 add_new_trail (existing_finger, updated_trail,
3385 finger_trail_length, finger_trail_id); 3452 updated_finger_trail_length, finger_trail_id);
3386 else 3453 else
3387 select_and_replace_trail (existing_finger, updated_trail, 3454 select_and_replace_trail (existing_finger, updated_trail,
3388 finger_trail_length, finger_trail_id); 3455 updated_finger_trail_length, finger_trail_id);
3456
3389 } 3457 }
3390 } 3458 }
3391 update_current_search_finger_index (finger_identity, finger_table_index); 3459 update_current_search_finger_index (finger_identity, finger_table_index);
3392 GNUNET_free_non_null (updated_trail);
3393 return; 3460 return;
3394} 3461}
3395 3462
@@ -3617,7 +3684,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3617 3684
3618 memcpy (&key_value, &(get->key), sizeof (uint64_t)); 3685 memcpy (&key_value, &(get->key), sizeof (uint64_t));
3619 key_value = GNUNET_ntohll (key_value); 3686 key_value = GNUNET_ntohll (key_value);
3620 3687
3621 /* I am not the final destination. I am part of trail to reach final dest. */ 3688 /* I am not the final destination. I am part of trail to reach final dest. */
3622 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))) 3689 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity)))
3623 { 3690 {
@@ -3650,7 +3717,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3650 memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); 3717 memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity));
3651 memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity)); 3718 memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity));
3652 get_length = get_length + 1; 3719 get_length = get_length + 1;
3653 3720 /* FIXME: here it may happen that we find our identity closest to key, but
3721 we don't have the data. then in that case, we should forward the packet
3722 to the next closest peer. */
3654 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, 3723 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0,
3655 get_length, final_get_path, 3724 get_length, final_get_path,
3656 &final_get_path[get_length-2], &my_identity); 3725 &final_get_path[get_length-2], &my_identity);
@@ -3781,7 +3850,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_value,
3781 local_best_known_dest, 3850 local_best_known_dest,
3782 new_intermediate_trail_id, 3851 new_intermediate_trail_id,
3783 is_predecessor); 3852 is_predecessor);
3784 3853
3785 /* Are we just a part of a trail towards a finger (current_destination)? */ 3854 /* Are we just a part of a trail towards a finger (current_destination)? */
3786 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest))) 3855 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest)))
3787 { 3856 {
@@ -3791,6 +3860,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_value,
3791 * that we got from network.*/ 3860 * that we got from network.*/
3792 if (0 != GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, current_dest)) 3861 if (0 != GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, current_dest))
3793 { 3862 {
3863 // GDS_ROUTING_test_print();
3794 closest_peer = select_closest_peer (local_best_known_dest, 3864 closest_peer = select_closest_peer (local_best_known_dest,
3795 current_dest, 3865 current_dest,
3796 final_dest_finger_value, 3866 final_dest_finger_value,
@@ -3890,9 +3960,8 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3890 CONGESTION_TIMEOUT); 3960 CONGESTION_TIMEOUT);
3891 return GNUNET_OK; 3961 return GNUNET_OK;
3892 } 3962 }
3893
3894 new_intermediate_trail_id = GNUNET_new (struct GNUNET_HashCode);
3895 3963
3964 new_intermediate_trail_id = GNUNET_new (struct GNUNET_HashCode);
3896 local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity); 3965 local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity);
3897 3966
3898 /* Get the next hop to forward the trail setup request. */ 3967 /* Get the next hop to forward the trail setup request. */
@@ -3949,7 +4018,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3949 new_intermediate_trail_id); 4018 new_intermediate_trail_id);
3950 } 4019 }
3951 GNUNET_free (local_best_known_dest); 4020 GNUNET_free (local_best_known_dest);
3952 GNUNET_free (next_hop_towards_local_best_known_dest);
3953 return GNUNET_OK; 4021 return GNUNET_OK;
3954} 4022}
3955 4023
@@ -4026,6 +4094,7 @@ is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list,
4026} 4094}
4027#endif 4095#endif
4028 4096
4097
4029/** 4098/**
4030 * FIXME: we should also add a case where we search if we are present in the trail 4099 * FIXME: we should also add a case where we search if we are present in the trail
4031 * twice. 4100 * twice.
@@ -4100,6 +4169,9 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4100 GDS_ROUTING_add (trail_id, my_identity, *peer); 4169 GDS_ROUTING_add (trail_id, my_identity, *peer);
4101 } 4170 }
4102 4171
4172 /* FIXME: Remove this assert later. */
4173 GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4174 peer));
4103 finger_table_add (finger_identity, trail_peer_list, 4175 finger_table_add (finger_identity, trail_peer_list,
4104 trail_length, ulitmate_destination_finger_value, 4176 trail_length, ulitmate_destination_finger_value,
4105 is_predecessor, trail_id); 4177 is_predecessor, trail_id);
@@ -4107,7 +4179,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4107 } 4179 }
4108 4180
4109 /* Get my location in the trail. */ 4181 /* Get my location in the trail. */
4110 my_index = search_my_index(trail_peer_list, trail_length); 4182 my_index = search_my_index (trail_peer_list, trail_length);
4111 if (-1 == my_index) 4183 if (-1 == my_index)
4112 { 4184 {
4113 GNUNET_break_op(0); 4185 GNUNET_break_op(0);
@@ -4116,6 +4188,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4116 4188
4117 /* FIXME: CHECK IF YOU ARE PRESENT MORE THAN ONCE IN THE TRAIL, IF YES 4189 /* FIXME: CHECK IF YOU ARE PRESENT MORE THAN ONCE IN THE TRAIL, IF YES
4118 THEN REMOVE ALL THE ENTRIES AND CHOOSE THE PEER THERE.*/ 4190 THEN REMOVE ALL THE ENTRIES AND CHOOSE THE PEER THERE.*/
4191
4119 if (my_index == 0) 4192 if (my_index == 0)
4120 next_hop = trail_result->querying_peer; 4193 next_hop = trail_result->querying_peer;
4121 else 4194 else
@@ -4154,7 +4227,7 @@ invert_trail (const struct GNUNET_PeerIdentity *trail,
4154 int i; 4227 int i;
4155 int j; 4228 int j;
4156 struct GNUNET_PeerIdentity *inverted_trail; 4229 struct GNUNET_PeerIdentity *inverted_trail;
4157 4230
4158 inverted_trail = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) * 4231 inverted_trail = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) *
4159 trail_length); 4232 trail_length);
4160 i = 0; 4233 i = 0;
@@ -4210,7 +4283,7 @@ trail_source_to_my_predecessor (const struct GNUNET_PeerIdentity *current_trail,
4210 4283
4211 *trail_length = shortest_trail_length; 4284 *trail_length = shortest_trail_length;
4212 trail_me_to_predecessor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) 4285 trail_me_to_predecessor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)
4213 * *trail_length); 4286 * (*trail_length));
4214 4287
4215 /* Copy the selected trail and send this trail to calling function. */ 4288 /* Copy the selected trail and send this trail to calling function. */
4216 i = 0; 4289 i = 0;
@@ -4253,14 +4326,14 @@ update_predecessor (struct GNUNET_PeerIdentity finger,
4253 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, 4326 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
4254 &trail_to_new_predecessor_id, 4327 &trail_to_new_predecessor_id,
4255 sizeof (trail_to_new_predecessor_id)); 4328 sizeof (trail_to_new_predecessor_id));
4256 4329 //test_finger_table_print();
4257 /* Finger is a friend. */ 4330 /* Finger is a friend. */
4258 if (trail_length == 0) 4331 if (trail_length == 0)
4259 { 4332 {
4260 trail_to_new_predecessor = NULL; 4333 trail_to_new_predecessor = NULL;
4261 /* FIXME: check that you always add trail entry even if your finger is 4334 /* FIXME: check that you always add trail entry even if your finger is
4262 friend. */ 4335 friend. */
4263 GDS_ROUTING_add (trail_to_new_predecessor_id, finger, my_identity); 4336 GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger);
4264 GNUNET_assert (NULL != (target_friend = 4337 GNUNET_assert (NULL != (target_friend =
4265 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4338 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4266 &finger))); 4339 &finger)));
@@ -4270,17 +4343,18 @@ update_predecessor (struct GNUNET_PeerIdentity finger,
4270 /* Invert the trail to get the trail from me to finger, NOT including the 4343 /* Invert the trail to get the trail from me to finger, NOT including the
4271 endpoints.*/ 4344 endpoints.*/
4272 trail_to_new_predecessor = invert_trail (trail, trail_length); 4345 trail_to_new_predecessor = invert_trail (trail, trail_length);
4273 /* FIXME: check that you always add trail entry even if your finger is 4346
4274 friend. */
4275
4276 /* Add an entry in your routing table. */ 4347 /* Add an entry in your routing table. */
4277 GDS_ROUTING_add (trail_to_new_predecessor_id, 4348 GDS_ROUTING_add (trail_to_new_predecessor_id,
4278 trail_to_new_predecessor[trail_length - 1], 4349 my_identity,
4279 my_identity); 4350 trail_to_new_predecessor[trail_length - 1]);
4280 4351
4281 GNUNET_assert (NULL != (target_friend = 4352 GNUNET_assert (NULL != (target_friend =
4282 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4353 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4283 &trail_to_new_predecessor[trail_length - 1]))); 4354 &trail_to_new_predecessor[0])));
4355 GNUNET_assert (NULL != (
4356 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4357 &trail[trail_length - 1])));
4284 } 4358 }
4285 4359
4286 /* Add entry in routing table of all peers that are part of trail from me 4360 /* Add entry in routing table of all peers that are part of trail from me
@@ -4345,7 +4419,7 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger,
4345 unsigned int is_predecessor = 1; 4419 unsigned int is_predecessor = 1;
4346 4420
4347 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; 4421 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID];
4348 4422
4349 GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger, &my_identity)); 4423 GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger, &my_identity));
4350 4424
4351 /* No predecessor. Add finger as your predecessor. */ 4425 /* No predecessor. Add finger as your predecessor. */
@@ -4354,7 +4428,11 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity finger,
4354 update_predecessor (finger, trail, trail_length); 4428 update_predecessor (finger, trail, trail_length);
4355 return; 4429 return;
4356 } 4430 }
4431 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_predecessor->finger_identity,
4432 &finger))
4433 return;
4357 4434
4435 //test_finger_table_print();
4358 predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID); 4436 predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID);
4359 closest_peer = select_closest_peer (&finger, 4437 closest_peer = select_closest_peer (&finger,
4360 &current_predecessor->finger_identity, 4438 &current_predecessor->finger_identity,
@@ -4431,7 +4509,7 @@ handle_dht_p2p_verify_successor(void *cls,
4431 GNUNET_break_op (0); 4509 GNUNET_break_op (0);
4432 return GNUNET_YES; 4510 return GNUNET_YES;
4433 } 4511 }
4434 4512
4435 vsm = (const struct PeerVerifySuccessorMessage *) message; 4513 vsm = (const struct PeerVerifySuccessorMessage *) message;
4436 trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/ 4514 trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/
4437 sizeof (struct GNUNET_PeerIdentity); 4515 sizeof (struct GNUNET_PeerIdentity);
@@ -4587,7 +4665,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity probable_successor,
4587 struct FingerInfo *current_successor; 4665 struct FingerInfo *current_successor;
4588 struct FriendInfo *target_friend; 4666 struct FriendInfo *target_friend;
4589 unsigned int is_predecessor = 0; 4667 unsigned int is_predecessor = 0;
4590 4668 //test_finger_table_print();
4591 current_successor = &finger_table[0]; 4669 current_successor = &finger_table[0];
4592 GNUNET_assert (GNUNET_YES == current_successor->is_present); 4670 GNUNET_assert (GNUNET_YES == current_successor->is_present);
4593 4671
@@ -4641,7 +4719,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity probable_successor,
4641 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4719 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4642 &probable_successor))); 4720 &probable_successor)));
4643 } 4721 }
4644 4722 //test_finger_table_print();
4645 GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor, 4723 GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor,
4646 trail_from_curr_to_probable_successor, 4724 trail_from_curr_to_probable_successor,
4647 trail_from_curr_to_probable_successor_length, 4725 trail_from_curr_to_probable_successor_length,
@@ -4936,6 +5014,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4936 my_identity, is_predecessor, 5014 my_identity, is_predecessor,
4937 new_trail,new_trail_length,trail_id, 5015 new_trail,new_trail_length,trail_id,
4938 target_friend, CONGESTION_TIMEOUT); 5016 target_friend, CONGESTION_TIMEOUT);
5017
4939 GNUNET_free (new_trail); 5018 GNUNET_free (new_trail);
4940 return GNUNET_OK; 5019 return GNUNET_OK;
4941 } 5020 }
@@ -4989,6 +5068,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4989 is_predecessor, trail_id, 5068 is_predecessor, trail_id,
4990 &new_intermediate_trail_id); 5069 &new_intermediate_trail_id);
4991 } 5070 }
5071
4992 GNUNET_free (next_hop); 5072 GNUNET_free (next_hop);
4993 return GNUNET_OK; 5073 return GNUNET_OK;
4994} 5074}
@@ -5191,19 +5271,26 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
5191 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer)) 5271 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer))
5192 { 5272 {
5193 struct FriendInfo *target_friend; 5273 struct FriendInfo *target_friend;
5194 5274
5195 /* Get my location in the trail. */ 5275 /* Get my location in the trail. */
5196 my_index = search_my_index (trail, trail_length); 5276 my_index = search_my_index (trail, trail_length);
5197 if (-1 == my_index) 5277 if (-1 == my_index)
5198 { 5278 {
5279
5199 GNUNET_break_op (0); 5280 GNUNET_break_op (0);
5200 return GNUNET_SYSERR; 5281 return GNUNET_SYSERR;
5201 } 5282 }
5202 5283
5203 if (0 == my_index) 5284
5204 next_hop = source_peer; 5285 if ((trail_length - 1) == my_index)
5286 {
5287
5288 next_hop = destination_peer;
5289 }
5205 else 5290 else
5206 next_hop = trail[trail_length - 1]; 5291 {
5292 next_hop = trail[my_index + 1];
5293 }
5207 /* FIXME: check that you always add trail entry even if your finger is 5294 /* FIXME: check that you always add trail entry even if your finger is
5208 friend. */ 5295 friend. */
5209 /* Add in your routing table. */ 5296 /* Add in your routing table. */
@@ -5250,13 +5337,10 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5250 struct Trail *trail; 5337 struct Trail *trail;
5251 trail = &remove_finger->trail_list[i]; 5338 trail = &remove_finger->trail_list[i];
5252 5339
5253 if (GNUNET_NO == trail->is_present) 5340 /* This assertion is ensure that there are no gaps in the trail list.
5254 continue; 5341 REMOVE IT AFTERWARDS. */
5342 GNUNET_assert (GNUNET_YES == trail->is_present);
5255 5343
5256 /*FIXME: This is here to ensure that no finger which is a friend should ever call this
5257 function. remove afterwards.*/
5258 GNUNET_assert (trail->trail_length > 0);
5259
5260 /* First friend to reach to finger is disconnected_peer. */ 5344 /* First friend to reach to finger is disconnected_peer. */
5261 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer, 5345 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer,
5262 disconnected_friend)) 5346 disconnected_friend))
@@ -5268,8 +5352,10 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5268 (remove_friend = 5352 (remove_friend =
5269 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 5353 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
5270 disconnected_friend))); 5354 disconnected_friend)));
5271 remove_friend->trails_count--; 5355 /* FIXME: removing no but check it. */
5272 next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, GDS_ROUTING_SRC_TO_DEST); 5356 //remove_friend->trails_count--;
5357 next_hop = GDS_ROUTING_get_next_hop (trail->trail_id,
5358 GDS_ROUTING_SRC_TO_DEST);
5273 5359
5274 /* Here it may happen that as all the peers got disconnected, the entry in 5360 /* Here it may happen that as all the peers got disconnected, the entry in
5275 routing table for that particular trail has been removed, because the 5361 routing table for that particular trail has been removed, because the
@@ -5311,8 +5397,6 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
5311 int removed_trails_count; 5397 int removed_trails_count;
5312 int i; 5398 int i;
5313 5399
5314 //test_finger_table_print();
5315
5316 /* Iterate over finger table entries. */ 5400 /* Iterate over finger table entries. */
5317 for (i = 0; i < MAX_FINGERS; i++) 5401 for (i = 0; i < MAX_FINGERS; i++)
5318 { 5402 {
@@ -5336,20 +5420,12 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
5336 5420
5337 5421
5338 GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present)); 5422 GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present));
5339 /* FIXME: I am adding this check just to ensure that for a finger which
5340 is also a friend, we are storing only one trail and not more. REMOVE
5341 IT AFTERWARDS. */
5342 GNUNET_assert (1 == remove_finger->trails_count);
5343 trail_id = remove_finger->trail_list[0].trail_id; 5423 trail_id = remove_finger->trail_list[0].trail_id;
5344 5424
5345 /* FIXME: This assertion fails. Check why. */
5346
5347 if(NULL != 5425 if(NULL !=
5348 (next_hop = 5426 (next_hop =
5349 GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST))) 5427 GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST)))
5350 { 5428 {
5351 /* As finger is a friend, you have no trail as such but you have entry in routing
5352 * table of source and dest, so next_hop will be same as finger identity. */
5353 GNUNET_assert (0 == 5429 GNUNET_assert (0 ==
5354 (GNUNET_CRYPTO_cmp_peer_identity (next_hop, 5430 (GNUNET_CRYPTO_cmp_peer_identity (next_hop,
5355 &remove_finger->finger_identity))); 5431 &remove_finger->finger_identity)));
@@ -5361,7 +5437,8 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
5361 } 5437 }
5362 5438
5363 remove_finger->trail_list[0].is_present = GNUNET_NO; 5439 remove_finger->trail_list[0].is_present = GNUNET_NO;
5364 remove_friend->trails_count--; 5440 //GNUNET_assert (0 != remove_friend->trails_count);
5441 //remove_friend->trails_count--; //FIXME; CHECK WHY IT FAILS AND THEN UNCOMMENT.
5365 remove_finger->is_present = GNUNET_NO; 5442 remove_finger->is_present = GNUNET_NO;
5366 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); 5443 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i]));
5367 continue; 5444 continue;
@@ -5373,17 +5450,18 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
5373 continue; 5450 continue;
5374 5451
5375 /* Iterate over the list of trails to reach remove_finger. Check if 5452 /* Iterate over the list of trails to reach remove_finger. Check if
5376 * disconnected_friend makis the first friend in any of the trail. */ 5453 * disconnected_friend is the first friend in any of the trail. */
5377 removed_trails_count = remove_matching_trails (disconnected_peer, 5454 removed_trails_count = remove_matching_trails (disconnected_peer,
5378 remove_finger); 5455 remove_finger);
5379 5456 remove_finger->trails_count =
5457 remove_finger->trails_count - removed_trails_count;
5380 /* All the finger trails had disconnected_friend as the first friend, 5458 /* All the finger trails had disconnected_friend as the first friend,
5381 * so free the finger. */ 5459 * so free the finger. */
5382 if (removed_trails_count == remove_finger->trails_count) 5460 if (remove_finger->trails_count == 0)
5383 { 5461 {
5384 remove_finger->is_present = GNUNET_NO; 5462 remove_finger->is_present = GNUNET_NO;
5385 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); 5463 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i]));
5386 } 5464 }
5387 } 5465 }
5388} 5466}
5389 5467
@@ -5406,7 +5484,7 @@ handle_core_disconnect (void *cls,
5406 5484
5407 GNUNET_assert (NULL != (remove_friend = 5485 GNUNET_assert (NULL != (remove_friend =
5408 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); 5486 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)));
5409 5487
5410 /* Remove fingers with peer as first friend or if peer is a finger. */ 5488 /* Remove fingers with peer as first friend or if peer is a finger. */
5411 remove_matching_fingers (peer); 5489 remove_matching_fingers (peer);
5412 5490
@@ -5415,7 +5493,7 @@ handle_core_disconnect (void *cls,
5415 * disconnected peer is not part of. */ 5493 * disconnected peer is not part of. */
5416 GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); 5494 GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer));
5417 5495
5418 //GNUNET_assert (0 == remove_friend->trails_count); 5496 //GNUNET_assert (0 == remove_friend->trails_count); //FIXME; why should this fai.
5419 5497
5420 /* Remove peer from friend_peermap. */ 5498 /* Remove peer from friend_peermap. */
5421 GNUNET_assert (GNUNET_YES == 5499 GNUNET_assert (GNUNET_YES ==
@@ -5426,8 +5504,6 @@ handle_core_disconnect (void *cls,
5426 if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) 5504 if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap))
5427 return; 5505 return;
5428 5506
5429 /* If there are no more friends in friend_peermap, then don't schedule
5430 * find_finger_trail_task. */
5431 if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) 5507 if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task)
5432 { 5508 {
5433 GNUNET_SCHEDULER_cancel (find_finger_trail_task); 5509 GNUNET_SCHEDULER_cancel (find_finger_trail_task);