aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-xdht_neighbours.c
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-06-16 14:46:24 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-06-16 14:46:24 +0000
commit2455afc820a66f0ca57f01fbb09ba57a9e57de5b (patch)
treef453de4d1eee88a4fe5451d8fd53b77deb9b9389 /src/dht/gnunet-service-xdht_neighbours.c
parent1eef01cd60f92a3d77061d655c0217bd6f9ffce4 (diff)
downloadgnunet-2455afc820a66f0ca57f01fbb09ba57a9e57de5b.tar.gz
gnunet-2455afc820a66f0ca57f01fbb09ba57a9e57de5b.zip
xvine dht: few fixes
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c369
1 files changed, 275 insertions, 94 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index ba4d13a56..f4aae1d1f 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -58,6 +58,9 @@
58 * 6. You have two variables - current_search_finger_index and finger map index 58 * 6. You have two variables - current_search_finger_index and finger map index
59 * , now you need to understand should you update current_search_finger_index 59 * , now you need to understand should you update current_search_finger_index
60 * based on finger map index. Make these two variables clear in their functionality. 60 * based on finger map index. Make these two variables clear in their functionality.
61 * URGENT 7. In case the finger is the friend do we add an entry in routing table
62 * for endpoints. There is no trail. So I don't think it makes sense to have
63 * an entry in routing table.
61 */ 64 */
62 65
63/** 66/**
@@ -759,8 +762,7 @@ struct FingerInfo
759 struct GNUNET_PeerIdentity finger_identity; 762 struct GNUNET_PeerIdentity finger_identity;
760 763
761 /** 764 /**
762 * FIXME: Better name 765 * Is any finger stored at this finger index.
763 * Is there any valid entry for this finger.
764 */ 766 */
765 unsigned int is_present; 767 unsigned int is_present;
766 768
@@ -1222,7 +1224,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer,
1222void 1224void
1223GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, 1225GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer,
1224 struct GNUNET_PeerIdentity successor, 1226 struct GNUNET_PeerIdentity successor,
1225 const struct GNUNET_HashCode trail_id, 1227 const struct GNUNET_HashCode *trail_id,
1226 struct GNUNET_PeerIdentity *trail, 1228 struct GNUNET_PeerIdentity *trail,
1227 unsigned int trail_length, 1229 unsigned int trail_length,
1228 struct FriendInfo *target_friend) 1230 struct FriendInfo *target_friend)
@@ -1254,7 +1256,10 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1254 vsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR); 1256 vsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR);
1255 vsm->source_peer = source_peer; 1257 vsm->source_peer = source_peer;
1256 vsm->successor = successor; 1258 vsm->successor = successor;
1257 vsm->trail_id = trail_id; 1259 if (NULL == trail_id)
1260 memset (&vsm->trail_id, 0, sizeof (vsm->trail_id));
1261 else
1262 vsm->trail_id = *trail_id;
1258 1263
1259 if (trail_length > 0) 1264 if (trail_length > 0)
1260 { 1265 {
@@ -1475,7 +1480,7 @@ void
1475GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer, 1480GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer,
1476 struct GNUNET_PeerIdentity destination_peer, 1481 struct GNUNET_PeerIdentity destination_peer,
1477 struct GNUNET_HashCode trail_id, 1482 struct GNUNET_HashCode trail_id,
1478 struct GNUNET_PeerIdentity *trail, 1483 const struct GNUNET_PeerIdentity *trail,
1479 unsigned int trail_length, 1484 unsigned int trail_length,
1480 struct FriendInfo *target_friend) 1485 struct FriendInfo *target_friend)
1481{ 1486{
@@ -1510,11 +1515,8 @@ GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer,
1510 adm->destination_peer = destination_peer; 1515 adm->destination_peer = destination_peer;
1511 adm->trail_id = trail_id; 1516 adm->trail_id = trail_id;
1512 1517
1513 if (trail_length > 0) 1518 peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
1514 { 1519 memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length);
1515 peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
1516 memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length);
1517 }
1518 1520
1519 /* Send the message to chosen friend. */ 1521 /* Send the message to chosen friend. */
1520 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 1522 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
@@ -1682,7 +1684,7 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1682 1684
1683 memcpy (&peer1_value, peer1, sizeof (uint64_t)); 1685 memcpy (&peer1_value, peer1, sizeof (uint64_t));
1684 memcpy (&peer2_value, peer2, sizeof (uint64_t)); 1686 memcpy (&peer2_value, peer2, sizeof (uint64_t));
1685 1687
1686 if (peer1_value == value) 1688 if (peer1_value == value)
1687 { 1689 {
1688 return peer1; 1690 return peer1;
@@ -1692,20 +1694,7 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1692 { 1694 {
1693 return peer2; 1695 return peer2;
1694 } 1696 }
1695 1697
1696 if (peer1_value < peer2_value)
1697 {
1698 if ((peer1_value < value) && (value < peer2_value))
1699 {
1700 return peer2;
1701 }
1702 else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1703 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer1_value)))
1704 {
1705 return peer1;
1706 }
1707 }
1708
1709 if (peer2_value < peer1_value) 1698 if (peer2_value < peer1_value)
1710 { 1699 {
1711 if ((peer2_value < value) && (value < peer1_value)) 1700 if ((peer2_value < value) && (value < peer1_value))
@@ -1713,11 +1702,24 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1713 return peer1; 1702 return peer1;
1714 } 1703 }
1715 else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || 1704 else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1716 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer2_value))) 1705 ((0 < value) && (value < peer2_value)))
1717 { 1706 {
1718 return peer2; 1707 return peer2;
1719 } 1708 }
1720 } 1709 }
1710
1711 if (peer1_value < peer2_value)
1712 {
1713 if ((peer1_value < value) && (value < peer2_value))
1714 {
1715 return peer2;
1716 }
1717 else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1718 ((0 < value) && (value < peer1_value)))
1719 {
1720 return peer1;
1721 }
1722 }
1721 return NULL; 1723 return NULL;
1722} 1724}
1723 1725
@@ -1760,7 +1762,7 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
1760 if ((peer1_value < value) && (value < peer2_value)) 1762 if ((peer1_value < value) && (value < peer2_value))
1761 return peer1; 1763 return peer1;
1762 else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || 1764 else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1763 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer1_value))) 1765 ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer1_value)))
1764 return peer2; 1766 return peer2;
1765 } 1767 }
1766 1768
@@ -1769,7 +1771,7 @@ select_closest_predecessor (struct GNUNET_PeerIdentity *peer1,
1769 if ((peer2_value < value) && (value < peer1_value)) 1771 if ((peer2_value < value) && (value < peer1_value))
1770 return peer2; 1772 return peer2;
1771 else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || 1773 else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
1772 ((PEER_IDENTITES_WRAP_AROUND < value) && (value < peer2_value))) 1774 ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer2_value)))
1773 return peer1; 1775 return peer1;
1774 } 1776 }
1775 return NULL; 1777 return NULL;
@@ -1817,7 +1819,6 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1,
1817 /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id) 1819 /* FIXME: select closest peer w.r.t. value. [friend_id, current_successor->id)
1818 and [current_successor->id, friend_id). Check in which range value lies. 1820 and [current_successor->id, friend_id). Check in which range value lies.
1819 Also, check for wrap around. Set the value of current_successor accordingly.*/ 1821 Also, check for wrap around. Set the value of current_successor accordingly.*/
1820
1821 if (PREDECESSOR_FINGER_ID == finger_table_index) 1822 if (PREDECESSOR_FINGER_ID == finger_table_index)
1822 closest_peer = select_closest_predecessor (peer1, peer2, value); 1823 closest_peer = select_closest_predecessor (peer1, peer2, value);
1823 else 1824 else
@@ -1852,6 +1853,11 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1852 if (GNUNET_NO == finger->is_present) 1853 if (GNUNET_NO == finger->is_present)
1853 continue; 1854 continue;
1854 1855
1856 /* If my identity is same as current closest peer then don't consider me*/
1857 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1858 &current_closest_peer->best_known_destination))
1859 continue;
1860
1855 /* If I am my own finger, then ignore this finger. */ 1861 /* If I am my own finger, then ignore this finger. */
1856 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 1862 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
1857 &my_identity)) 1863 &my_identity))
@@ -1929,6 +1935,11 @@ compare_friend_and_current_closest_peer (void *cls,
1929 if (GNUNET_YES == is_friend_congested (friend)) 1935 if (GNUNET_YES == is_friend_congested (friend))
1930 return GNUNET_YES; 1936 return GNUNET_YES;
1931 1937
1938 if (0 ==
1939 GNUNET_CRYPTO_cmp_peer_identity (&friend->id,
1940 &current_closest_peer->best_known_destination))
1941 return GNUNET_YES;
1942
1932 closest_peer = select_closest_peer (&friend->id, 1943 closest_peer = select_closest_peer (&friend->id,
1933 &current_closest_peer->best_known_destination, 1944 &current_closest_peer->best_known_destination,
1934 current_closest_peer->destination_finger_value, 1945 current_closest_peer->destination_finger_value,
@@ -2351,7 +2362,7 @@ select_random_friend ()
2351 &key_ret, 2362 &key_ret,
2352 (const void **)&friend)); 2363 (const void **)&friend));
2353 2364
2354 2365 /* This friend is not congested and has not crossed trail threshold. */
2355 if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) && 2366 if ((TRAILS_THROUGH_FRIEND_THRESHOLD > friend->trails_count) &&
2356 (0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_timestamp).rel_value_us)) 2367 (0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_timestamp).rel_value_us))
2357 { 2368 {
@@ -2367,9 +2378,17 @@ select_random_friend ()
2367 2378
2368 2379
2369/** 2380/**
2370 * Compute 64 bit value of finger_identity to which we want to setup 2381 * Compute 64 bit value of finger_identity corresponding to a finger index using
2371 * the trail using chord formula. 2382 * chord formula.
2372 * @return finger_identity 2383 * For all fingers:
2384 * n.finger[i] = n + pow (2,i),
2385 * For predecessor
2386 * n.finger[i] = n - 1, where
2387 * n = my_identity
2388 * i = finger_index.
2389 * n.finger[i] = 64 bit finger value
2390 * @param finger_index Index corresponding to which we calculate 64 bit value.
2391 * @return 64 bit value.
2373 */ 2392 */
2374static uint64_t 2393static uint64_t
2375compute_finger_identity_value (unsigned int finger_index) 2394compute_finger_identity_value (unsigned int finger_index)
@@ -2388,8 +2407,9 @@ compute_finger_identity_value (unsigned int finger_index)
2388 2407
2389 2408
2390/* 2409/*
2391 * Choose a random friend and start looking for the trail to reach to 2410 * Choose a random friend. Start looking for the trail to reach to
2392 * finger identity through this random friend. 2411 * finger identity corresponding to current_search_finger_index through
2412 * this random friend.
2393 * 2413 *
2394 * @param cls closure for this task 2414 * @param cls closure for this task
2395 * @param tc the context under which the task is running 2415 * @param tc the context under which the task is running
@@ -2404,6 +2424,7 @@ send_find_finger_trail_message (void *cls,
2404 unsigned int is_predecessor; 2424 unsigned int is_predecessor;
2405 uint64_t finger_id_value; 2425 uint64_t finger_id_value;
2406 2426
2427 /* Schedule another send_find_finger_trail_message task. */
2407 next_send_time.rel_value_us = 2428 next_send_time.rel_value_us =
2408 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + 2429 DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
2409 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 2430 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -2424,6 +2445,7 @@ send_find_finger_trail_message (void *cls,
2424 else 2445 else
2425 is_predecessor = 0; 2446 is_predecessor = 0;
2426 2447
2448 /* Generate a unique trail id for trail we are trying to setup. */
2427 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, 2449 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
2428 &trail_id, sizeof (trail_id)); 2450 &trail_id, sizeof (trail_id));
2429 GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, 2451 GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value,
@@ -2690,6 +2712,7 @@ free_finger (struct FingerInfo *finger)
2690 trail = &finger->trail_list[i]; 2712 trail = &finger->trail_list[i];
2691 free_trail (trail); 2713 free_trail (trail);
2692 } 2714 }
2715
2693 GNUNET_free (finger); 2716 GNUNET_free (finger);
2694} 2717}
2695 2718
@@ -2715,7 +2738,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2715 struct FriendInfo *first_trail_hop; 2738 struct FriendInfo *first_trail_hop;
2716 struct Trail *trail; 2739 struct Trail *trail;
2717 int i = 0; 2740 int i = 0;
2718 2741
2719 new_entry = GNUNET_new (struct FingerInfo); 2742 new_entry = GNUNET_new (struct FingerInfo);
2720 new_entry->finger_identity = finger_identity; 2743 new_entry->finger_identity = finger_identity;
2721 new_entry->finger_table_index = finger_table_index; 2744 new_entry->finger_table_index = finger_table_index;
@@ -2804,6 +2827,9 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2804 { 2827 {
2805 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2828 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2806 &trail[0]); 2829 &trail[0]);
2830 /* FIXME: In case its finger == friend, then may be we send a trail
2831 teardown message as it does not make any sense to have any routing e
2832 entry in your own routing table.*/
2807 GDS_NEIGHBOURS_send_trail_compression (my_identity, 2833 GDS_NEIGHBOURS_send_trail_compression (my_identity,
2808 trail_id, finger_identity, 2834 trail_id, finger_identity,
2809 target_friend); 2835 target_friend);
@@ -2862,7 +2888,7 @@ static void
2862send_verify_successor_message (struct FingerInfo *successor) 2888send_verify_successor_message (struct FingerInfo *successor)
2863{ 2889{
2864 struct Trail *trail_list_iterator; 2890 struct Trail *trail_list_iterator;
2865 struct GNUNET_HashCode trail_id; 2891 struct GNUNET_HashCode *trail_id;
2866 struct GNUNET_PeerIdentity next_hop; 2892 struct GNUNET_PeerIdentity next_hop;
2867 struct FriendInfo *target_friend; 2893 struct FriendInfo *target_friend;
2868 struct GNUNET_PeerIdentity *trail; 2894 struct GNUNET_PeerIdentity *trail;
@@ -2870,6 +2896,19 @@ send_verify_successor_message (struct FingerInfo *successor)
2870 int i; 2896 int i;
2871 int j; 2897 int j;
2872 2898
2899 /* If successor is a friend. */
2900 if (successor->trails_count == 0)
2901 {
2902 struct FriendInfo *target_friend;
2903 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2904 &successor->finger_identity);
2905 GDS_NEIGHBOURS_send_verify_successor_message (my_identity,
2906 successor->finger_identity,
2907 NULL, NULL, 0,
2908 target_friend);
2909 }
2910
2911 trail_id = GNUNET_new (struct GNUNET_HashCode);
2873 for (i = 0; i < successor->trails_count; i++) 2912 for (i = 0; i < successor->trails_count; i++)
2874 { 2913 {
2875 trail_list_iterator = &successor->trail_list[i]; 2914 trail_list_iterator = &successor->trail_list[i];
@@ -2893,7 +2932,7 @@ send_verify_successor_message (struct FingerInfo *successor)
2893 trail_length = 0; 2932 trail_length = 0;
2894 next_hop = successor->finger_identity; 2933 next_hop = successor->finger_identity;
2895 } 2934 }
2896 trail_id = trail_list_iterator->trail_id; 2935 *trail_id = trail_list_iterator->trail_id;
2897 GNUNET_assert (NULL != (target_friend = 2936 GNUNET_assert (NULL != (target_friend =
2898 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); 2937 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop)));
2899 2938
@@ -2912,9 +2951,13 @@ send_verify_successor_message (struct FingerInfo *successor)
2912 * Update the current search finger index. 2951 * Update the current search finger index.
2913 */ 2952 */
2914static void 2953static void
2915update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity) 2954update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity,
2955 unsigned int finger_table_index)
2916{ 2956{
2917 struct FingerInfo *successor; 2957 struct FingerInfo *successor;
2958
2959 if (finger_table_index != current_search_finger_index)
2960 return;
2918 2961
2919 successor = &finger_table[0]; 2962 successor = &finger_table[0];
2920 if (GNUNET_NO == successor->is_present) 2963 if (GNUNET_NO == successor->is_present)
@@ -2989,6 +3032,7 @@ remove_existing_finger (struct FingerInfo *finger)
2989 struct FriendInfo *friend; 3032 struct FriendInfo *friend;
2990 3033
2991 GNUNET_assert (GNUNET_YES == finger->is_present); 3034 GNUNET_assert (GNUNET_YES == finger->is_present);
3035
2992 /* If I am my own finger, then we have no trails. */ 3036 /* If I am my own finger, then we have no trails. */
2993 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, 3037 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity,
2994 &my_identity)) 3038 &my_identity))
@@ -3014,6 +3058,80 @@ remove_existing_finger (struct FingerInfo *finger)
3014 return; 3058 return;
3015} 3059}
3016 3060
3061#if 0
3062/**
3063 * This is a test function to print all the entries of friend table.
3064 */
3065static void
3066test_friend_peermap_print ()
3067{
3068 struct FriendInfo *friend;
3069 struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter;
3070 struct GNUNET_PeerIdentity print_peer;
3071 struct GNUNET_PeerIdentity key_ret;
3072 int i;
3073
3074 FPRINTF (stderr,_("\nSUPU FRIEND TABLE ********"));
3075
3076
3077 friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
3078
3079 for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++)
3080 {
3081 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (friend_iter,
3082 &key_ret,
3083 (const void **)&friend))
3084 {
3085 memcpy (&print_peer, &key_ret, sizeof (struct GNUNET_PeerIdentity));
3086 FPRINTF (stderr,_("\nSUPU %s, %s, %d, friend = %s, friend->trails_count = %d"),
3087 __FILE__, __func__,__LINE__, GNUNET_i2s(&print_peer), friend->trails_count);
3088 }
3089 }
3090}
3091
3092
3093/**
3094 * This is a test function, to print all the entries of finger table.
3095 */
3096static void
3097test_finger_table_print()
3098{
3099 struct FingerInfo *finger;
3100 struct GNUNET_PeerIdentity print_peer;
3101 struct Trail *trail;
3102 int i;
3103 int j;
3104 int k;
3105
3106 FPRINTF (stderr,_("\nSUPU************ FINGER_TABLE"));
3107 for (i = 0; i < MAX_FINGERS; i++)
3108 {
3109 finger = &finger_table[i];
3110
3111 if (GNUNET_NO == finger->is_present)
3112 continue;
3113
3114 print_peer = finger->finger_identity;
3115 FPRINTF (stderr,_("\nSUPU %s, %s, %d, finger_table[%d] = %s, trails_count = %d"),
3116 __FILE__, __func__,__LINE__,i,GNUNET_i2s (&print_peer), finger->trails_count);
3117
3118
3119 for (j = 0; j < finger->trails_count; j++)
3120 {
3121 trail = &finger->trail_list[j];
3122 FPRINTF (stderr,_("\nSUPU %s, %s, %d, trail_id[%d]=%s"),__FILE__, __func__,__LINE__,j, GNUNET_h2s(&trail->trail_id));
3123 struct Trail_Element *element;
3124 element = trail->trail_head;
3125 for (k = 0; k < trail->trail_length; k++)
3126 {
3127 print_peer = element->peer;
3128 FPRINTF (stderr,_("\nSUPU %s, %s, %d,trail[%d] = %s "),__FILE__, __func__,__LINE__,k, GNUNET_i2s(&print_peer));
3129 element = element->next;
3130 }
3131 }
3132 }
3133}
3134#endif
3017 3135
3018/** 3136/**
3019 * -- Check if there is already an entry in finger_table at finger_table_index. 3137 * -- Check if there is already an entry in finger_table at finger_table_index.
@@ -3051,9 +3169,14 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3051 int updated_finger_trail_length; 3169 int updated_finger_trail_length;
3052 unsigned int finger_table_index; 3170 unsigned int finger_table_index;
3053 3171
3172#if 0
3173 test_friend_peermap_print();
3174 test_finger_table_print();
3175#endif
3176
3054 /* Get the finger_table_index corresponding to finger_value we got from network.*/ 3177 /* Get the finger_table_index corresponding to finger_value we got from network.*/
3055 finger_table_index = get_finger_table_index (finger_value, is_predecessor); 3178 finger_table_index = get_finger_table_index (finger_value, is_predecessor);
3056 3179
3057 /* Invalid finger_table_index. */ 3180 /* Invalid finger_table_index. */
3058 if ((finger_table_index > PREDECESSOR_FINGER_ID) || (finger_table_index < 0)) 3181 if ((finger_table_index > PREDECESSOR_FINGER_ID) || (finger_table_index < 0))
3059 { 3182 {
@@ -3066,7 +3189,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3066 scan_and_compress_trail (finger_identity, finger_trail, 3189 scan_and_compress_trail (finger_identity, finger_trail,
3067 finger_trail_length, finger_trail_id, 3190 finger_trail_length, finger_trail_id,
3068 &updated_finger_trail_length); 3191 &updated_finger_trail_length);
3069 3192
3070 /* If the new entry is same as successor then don't add it in finger table, 3193 /* If the new entry is same as successor then don't add it in finger table,
3071 reset the current search finger index and exit. */ 3194 reset the current search finger index and exit. */
3072 if ((0 != finger_table_index) && (PREDECESSOR_FINGER_ID != finger_table_index)) 3195 if ((0 != finger_table_index) && (PREDECESSOR_FINGER_ID != finger_table_index))
@@ -3082,12 +3205,13 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3082 } 3205 }
3083 3206
3084 existing_finger = &finger_table[finger_table_index]; 3207 existing_finger = &finger_table[finger_table_index];
3208
3085 /* No entry present in finger_table for given finger map index. */ 3209 /* No entry present in finger_table for given finger map index. */
3086 if (GNUNET_NO == existing_finger->is_present) 3210 if (GNUNET_NO == existing_finger->is_present)
3087 { 3211 {
3088 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, 3212 add_new_finger (finger_identity, updated_trail, updated_finger_trail_length,
3089 finger_trail_id, finger_table_index); 3213 finger_trail_id, finger_table_index);
3090 update_current_search_finger_index (finger_identity); 3214 update_current_search_finger_index (finger_identity, finger_table_index);
3091 return; 3215 return;
3092 } 3216 }
3093 3217
@@ -3128,7 +3252,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3128 finger_trail_length, finger_trail_id); 3252 finger_trail_length, finger_trail_id);
3129 } 3253 }
3130 } 3254 }
3131 update_current_search_finger_index (finger_identity); 3255 update_current_search_finger_index (finger_identity, finger_table_index);
3132 return; 3256 return;
3133} 3257}
3134 3258
@@ -3618,6 +3742,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3618 } 3742 }
3619 3743
3620 local_best_known_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 3744 local_best_known_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
3745
3621 /* Get the next hop to forward the trail setup request. */ 3746 /* Get the next hop to forward the trail setup request. */
3622 next_hop_towards_local_best_known_dest = 3747 next_hop_towards_local_best_known_dest =
3623 get_local_best_known_next_hop (final_dest_finger_val, 3748 get_local_best_known_next_hop (final_dest_finger_val,
@@ -3737,6 +3862,8 @@ is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list,
3737 3862
3738 3863
3739/** 3864/**
3865 * FIXME: we should also add a case where we search if we are present in the trail
3866 * twice.
3740 * FIXME: we have a new field is next_hop desintation or prev_hop source. 3867 * FIXME: we have a new field is next_hop desintation or prev_hop source.
3741 * think how to add it. I am not adding any entry in destination or source 3868 * think how to add it. I am not adding any entry in destination or source
3742 * peer routing table as in case of handle core disconnect when we remove 3869 * peer routing table as in case of handle core disconnect when we remove
@@ -3938,6 +4065,10 @@ trail_source_to_my_predecessor (const struct GNUNET_PeerIdentity *current_trail,
3938 4065
3939 4066
3940/** 4067/**
4068 * FIXME In case predecessor is a friend then do we add it in routing table.
4069 * if not then check the logic of trail teardown in case we compress the trail
4070 * such that friend is finger. then do we remove the entry from end points or
4071 * not. Ideally we should remove the entries from end point.
3941 * Add finger as your predecessor. To add, first generate a new trail id, invert 4072 * Add finger as your predecessor. To add, first generate a new trail id, invert
3942 * the trail to get the trail from me to finger, add an entry in your routing 4073 * the trail to get the trail from me to finger, add an entry in your routing
3943 * table, send add trail message to peers which are part of trail from me to 4074 * table, send add trail message to peers which are part of trail from me to
@@ -3947,11 +4078,11 @@ trail_source_to_my_predecessor (const struct GNUNET_PeerIdentity *current_trail,
3947 * @param trail_length 4078 * @param trail_length
3948 */ 4079 */
3949static void 4080static void
3950update_predecessor (struct GNUNET_PeerIdentity *finger, 4081update_predecessor (struct GNUNET_PeerIdentity finger,
3951 struct GNUNET_PeerIdentity *trail, 4082 struct GNUNET_PeerIdentity *trail,
3952 unsigned int trail_length) 4083 unsigned int trail_length)
3953{ 4084{
3954 struct GNUNET_HashCode *trail_to_new_predecessor_id; 4085 struct GNUNET_HashCode trail_to_new_predecessor_id;
3955 struct GNUNET_PeerIdentity *trail_to_new_predecessor; 4086 struct GNUNET_PeerIdentity *trail_to_new_predecessor;
3956 struct FriendInfo *target_friend; 4087 struct FriendInfo *target_friend;
3957 4088
@@ -3961,11 +4092,14 @@ update_predecessor (struct GNUNET_PeerIdentity *finger,
3961 sizeof (trail_to_new_predecessor_id)); 4092 sizeof (trail_to_new_predecessor_id));
3962 4093
3963 /* Invert the trail from finger to me to get the trail from me to finger. */ 4094 /* Invert the trail from finger to me to get the trail from me to finger. */
3964 trail_to_new_predecessor = invert_trail (trail, trail_length); 4095 if (trail_length == 0)
4096 trail_to_new_predecessor = NULL;
4097
3965 if (trail_length > 0) 4098 if (trail_length > 0)
3966 { 4099 {
4100 trail_to_new_predecessor = invert_trail (trail, trail_length);
3967 /* Add an entry in your routing table. */ 4101 /* Add an entry in your routing table. */
3968 GDS_ROUTING_add (*trail_to_new_predecessor_id, 4102 GDS_ROUTING_add (trail_to_new_predecessor_id,
3969 trail_to_new_predecessor[trail_length - 1], 4103 trail_to_new_predecessor[trail_length - 1],
3970 my_identity); 4104 my_identity);
3971 4105
@@ -3973,17 +4107,22 @@ update_predecessor (struct GNUNET_PeerIdentity *finger,
3973 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 4107 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
3974 &trail_to_new_predecessor[trail_length - 1]); 4108 &trail_to_new_predecessor[trail_length - 1]);
3975 4109
4110 // Before sending the trail may be you need to compress it. And in case
4111 // it was a friend how did we got the trail. ??
4112
3976 /* Add entry in routing table of all peers that are part of trail from me 4113 /* Add entry in routing table of all peers that are part of trail from me
3977 to finger. */ 4114 to finger. */
4115
3978 GDS_NEIGHBOURS_send_add_trail (my_identity, 4116 GDS_NEIGHBOURS_send_add_trail (my_identity,
3979 *finger, 4117 finger,
3980 *trail_to_new_predecessor_id, 4118 trail_to_new_predecessor_id,
3981 trail_to_new_predecessor, 4119 trail_to_new_predecessor,
3982 trail_length, 4120 trail_length,
3983 target_friend); 4121 target_friend);
3984 } 4122 }
3985 add_new_finger (*finger, trail_to_new_predecessor, trail_length, 4123
3986 *trail_to_new_predecessor_id, PREDECESSOR_FINGER_ID); 4124 add_new_finger (finger, trail_to_new_predecessor, trail_length,
4125 trail_to_new_predecessor_id, PREDECESSOR_FINGER_ID);
3987} 4126}
3988 4127
3989 4128
@@ -4024,7 +4163,7 @@ update_predecessor (struct GNUNET_PeerIdentity *finger,
4024 * @return 4163 * @return
4025 */ 4164 */
4026static void 4165static void
4027compare_and_update_predecessor (struct GNUNET_PeerIdentity *finger, 4166compare_and_update_predecessor (struct GNUNET_PeerIdentity finger,
4028 struct GNUNET_PeerIdentity *trail, 4167 struct GNUNET_PeerIdentity *trail,
4029 unsigned int trail_length) 4168 unsigned int trail_length)
4030{ 4169{
@@ -4033,22 +4172,22 @@ compare_and_update_predecessor (struct GNUNET_PeerIdentity *finger,
4033 uint64_t predecessor_value; 4172 uint64_t predecessor_value;
4034 4173
4035 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; 4174 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID];
4036 4175
4037 /* No predecessor. Add finger as your predecessor. */ 4176 /* No predecessor. Add finger as your predecessor. */
4038 if (NULL == current_predecessor) /*FIXME: is it correct value to check if there is no predecessor. */ 4177 if (GNUNET_NO == current_predecessor->is_present)
4039 { 4178 {
4040 update_predecessor (finger, trail, trail_length); 4179 update_predecessor (finger, trail, trail_length);
4041 return; 4180 return;
4042 } 4181 }
4043 4182
4044 predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID); 4183 predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID);
4045 closest_peer = select_closest_peer (finger, 4184 closest_peer = select_closest_peer (&finger,
4046 &current_predecessor->finger_identity, 4185 &current_predecessor->finger_identity,
4047 predecessor_value, PREDECESSOR_FINGER_ID); 4186 predecessor_value, PREDECESSOR_FINGER_ID);
4048 4187
4049 /* Finger is the closest predecessor. Remove the existing one and add the new 4188 /* Finger is the closest predecessor. Remove the existing one and add the new
4050 one. */ 4189 one. */
4051 if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, finger)) 4190 if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, &finger))
4052 { 4191 {
4053 remove_existing_finger (current_predecessor); 4192 remove_existing_finger (current_predecessor);
4054 update_predecessor (finger, trail, trail_length); 4193 update_predecessor (finger, trail, trail_length);
@@ -4089,7 +4228,7 @@ handle_dht_p2p_verify_successor(void *cls,
4089 * predecessor. 4228 * predecessor.
4090 */ 4229 */
4091 const struct PeerVerifySuccessorMessage *vsm; 4230 const struct PeerVerifySuccessorMessage *vsm;
4092 struct GNUNET_HashCode trail_id; 4231 struct GNUNET_HashCode *trail_id;
4093 struct GNUNET_PeerIdentity successor; 4232 struct GNUNET_PeerIdentity successor;
4094 struct GNUNET_PeerIdentity source_peer; 4233 struct GNUNET_PeerIdentity source_peer;
4095 struct GNUNET_PeerIdentity *trail; 4234 struct GNUNET_PeerIdentity *trail;
@@ -4119,21 +4258,24 @@ handle_dht_p2p_verify_successor(void *cls,
4119 } 4258 }
4120 4259
4121 trail = (struct GNUNET_PeerIdentity *)&vsm[1]; 4260 trail = (struct GNUNET_PeerIdentity *)&vsm[1];
4261
4122 source_peer = vsm->source_peer; 4262 source_peer = vsm->source_peer;
4123 successor = vsm->successor; 4263 successor = vsm->successor;
4124 trail_id = vsm->trail_id; 4264 trail_id = GNUNET_new (struct GNUNET_HashCode);
4265 *trail_id = vsm->trail_id;
4125 4266
4126 /* I am not the successor of source_peer. Pass the message to next_hop on 4267 /* I am not the successor of source_peer. Pass the message to next_hop on
4127 * the trail. */ 4268 * the trail. */
4128 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) 4269 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity)))
4129 { 4270 {
4130 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); 4271 next_hop = GDS_ROUTING_get_next_hop (*trail_id, GDS_ROUTING_SRC_TO_DEST);
4131 if (NULL == next_hop) 4272 if (NULL == next_hop)
4132 { 4273 {
4133 GNUNET_break (0); 4274 GNUNET_break (0);
4134 return GNUNET_SYSERR; 4275 return GNUNET_SYSERR;
4135 } 4276 }
4136 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 4277 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
4278
4137 GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor, 4279 GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor,
4138 trail_id, trail, trail_length, 4280 trail_id, trail, trail_length,
4139 target_friend); 4281 target_friend);
@@ -4142,7 +4284,7 @@ handle_dht_p2p_verify_successor(void *cls,
4142 4284
4143 /* I am the successor of this message. */ 4285 /* I am the successor of this message. */
4144 4286
4145 compare_and_update_predecessor (&source_peer, trail, trail_length); 4287 compare_and_update_predecessor (source_peer, trail, trail_length);
4146 4288
4147 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; 4289 current_predecessor = &finger_table[PREDECESSOR_FINGER_ID];
4148 /* Is source of this message my predecessor. */ 4290 /* Is source of this message my predecessor. */
@@ -4164,7 +4306,7 @@ handle_dht_p2p_verify_successor(void *cls,
4164 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 4306 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
4165 GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, 4307 GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity,
4166 current_predecessor->finger_identity, 4308 current_predecessor->finger_identity,
4167 trail_id, new_trail, 4309 *trail_id, new_trail,
4168 new_trail_length, 4310 new_trail_length,
4169 GDS_ROUTING_DEST_TO_SRC, 4311 GDS_ROUTING_DEST_TO_SRC,
4170 target_friend); 4312 target_friend);
@@ -4205,16 +4347,17 @@ handle_dht_p2p_verify_successor_result(void *cls,
4205 size_t msize; 4347 size_t msize;
4206 4348
4207 msize = ntohs (message->size); 4349 msize = ntohs (message->size);
4208 if (msize != sizeof (struct PeerVerifySuccessorResultMessage)) 4350 if (msize < sizeof (struct PeerVerifySuccessorResultMessage))
4209 { 4351 {
4210 GNUNET_break_op (0); 4352 GNUNET_break_op (0);
4211 return GNUNET_YES; 4353 return GNUNET_YES;
4212 } 4354 }
4213 4355
4214 vsrm = (struct PeerVerifySuccessorResultMessage *) message; 4356 vsrm = (struct PeerVerifySuccessorResultMessage *) message;
4215 trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ 4357 trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/
4216 sizeof (struct GNUNET_PeerIdentity); 4358 sizeof (struct GNUNET_PeerIdentity);
4217 if ((msize - sizeof (struct PeerTrailSetupMessage)) % 4359
4360 if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) %
4218 sizeof (struct GNUNET_PeerIdentity) != 0) 4361 sizeof (struct GNUNET_PeerIdentity) != 0)
4219 { 4362 {
4220 GNUNET_break_op (0); 4363 GNUNET_break_op (0);
@@ -4233,6 +4376,43 @@ handle_dht_p2p_verify_successor_result(void *cls,
4233 //Fixme: you check if successor is same of different. if differentthen 4376 //Fixme: you check if successor is same of different. if differentthen
4234 // send notify new successor. in that function we will add in trail. scan 4377 // send notify new successor. in that function we will add in trail. scan
4235 // and compress the trail too. 4378 // and compress the trail too.
4379 struct FingerInfo *current_successor;
4380
4381 current_successor = &finger_table[0];
4382
4383 GNUNET_assert (GNUNET_YES == (current_successor->is_present));
4384
4385 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&current_successor->finger_identity,
4386 &current_predecessor))
4387 return GNUNET_OK;
4388
4389 struct GNUNET_PeerIdentity *closest_peer;
4390 struct GNUNET_HashCode new_trail_id;
4391
4392 uint64_t value = compute_finger_identity_value (0);
4393 closest_peer = select_closest_peer (&current_successor->finger_identity,
4394 &current_predecessor,
4395 value,
4396 0);
4397
4398 if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer,
4399 &current_successor->finger_identity))
4400 return GNUNET_OK;
4401
4402 remove_existing_finger (current_successor);
4403 //FIXME: shortcut the trail if possible but in this case we don't send a
4404 // trail compression message as we have no entry in any routing table.
4405
4406 //FIXME: we don't send add trail message but in notify new successor
4407 // we add in our routing table.
4408 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
4409 &new_trail_id, sizeof (new_trail_id));
4410 GDS_ROUTING_add (new_trail_id, my_identity, *peer);
4411 add_new_finger (current_predecessor, trail, trail_length, new_trail_id, 0);
4412 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
4413 GDS_NEIGHBOURS_send_notify_new_successor (my_identity, current_predecessor,
4414 trail, trail_length, trail_id,
4415 target_friend);
4236 } 4416 }
4237 4417
4238 /*If you are not the querying peer then pass on the message */ 4418 /*If you are not the querying peer then pass on the message */
@@ -4250,6 +4430,7 @@ handle_dht_p2p_verify_successor_result(void *cls,
4250 4430
4251 4431
4252/* 4432/*
4433 * FIXME: You should add an entry in routing table.
4253 * Core handle for p2p notify new successor messages. 4434 * Core handle for p2p notify new successor messages.
4254 * @param cls closure 4435 * @param cls closure
4255 * @param message message 4436 * @param message message
@@ -4273,7 +4454,7 @@ handle_dht_p2p_notify_new_successor(void *cls,
4273 uint32_t trail_length; 4454 uint32_t trail_length;
4274 4455
4275 msize = ntohs (message->size); 4456 msize = ntohs (message->size);
4276 if (msize != sizeof (struct PeerNotifyNewSuccessorMessage)) 4457 if (msize < sizeof (struct PeerNotifyNewSuccessorMessage))
4277 { 4458 {
4278 GNUNET_break_op (0); 4459 GNUNET_break_op (0);
4279 return GNUNET_YES; 4460 return GNUNET_YES;
@@ -4301,7 +4482,7 @@ handle_dht_p2p_notify_new_successor(void *cls,
4301 { 4482 {
4302 /* Add an entry in routing table. */ 4483 /* Add an entry in routing table. */
4303 GDS_ROUTING_add (trail_id, *peer, my_identity); 4484 GDS_ROUTING_add (trail_id, *peer, my_identity);
4304 compare_and_update_predecessor (&source, trail, trail_length); 4485 compare_and_update_predecessor (source, trail, trail_length);
4305 return GNUNET_OK; 4486 return GNUNET_OK;
4306 } 4487 }
4307 4488
@@ -4356,7 +4537,7 @@ handle_dht_p2p_trail_rejection(void *cls, const struct GNUNET_PeerIdentity *peer
4356 size_t msize; 4537 size_t msize;
4357 4538
4358 msize = ntohs (message->size); 4539 msize = ntohs (message->size);
4359 if (msize != sizeof (struct PeerTrailRejectionMessage)) 4540 if (msize < sizeof (struct PeerTrailRejectionMessage))
4360 { 4541 {
4361 GNUNET_break_op (0); 4542 GNUNET_break_op (0);
4362 return GNUNET_YES; 4543 return GNUNET_YES;
@@ -4561,11 +4742,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
4561 4742
4562 4743
4563/** 4744/**
4564 * Fixme: this function is called only in case in notify new successor, the new 4745 * Core handle for p2p add trail message.
4565 * successor wants to add the source of the peer as its predecessor. Identify
4566 * if there is any other use case where it is required and if yes then adapt the
4567 * code for it.
4568 * Core handle for p2p add trail message.
4569 * @param cls closure 4746 * @param cls closure
4570 * @param message message 4747 * @param message message
4571 * @param peer peer identity this notification is about 4748 * @param peer peer identity this notification is about
@@ -4575,8 +4752,8 @@ static int
4575handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, 4752handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4576 const struct GNUNET_MessageHeader *message) 4753 const struct GNUNET_MessageHeader *message)
4577{ 4754{
4578 struct PeerAddTrailMessage *add_trail; 4755 const struct PeerAddTrailMessage *add_trail;
4579 struct GNUNET_PeerIdentity *trail; 4756 const struct GNUNET_PeerIdentity *trail;
4580 struct GNUNET_HashCode trail_id; 4757 struct GNUNET_HashCode trail_id;
4581 struct GNUNET_PeerIdentity destination_peer; 4758 struct GNUNET_PeerIdentity destination_peer;
4582 struct GNUNET_PeerIdentity source_peer; 4759 struct GNUNET_PeerIdentity source_peer;
@@ -4586,13 +4763,14 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4586 size_t msize; 4763 size_t msize;
4587 4764
4588 msize = ntohs (message->size); 4765 msize = ntohs (message->size);
4589 if (msize != sizeof (struct PeerAddTrailMessage)) 4766 if (msize < sizeof (struct PeerAddTrailMessage))
4590 { 4767 {
4591 GNUNET_break_op (0); 4768 GNUNET_break_op (0);
4592 return GNUNET_OK; 4769 return GNUNET_OK;
4593 } 4770 }
4594 4771
4595 add_trail = (struct PeerAddTrailMessage *) message; 4772 add_trail = (const struct PeerAddTrailMessage *) message;
4773
4596 trail_length = (msize - sizeof (struct PeerAddTrailMessage))/ 4774 trail_length = (msize - sizeof (struct PeerAddTrailMessage))/
4597 sizeof (struct GNUNET_PeerIdentity); 4775 sizeof (struct GNUNET_PeerIdentity);
4598 if ((msize - sizeof (struct PeerAddTrailMessage)) % 4776 if ((msize - sizeof (struct PeerAddTrailMessage)) %
@@ -4602,25 +4780,17 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4602 return GNUNET_OK; 4780 return GNUNET_OK;
4603 } 4781 }
4604 4782
4605 if ((msize < sizeof (struct PeerAddTrailMessage) + 4783 trail = (const struct GNUNET_PeerIdentity *)&add_trail[1];
4606 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
4607 (trail_length >
4608 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
4609 {
4610 GNUNET_break_op (0);
4611 return GNUNET_OK;
4612 }
4613
4614 trail = (struct GNUNET_PeerIdentity *)&add_trail[1];
4615 destination_peer = add_trail->destination_peer; 4784 destination_peer = add_trail->destination_peer;
4616 source_peer = add_trail->source_peer; 4785 source_peer = add_trail->source_peer;
4617 trail_id = add_trail->trail_id; 4786 trail_id = add_trail->trail_id;
4618 4787
4619 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 4788 /* If I am not the destination of the trail. */
4620 &destination_peer)) 4789 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer))
4621 { 4790 {
4622 struct FriendInfo *target_friend; 4791 struct FriendInfo *target_friend;
4623 4792
4793 /* Get your location in the trail. */
4624 my_index = search_my_index (trail, trail_length); 4794 my_index = search_my_index (trail, trail_length);
4625 if (GNUNET_SYSERR == my_index) 4795 if (GNUNET_SYSERR == my_index)
4626 { 4796 {
@@ -4632,12 +4802,17 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
4632 next_hop = source_peer; 4802 next_hop = source_peer;
4633 else 4803 else
4634 next_hop = trail[trail_length - 1]; 4804 next_hop = trail[trail_length - 1];
4635 4805
4806 /* Add in your routing table. */
4636 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); 4807 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer));
4637 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 4808 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
4638 GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id, 4809 GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id,
4639 trail, trail_length, target_friend); 4810 trail, trail_length, target_friend);
4811 return GNUNET_OK;
4640 } 4812 }
4813
4814 /* I am the destination. Add an entry in routing table. */
4815 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, my_identity));
4641 return GNUNET_OK; 4816 return GNUNET_OK;
4642} 4817}
4643 4818
@@ -4718,6 +4893,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer)
4718 { 4893 {
4719 finger_table[i].is_present = GNUNET_NO; 4894 finger_table[i].is_present = GNUNET_NO;
4720 memset ((void *)&finger_table[i], 0, sizeof (struct FingerInfo)); 4895 memset ((void *)&finger_table[i], 0, sizeof (struct FingerInfo));
4896
4721 /* No trail to reach this finger, don't send trail_teardown message. */ 4897 /* No trail to reach this finger, don't send trail_teardown message. */
4722 GNUNET_free (remove_finger); 4898 GNUNET_free (remove_finger);
4723 continue; 4899 continue;
@@ -4798,7 +4974,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
4798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity)); 4974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity));
4799 4975
4800 /* If peer already exists in our friend_peermap, then exit. */ 4976 /* If peer already exists in our friend_peermap, then exit. */
4801 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, peer_identity)) 4977 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap,
4978 peer_identity))
4802 { 4979 {
4803 GNUNET_break (0); 4980 GNUNET_break (0);
4804 return; 4981 return;
@@ -4833,11 +5010,16 @@ core_init (void *cls,
4833 const struct GNUNET_PeerIdentity *identity) 5010 const struct GNUNET_PeerIdentity *identity)
4834{ 5011{
4835 my_identity = *identity; 5012 my_identity = *identity;
5013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5014 "my_indentity = %s\n",GNUNET_i2s(&my_identity));
5015 FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"),
5016 __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity));
5017
4836} 5018}
4837 5019
4838 5020
4839/** 5021/**
4840 * Initialize finger table. 5022 * Initialize finger table entries.
4841 */ 5023 */
4842static void 5024static void
4843finger_table_init () 5025finger_table_init ()
@@ -4865,7 +5047,8 @@ GDS_NEIGHBOURS_init (void)
4865 {&handle_dht_p2p_get_result, GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT, 0}, 5047 {&handle_dht_p2p_get_result, GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT, 0},
4866 {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, 5048 {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0},
4867 {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, 5049 {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0},
4868 {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR, 0}, 5050 {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR,
5051 sizeof (struct PeerVerifySuccessorMessage)},
4869 {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, 5052 {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT, 0},
4870 {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, 5053 {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR, 0},
4871 {&handle_dht_p2p_trail_rejection, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_REJECTION, 0}, 5054 {&handle_dht_p2p_trail_rejection, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_REJECTION, 0},
@@ -4907,14 +5090,12 @@ GDS_NEIGHBOURS_done (void)
4907 GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); 5090 GNUNET_CONTAINER_multipeermap_destroy (friend_peermap);
4908 friend_peermap = NULL; 5091 friend_peermap = NULL;
4909 5092
4910#if 0
4911 if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) 5093 if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task)
4912 { 5094 {
4913 GNUNET_break (0); 5095 GNUNET_break (0);
4914 GNUNET_SCHEDULER_cancel (find_finger_trail_task); 5096 GNUNET_SCHEDULER_cancel (find_finger_trail_task);
4915 find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; 5097 find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK;
4916 } 5098 }
4917#endif
4918} 5099}
4919 5100
4920 5101