aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-xdht_neighbours.c
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-06-26 14:09:46 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-06-26 14:09:46 +0000
commit8a8efc73d30f0358cbc784293dd6df0e8803dfd2 (patch)
treea0dd0f7f1e923d3acbdb3239677e2a2cc41a011c /src/dht/gnunet-service-xdht_neighbours.c
parent3ccf16e152da02c842220d1d653f5f303eee9b4f (diff)
downloadgnunet-8a8efc73d30f0358cbc784293dd6df0e8803dfd2.tar.gz
gnunet-8a8efc73d30f0358cbc784293dd6df0e8803dfd2.zip
xvine: bug fix
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c360
1 files changed, 216 insertions, 144 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 1dba50e23..9dc4f0f74 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -1306,7 +1306,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1306void 1306void
1307GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id, 1307GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
1308 unsigned int trail_direction, 1308 unsigned int trail_direction,
1309 struct GNUNET_PeerIdentity *peer) 1309 struct GNUNET_PeerIdentity peer)
1310{ 1310{
1311 struct PeerTrailTearDownMessage *ttdm; 1311 struct PeerTrailTearDownMessage *ttdm;
1312 struct P2PPendingMessage *pending; 1312 struct P2PPendingMessage *pending;
@@ -1320,9 +1320,11 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
1320 GNUNET_break (0); 1320 GNUNET_break (0);
1321 return; 1321 return;
1322 } 1322 }
1323 1323 struct GNUNET_PeerIdentity *test_peer;
1324 test_peer = GNUNET_new (struct GNUNET_PeerIdentity);
1325 memcpy (test_peer, &peer, sizeof (struct GNUNET_PeerIdentity));
1324 GNUNET_assert (NULL != (target_friend = 1326 GNUNET_assert (NULL != (target_friend =
1325 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); 1327 GNUNET_CONTAINER_multipeermap_get (friend_peermap, test_peer)));
1326 1328
1327 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) 1329 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
1328 { 1330 {
@@ -1341,7 +1343,6 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
1341 ttdm->trail_direction = htonl (trail_direction); 1343 ttdm->trail_direction = htonl (trail_direction);
1342 1344
1343 /* Send the message to chosen friend. */ 1345 /* Send the message to chosen friend. */
1344
1345 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1346 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1346 target_friend->pending_count++; 1347 target_friend->pending_count++;
1347 process_friend_queue (target_friend); 1348 process_friend_queue (target_friend);
@@ -1658,9 +1659,8 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1658 memcpy (&peer2_value, peer2, sizeof (uint64_t)); 1659 memcpy (&peer2_value, peer2, sizeof (uint64_t));
1659 peer1_value = GNUNET_ntohll (peer1_value); 1660 peer1_value = GNUNET_ntohll (peer1_value);
1660 peer2_value = GNUNET_ntohll (peer2_value); 1661 peer2_value = GNUNET_ntohll (peer2_value);
1661 value = GNUNET_ntohll (value); //FIXME: Is it correct to do it here? 1662 //value = GNUNET_ntohll (value); //FIXME: Is it correct to do it here?
1662 // we do it when we get from the network. 1663
1663
1664 if (peer1_value == value) 1664 if (peer1_value == value)
1665 { 1665 {
1666 return peer1; 1666 return peer1;
@@ -1807,10 +1807,14 @@ select_finger_trail (struct FingerInfo *finger)
1807 1807
1808 /* No trail stored at this index. */ 1808 /* No trail stored at this index. */
1809 if (GNUNET_NO == iterator->is_present) 1809 if (GNUNET_NO == iterator->is_present)
1810 {
1810 continue; 1811 continue;
1811 1812 }
1812 friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 1813
1813 &iterator->trail_head->peer); 1814 GNUNET_assert (NULL !=
1815 (friend =
1816 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
1817 &iterator->trail_head->peer)));
1814 1818
1815 /* First friend to reach trail is not free. */ 1819 /* First friend to reach trail is not free. */
1816 if (GNUNET_YES == is_friend_congested (friend)) 1820 if (GNUNET_YES == is_friend_congested (friend))
@@ -1824,6 +1828,8 @@ select_finger_trail (struct FingerInfo *finger)
1824 { 1828 {
1825 flag = 1; 1829 flag = 1;
1826 finger_trail->trail_length = iterator->trail_length; 1830 finger_trail->trail_length = iterator->trail_length;
1831 finger_trail->friend = *friend;
1832 finger_trail->trail_id = iterator->trail_id;
1827 } 1833 }
1828 else if (finger_trail->trail_length > iterator->trail_length) 1834 else if (finger_trail->trail_length > iterator->trail_length)
1829 { 1835 {
@@ -1843,6 +1849,49 @@ select_finger_trail (struct FingerInfo *finger)
1843 return finger_trail; 1849 return finger_trail;
1844} 1850}
1845 1851
1852#if 0
1853/**
1854 * This is a test function, to print all the entries of finger table.
1855 */
1856static void
1857test_finger_table_print()
1858{
1859 struct FingerInfo *finger;
1860 struct GNUNET_PeerIdentity print_peer;
1861 struct Trail *trail;
1862 int i;
1863 int j;
1864 int k;
1865
1866 FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE"));
1867 for (i = 0; i < MAX_FINGERS; i++)
1868 {
1869 finger = &finger_table[i];
1870
1871 if (GNUNET_NO == finger->is_present)
1872 continue;
1873
1874 print_peer = finger->finger_identity;
1875 FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"),
1876 __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count);
1877
1878
1879 for (j = 0; j < finger->trails_count; j++)
1880 {
1881 trail = &finger->trail_list[j];
1882 FPRINTF (stderr,_("\nSUPU %s, %s, %d, trail_id[%d]=%s"),__FILE__, __func__,__LINE__,j, GNUNET_h2s(&trail->trail_id));
1883 struct Trail_Element *element;
1884 element = trail->trail_head;
1885 for (k = 0; k < trail->trail_length; k++)
1886 {
1887 print_peer = element->peer;
1888 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer));
1889 element = element->next;
1890 }
1891 }
1892 }
1893}
1894#endif
1846 1895
1847/** 1896/**
1848 * Compare FINGER entry with current successor. If finger's first friend of all 1897 * Compare FINGER entry with current successor. If finger's first friend of all
@@ -1886,8 +1935,9 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1886 if (NULL != 1935 if (NULL !=
1887 (friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 1936 (friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
1888 &finger->finger_identity))) 1937 &finger->finger_identity)))
1938 {
1889 continue; 1939 continue;
1890 1940 }
1891 /* We have a finger which not a friend, not my identity */ 1941 /* We have a finger which not a friend, not my identity */
1892 /* Choose one of the trail to reach to finger. */ 1942 /* Choose one of the trail to reach to finger. */
1893 finger_trail = select_finger_trail (finger); 1943 finger_trail = select_finger_trail (finger);
@@ -1900,6 +1950,7 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1900 &current_closest_peer->best_known_destination, 1950 &current_closest_peer->best_known_destination,
1901 current_closest_peer->destination_finger_value, 1951 current_closest_peer->destination_finger_value,
1902 current_closest_peer->is_predecessor); 1952 current_closest_peer->is_predecessor);
1953
1903 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 1954 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1904 closest_peer)) 1955 closest_peer))
1905 { 1956 {
@@ -2112,12 +2163,15 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2112 return; 2163 return;
2113 } 2164 }
2114 else 2165 else
2115 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2166 GNUNET_assert (NULL !=
2167 (target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)));
2116 GNUNET_free (next_hop); 2168 GNUNET_free (next_hop);
2117 } 2169 }
2118 else 2170 else
2119 { 2171 {
2120 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); 2172 GNUNET_assert (NULL !=
2173 (target_friend =
2174 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2121 } 2175 }
2122 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2176 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2123 pending->timeout = expiration_time; 2177 pending->timeout = expiration_time;
@@ -2224,14 +2278,18 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2224 } 2278 }
2225 else 2279 else
2226 { 2280 {
2227 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2281 GNUNET_assert (NULL !=
2282 (target_friend =
2283 GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)));
2228 } 2284 }
2229 GNUNET_free (next_hop); 2285 GNUNET_free (next_hop);
2230 } 2286 }
2231 else 2287 else
2232 { 2288 {
2233 local_best_known_dest = *best_known_dest; 2289 local_best_known_dest = *best_known_dest;
2234 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); 2290 GNUNET_assert (NULL !=
2291 (target_friend =
2292 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2235 } 2293 }
2236 2294
2237 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2295 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
@@ -2343,8 +2401,10 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
2343 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2401 get_path_length * sizeof (struct GNUNET_PeerIdentity));
2344 memcpy (&paths[put_path_length + get_path_length], data, data_size); 2402 memcpy (&paths[put_path_length + get_path_length], data, data_size);
2345 2403
2346 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2404 GNUNET_assert (NULL !=
2347 &get_path[current_path_index - 1]); 2405 (target_friend =
2406 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2407 &get_path[current_path_index - 1])));
2348 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 2408 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
2349 target_friend->pending_count++; 2409 target_friend->pending_count++;
2350 process_friend_queue (target_friend); 2410 process_friend_queue (target_friend);
@@ -2548,7 +2608,7 @@ select_and_replace_trail (struct FingerInfo *existing_finger,
2548 GDS_ROUTING_remove_trail (new_trail_id); 2608 GDS_ROUTING_remove_trail (new_trail_id);
2549 GDS_NEIGHBOURS_send_trail_teardown (new_trail_id, 2609 GDS_NEIGHBOURS_send_trail_teardown (new_trail_id,
2550 GDS_ROUTING_SRC_TO_DEST, 2610 GDS_ROUTING_SRC_TO_DEST,
2551 &next_hop); 2611 next_hop);
2552 return; 2612 return;
2553 } 2613 }
2554 2614
@@ -2557,7 +2617,7 @@ select_and_replace_trail (struct FingerInfo *existing_finger,
2557 GDS_ROUTING_remove_trail (replace_trail->trail_id); 2617 GDS_ROUTING_remove_trail (replace_trail->trail_id);
2558 GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id, 2618 GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id,
2559 GDS_ROUTING_SRC_TO_DEST, 2619 GDS_ROUTING_SRC_TO_DEST,
2560 &replace_trail->trail_head->peer); 2620 replace_trail->trail_head->peer);
2561 /* Free the trail. */ 2621 /* Free the trail. */
2562 while (NULL != (trail_element = replace_trail->trail_head)) 2622 while (NULL != (trail_element = replace_trail->trail_head))
2563 { 2623 {
@@ -2725,7 +2785,7 @@ send_trail_teardown (struct FingerInfo *finger,
2725 friend->trails_count--; 2785 friend->trails_count--;
2726 GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id, 2786 GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id,
2727 GDS_ROUTING_SRC_TO_DEST, 2787 GDS_ROUTING_SRC_TO_DEST,
2728 &trail->trail_head->peer); 2788 trail->trail_head->peer);
2729} 2789}
2730 2790
2731 2791
@@ -2736,11 +2796,12 @@ send_trail_teardown (struct FingerInfo *finger,
2736static void 2796static void
2737send_all_finger_trails_teardown (struct FingerInfo *finger) 2797send_all_finger_trails_teardown (struct FingerInfo *finger)
2738{ 2798{
2739 struct Trail *trail;
2740 unsigned int i; 2799 unsigned int i;
2741 2800
2742 for (i = 0; i < finger->trails_count; i++) 2801 for (i = 0; i < finger->trails_count; i++)
2743 { 2802 {
2803 struct Trail *trail;
2804
2744 trail = &finger->trail_list[i]; 2805 trail = &finger->trail_list[i];
2745 GNUNET_assert (trail->is_present == GNUNET_YES); 2806 GNUNET_assert (trail->is_present == GNUNET_YES);
2746 send_trail_teardown (finger, trail); 2807 send_trail_teardown (finger, trail);
@@ -2939,11 +3000,15 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2939 /* If there is trail to reach this finger/friend */ 3000 /* If there is trail to reach this finger/friend */
2940 if (trail_length > 0) 3001 if (trail_length > 0)
2941 { 3002 {
2942 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3003 GNUNET_assert (NULL !=
2943 &trail[0]); 3004 (target_friend =
2944 /* FIXME: In case its finger == friend, then may be we send a trail 3005 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2945 teardown message as it does not make any sense to have any routing e 3006 &trail[0])));
2946 entry in your own routing table.*/ 3007
3008 /* Before you send a trail compression, get the routing entry
3009 from you routing table. update the fields in routing table
3010 to update your next hop to finger identity. */
3011 GDS_ROUTING_update_trail_next_hop (trail_id, finger_identity);
2947 GDS_NEIGHBOURS_send_trail_compression (my_identity, 3012 GDS_NEIGHBOURS_send_trail_compression (my_identity,
2948 trail_id, finger_identity, 3013 trail_id, finger_identity,
2949 target_friend); 3014 target_friend);
@@ -2964,6 +3029,7 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2964 (target_friend = 3029 (target_friend =
2965 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3030 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2966 &trail[0]))); 3031 &trail[0])));
3032 GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]);
2967 GDS_NEIGHBOURS_send_trail_compression (my_identity, 3033 GDS_NEIGHBOURS_send_trail_compression (my_identity,
2968 trail_id, trail[i], 3034 trail_id, trail[i],
2969 target_friend); 3035 target_friend);
@@ -3201,49 +3267,6 @@ test_friend_peermap_print ()
3201 } 3267 }
3202 } 3268 }
3203} 3269}
3204
3205
3206/**
3207 * This is a test function, to print all the entries of finger table.
3208 */
3209static void
3210test_finger_table_print()
3211{
3212 struct FingerInfo *finger;
3213 struct GNUNET_PeerIdentity print_peer;
3214 struct Trail *trail;
3215 int i;
3216 int j;
3217 int k;
3218
3219 FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE"));
3220 for (i = 0; i < MAX_FINGERS; i++)
3221 {
3222 finger = &finger_table[i];
3223
3224 if (GNUNET_NO == finger->is_present)
3225 continue;
3226
3227 print_peer = finger->finger_identity;
3228 FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"),
3229 __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count);
3230
3231
3232 for (j = 0; j < finger->trails_count; j++)
3233 {
3234 trail = &finger->trail_list[j];
3235 FPRINTF (stderr,_("\nSUPU %s, %s, %d, trail_id[%d]=%s"),__FILE__, __func__,__LINE__,j, GNUNET_h2s(&trail->trail_id));
3236 struct Trail_Element *element;
3237 element = trail->trail_head;
3238 for (k = 0; k < trail->trail_length; k++)
3239 {
3240 print_peer = element->peer;
3241 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer));
3242 element = element->next;
3243 }
3244 }
3245 }
3246}
3247#endif 3270#endif
3248 3271
3249/** 3272/**
@@ -3281,11 +3304,11 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3281 struct FingerInfo *successor; 3304 struct FingerInfo *successor;
3282 int updated_finger_trail_length; 3305 int updated_finger_trail_length;
3283 unsigned int finger_table_index; 3306 unsigned int finger_table_index;
3284 3307 //GDS_ROUTING_test_print();
3285#if 0 3308
3286 test_friend_peermap_print(); 3309 //test_friend_peermap_print();
3287 test_finger_table_print(); 3310 //test_finger_table_print();
3288#endif 3311
3289 3312
3290 /* Get the finger_table_index corresponding to finger_value we got from network.*/ 3313 /* Get the finger_table_index corresponding to finger_value we got from network.*/
3291 finger_table_index = get_finger_table_index (finger_value, is_predecessor); 3314 finger_table_index = get_finger_table_index (finger_value, is_predecessor);
@@ -3502,6 +3525,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3502 } 3525 }
3503 else 3526 else
3504 { 3527 {
3528 key_value = GNUNET_ntohll (key_value);
3505 next_hop = find_successor (key_value, &best_known_dest, 3529 next_hop = find_successor (key_value, &best_known_dest,
3506 &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); 3530 &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR);
3507 } 3531 }
@@ -3637,7 +3661,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3637 memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); 3661 memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity));
3638 memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity)); 3662 memcpy (&final_get_path[get_length], &my_identity, sizeof (struct GNUNET_PeerIdentity));
3639 get_length = get_length + 1; 3663 get_length = get_length + 1;
3640 3664
3641 /* Get the next hop to pass the get result message. */ 3665 /* Get the next hop to pass the get result message. */
3642 memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); 3666 memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity));
3643 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, 3667 GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0,
@@ -3776,28 +3800,31 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_value,
3776 3800
3777 /* Select best successor among one found locally and current_destination 3801 /* Select best successor among one found locally and current_destination
3778 * that we got from network.*/ 3802 * that we got from network.*/
3779 closest_peer = select_closest_peer (local_best_known_dest, 3803 if (0 != GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, current_dest))
3780 current_dest, 3804 {
3781 final_dest_finger_value, 3805 closest_peer = select_closest_peer (local_best_known_dest,
3782 is_predecessor); 3806 current_dest,
3807 final_dest_finger_value,
3808 is_predecessor);
3783 3809
3784 /* Is current dest (end point of the trail of which I am a part) closest_peer? */ 3810 /* Is current dest (end point of the trail of which I am a part) closest_peer? */
3785 if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, closest_peer)) 3811 if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, closest_peer))
3786 {
3787 struct GNUNET_PeerIdentity *next_hop;
3788 next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id,
3789 GDS_ROUTING_SRC_TO_DEST);
3790 /* FIXME: Here we found next_hop NULL from routing table, but we still
3791 * have a next_hop from find_successor should we not break and choose that
3792 * next_hop. */
3793 if (NULL == next_hop)
3794 { 3812 {
3795 GNUNET_break_op (0); 3813 struct GNUNET_PeerIdentity *next_hop;
3796 return NULL; 3814 next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id,
3815 GDS_ROUTING_SRC_TO_DEST);
3816 /* FIXME: Here we found next_hop NULL from routing table, but we still
3817 * have a next_hop from find_successor should we not break and choose that
3818 * next_hop. */
3819 if (NULL == next_hop)
3820 {
3821 GNUNET_break_op (0);
3822 return NULL;
3823 }
3824 next_hop_to_local_best_known_dest = next_hop;
3825 local_best_known_dest = current_dest;
3826 *new_intermediate_trail_id = intermediate_trail_id;
3797 } 3827 }
3798 next_hop_to_local_best_known_dest = next_hop;
3799 local_best_known_dest = current_dest;
3800 *new_intermediate_trail_id = intermediate_trail_id;
3801 } 3828 }
3802 } 3829 }
3803 3830
@@ -3822,7 +3849,6 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3822 struct GNUNET_PeerIdentity *local_best_known_dest; 3849 struct GNUNET_PeerIdentity *local_best_known_dest;
3823 struct GNUNET_PeerIdentity current_dest; 3850 struct GNUNET_PeerIdentity current_dest;
3824 struct GNUNET_PeerIdentity *next_hop_towards_local_best_known_dest; 3851 struct GNUNET_PeerIdentity *next_hop_towards_local_best_known_dest;
3825 struct GNUNET_PeerIdentity next_peer;
3826 struct FriendInfo *target_friend; 3852 struct FriendInfo *target_friend;
3827 struct GNUNET_PeerIdentity source; 3853 struct GNUNET_PeerIdentity source;
3828 uint64_t final_dest_finger_val; 3854 uint64_t final_dest_finger_val;
@@ -3864,7 +3890,9 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3864 { 3890 {
3865 /* As my routing table is full, I can no longer handle any more trail 3891 /* As my routing table is full, I can no longer handle any more trail
3866 * through me */ 3892 * through me */
3867 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 3893 GNUNET_assert (NULL !=
3894 (target_friend =
3895 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)));
3868 GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, 3896 GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val,
3869 my_identity, is_predecessor, 3897 my_identity, is_predecessor,
3870 trail_peer_list, trail_length, 3898 trail_peer_list, trail_length,
@@ -3884,22 +3912,23 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3884 is_predecessor, 3912 is_predecessor,
3885 &current_dest); 3913 &current_dest);
3886 3914
3915 GNUNET_assert (NULL != local_best_known_dest);
3916 GNUNET_assert (NULL != next_hop_towards_local_best_known_dest);
3887 /* Am I the final destination? */ 3917 /* Am I the final destination? */
3888 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, 3918 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest,
3889 &my_identity))) 3919 &my_identity)))
3890 { 3920 {
3921 /* FIXME: check that you always add trail entry even if your finger is
3922 friend. */
3891 /* If I was not the source of this message for which now I am destination */ 3923 /* If I was not the source of this message for which now I am destination */
3892 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) 3924 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity))
3893 { 3925 {
3894 GDS_ROUTING_add (trail_id, *peer, my_identity); 3926 GDS_ROUTING_add (trail_id, *peer, my_identity);
3895 } 3927 }
3896 3928
3897 if (0 == trail_length) 3929 GNUNET_assert (NULL !=
3898 memcpy (&next_peer, &source, sizeof (struct GNUNET_PeerIdentity)); 3930 (target_friend =
3899 else 3931 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)));
3900 memcpy (&next_peer, &trail_peer_list[trail_length-1], sizeof (struct GNUNET_PeerIdentity));
3901
3902 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer);
3903 GDS_NEIGHBOURS_send_trail_setup_result (source, 3932 GDS_NEIGHBOURS_send_trail_setup_result (source,
3904 my_identity, 3933 my_identity,
3905 target_friend, trail_length, 3934 target_friend, trail_length,
@@ -3915,9 +3944,10 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3915 memcpy (peer_list, trail_peer_list, 3944 memcpy (peer_list, trail_peer_list,
3916 trail_length * sizeof (struct GNUNET_PeerIdentity)); 3945 trail_length * sizeof (struct GNUNET_PeerIdentity));
3917 peer_list[trail_length] = my_identity; 3946 peer_list[trail_length] = my_identity;
3918 target_friend = 3947 GNUNET_assert (NULL !=
3919 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 3948 (target_friend =
3920 next_hop_towards_local_best_known_dest); 3949 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3950 next_hop_towards_local_best_known_dest)));
3921 GDS_NEIGHBOURS_send_trail_setup (source, 3951 GDS_NEIGHBOURS_send_trail_setup (source,
3922 final_dest_finger_val, 3952 final_dest_finger_val,
3923 *local_best_known_dest, 3953 *local_best_known_dest,
@@ -3930,7 +3960,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3930 return GNUNET_OK; 3960 return GNUNET_OK;
3931} 3961}
3932 3962
3933 3963#if 0
3934/* FIXME: here we are calculating my_index and comparing also in this function. 3964/* FIXME: here we are calculating my_index and comparing also in this function.
3935 And we are doing it again here in this function. Re factor the code. */ 3965 And we are doing it again here in this function. Re factor the code. */
3936/** 3966/**
@@ -4001,7 +4031,7 @@ is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list,
4001 } 4031 }
4002 return GNUNET_YES; 4032 return GNUNET_YES;
4003} 4033}
4004 4034#endif
4005 4035
4006/** 4036/**
4007 * FIXME: we should also add a case where we search if we are present in the trail 4037 * FIXME: we should also add a case where we search if we are present in the trail
@@ -4057,6 +4087,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4057 /* FIXME: here we are calculating my_index and comparing also in this function. 4087 /* FIXME: here we are calculating my_index and comparing also in this function.
4058 And we are doing it again here in this function. Re factor the code. */ 4088 And we are doing it again here in this function. Re factor the code. */
4059 /* Ensure that sender peer is the peer from which we were expecting the message. */ 4089 /* Ensure that sender peer is the peer from which we were expecting the message. */
4090#if 0
4060 if (GNUNET_NO == is_sender_peer_correct (trail_peer_list, 4091 if (GNUNET_NO == is_sender_peer_correct (trail_peer_list,
4061 trail_length, 4092 trail_length,
4062 peer, finger_identity, querying_peer)) 4093 peer, finger_identity, querying_peer))
@@ -4064,6 +4095,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4064 GNUNET_break_op (0); 4095 GNUNET_break_op (0);
4065 return GNUNET_SYSERR; 4096 return GNUNET_SYSERR;
4066 } 4097 }
4098#endif
4067 4099
4068 /* Am I the one who initiated the query? */ 4100 /* Am I the one who initiated the query? */
4069 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, 4101 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer,
@@ -4072,6 +4104,8 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4072 /* If I am not my own finger identity, then add routing table entry. */ 4104 /* If I am not my own finger identity, then add routing table entry. */
4073 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) 4105 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity))
4074 { 4106 {
4107 /* FIXME: check that you always add trail entry even if your finger is
4108 friend. */
4075 GDS_ROUTING_add (trail_id, my_identity, *peer); 4109 GDS_ROUTING_add (trail_id, my_identity, *peer);
4076 } 4110 }
4077 4111
@@ -4101,10 +4135,14 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4101 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), 4135 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer),
4102 &(trail_result->finger_identity)))) 4136 &(trail_result->finger_identity))))
4103 { 4137 {
4138 /* FIXME: check that you always add trail entry even if your finger is
4139 friend. */
4104 GDS_ROUTING_add (trail_id, next_hop, *peer); 4140 GDS_ROUTING_add (trail_id, next_hop, *peer);
4105 } 4141 }
4106 4142
4107 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4143 GNUNET_assert (NULL !=
4144 (target_friend =
4145 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop)));
4108 GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, 4146 GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity,
4109 target_friend, trail_length, trail_peer_list, 4147 target_friend, trail_length, trail_peer_list,
4110 is_predecessor, 4148 is_predecessor,
@@ -4231,25 +4269,28 @@ update_predecessor (struct GNUNET_PeerIdentity finger,
4231 if (trail_length == 0) 4269 if (trail_length == 0)
4232 { 4270 {
4233 trail_to_new_predecessor = NULL; 4271 trail_to_new_predecessor = NULL;
4272 /* FIXME: check that you always add trail entry even if your finger is
4273 friend. */
4234 GDS_ROUTING_add (trail_to_new_predecessor_id, finger, my_identity); 4274 GDS_ROUTING_add (trail_to_new_predecessor_id, finger, my_identity);
4235 target_friend = 4275 GNUNET_assert (NULL != (target_friend =
4236 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4276 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4237 &finger); 4277 &finger)));
4238 } 4278 }
4239 else 4279 else
4240 { 4280 {
4241 /* Invert the trail to get the trail from me to finger, NOT including the 4281 /* Invert the trail to get the trail from me to finger, NOT including the
4242 endpoints.*/ 4282 endpoints.*/
4243 trail_to_new_predecessor = invert_trail (trail, trail_length); 4283 trail_to_new_predecessor = invert_trail (trail, trail_length);
4244 4284 /* FIXME: check that you always add trail entry even if your finger is
4285 friend. */
4245 /* Add an entry in your routing table. */ 4286 /* Add an entry in your routing table. */
4246 GDS_ROUTING_add (trail_to_new_predecessor_id, 4287 GDS_ROUTING_add (trail_to_new_predecessor_id,
4247 trail_to_new_predecessor[trail_length - 1], 4288 trail_to_new_predecessor[trail_length - 1],
4248 my_identity); 4289 my_identity);
4249 4290
4250 target_friend = 4291 GNUNET_assert (NULL != (target_friend =
4251 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4292 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4252 &trail_to_new_predecessor[trail_length - 1]); 4293 &trail_to_new_predecessor[trail_length - 1])));
4253 } 4294 }
4254 4295
4255 /* Add entry in routing table of all peers that are part of trail from me 4296 /* Add entry in routing table of all peers that are part of trail from me
@@ -4468,7 +4509,9 @@ handle_dht_p2p_verify_successor(void *cls,
4468 trail_to_predecessor = NULL; 4509 trail_to_predecessor = NULL;
4469 trail_to_predecessor_length = 0; 4510 trail_to_predecessor_length = 0;
4470 } 4511 }
4471 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 4512 GNUNET_assert (NULL !=
4513 (target_friend =
4514 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)));
4472 GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, 4515 GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity,
4473 current_predecessor->finger_identity, 4516 current_predecessor->finger_identity,
4474 trail_id, trail_to_predecessor, 4517 trail_id, trail_to_predecessor,
@@ -4591,15 +4634,22 @@ compare_and_update_successor (struct GNUNET_PeerIdentity probable_successor,
4591 routing table. */ 4634 routing table. */
4592 if (trail_to_new_successor_length > 0) 4635 if (trail_to_new_successor_length > 0)
4593 { 4636 {
4637 /* FIXME: check that you always add trail entry even if your finger is
4638 friend. */
4594 GDS_ROUTING_add (trail_id, my_identity, trail_to_new_successor[0]); 4639 GDS_ROUTING_add (trail_id, my_identity, trail_to_new_successor[0]);
4595 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4640 GNUNET_assert (NULL !=
4596 &trail_to_new_successor[0]); 4641 (target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4642 &trail_to_new_successor[0])));
4597 } 4643 }
4598 else 4644 else
4599 { 4645 {
4646 /* FIXME: check that you always add trail entry even if your finger is
4647 friend. */
4600 GDS_ROUTING_add (trail_id, my_identity, probable_successor); 4648 GDS_ROUTING_add (trail_id, my_identity, probable_successor);
4601 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4649 GNUNET_assert (NULL !=
4602 &probable_successor); 4650 (target_friend =
4651 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4652 &probable_successor)));
4603 } 4653 }
4604 4654
4605 GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor, 4655 GDS_NEIGHBOURS_send_notify_new_successor (my_identity, probable_successor,
@@ -4681,7 +4731,9 @@ handle_dht_p2p_verify_successor_result(void *cls,
4681 /*If you are not the querying peer then pass on the message */ 4731 /*If you are not the querying peer then pass on the message */
4682 GNUNET_assert (NULL != (next_hop = 4732 GNUNET_assert (NULL != (next_hop =
4683 GDS_ROUTING_get_next_hop (trail_id, trail_direction))); 4733 GDS_ROUTING_get_next_hop (trail_id, trail_direction)));
4684 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 4734 GNUNET_assert (NULL !=
4735 (target_friend =
4736 GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)));
4685 GDS_NEIGHBOURS_send_verify_successor_result (querying_peer, 4737 GDS_NEIGHBOURS_send_verify_successor_result (querying_peer,
4686 vsrm->current_successor, 4738 vsrm->current_successor,
4687 probable_successor, trail_id, 4739 probable_successor, trail_id,
@@ -4755,6 +4807,8 @@ handle_dht_p2p_notify_new_successor(void *cls,
4755 /* Add an entry in routing table only if new predecessor is not a friend. */ 4807 /* Add an entry in routing table only if new predecessor is not a friend. */
4756 if (NULL == GNUNET_CONTAINER_multipeermap_get(friend_peermap, &source)) 4808 if (NULL == GNUNET_CONTAINER_multipeermap_get(friend_peermap, &source))
4757 { 4809 {
4810 /* FIXME: check that you always add trail entry even if your finger is
4811 friend. */
4758 GDS_ROUTING_add (trail_id, *peer, my_identity); 4812 GDS_ROUTING_add (trail_id, *peer, my_identity);
4759 } 4813 }
4760 compare_and_update_predecessor (source, trail, trail_length); 4814 compare_and_update_predecessor (source, trail, trail_length);
@@ -4772,10 +4826,13 @@ handle_dht_p2p_notify_new_successor(void *cls,
4772 next_hop = new_successor; 4826 next_hop = new_successor;
4773 else 4827 else
4774 next_hop = trail[my_index + 1]; 4828 next_hop = trail[my_index + 1];
4775 4829 /* FIXME: check that you always add trail entry even if your finger is
4830 friend. */
4776 /* Add an entry in routing table for trail from source to its new successor. */ 4831 /* Add an entry in routing table for trail from source to its new successor. */
4777 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); 4832 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop));
4778 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4833 GNUNET_assert (NULL !=
4834 (target_friend =
4835 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop)));
4779 GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail, 4836 GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail,
4780 trail_length, 4837 trail_length,
4781 trail_id, target_friend); 4838 trail_id, target_friend);
@@ -4852,7 +4909,9 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4852 GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); 4909 GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value);
4853 4910
4854 /* First set the congestion time of the friend that sent you this message. */ 4911 /* First set the congestion time of the friend that sent you this message. */
4855 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 4912 GNUNET_assert (NULL !=
4913 (target_friend =
4914 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)));
4856 target_friend->congestion_timestamp = 4915 target_friend->congestion_timestamp =
4857 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), 4916 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
4858 congestion_timeout); 4917 congestion_timeout);
@@ -4886,7 +4945,9 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4886 memcpy (new_trail, trail_peer_list, new_trail_length * sizeof (struct GNUNET_PeerIdentity)); 4945 memcpy (new_trail, trail_peer_list, new_trail_length * sizeof (struct GNUNET_PeerIdentity));
4887 } 4946 }
4888 4947
4889 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 4948 GNUNET_assert (NULL !=
4949 (target_friend =
4950 GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)));
4890 GDS_NEIGHBOURS_send_trail_rejection (source, 4951 GDS_NEIGHBOURS_send_trail_rejection (source,
4891 ultimate_destination_finger_value, 4952 ultimate_destination_finger_value,
4892 my_identity, is_predecessor, 4953 my_identity, is_predecessor,
@@ -4912,6 +4973,8 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4912 * an entry in routing table,as we will send a trail compression message 4973 * an entry in routing table,as we will send a trail compression message
4913 * later. 4974 * later.
4914 */ 4975 */
4976 /* FIXME: check that you always add trail entry even if your finger is
4977 friend. */
4915 if ((0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) || 4978 if ((0 != GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) ||
4916 (trail_length > 0)) 4979 (trail_length > 0))
4917 GNUNET_assert (GNUNET_YES == GDS_ROUTING_add (trail_id, *peer, my_identity)); 4980 GNUNET_assert (GNUNET_YES == GDS_ROUTING_add (trail_id, *peer, my_identity));
@@ -4921,7 +4984,9 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4921 else 4984 else
4922 next_peer = trail_peer_list[trail_length-1]; 4985 next_peer = trail_peer_list[trail_length-1];
4923 4986
4924 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer); 4987 GNUNET_assert (NULL !=
4988 (target_friend =
4989 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer)));
4925 GDS_NEIGHBOURS_send_trail_setup_result (source, 4990 GDS_NEIGHBOURS_send_trail_setup_result (source,
4926 my_identity, 4991 my_identity,
4927 target_friend, trail_length, 4992 target_friend, trail_length,
@@ -4937,7 +5002,9 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4937 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 5002 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
4938 peer_list[trail_length] = my_identity; 5003 peer_list[trail_length] = my_identity;
4939 5004
4940 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 5005 GNUNET_assert (NULL !=
5006 (target_friend =
5007 GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)));
4941 GDS_NEIGHBOURS_send_trail_setup (source, 5008 GDS_NEIGHBOURS_send_trail_setup (source,
4942 ultimate_destination_finger_value, 5009 ultimate_destination_finger_value,
4943 next_destination, 5010 next_destination,
@@ -4992,7 +5059,7 @@ handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *p
4992 trail_compression->source_peer); 5059 trail_compression->source_peer);
4993 return GNUNET_OK; 5060 return GNUNET_OK;
4994 } 5061 }
4995 5062 //GDS_ROUTING_test_print();
4996 /* Pass the message to next hop to finally reach to new_first_friend. */ 5063 /* Pass the message to next hop to finally reach to new_first_friend. */
4997 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); 5064 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST);
4998 if (NULL == next_hop) 5065 if (NULL == next_hop)
@@ -5070,7 +5137,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
5070 return GNUNET_OK; 5137 return GNUNET_OK;
5071 5138
5072 /* If not final destination, then send a trail teardown message to next hop.*/ 5139 /* If not final destination, then send a trail teardown message to next hop.*/
5073 GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, next_hop); 5140 GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, *next_hop);
5074 //GNUNET_free_non_null (next_hop); 5141 //GNUNET_free_non_null (next_hop);
5075 return GNUNET_OK; 5142 return GNUNET_OK;
5076} 5143}
@@ -5145,15 +5212,19 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
5145 next_hop = source_peer; 5212 next_hop = source_peer;
5146 else 5213 else
5147 next_hop = trail[trail_length - 1]; 5214 next_hop = trail[trail_length - 1];
5148 5215 /* FIXME: check that you always add trail entry even if your finger is
5216 friend. */
5149 /* Add in your routing table. */ 5217 /* Add in your routing table. */
5150 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); 5218 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer));
5151 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 5219 GNUNET_assert (NULL !=
5220 (target_friend =
5221 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop)));
5152 GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id, 5222 GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id,
5153 trail, trail_length, target_friend); 5223 trail, trail_length, target_friend);
5154 return GNUNET_OK; 5224 return GNUNET_OK;
5155 } 5225 }
5156 5226 /* FIXME: check that you always add trail entry even if your finger is
5227 friend. */
5157 /* I am the destination. Add an entry in routing table. */ 5228 /* I am the destination. Add an entry in routing table. */
5158 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, my_identity)); 5229 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, my_identity));
5159 return GNUNET_OK; 5230 return GNUNET_OK;
@@ -5219,8 +5290,6 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5219 5290
5220 5291
5221/** 5292/**
5222 * FIXME; make sure you handle friend correctle. remove entry from you
5223 * routing table if you are the source.
5224 * Iterate over finger_table entries. 5293 * Iterate over finger_table entries.
5225 * 0. Ignore finger which is my_identity or if no valid entry present at 5294 * 0. Ignore finger which is my_identity or if no valid entry present at
5226 * that finger index. 5295 * that finger index.
@@ -5233,7 +5302,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5233 * @param disconnected_friend Peer identity of friend which got disconnected. 5302 * @param disconnected_friend Peer identity of friend which got disconnected.
5234 */ 5303 */
5235static void 5304static void
5236remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend) 5305remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
5237{ 5306{
5238 struct FingerInfo *remove_finger; 5307 struct FingerInfo *remove_finger;
5239 struct FriendInfo *remove_friend; 5308 struct FriendInfo *remove_friend;
@@ -5254,14 +5323,18 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend)
5254 &my_identity)) 5323 &my_identity))
5255 continue; 5324 continue;
5256 5325
5257 /* Is disconnected_friend a finger? */ 5326 /* Is disconnected_peer a finger? */
5258 if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, 5327 if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_peer,
5259 &remove_finger->finger_identity)) 5328 &remove_finger->finger_identity))
5260 { 5329 {
5261 struct GNUNET_PeerIdentity *next_hop; 5330 struct GNUNET_PeerIdentity *next_hop;
5262 struct GNUNET_HashCode trail_id; 5331 struct GNUNET_HashCode trail_id;
5263 5332
5264 GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present)); 5333 GNUNET_assert (GNUNET_YES == (remove_finger->trail_list[0].is_present));
5334 /* FIXME: I am adding this check just to ensure that for a finger which
5335 is also a friend, we are storing only one trail and not more. REMOVE
5336 IT AFTERWARDS. */
5337 GNUNET_assert (1 == remove_finger->trails_count);
5265 trail_id = remove_finger->trail_list[0].trail_id; 5338 trail_id = remove_finger->trail_list[0].trail_id;
5266 5339
5267 GNUNET_assert (NULL != 5340 GNUNET_assert (NULL !=
@@ -5274,7 +5347,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend)
5274 &remove_finger->finger_identity))); 5347 &remove_finger->finger_identity)));
5275 GDS_ROUTING_remove_trail (trail_id); 5348 GDS_ROUTING_remove_trail (trail_id);
5276 remove_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 5349 remove_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
5277 disconnected_friend); 5350 disconnected_peer);
5278 remove_friend->trails_count--; 5351 remove_friend->trails_count--;
5279 remove_finger->is_present = GNUNET_NO; 5352 remove_finger->is_present = GNUNET_NO;
5280 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); 5353 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i]));
@@ -5288,7 +5361,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend)
5288 5361
5289 /* Iterate over the list of trails to reach remove_finger. Check if 5362 /* Iterate over the list of trails to reach remove_finger. Check if
5290 * disconnected_friend makis the first friend in any of the trail. */ 5363 * disconnected_friend makis the first friend in any of the trail. */
5291 removed_trails_count = remove_matching_trails (disconnected_friend, 5364 removed_trails_count = remove_matching_trails (disconnected_peer,
5292 remove_finger); 5365 remove_finger);
5293 5366
5294 /* All the finger trails had disconnected_friend as the first friend, 5367 /* All the finger trails had disconnected_friend as the first friend,
@@ -5330,6 +5403,7 @@ handle_core_disconnect (void *cls,
5330 GDS_ROUTING_remove_trail_by_peer (peer); 5403 GDS_ROUTING_remove_trail_by_peer (peer);
5331 5404
5332 GNUNET_assert (0 == remove_friend->trails_count); 5405 GNUNET_assert (0 == remove_friend->trails_count);
5406
5333 /* Remove peer from friend_peermap. */ 5407 /* Remove peer from friend_peermap. */
5334 GNUNET_assert (GNUNET_YES == 5408 GNUNET_assert (GNUNET_YES ==
5335 GNUNET_CONTAINER_multipeermap_remove (friend_peermap, 5409 GNUNET_CONTAINER_multipeermap_remove (friend_peermap,
@@ -5417,11 +5491,9 @@ core_init (void *cls,
5417static void 5491static void
5418finger_table_init () 5492finger_table_init ()
5419{ 5493{
5420 int i; 5494 unsigned int i;
5421 int j; 5495 unsigned int j;
5422 5496
5423 /* FIXME: here we have set the whole entry of finger table to 0, so do we
5424 * need to initialize the trails to 0 */
5425 for(i = 0; i < MAX_FINGERS; i++) 5497 for(i = 0; i < MAX_FINGERS; i++)
5426 { 5498 {
5427 finger_table[i].is_present = GNUNET_NO; 5499 finger_table[i].is_present = GNUNET_NO;